home_feed_spec.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. expect(results.first.attributes.keys).to eq %w(id updated_at)
  24. end
  25. end
  26. context 'when feed is being generated' do
  27. before do
  28. redis.set("account:#{account.id}:regeneration", true)
  29. end
  30. it 'returns nothing' do
  31. results = subject.get(3)
  32. expect(results.map(&:id)).to eq []
  33. end
  34. end
  35. end
  36. end