From 99fff3d2796f37afd683df942e2d531e0d3d3001 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Fri, 21 Sep 2018 17:12:03 +0100 Subject: [PATCH 1/4] Fixed factory completed_order_with_fees by skipping a failing and unnecessary part of the checkout workflow Fixed factory's shipment_with shipping_fees trait by ensuring only one shipping_rate in the shipment --- spec/factories.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/factories.rb b/spec/factories.rb index 35028e832c..449c4cdc92 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -385,6 +385,7 @@ FactoryBot.define do after(:create) do |shipment, evaluator| shipping_method = create(:shipping_method_with, :shipping_fee, shipping_fee: evaluator.shipping_fee) + shipment.shipping_rates.destroy_all # remove existing shipping_rates from shipment shipment.add_shipping_method(shipping_method, true) end end @@ -408,6 +409,9 @@ FactoryBot.define do payment_calculator = build(:calculator_per_item, preferred_amount: evaluator.payment_fee) payment_method = create(:payment_method, calculator: payment_calculator) create(:payment, order: order, amount: order.total, payment_method: payment_method, state: 'checkout') + + # skip the rebuilding of order.shipments from line_items and stock locations (this is enforced in checkout step :address to :delivery) + order.stub(:create_proposed_shipments) while !order.completed? do break unless order.next! end end end From 4476b880447ba72322df67a1437a2886f3a29e43 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Fri, 21 Sep 2018 17:15:54 +0100 Subject: [PATCH 2/4] Fixed shipping_method update in models/spree/order_spec, order.shipment is now updated instead of order.shipping_method_id --- spec/models/spree/order_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 182c790f7e..3befd7aa80 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -708,7 +708,7 @@ describe Spree::Order do it "updates shipping fees" do # Change the shipping method - order.shipment.update_attributes(shipping_method_id: shipping_method.id) + order.shipments = [create(:shipment_with, :shipping_method, shipping_method: shipping_method)] order.save # Check if fees got updated From 89114655fd9b20befb09d1b39b4b96e8c61afb10 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Fri, 21 Sep 2018 22:12:37 +0100 Subject: [PATCH 3/4] Fixed shipping_method update in features/consumer/shopping/orders_spec, order.shipment is now updated instead of order.shipping_method_id --- spec/features/consumer/shopping/orders_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/consumer/shopping/orders_spec.rb b/spec/features/consumer/shopping/orders_spec.rb index 24ec737cd7..e8a6da1d8b 100644 --- a/spec/features/consumer/shopping/orders_spec.rb +++ b/spec/features/consumer/shopping/orders_spec.rb @@ -16,7 +16,7 @@ feature "Order Management", js: true do before do shipping_method.calculator.update_attributes(preferred_amount: 5.0) - order.update_attributes(shipping_method_id: shipping_method.id) + order.shipments = [create(:shipment_with, :shipping_method, shipping_method: shipping_method)] order.reload.save quick_login_as user end From 4f32a8efc20bd5d02a1433f4db2fd612cd7f0c06 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 25 Sep 2018 00:49:03 +0100 Subject: [PATCH 4/4] Fixed shipment factory by making shipments unique per order and stock_location factory by making stock_location unique --- spec/factories.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/factories.rb b/spec/factories.rb index 449c4cdc92..1da7e5d478 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -616,3 +616,15 @@ FactoryBot.modify do end end end + +FactoryBot.modify do + factory :stock_location, class: Spree::StockLocation do + # keeps the test stock_location unique + initialize_with { Spree::StockLocation.find_or_create_by_name(name)} + end + + factory :shipment, class: Spree::Shipment do + # keeps test shipments unique per order + initialize_with { Spree::Shipment.find_or_create_by_order_id(order.id)} + end +end