mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #2546 from Matt-Yorkley/pi/sku_validation
Remove empty SKU values if empty
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user