feed_insert_worker_spec.rb 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe FeedInsertWorker do
  4. subject { described_class.new }
  5. describe 'perform' do
  6. let(:follower) { Fabricate(:account) }
  7. let(:status) { Fabricate(:status) }
  8. let(:list) { Fabricate(:list) }
  9. context 'when there are no records' do
  10. it 'skips push with missing status' do
  11. instance = instance_double(FeedManager, push_to_home: nil)
  12. allow(FeedManager).to receive(:instance).and_return(instance)
  13. result = subject.perform(nil, follower.id)
  14. expect(result).to be true
  15. expect(instance).to_not have_received(:push_to_home)
  16. end
  17. it 'skips push with missing account' do
  18. instance = instance_double(FeedManager, push_to_home: nil)
  19. allow(FeedManager).to receive(:instance).and_return(instance)
  20. result = subject.perform(status.id, nil)
  21. expect(result).to be true
  22. expect(instance).to_not have_received(:push_to_home)
  23. end
  24. end
  25. context 'when there are real records' do
  26. it 'skips the push when there is a filter' do
  27. instance = instance_double(FeedManager, push_to_home: nil, filter?: true)
  28. allow(FeedManager).to receive(:instance).and_return(instance)
  29. result = subject.perform(status.id, follower.id)
  30. expect(result).to be_nil
  31. expect(instance).to_not have_received(:push_to_home)
  32. end
  33. it 'pushes the status onto the home timeline without filter' do
  34. instance = instance_double(FeedManager, push_to_home: nil, filter?: false)
  35. allow(FeedManager).to receive(:instance).and_return(instance)
  36. result = subject.perform(status.id, follower.id, :home)
  37. expect(result).to be_nil
  38. expect(instance).to have_received(:push_to_home).with(follower, status, update: nil)
  39. end
  40. it 'pushes the status onto the tags timeline without filter' do
  41. instance = instance_double(FeedManager, push_to_home: nil, filter?: false)
  42. allow(FeedManager).to receive(:instance).and_return(instance)
  43. result = subject.perform(status.id, follower.id, :tags)
  44. expect(result).to be_nil
  45. expect(instance).to have_received(:push_to_home).with(follower, status, update: nil)
  46. end
  47. it 'pushes the status onto the list timeline without filter' do
  48. instance = instance_double(FeedManager, push_to_list: nil, filter?: false)
  49. allow(FeedManager).to receive(:instance).and_return(instance)
  50. result = subject.perform(status.id, list.id, :list)
  51. expect(result).to be_nil
  52. expect(instance).to have_received(:push_to_list).with(list, status, update: nil)
  53. end
  54. end
  55. end
  56. end