Skip to content

Commit

Permalink
Create shipment when creating a order for a subscription
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kristinalim committed Mar 1, 2019
1 parent 76cf889 commit 7206cd8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/services/order_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ def create
set_user
build_line_items
set_addresses
create_shipment
set_shipping_method
create_payment

@order
end

Expand Down Expand Up @@ -66,6 +68,10 @@ def set_addresses
@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
Expand Down
13 changes: 13 additions & 0 deletions spec/services/order_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@
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) }

Expand Down

0 comments on commit 7206cd8

Please sign in to comment.