Merge remote-tracking branch 'parent/main' into kbtopic-remove-quote
This commit is contained in:
commit
80542ea172
76 changed files with 658 additions and 390 deletions
|
@ -8,95 +8,82 @@ RSpec.describe Import::RowWorker do
|
|||
let(:row) { Fabricate(:bulk_import_row, bulk_import: import) }
|
||||
|
||||
describe '#perform' do
|
||||
before do
|
||||
allow(BulkImportRowService).to receive(:new).and_return(service_double)
|
||||
before { allow(BulkImportRowService).to receive(:new).and_return(service_double) }
|
||||
|
||||
shared_context 'when service succeeds' do
|
||||
let(:service_double) { instance_double(BulkImportRowService, call: true) }
|
||||
end
|
||||
|
||||
shared_context 'when service fails' do
|
||||
let(:service_double) { instance_double(BulkImportRowService, call: false) }
|
||||
end
|
||||
|
||||
shared_context 'when service errors' do
|
||||
let(:service_double) { instance_double(BulkImportRowService) }
|
||||
before { allow(service_double).to receive(:call).and_raise('dummy error') }
|
||||
end
|
||||
|
||||
shared_examples 'clean failure' do
|
||||
let(:service_double) { instance_double(BulkImportRowService, call: false) }
|
||||
|
||||
it 'calls BulkImportRowService' do
|
||||
subject.perform(row.id)
|
||||
expect(service_double).to have_received(:call).with(row)
|
||||
end
|
||||
|
||||
it 'increases the number of processed items' do
|
||||
expect { subject.perform(row.id) }.to(change { import.reload.processed_items }.by(+1))
|
||||
end
|
||||
|
||||
it 'does not increase the number of imported items' do
|
||||
expect { subject.perform(row.id) }.to_not(change { import.reload.imported_items })
|
||||
end
|
||||
|
||||
it 'does not delete the row' do
|
||||
subject.perform(row.id)
|
||||
expect(BulkImportRow.exists?(row.id)).to be true
|
||||
it 'calls service, increases processed items, preserves imported items, and keeps row' do
|
||||
expect { subject.perform(row.id) }
|
||||
.to change { import.reload.processed_items }.by(+1)
|
||||
.and not_change { import.reload.imported_items }
|
||||
.and(not_change { BulkImportRow.exists?(row.id) }.from(true))
|
||||
expect(service_double)
|
||||
.to have_received(:call).with(row)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples 'unclean failure' do
|
||||
let(:service_double) { instance_double(BulkImportRowService) }
|
||||
|
||||
before do
|
||||
allow(service_double).to receive(:call) do
|
||||
raise 'dummy error'
|
||||
end
|
||||
end
|
||||
|
||||
it 'raises an error and does not change processed items count' do
|
||||
expect { subject.perform(row.id) }.to raise_error(StandardError, 'dummy error').and(not_change { import.reload.processed_items })
|
||||
end
|
||||
|
||||
it 'does not delete the row' do
|
||||
expect { subject.perform(row.id) }.to raise_error(StandardError, 'dummy error').and(not_change { BulkImportRow.exists?(row.id) })
|
||||
it 'raises an error, preserves processed items, and keeps row' do
|
||||
expect { subject.perform(row.id) }
|
||||
.to raise_error(StandardError, 'dummy error')
|
||||
.and(not_change { import.reload.processed_items })
|
||||
.and(not_change { BulkImportRow.exists?(row.id) }.from(true))
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples 'clean success' do
|
||||
let(:service_double) { instance_double(BulkImportRowService, call: true) }
|
||||
|
||||
it 'calls BulkImportRowService' do
|
||||
subject.perform(row.id)
|
||||
it 'calls service, increases processed items, increases imported items, and deletes row' do
|
||||
expect { subject.perform(row.id) }
|
||||
.to change { import.reload.processed_items }.by(+1)
|
||||
.and change { import.reload.imported_items }.by(+1)
|
||||
.and(change { BulkImportRow.exists?(row.id) }.from(true).to(false))
|
||||
expect(service_double).to have_received(:call).with(row)
|
||||
end
|
||||
|
||||
it 'increases the number of processed items' do
|
||||
expect { subject.perform(row.id) }.to(change { import.reload.processed_items }.by(+1))
|
||||
end
|
||||
|
||||
it 'increases the number of imported items' do
|
||||
expect { subject.perform(row.id) }.to(change { import.reload.imported_items }.by(+1))
|
||||
end
|
||||
|
||||
it 'deletes the row' do
|
||||
expect { subject.perform(row.id) }.to change { BulkImportRow.exists?(row.id) }.from(true).to(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there are multiple rows to process' do
|
||||
let(:import) { Fabricate(:bulk_import, total_items: 2, processed_items: 0, imported_items: 0, state: :in_progress) }
|
||||
|
||||
context 'with a clean failure' do
|
||||
include_examples 'clean failure'
|
||||
include_context 'when service fails'
|
||||
it_behaves_like 'clean failure'
|
||||
|
||||
it 'does not mark the import as finished' do
|
||||
expect { subject.perform(row.id) }.to_not(change { import.reload.state.to_sym })
|
||||
expect { subject.perform(row.id) }
|
||||
.to_not(change { import.reload.state.to_sym })
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an unclean failure' do
|
||||
include_examples 'unclean failure'
|
||||
include_context 'when service errors'
|
||||
it_behaves_like 'unclean failure'
|
||||
|
||||
it 'does not mark the import as finished' do
|
||||
expect { subject.perform(row.id) }.to raise_error(StandardError).and(not_change { import.reload.state.to_sym })
|
||||
expect { subject.perform(row.id) }
|
||||
.to raise_error(StandardError)
|
||||
.and(not_change { import.reload.state.to_sym })
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a clean success' do
|
||||
include_examples 'clean success'
|
||||
include_context 'when service succeeds'
|
||||
it_behaves_like 'clean success'
|
||||
|
||||
it 'does not mark the import as finished' do
|
||||
expect { subject.perform(row.id) }.to_not(change { import.reload.state.to_sym })
|
||||
expect { subject.perform(row.id) }
|
||||
.to_not(change { import.reload.state.to_sym })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -105,21 +92,28 @@ RSpec.describe Import::RowWorker do
|
|||
let(:import) { Fabricate(:bulk_import, total_items: 2, processed_items: 1, imported_items: 0, state: :in_progress) }
|
||||
|
||||
context 'with a clean failure' do
|
||||
include_examples 'clean failure'
|
||||
include_context 'when service fails'
|
||||
it_behaves_like 'clean failure'
|
||||
|
||||
it 'marks the import as finished' do
|
||||
expect { subject.perform(row.id) }.to change { import.reload.state.to_sym }.from(:in_progress).to(:finished)
|
||||
expect { subject.perform(row.id) }
|
||||
.to change { import.reload.state.to_sym }.from(:in_progress).to(:finished)
|
||||
end
|
||||
end
|
||||
|
||||
# NOTE: sidekiq retry logic may be a bit too difficult to test, so leaving this blind spot for now
|
||||
it_behaves_like 'unclean failure'
|
||||
context 'with an unclean failure' do
|
||||
# NOTE: sidekiq retry logic may be a bit too difficult to test, so leaving this blind spot for now
|
||||
include_context 'when service errors'
|
||||
it_behaves_like 'unclean failure'
|
||||
end
|
||||
|
||||
context 'with a clean success' do
|
||||
include_examples 'clean success'
|
||||
include_context 'when service succeeds'
|
||||
it_behaves_like 'clean success'
|
||||
|
||||
it 'marks the import as finished' do
|
||||
expect { subject.perform(row.id) }.to change { import.reload.state.to_sym }.from(:in_progress).to(:finished)
|
||||
expect { subject.perform(row.id) }
|
||||
.to change { import.reload.state.to_sym }.from(:in_progress).to(:finished)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -113,27 +113,27 @@ RSpec.describe MoveWorker do
|
|||
end
|
||||
|
||||
shared_examples 'common tests' do
|
||||
include_examples 'user note handling'
|
||||
include_examples 'block and mute handling'
|
||||
include_examples 'followers count handling'
|
||||
include_examples 'lists handling'
|
||||
it_behaves_like 'user note handling'
|
||||
it_behaves_like 'block and mute handling'
|
||||
it_behaves_like 'followers count handling'
|
||||
it_behaves_like 'lists handling'
|
||||
|
||||
context 'when a local user already follows both source and target' do
|
||||
before do
|
||||
local_follower.request_follow!(target_account)
|
||||
end
|
||||
|
||||
include_examples 'user note handling'
|
||||
include_examples 'block and mute handling'
|
||||
include_examples 'followers count handling'
|
||||
include_examples 'lists handling'
|
||||
it_behaves_like 'user note handling'
|
||||
it_behaves_like 'block and mute handling'
|
||||
it_behaves_like 'followers count handling'
|
||||
it_behaves_like 'lists handling'
|
||||
|
||||
context 'when the local user already has the target in a list' do
|
||||
before do
|
||||
list.accounts << target_account
|
||||
end
|
||||
|
||||
include_examples 'lists handling'
|
||||
it_behaves_like 'lists handling'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -142,17 +142,17 @@ RSpec.describe MoveWorker do
|
|||
local_follower.follow!(target_account)
|
||||
end
|
||||
|
||||
include_examples 'user note handling'
|
||||
include_examples 'block and mute handling'
|
||||
include_examples 'followers count handling'
|
||||
include_examples 'lists handling'
|
||||
it_behaves_like 'user note handling'
|
||||
it_behaves_like 'block and mute handling'
|
||||
it_behaves_like 'followers count handling'
|
||||
it_behaves_like 'lists handling'
|
||||
|
||||
context 'when the local user already has the target in a list' do
|
||||
before do
|
||||
list.accounts << target_account
|
||||
end
|
||||
|
||||
include_examples 'lists handling'
|
||||
it_behaves_like 'lists handling'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -164,7 +164,7 @@ RSpec.describe MoveWorker do
|
|||
expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, false)
|
||||
end
|
||||
|
||||
include_examples 'common tests'
|
||||
it_behaves_like 'common tests'
|
||||
end
|
||||
|
||||
context 'when target account is local' do
|
||||
|
@ -175,7 +175,7 @@ RSpec.describe MoveWorker do
|
|||
expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, true)
|
||||
end
|
||||
|
||||
include_examples 'common tests'
|
||||
it_behaves_like 'common tests'
|
||||
end
|
||||
|
||||
context 'when both target and source accounts are local' do
|
||||
|
@ -187,7 +187,7 @@ RSpec.describe MoveWorker do
|
|||
expect(local_follower.following?(target_account)).to be true
|
||||
end
|
||||
|
||||
include_examples 'common tests'
|
||||
it_behaves_like 'common tests'
|
||||
|
||||
it 'does not allow the moved account to follow themselves' do
|
||||
source_account.follow!(target_account)
|
||||
|
|
|
@ -108,7 +108,7 @@ RSpec.describe Scheduler::AccountsStatusesCleanupScheduler do
|
|||
|
||||
context 'when the budget is lower than the number of toots to delete' do
|
||||
it 'deletes the appropriate statuses' do
|
||||
expect(Status.count).to be > (subject.compute_budget) # Data check
|
||||
expect(Status.count).to be > subject.compute_budget # Data check
|
||||
|
||||
expect { subject.perform }
|
||||
.to change(Status, :count).by(-subject.compute_budget) # Cleanable statuses
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue