From be413d67de3357ad7cd601970cb9884431edad9e Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 18 Nov 2024 04:22:09 -0500 Subject: [PATCH] `Form::Import` spec reduce factories (#32924) --- spec/models/form/import_spec.rb | 57 +++++++++------------------------ 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/spec/models/form/import_spec.rb b/spec/models/form/import_spec.rb index 22ffdfd877..e14ad6eca0 100644 --- a/spec/models/form/import_spec.rb +++ b/spec/models/form/import_spec.rb @@ -237,51 +237,26 @@ RSpec.describe Form::Import do let(:import_file) { file } let(:import_mode) { mode } - before do - subject.save - end - - it 'creates the expected rows' do - expect(account.bulk_imports.first.rows.pluck(:data)).to match_array(expected_rows) - end + before { subject.save } context 'with a BulkImport' do let(:bulk_import) { account.bulk_imports.first } - it 'creates a non-nil bulk import' do - expect(bulk_import).to_not be_nil - end - - it 'matches the subjects type' do - expect(bulk_import.type.to_sym).to eq subject.type.to_sym - end - - it 'matches the subjects original filename' do - expect(bulk_import.original_filename).to eq subject.data.original_filename - end - - it 'matches the subjects likely_mismatched? value' do - expect(bulk_import.likely_mismatched?).to eq subject.likely_mismatched? - end - - it 'matches the subject overwrite value' do - expect(bulk_import.overwrite?).to eq !!subject.overwrite # rubocop:disable Style/DoubleNegation - end - - it 'has zero processed items' do - expect(bulk_import.processed_items).to eq 0 - end - - it 'has zero imported items' do - expect(bulk_import.imported_items).to eq 0 - end - - it 'has a correct total_items value' do - expect(bulk_import.total_items).to eq bulk_import.rows.count - end - - it 'defaults to unconfirmed true' do - expect(bulk_import.state_unconfirmed?).to be true + it 'creates a bulk import with correct values' do + expect(bulk_import) + .to be_present + .and have_attributes( + type: eq(subject.type), + original_filename: eq(subject.data.original_filename), + likely_mismatched?: eq(subject.likely_mismatched?), + overwrite?: eq(!!subject.overwrite), # rubocop:disable Style/DoubleNegation + processed_items: eq(0), + imported_items: eq(0), + total_items: eq(bulk_import.rows.count), + state_unconfirmed?: be(true) + ) + expect(bulk_import.rows.pluck(:data)) + .to match_array(expected_rows) end end end