Skip to content

Commit

Permalink
Merge pull request #90 from johnpitchko/master
Browse files Browse the repository at this point in the history
Fix broken specs
  • Loading branch information
kennyadsl authored May 2, 2023
2 parents 74399e7 + f7f363c commit df625b8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
6 changes: 4 additions & 2 deletions spec/features/solidus_importer/import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
let(:csv_file_rows) { 4 }
let(:user_emails) { ['jane.doe@acme.com', 'john.doe@acme.com'] }
let(:imported_customer) { Spree::User.last }
let(:state) { create(:state, abbr: 'ON', country_iso: 'CA') }

before { state }
# rubocop:disable RSpec/LetSetup
let!(:state_on) { create(:state, abbr: 'ON', country_iso: 'CA') }
let!(:state_qc) { create(:state, abbr: 'QC', country_iso: 'CA') }
# rubocop:enable RSpec/LetSetup

it 'imports some customers' do
expect { import }.to change(Spree::User, :count).by(2)
Expand Down
19 changes: 14 additions & 5 deletions spec/lib/solidus_importer/processors/customer_address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,27 @@
let(:address) { Spree::Address.last }

context 'when there is a state with the same code attached to another country' do
let(:wrong_state) { create(:state, state_code: 'WA', country_iso: 'IT') }
let(:state) { create(:state, state_code: 'XX', country_iso: 'US') }
let!(:wrong_country) { create(:country, iso: 'IT') }
let!(:right_state_wrong_country) { create(:state) }

before { state and wrong_state }
# Updating the state to the wrong country cannot be done via factory.
# The model/factory performs some validation that prevents a state from
# being added to an incorrect country.
before do
right_state_wrong_country.update(abbr: 'WA', name: 'Washington', country: wrong_country)
end

it 'tries to fetch it from the current country' do
expect { described_method }.to change(Spree::Address, :count).by(1)
expect(Spree::Address.last.state).to be_nil
end
end

context 'when the country does not have a state' do
context 'when the country requires a states' do
before { country.update states_required: true }
before do
country.update states_required: true
state.update(abbr: 'XX')
end

it 'fails creating the address' do
expect { described_method }.not_to change(Spree::Address, :count)
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/solidus_importer/processors/customer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
let(:result) { context.merge(user: Spree::User.last) }

it 'creates a new user' do
expect { described_method }.to change { Spree::User.count }.by(1)
expect { described_method }.to change(Spree::User, :count).by(1)
expect(described_method).to eq(result)
end

Expand All @@ -59,7 +59,7 @@
before { allow(Spree::User).to receive(:find_or_initialize_by).and_return(user) }

it 'updates the user' do
expect { described_method }.not_to(change { Spree::User.count })
expect { described_method }.not_to(change(Spree::User, :count))
expect(described_method).to eq(result)
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/solidus_importer/processors/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
before { shipping_category }

it 'creates a new product' do
expect { described_method }.to change { Spree::Product.count }.by(1)
expect { described_method }.to change(Spree::Product, :count).by(1)
expect(described_method).to eq(result)
expect(product).not_to be_available
end
Expand Down Expand Up @@ -58,7 +58,7 @@
let!(:product) { create(:product, slug: data['Handle']) }

it 'updates the product' do
expect { described_method }.not_to(change { Spree::Product.count })
expect { described_method }.not_to(change(Spree::Product, :count))
expect(described_method).to eq(result)
expect(product.reload.name).to eq('A product name')
end
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/solidus_importer/processors/variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
before { data.merge! 'Option1 Value' => 'Some value' }

it 'creates a new variant' do
expect { described_method }.to change { Spree::Variant.count }.by(1)
expect { described_method }.to change(Spree::Variant, :count).by(1)
expect(described_method).to eq(result)
expect(product.variants.first.weight).to eq 20.0
expect(product.variants.first.price).to eq 60.5
Expand All @@ -49,7 +49,7 @@
before { data.merge! 'Option1 Value' => 'Default Title' }

it 'updates master variant' do
expect { described_method }.not_to(change { Spree::Variant.count })
expect { described_method }.not_to(change(Spree::Variant, :count))
expect(described_method).to eq(result)
expect(product.master.weight).to eq 20.0
expect(product.master.price).to eq 60.5
Expand All @@ -62,7 +62,7 @@
before { data.merge! 'Option1 Value' => nil }

it 'updates master variant' do
expect { described_method }.not_to(change { Spree::Variant.count })
expect { described_method }.not_to(change(Spree::Variant, :count))
expect(described_method).to eq(result)
expect(product.master.weight).to eq 20.0
expect(product.master.price).to eq 60.5
Expand All @@ -76,7 +76,7 @@
before { data.merge! 'Option1 Value' => 'Some value' }

it 'updates the variant' do
expect { described_method }.not_to(change { Spree::Variant.count })
expect { described_method }.not_to(change(Spree::Variant, :count))
expect(described_method).to eq(result)
expect(variant.reload.weight.to_f).to eq(data['Variant Weight'])
expect(variant.reload.price).to eq(data['Variant Price'])
Expand Down

0 comments on commit df625b8

Please sign in to comment.