2017-05-10 20:32:05 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 07:12:25 +02:00
|
|
|
RSpec.describe FeedInsertWorker do
|
2017-05-10 20:32:05 +02:00
|
|
|
subject { described_class.new }
|
|
|
|
|
|
|
|
describe 'perform' do
|
|
|
|
let(:follower) { Fabricate(:account) }
|
|
|
|
let(:status) { Fabricate(:status) }
|
2023-11-16 15:36:59 +01:00
|
|
|
let(:list) { Fabricate(:list) }
|
2017-05-10 20:32:05 +02:00
|
|
|
|
|
|
|
context 'when there are no records' do
|
|
|
|
it 'skips push with missing status' do
|
2023-06-22 14:55:22 +02:00
|
|
|
instance = instance_double(FeedManager, push_to_home: nil)
|
2017-05-10 20:32:05 +02:00
|
|
|
allow(FeedManager).to receive(:instance).and_return(instance)
|
|
|
|
result = subject.perform(nil, follower.id)
|
|
|
|
|
2023-02-20 06:14:50 +01:00
|
|
|
expect(result).to be true
|
2023-02-20 02:33:27 +01:00
|
|
|
expect(instance).to_not have_received(:push_to_home)
|
2017-05-10 20:32:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'skips push with missing account' do
|
2023-06-22 14:55:22 +02:00
|
|
|
instance = instance_double(FeedManager, push_to_home: nil)
|
2017-05-10 20:32:05 +02:00
|
|
|
allow(FeedManager).to receive(:instance).and_return(instance)
|
|
|
|
result = subject.perform(status.id, nil)
|
|
|
|
|
2023-02-20 06:14:50 +01:00
|
|
|
expect(result).to be true
|
2023-02-20 02:33:27 +01:00
|
|
|
expect(instance).to_not have_received(:push_to_home)
|
2017-05-10 20:32:05 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are real records' do
|
|
|
|
it 'skips the push when there is a filter' do
|
2024-12-02 10:26:04 +01:00
|
|
|
instance = instance_double(FeedManager, push_to_home: nil, filter?: true, filter: :filter)
|
2017-05-10 20:32:05 +02:00
|
|
|
allow(FeedManager).to receive(:instance).and_return(instance)
|
|
|
|
result = subject.perform(status.id, follower.id)
|
|
|
|
|
|
|
|
expect(result).to be_nil
|
2023-02-20 02:33:27 +01:00
|
|
|
expect(instance).to_not have_received(:push_to_home)
|
2017-05-10 20:32:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'pushes the status onto the home timeline without filter' do
|
2024-12-02 10:26:04 +01:00
|
|
|
instance = instance_double(FeedManager, push_to_home: nil, filter?: false, filter: nil)
|
2017-05-10 20:32:05 +02:00
|
|
|
allow(FeedManager).to receive(:instance).and_return(instance)
|
2023-11-16 15:36:59 +01:00
|
|
|
result = subject.perform(status.id, follower.id, :home)
|
2017-05-10 20:32:05 +02:00
|
|
|
|
|
|
|
expect(result).to be_nil
|
2022-01-19 22:37:27 +01:00
|
|
|
expect(instance).to have_received(:push_to_home).with(follower, status, update: nil)
|
2017-05-10 20:32:05 +02:00
|
|
|
end
|
2023-11-16 15:36:59 +01:00
|
|
|
|
|
|
|
it 'pushes the status onto the tags timeline without filter' do
|
2024-12-02 10:26:04 +01:00
|
|
|
instance = instance_double(FeedManager, push_to_home: nil, filter?: false, filter: nil)
|
2023-11-16 15:36:59 +01:00
|
|
|
allow(FeedManager).to receive(:instance).and_return(instance)
|
|
|
|
result = subject.perform(status.id, follower.id, :tags)
|
|
|
|
|
|
|
|
expect(result).to be_nil
|
|
|
|
expect(instance).to have_received(:push_to_home).with(follower, status, update: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'pushes the status onto the list timeline without filter' do
|
2024-12-02 10:26:04 +01:00
|
|
|
instance = instance_double(FeedManager, push_to_list: nil, filter?: false, filter: nil)
|
2023-11-16 15:36:59 +01:00
|
|
|
allow(FeedManager).to receive(:instance).and_return(instance)
|
|
|
|
result = subject.perform(status.id, list.id, :list)
|
|
|
|
|
|
|
|
expect(result).to be_nil
|
|
|
|
expect(instance).to have_received(:push_to_list).with(list, status, update: nil)
|
|
|
|
end
|
2017-05-10 20:32:05 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|