home_feed_spec.rb 1.2 KB

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