From 0c5cc234158f8f6ba98e5f82e3bf3680b1df2cb0 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 3 Feb 2019 13:04:01 +0000 Subject: [PATCH] Fix hash merge for recording already created products by name --- app/models/product_import/entry_processor.rb | 2 +- spec/models/product_importer_spec.rb | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/models/product_import/entry_processor.rb b/app/models/product_import/entry_processor.rb index 6286646023..05643a3b3c 100644 --- a/app/models/product_import/entry_processor.rb +++ b/app/models/product_import/entry_processor.rb @@ -175,7 +175,7 @@ module ProductImport assign_errors product.errors.full_messages, entry.line_number end - @already_created[entry.enterprise_id] = { entry.name => product.id } + @already_created.deep_merge! entry.enterprise_id => { entry.name => product.id } end def save_variant(entry) diff --git a/spec/models/product_importer_spec.rb b/spec/models/product_importer_spec.rb index 7a259f53fe..77dc57c0b7 100644 --- a/spec/models/product_importer_spec.rb +++ b/spec/models/product_importer_spec.rb @@ -247,6 +247,7 @@ describe ProductImport::ProductImporter do csv_data = CSV.generate do |csv| csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "display_name"] csv << ["Potatoes", "User Enterprise", "Vegetables", "5", "3.50", "500", "g", "Small Bag"] + csv << ["Chives", "User Enterprise", "Vegetables", "6", "4.50", "500", "g", "Small Bag"] csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "5.50", "2", "kg", "Big Bag"] end File.write('/tmp/test-m.csv', csv_data) @@ -260,17 +261,17 @@ describe ProductImport::ProductImporter do @importer.validate_entries entries = JSON.parse(@importer.entries_json) - expect(filter('valid', entries)).to eq 2 + expect(filter('valid', entries)).to eq 3 expect(filter('invalid', entries)).to eq 0 - expect(filter('create_product', entries)).to eq 2 + expect(filter('create_product', entries)).to eq 3 end it "saves and updates" do @importer.save_entries - expect(@importer.products_created_count).to eq 2 + expect(@importer.products_created_count).to eq 3 expect(@importer.updated_ids).to be_a(Array) - expect(@importer.updated_ids.count).to eq 2 + expect(@importer.updated_ids.count).to eq 3 small_bag = Spree::Variant.find_by_display_name('Small Bag') expect(small_bag.product.name).to eq 'Potatoes'