Skip to content

Commit

Permalink
adds test for quantity_available
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Jurke committed Jul 23, 2015
1 parent e04cdb4 commit f8e0fdc
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/factories/mass_upload_articles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'ffaker'

FactoryGirl.define do
factory :mass_upload_article do
mass_upload
action "create"
row_index 1
article_csv { ";;Richard Fischer: Tabellenbuch Kraftfahrzeugtechnik mit Formelsammlung (Taschenbuch, EAN 9783808521366);309;new;;<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>;100;3120;;;7;http://media.ecobookstore.de/366/EAN_9783808521366.jpg;;;true;Postversand;0;9;;;;;1-3;;false;true;;true;;true;;false;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;9783808521366;LIB-9783808521366;update\n" }

factory :update_mass_upload_article do
action "update"
end
end
end
55 changes: 55 additions & 0 deletions test/models/mass_upload_article_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,59 @@
end
end
end

# see https://github.com/fairmondo/fairmondo/issues/1414:
# The issue was already fixed but only after the quantity was updated.
#
# see app/observers/article_observer.rb:
# The callback is only triggered if the quantity is changed again
describe 'quantity and quantity_available' do

let(:old_quantity) { 1 }
let(:quantity) { 100 }

before do
Article.any_instance.stubs(:valid?).returns(true)
MassUploadArticle.any_instance.stubs(:update_index)
Indexer.stubs(:index_article)
end

let(:unsanitized_row_hash) do
{
"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"
}
end

it 'should be updated' do
Sidekiq.logger.stubs(:warn)

mass_upload_article = FactoryGirl.create :update_mass_upload_article
mass_upload = mass_upload_article.mass_upload
user = mass_upload.user
article = FactoryGirl.create :article, seller: user, custom_seller_identifier: "LIB-9783808521366", quantity: old_quantity

mass_upload_article.process unsanitized_row_hash
article.reload

article.quantity.must_equal quantity
end

it 'should update available quantity even if database column is not empty' do
Sidekiq.logger.stubs(:warn)

mass_upload_article = FactoryGirl.create :update_mass_upload_article
mass_upload = mass_upload_article.mass_upload
user = mass_upload.user
article = FactoryGirl.create :article, seller: user, custom_seller_identifier: "LIB-9783808521366", quantity: old_quantity, quantity_available: old_quantity

mass_upload_article.process unsanitized_row_hash
article.reload

article.activate
article.quantity_available.must_equal quantity
end

end
end

0 comments on commit f8e0fdc

Please sign in to comment.