From f42eb3dab1cbc72c97e89a0d69de9a86f2b1c7cf Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Tue, 26 Feb 2019 15:51:59 +0800 Subject: [PATCH] Create shipment when creating a order for a subscription A spec has been added to check that the attributes for the order states after "cart" ("address", "delivery", "payment") are retained if the order is transitioned to completion, BUT currently this is passing because it is the only shipping method available. --- app/services/order_factory.rb | 6 ++++++ spec/services/order_factory_spec.rb | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/services/order_factory.rb b/app/services/order_factory.rb index 9aa5c9fb05..fc4bd5f424 100644 --- a/app/services/order_factory.rb +++ b/app/services/order_factory.rb @@ -15,8 +15,10 @@ class OrderFactory set_user build_line_items set_addresses + create_shipment set_shipping_method create_payment + @order end @@ -66,6 +68,10 @@ class OrderFactory @order.update_attributes(attrs.slice(:bill_address_attributes, :ship_address_attributes)) end + def create_shipment + @order.create_proposed_shipments + end + def set_shipping_method @order.select_shipping_method(attrs[:shipping_method_id]) end diff --git a/spec/services/order_factory_spec.rb b/spec/services/order_factory_spec.rb index 672ac0a780..1aa28486bd 100644 --- a/spec/services/order_factory_spec.rb +++ b/spec/services/order_factory_spec.rb @@ -42,6 +42,19 @@ describe OrderFactory do expect(order.complete?).to be false end + it "retains address, delivery, and payment attributes until completion of the order" do + while !order.completed? do break unless order.next! end + + order.reload + + expect(order.customer).to eq customer + expect(order.shipping_method).to eq shipping_method + expect(order.payments.first.payment_method).to eq payment_method + expect(order.bill_address).to eq bill_address + expect(order.ship_address).to eq ship_address + expect(order.total).to eq 38.0 + end + context "when the customer does not have a user associated with it" do before { customer.update_attribute(:user_id, nil) }