Merge pull request #2546 from Matt-Yorkley/pi/sku_validation

Remove empty SKU values if empty
This commit is contained in:
Maikel
2018-08-24 14:32:00 +10:00
committed by GitHub
2 changed files with 8 additions and 3 deletions

View File

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

View File

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