mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: s/\$redis/Discourse\.redis (#8431)
This commit also adds a rubocop rule to prevent global variables.
This commit is contained in:
@@ -84,36 +84,36 @@ describe GroupMessage do
|
||||
|
||||
describe 'sent_recently?' do
|
||||
it 'returns true if redis says so' do
|
||||
$redis.stubs(:get).with(group_message.sent_recently_key).returns('1')
|
||||
Discourse.redis.stubs(:get).with(group_message.sent_recently_key).returns('1')
|
||||
expect(group_message.sent_recently?).to be_truthy
|
||||
end
|
||||
|
||||
it 'returns false if redis returns nil' do
|
||||
$redis.stubs(:get).with(group_message.sent_recently_key).returns(nil)
|
||||
Discourse.redis.stubs(:get).with(group_message.sent_recently_key).returns(nil)
|
||||
expect(group_message.sent_recently?).to be_falsey
|
||||
end
|
||||
|
||||
it 'always returns false if limit_once_per is false' do
|
||||
gm = GroupMessage.new(moderators_group, :user_automatically_silenced, user: user, limit_once_per: false)
|
||||
gm.stubs(:sent_recently_key).returns('the_key')
|
||||
$redis.stubs(:get).with(gm.sent_recently_key).returns('1')
|
||||
Discourse.redis.stubs(:get).with(gm.sent_recently_key).returns('1')
|
||||
expect(gm.sent_recently?).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
describe 'remember_message_sent' do
|
||||
it 'stores a key in redis that expires after 24 hours' do
|
||||
$redis.expects(:setex).with(group_message.sent_recently_key, 24 * 60 * 60, anything).returns('OK')
|
||||
Discourse.redis.expects(:setex).with(group_message.sent_recently_key, 24 * 60 * 60, anything).returns('OK')
|
||||
group_message.remember_message_sent
|
||||
end
|
||||
|
||||
it 'can use a given expiry time' do
|
||||
$redis.expects(:setex).with(anything, 30 * 60, anything).returns('OK')
|
||||
Discourse.redis.expects(:setex).with(anything, 30 * 60, anything).returns('OK')
|
||||
GroupMessage.new(moderators_group, :user_automatically_silenced, user: user, limit_once_per: 30.minutes).remember_message_sent
|
||||
end
|
||||
|
||||
it 'can be disabled' do
|
||||
$redis.expects(:setex).never
|
||||
Discourse.redis.expects(:setex).never
|
||||
GroupMessage.new(moderators_group, :user_automatically_silenced, user: user, limit_once_per: false).remember_message_sent
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,18 +7,18 @@ describe RandomTopicSelector do
|
||||
it 'can correctly use cache' do
|
||||
key = RandomTopicSelector.cache_key
|
||||
|
||||
$redis.del key
|
||||
Discourse.redis.del key
|
||||
|
||||
4.times do |t|
|
||||
$redis.rpush key, t
|
||||
Discourse.redis.rpush key, t
|
||||
end
|
||||
|
||||
expect(RandomTopicSelector.next(0)).to eq([])
|
||||
expect(RandomTopicSelector.next(2)).to eq([0, 1])
|
||||
|
||||
$redis.expects(:multi).returns(Discourse.received_redis_readonly!)
|
||||
Discourse.redis.expects(:multi).returns(Discourse.received_redis_readonly!)
|
||||
expect(RandomTopicSelector.next(2)).to eq([2, 3])
|
||||
$redis.unstub(:multi)
|
||||
Discourse.redis.unstub(:multi)
|
||||
|
||||
expect(RandomTopicSelector.next(2)).to eq([2, 3])
|
||||
expect(RandomTopicSelector.next(2)).to eq([])
|
||||
|
||||
@@ -64,13 +64,13 @@ describe TopicTimestampChanger do
|
||||
end
|
||||
|
||||
it 'deletes the stats cache' do
|
||||
$redis.set AdminDashboardData.stats_cache_key, "X"
|
||||
$redis.set About.stats_cache_key, "X"
|
||||
Discourse.redis.set AdminDashboardData.stats_cache_key, "X"
|
||||
Discourse.redis.set About.stats_cache_key, "X"
|
||||
|
||||
TopicTimestampChanger.new(topic: topic, timestamp: Time.zone.now.to_f).change!
|
||||
|
||||
expect($redis.get(AdminDashboardData.stats_cache_key)).to eq(nil)
|
||||
expect($redis.get(About.stats_cache_key)).to eq(nil)
|
||||
expect(Discourse.redis.get(AdminDashboardData.stats_cache_key)).to eq(nil)
|
||||
expect(Discourse.redis.get(About.stats_cache_key)).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ describe WordWatcher do
|
||||
let(:raw) { "Do you like liquorice?\n\nI really like them. One could even say that I am *addicted* to liquorice. Anf if\nyou can mix it up with some anise, then I'm in heaven ;)" }
|
||||
|
||||
after do
|
||||
$redis.flushall
|
||||
Discourse.redis.flushall
|
||||
end
|
||||
|
||||
describe '.word_matcher_regexp' do
|
||||
|
||||
Reference in New Issue
Block a user