Skip to content

Commit

Permalink
Possible fix for #1491
Browse files Browse the repository at this point in the history
  • Loading branch information
marcaltmann committed Dec 18, 2016
1 parent 0c56b9b commit 8808cce
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
9 changes: 9 additions & 0 deletions app/models/mass_upload_article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,22 @@ def prepare_attributes
prepare_categories
prepare_questionaires
prepare_action
strip_nil_fields
end

# Throw away additional fields that are not needed
def sanitize_fields
@article_attributes.slice!(*MassUpload.article_attributes)
end

# Strip price_cents and categories fields if they are nil because they would cause problems
def strip_nil_fields
@article_attributes.delete_if do |key, value|
(key == 'price_cents' && value.nil?) ||
(key == 'categories' && value.nil?)
end
end

def prepare_categories
@article_attributes['category_ids'] = @article_attributes.delete('categories').split(',') if @article_attributes['categories']
end
Expand Down
38 changes: 26 additions & 12 deletions test/models/mass_upload_article_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,24 @@
{
'title' => 'Richard Fischer: Tabellenbuch Kraftfahrzeugtechnik mit Formelsammlung (Taschenbuch, EAN 9783808521366)', 'categories' => '1', 'condition' => 'new', 'content' => '<h3>Tabellenbuch Kraftfahrzeugtechnik mit Formelsammlung</h3><p>von <b>Richard Fischer</b></p><p>Deutsch, September 2008, Europa Lehrmittel Verlag, Taschenbuch, ISBN 3808521368, EAN 9783808521366</p><p><b>Beschreibung</b></p><p><br \\>Das Standardwerk zur Lösung von kraftfahrzeugtechnischen Problemstellungen und Aufgaben in der Arbeitsplanung, im Technologiepraktikum und im Techniklabor.<br \\>Alle wichtigen Formeln, häufig mit Beispielaufgaben, Diagrammen und technischen Werten der Kfz-Technik.<br \\>Mathematik, technische Formeln, Grundkenntnisse der Metalltechnik, Fachkenntnisse Kfz-Technik, Werkstoffkunde, Technisches Zeichnen, Normteile.<br \\>Anschauliche und übersichtliche Darstellung.</p>',
'quantity' => quantity,
'price_cents' => '3120', 'vat' => '7', 'external_title_image_url' => 'http://media.ecobookstore.de/366/EAN_9783808521366.jpg', 'transport_type1' => 'true', 'transport_type1_provider' => 'Postversand', 'transport_type1_price_cents' => '0', 'transport_type1_number' => '9', 'transport_details' => nil, 'transport_time' => '1-3', 'unified_transport' => 'false', 'payment_bank_transfer' => 'true', 'payment_paypal' => 'true', 'payment_invoice' => 'false', 'payment_voucher' => 'true', 'payment_details' => nil, 'gtin' => '9783808521366', 'custom_seller_identifier' => 'LIB-9783808521366', 'action' => 'update'
'price_cents' => '3120',
'vat' => '7',
'external_title_image_url' => 'http://media.ecobookstore.de/366/EAN_9783808521366.jpg',
'transport_type1' => 'true',
'transport_type1_provider' => 'Postversand',
'transport_type1_price_cents' => '0',
'transport_type1_number' => '9',
'transport_details' => nil,
'transport_time' => '1-3',
'unified_transport' => 'false',
'payment_bank_transfer' => 'true',
'payment_paypal' => 'true',
'payment_invoice' => 'false',
'payment_voucher' => 'true',
'payment_details' => nil,
'gtin' => '9783808521366',
'custom_seller_identifier' => 'LIB-9783808521366',
'action' => 'update'
}
end

Expand Down Expand Up @@ -95,21 +112,18 @@

let(:unsanitized_row_hash) do
{
"€"=>"NULL", "title"=>nil, "categories"=>nil, "condition"=>nil, "content"=>nil, "quantity"=>nil,
"price_cents"=>nil, "vat"=>nil, "external_title_image_url"=>nil, "transport_type1"=>nil,
"transport_type1_provider"=>nil, "transport_type1_price_cents"=>nil, "transport_type1_number"=>nil,
"transport_details"=>nil, "transport_time"=>nil, "unified_transport"=>nil,
"payment_bank_transfer"=>nil, "payment_paypal"=>nil, "payment_invoice"=>nil,
"payment_voucher"=>nil, "payment_details"=>nil, "gtin"=>nil, "custom_seller_identifier"=>nil,
"action"=>nil
'€' => 'NULL', 'title' => nil, 'categories' => nil, 'condition' => nil, 'content' => nil, 'quantity' => nil,
'price_cents' => nil, 'vat' => nil, 'external_title_image_url' => nil, 'transport_type1' => nil,
'transport_type1_provider' => nil, 'transport_type1_price_cents' => nil, 'transport_type1_number' => nil,
'transport_details' => nil, 'transport_time' => nil, 'unified_transport' => nil,
'payment_bank_transfer' => nil, 'payment_paypal' => nil, 'payment_invoice' => nil,
'payment_voucher' => nil, 'payment_details' => nil, 'gtin' => nil, 'custom_seller_identifier' => nil,
'action' => nil
}
end

it 'should be updated' do
skip('Bug not yet fixed')

it 'should not raise an exception' do
mass_upload_article = create :mass_upload_article
mass_upload = mass_upload_article.mass_upload

mass_upload_article.process unsanitized_row_hash
end
Expand Down

0 comments on commit 8808cce

Please sign in to comment.