1
0

home_feed_spec.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe HomeFeed do
  4. subject { described_class.new(account) }
  5. let(:account) { Fabricate(:account) }
  6. describe '#get' do
  7. before do
  8. Fabricate(:status, account: account, id: 1)
  9. Fabricate(:status, account: account, id: 2)
  10. Fabricate(:status, account: account, id: 3)
  11. Fabricate(:status, account: account, id: 10)
  12. end
  13. context 'when feed is generated' do
  14. before do
  15. redis.zadd(
  16. FeedManager.instance.key(:home, account.id),
  17. [[4, 4], [3, 3], [2, 2], [1, 1]]
  18. )
  19. end
  20. it 'gets statuses with ids in the range from redis' do
  21. results = subject.get(3)
  22. expect(results.map(&:id)).to eq [3, 2]
  23. end
  24. end
  25. context 'when feed is being generated' do
  26. before do
  27. redis.set("account:#{account.id}:regeneration", true)
  28. end
  29. it 'returns nothing' do
  30. results = subject.get(3)
  31. expect(results.map(&:id)).to eq []
  32. end
  33. end
  34. end
  35. end