You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1 KiB

  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 'returns nothing' do
  30. results = subject.get(3)
  31. expect(results.map(&:id)).to eq []
  32. end
  33. end
  34. end
  35. end