From 64d16258cfe7821122ad534dbe12570f03b90e46 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sat, 24 Nov 2018 23:27:29 +0000 Subject: [PATCH] Fix tests in bulk_product_update spec by: - setting on_hand in the variant and not in the product directly - setting variant on_demand to false (default from the factory is on_demand true) - saving the variant after doing this to trigger appropriate callbacks like creating missing variant stock items --- .../admin/bulk_product_update_spec.rb | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index 5ea80b6e5e..c658e9f5b8 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -55,15 +55,14 @@ feature %q{ end it "displays an on hand count in a span for each product" do - p1 = FactoryBot.create(:product, on_hand: 15) + p1 = FactoryBot.create(:product) v1 = p1.variants.first - v1.on_hand = 4 - v1.save! + v1.update_attribute(:on_demand, false) + v1.update_attribute(:on_hand, 4) visit spree.admin_products_path within "#p_#{p1.id}" do - expect(page).to have_no_field "on_hand", with: "15" expect(page).to have_selector "span[name='on_hand']", text: "4" end end @@ -122,8 +121,14 @@ feature %q{ it "displays an on_hand input (for each variant) for each product" do p1 = FactoryBot.create(:product) + v0 = p1.variants.first + v0.update_attribute(:on_demand, false) v1 = FactoryBot.create(:variant, product: p1, is_master: false, on_hand: 15) + v1.update_attribute(:on_demand, false) + p1.variants << v1 v2 = FactoryBot.create(:variant, product: p1, is_master: false, on_hand: 6) + v2.update_attribute(:on_demand, false) + p1.variants << v2 visit spree.admin_products_path expect(page).to have_selector "a.view-variants", count: 1 @@ -309,9 +314,11 @@ feature %q{ s1 = FactoryBot.create(:supplier_enterprise) s2 = FactoryBot.create(:supplier_enterprise) p = FactoryBot.create(:product, supplier: s1, available_on: Date.current, variant_unit: 'volume', variant_unit_scale: 0.001, - price: 3.0, on_hand: 9, unit_value: 0.25, unit_description: '(bottle)' ) + price: 3.0, unit_value: 0.25, unit_description: '(bottle)' ) v = p.variants.first - v.update_column(:sku, "VARIANTSKU") + v.update_attribute(:sku, "VARIANTSKU") + v.update_attribute(:on_demand, false) + v.update_attribute(:on_hand, 9) quick_login_as_admin visit spree.admin_products_path @@ -630,10 +637,10 @@ feature %q{ let(:supplier_permitted) { create(:supplier_enterprise, name: 'Supplier Permitted') } let(:distributor_managed) { create(:distributor_enterprise, name: 'Distributor Managed') } let(:distributor_unmanaged) { create(:distributor_enterprise, name: 'Distributor Unmanaged') } - let!(:product_supplied) { create(:product, supplier: supplier_managed1, price: 10.0, on_hand: 6) } + let!(:product_supplied) { create(:product, supplier: supplier_managed1, price: 10.0) } let!(:product_not_supplied) { create(:product, supplier: supplier_unmanaged) } - let!(:product_supplied_permitted) { create(:product, name: 'Product Permitted', supplier: supplier_permitted, price: 10.0, on_hand: 6) } - let(:product_supplied_inactive) { create(:product, supplier: supplier_managed1, price: 10.0, on_hand: 6, available_on: 1.week.from_now) } + let!(:product_supplied_permitted) { create(:product, name: 'Product Permitted', supplier: supplier_permitted, price: 10.0) } + let(:product_supplied_inactive) { create(:product, supplier: supplier_managed1, price: 10.0, available_on: 1.week.from_now) } let!(:supplier_permitted_relationship) do create(:enterprise_relationship, parent: supplier_permitted, child: supplier_managed1, @@ -699,6 +706,7 @@ feature %q{ it "allows me to update a product" do p = product_supplied_permitted v = p.variants.first + v.update_attribute(:on_demand, false) visit spree.admin_products_path find("div#columns-dropdown", :text => "COLUMNS").click