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')