From e75b55a6d7acabe0d70eac96ff773ac1ca681855 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 15 Mar 2024 05:31:25 -0400 Subject: [PATCH] Extract target account on list method in bulk import row service spec (#29601) --- spec/services/bulk_import_row_service_spec.rb | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/spec/services/bulk_import_row_service_spec.rb b/spec/services/bulk_import_row_service_spec.rb index a77acc0732..d295c28067 100644 --- a/spec/services/bulk_import_row_service_spec.rb +++ b/spec/services/bulk_import_row_service_spec.rb @@ -110,7 +110,7 @@ RSpec.describe BulkImportRowService do end it 'adds the target account to the list' do - expect { subject.call(import_row) }.to change { ListAccount.joins(:list).exists?(account_id: target_account.id, list: { title: 'my list' }) }.from(false).to(true) + expect { subject.call(import_row) }.to add_target_account_to_list end end @@ -124,7 +124,7 @@ RSpec.describe BulkImportRowService do end it 'adds the target account to the list' do - expect { subject.call(import_row) }.to change { ListAccount.joins(:list).exists?(account_id: target_account.id, list: { title: 'my list' }) }.from(false).to(true) + expect { subject.call(import_row) }.to add_target_account_to_list end end @@ -134,7 +134,7 @@ RSpec.describe BulkImportRowService do end it 'adds the target account to the list' do - expect { subject.call(import_row) }.to change { ListAccount.joins(:list).exists?(account_id: target_account.id, list: { title: 'my list' }) }.from(false).to(true) + expect { subject.call(import_row) }.to add_target_account_to_list end end @@ -146,9 +146,24 @@ RSpec.describe BulkImportRowService do end it 'adds the target account to the list' do - expect { subject.call(import_row) }.to change { ListAccount.joins(:list).exists?(account_id: target_account.id, list: { title: 'my list' }) }.from(false).to(true) + expect { subject.call(import_row) }.to add_target_account_to_list end end + + def add_target_account_to_list + change { target_account_on_list? } + .from(false) + .to(true) + end + + def target_account_on_list? + ListAccount + .joins(:list) + .exists?( + account_id: target_account.id, + list: { title: 'my list' } + ) + end end context 'when the list does not exist yet' do