Skip to content

Commit

Permalink
[fixup!] Fix variant processor
Browse files Browse the repository at this point in the history
  • Loading branch information
Flavio Auciello committed Apr 17, 2020
1 parent 9ca6b51 commit 24f0d73
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/solidus_importer/processors/variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ def call(context)
private

def prepare_variant
return product.master if master_variant?

@prepare_variant ||= Spree::Variant.find_or_initialize_by(sku: sku) do |variant|
variant.product = product
end
end

def process_variant
return product.master if master_variant?

prepare_variant.tap do |variant|
# Apply the row attributes
variant.weight = @data['Variant Weight'] unless @data['Variant Weight'].nil?
Expand Down
5 changes: 4 additions & 1 deletion spec/lib/solidus_importer/processors/variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{ data: data, product: product }
end
let(:data) { build(:solidus_importer_row_variant, :with_import).data }
let(:product) { build_stubbed(:product, slug: data['Handle']) }
let(:product) { create(:product, slug: data['Handle']) }

before do
allow(product).to receive(:touch)
Expand All @@ -38,6 +38,7 @@
it 'creates a new variant' do
expect { described_method }.to change { Spree::Variant.count }.by(1)
expect(described_method).to eq(result)
expect(result[:variant].weight).to eq 20.0
end
end

Expand All @@ -49,6 +50,7 @@
it 'updates master variant' do
expect { described_method }.not_to(change { Spree::Variant.count })
expect(described_method).to eq(result)
expect(result[:variant].weight).to eq 20.0
end
end

Expand All @@ -60,6 +62,7 @@
it 'updates master variant' do
expect { described_method }.not_to(change { Spree::Variant.count })
expect(described_method).to eq(result)
expect(result[:variant].weight).to eq 20.0
end
end

Expand Down

0 comments on commit 24f0d73

Please sign in to comment.