mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 05:23:43 +08:00
493d437e79
* Remove outdated option
04078317ba
* Use the non-globally exposed RSpec syntax
https://github.com/rspec/rspec-core/pull/2803
* Use the non-globally exposed RSpec syntax, cont
https://github.com/rspec/rspec-core/pull/2803
* Comply to strict predicate matchers
See:
- https://github.com/rspec/rspec-expectations/pull/1195
- https://github.com/rspec/rspec-expectations/pull/1196
- https://github.com/rspec/rspec-expectations/pull/1277
35 lines
1.0 KiB
Ruby
35 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe RandomTopicSelector do
|
|
|
|
it 'can correctly use cache' do
|
|
key = RandomTopicSelector.cache_key
|
|
|
|
Discourse.redis.del key
|
|
|
|
4.times do |t|
|
|
Discourse.redis.rpush key, t
|
|
end
|
|
|
|
expect(RandomTopicSelector.next(0)).to eq([])
|
|
expect(RandomTopicSelector.next(2)).to eq([0, 1])
|
|
|
|
Discourse.redis.expects(:multi).returns(Discourse.received_redis_readonly!)
|
|
expect(RandomTopicSelector.next(2)).to eq([2, 3])
|
|
Discourse.redis.unstub(:multi)
|
|
|
|
expect(RandomTopicSelector.next(2)).to eq([2, 3])
|
|
expect(RandomTopicSelector.next(2)).to eq([])
|
|
end
|
|
|
|
it 'can correctly backfill' do
|
|
category = Fabricate(:category, sort_order: 'op_likes')
|
|
t1 = Fabricate(:topic, category_id: category.id)
|
|
_t2 = Fabricate(:topic, category_id: category.id, visible: false)
|
|
_t3 = Fabricate(:topic, category_id: category.id, deleted_at: 1.minute.ago)
|
|
t4 = Fabricate(:topic, category_id: category.id)
|
|
|
|
expect(RandomTopicSelector.next(5, category).sort).to eq([t1.id, t4.id].sort)
|
|
end
|
|
end
|