From d6cff9bc68119cd7261be54dd7b4e40c8fa6deb4 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Fri, 7 Sep 2018 11:56:26 +0100 Subject: [PATCH 1/3] Removed calls to the now inexistent order.create_shipment! from specs --- spec/factories.rb | 1 - spec/models/spree/order_spec.rb | 5 ----- 2 files changed, 6 deletions(-) diff --git a/spec/factories.rb b/spec/factories.rb index c405e09c9a4..966d75763d3 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -348,7 +348,6 @@ after(:create) do |order, evaluator| create(:line_item, order: order) - order.create_shipment! 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') diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 4e23a102efc..1705c835482 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -185,7 +185,6 @@ let(:shipping_method) { create(:shipping_method) } before do - order.create_shipment! order.reload order.state = 'complete' order.shipment.update!(order) @@ -214,7 +213,6 @@ let(:shipping_method) { create(:shipping_method) } before do - order.create_shipment! order.payment_state = 'paid' order.state = 'complete' order.shipment.update!(order) @@ -233,7 +231,6 @@ before do Spree::Config.shipment_inc_vat = true Spree::Config.shipping_tax_rate = 0.25 - order.create_shipment! end it "returns the shipping tax" do @@ -267,7 +264,6 @@ before do Spree::Config.shipment_inc_vat = true Spree::Config.shipping_tax_rate = 0.25 - order.create_shipment! order.reload end @@ -301,7 +297,6 @@ before do Spree::Config.shipment_inc_vat = true Spree::Config.shipping_tax_rate = tax_rate15.amount - order.create_shipment! Spree::TaxRate.adjust(order) order.reload.update_distribution_charge! end From afedbe45abf71ccd806325680803dd46756c325b Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Fri, 7 Sep 2018 12:02:19 +0100 Subject: [PATCH 2/3] Fixed scenario "guest order with registered email" in order_spec Spree order factory requires user (we are setting it to nil below so, no impact on the test) Defining shipping method is not necessary for this test --- spec/models/spree/order_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 1705c835482..ddb8db5d049 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -634,7 +634,7 @@ end describe "when a guest order is placed with a registered email" do - let(:order) { create(:order_with_totals_and_distribution, user: nil) } + let(:order) { create(:order_with_totals_and_distribution, user: user) } let(:payment_method) { create(:payment_method, distributors: [order.distributor]) } let(:shipping_method) { create(:shipping_method, distributors: [order.distributor]) } let(:user) { create(:user, email: 'registered@email.com') } @@ -642,7 +642,6 @@ before do order.bill_address = create(:address) order.ship_address = create(:address) - order.shipping_method = shipping_method order.email = user.email order.user = nil order.state = 'cart' From 73512d35919c3bb6d9cc8cb0d578d41b157e18e6 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sat, 8 Sep 2018 20:27:18 +0100 Subject: [PATCH 3/3] Replaced order.shipping_method with order.shipments in models.order_spec. Fixed factory completed_order_with_fees used in order_spec and also in line_items_controller_spec and orders_controller_spec. --- .../controllers/line_items_controller_spec.rb | 3 +- .../spree/orders_controller_spec.rb | 3 +- spec/factories.rb | 41 +++++++++++++++++-- spec/models/spree/order_spec.rb | 27 ++++++------ 4 files changed, 52 insertions(+), 22 deletions(-) diff --git a/spec/controllers/line_items_controller_spec.rb b/spec/controllers/line_items_controller_spec.rb index 24f69423f55..6b95068bf63 100644 --- a/spec/controllers/line_items_controller_spec.rb +++ b/spec/controllers/line_items_controller_spec.rb @@ -91,10 +91,9 @@ end context "where shipping and payment fees apply" do - let(:distributor) { create(:distributor_enterprise, charges_sales_tax: true, allow_order_changes: true) } let(:shipping_fee) { 3 } let(:payment_fee) { 5 } - let(:order) { create(:completed_order_with_fees, distributor: distributor, shipping_fee: shipping_fee, payment_fee: payment_fee) } + let(:order) { create(:completed_order_with_fees, shipping_fee: shipping_fee, payment_fee: payment_fee) } before do Spree::Config.shipment_inc_vat = true diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index b9012ff8908..b2ba417a226 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -94,8 +94,7 @@ describe "removing items from a completed order" do context "with shipping and transaction fees" do - let(:distributor) { create(:distributor_enterprise, charges_sales_tax: true, allow_order_changes: true) } - let(:order) { create(:completed_order_with_fees, distributor: distributor, shipping_fee: shipping_fee, payment_fee: payment_fee) } + let(:order) { create(:completed_order_with_fees, shipping_fee: shipping_fee, payment_fee: payment_fee) } let(:line_item1) { order.line_items.first } let(:line_item2) { order.line_items.second } let(:shipping_fee) { 3 } diff --git a/spec/factories.rb b/spec/factories.rb index 966d75763d3..9c0a88e3181 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -335,16 +335,49 @@ end end + factory :shipping_method_with_flat_rate, parent: :shipping_method do + calculator { Spree::Calculator::FlatRate.new(preferred_amount: 50.0) } + end + + factory :shipment_with_flat_rate, parent: :shipment do + after(:create) do |shipment| + shipment.add_shipping_method(create(:shipping_method_with_flat_rate), true) + end + end + + factory :distributor_enterprise_with_tax, parent: :distributor_enterprise do + charges_sales_tax { true } + allow_order_changes { true } + end + + factory :shipping_method_with_shipping_fee, parent: :shipping_method do + transient do + shipping_fee 3 + end + + calculator { build(:calculator_per_item, preferred_amount: shipping_fee) } + require_ship_address { false } + distributors { [create(:distributor_enterprise_with_tax)] } + end + + factory :shipment_with_shipping_fee, parent: :shipment do + transient do + shipping_fee 3 + end + + after(:create) do |shipment, evaluator| + shipping_method = create(:shipping_method_with_shipping_fee, shipping_fee: evaluator.shipping_fee) + shipment.add_shipping_method(shipping_method, true) + end + end + factory :completed_order_with_fees, parent: :order_with_totals_and_distribution do transient do shipping_fee 3 payment_fee 5 end - shipping_method do - shipping_calculator = build(:calculator_per_item, preferred_amount: shipping_fee) - create(:shipping_method, calculator: shipping_calculator, require_ship_address: false, distributors: [distributor]) - end + shipments { [ create(:shipment_with_shipping_fee, shipping_fee: shipping_fee) ] } after(:create) do |order, evaluator| create(:line_item, order: order) diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index ddb8db5d049..2945b795f0d 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -181,8 +181,7 @@ end describe "an unpaid order with a shipment" do - let(:order) { create(:order_with_totals, shipping_method: shipping_method) } - let(:shipping_method) { create(:shipping_method) } + let(:order) { create(:order_with_totals, shipments: [create(:shipment)]) } before do order.reload @@ -209,8 +208,7 @@ end describe "a paid order with a shipment" do - let(:order) { create(:order, shipping_method: shipping_method) } - let(:shipping_method) { create(:shipping_method) } + let(:order) { create(:order_with_line_items) } before do order.payment_state = 'paid' @@ -224,8 +222,8 @@ end describe "getting the shipping tax" do - let(:order) { create(:order, shipping_method: shipping_method) } - let(:shipping_method) { create(:shipping_method, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 50.0)) } + let(:shipment) { create(:shipment_with_flat_rate) } + let(:order) { create(:order, shipments: [shipment]) } context "with a taxed shipment" do before do @@ -256,10 +254,10 @@ end describe "getting the total tax" do - let(:order) { create(:order, shipping_method: shipping_method) } - let(:shipping_method) { create(:shipping_method, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 50.0)) } - let(:enterprise_fee) { create(:enterprise_fee) } - let!(:adjustment) { create(:adjustment, adjustable: order, originator: enterprise_fee, label: "EF", amount: 123, included_tax: 2) } + let(:shipment) { create(:shipment_with_flat_rate) } + let(:order) { create(:order, shipments: [shipment]) } + let(:enterprise_fee) { create(:enterprise_fee) } + let!(:adjustment) { create(:adjustment, adjustable: order, originator: enterprise_fee, label: "EF", amount: 123, included_tax: 2) } before do Spree::Config.shipment_inc_vat = true @@ -287,14 +285,16 @@ let(:variant) { create(:variant, product: create(:product, tax_category: tax_category10)) } let(:shipping_method) { create(:shipping_method, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 46.0)) } + let(:shipment) { create(:shipment) } let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, tax_category: tax_category20, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 48.0)) } let(:additional_adjustment) { create(:adjustment, amount: 50.0, included_tax: tax_rate25.compute_tax(50.0)) } let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator, coordinator_fees: [enterprise_fee], distributors: [coordinator], variants: [variant]) } - let!(:order) { create(:order, shipping_method: shipping_method, bill_address: create(:address), order_cycle: order_cycle, distributor: coordinator, adjustments: [additional_adjustment]) } + let!(:order) { create(:order, shipments: [shipment], bill_address: create(:address), order_cycle: order_cycle, distributor: coordinator, adjustments: [additional_adjustment]) } let!(:line_item) { create(:line_item, order: order, variant: variant, price: 44.0) } before do + shipment.add_shipping_method(shipping_method, true) Spree::Config.shipment_inc_vat = true Spree::Config.shipping_tax_rate = tax_rate15.amount Spree::TaxRate.adjust(order) @@ -386,7 +386,7 @@ describe "emptying the order" do it "removes shipping method" do - subject.shipping_method = create(:shipping_method) + subject.shipments = [create(:shipment)] subject.save! subject.empty! subject.shipping_method.should == nil @@ -655,8 +655,7 @@ end describe "a completed order with shipping and transaction fees" do - let(:distributor) { create(:distributor_enterprise, charges_sales_tax: true, allow_order_changes: true) } - let(:order) { create(:completed_order_with_fees, distributor: distributor, shipping_fee: shipping_fee, payment_fee: payment_fee) } + let(:order) { create(:completed_order_with_fees, shipping_fee: shipping_fee, payment_fee: payment_fee) } let(:shipping_fee) { 3 } let(:payment_fee) { 5 } let(:item_num) { order.line_items.length }