home_feed_spec.rb 1021 B

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