From 28b1fc076ab87d0d275639dea9b37917ccb1f25a Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 16 Aug 2018 14:29:50 +0100 Subject: [PATCH] Remove empty SKU values if empty --- app/models/product_import/spreadsheet_entry.rb | 5 +++++ spec/models/product_importer_spec.rb | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/product_import/spreadsheet_entry.rb b/app/models/product_import/spreadsheet_entry.rb index b32c96a811..b8db4b44d7 100644 --- a/app/models/product_import/spreadsheet_entry.rb +++ b/app/models/product_import/spreadsheet_entry.rb @@ -14,6 +14,7 @@ module ProductImport def initialize(attrs) @validates_as = '' + remove_empty_skus attrs assign_units attrs end @@ -57,6 +58,10 @@ module ProductImport private + def remove_empty_skus(attrs) + attrs.delete('sku') if attrs.key?('sku') && attrs['sku'].blank? + end + def assign_units(attrs) units = UnitConverter.new(attrs) diff --git a/spec/models/product_importer_spec.rb b/spec/models/product_importer_spec.rb index 4df09d328c..b1fd165fa1 100644 --- a/spec/models/product_importer_spec.rb +++ b/spec/models/product_importer_spec.rb @@ -254,9 +254,9 @@ describe ProductImport::ProductImporter do describe "updating various fields" do before do csv_data = CSV.generate do |csv| - csv << ["name", "supplier", "category", "on_hand", "price", "units", "unit_type", "on_demand"] - csv << ["Beetroot", "And Another Enterprise", "Vegetables", "5", "3.50", "500", "g", "0"] - csv << ["Tomato", "And Another Enterprise", "Vegetables", "6", "5.50", "500", "g", "1"] + csv << ["name", "supplier", "category", "on_hand", "price", "units", "unit_type", "on_demand", "sku"] + csv << ["Beetroot", "And Another Enterprise", "Vegetables", "5", "3.50", "500", "g", "0", nil] + csv << ["Tomato", "And Another Enterprise", "Vegetables", "6", "5.50", "500", "g", "1", "TOMS"] end File.write('/tmp/test-m.csv', csv_data) file = File.new('/tmp/test-m.csv')