home_feed_spec.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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.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.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