Link standing order orders to user on initialisation if customer user exists

This commit is contained in:
Rob Harrington
2016-12-15 13:11:21 +11:00
parent 439c81d836
commit 0cf7d1a63d
2 changed files with 16 additions and 0 deletions

View File

@@ -45,6 +45,7 @@ class ProxyOrder < ActiveRecord::Base
distributor_id: standing_order.shop_id,
shipping_method_id: standing_order.shipping_method_id,
})
order.update_attribute(:user, standing_order.customer.user)
standing_order.standing_line_items.each do |sli|
order.line_items.build(variant_id: sli.variant_id, quantity: sli.quantity, skip_stock_check: true)
end

View File

@@ -149,6 +149,8 @@ describe ProxyOrder, type: :model do
expect(proxy_order.reload.order).to be_a Spree::Order
order = proxy_order.order
expect(order.line_items.count).to eq standing_order.standing_line_items.count
expect(order.customer).to eq standing_order.customer
expect(order.user).to eq standing_order.customer.user
expect(order.distributor).to eq standing_order.shop
expect(order.order_cycle).to eq proxy_order.order_cycle
expect(order.shipping_method).to eq standing_order.shipping_method
@@ -175,6 +177,19 @@ describe ProxyOrder, type: :model do
expect(order.line_items.find_by_variant_id(variant.id).quantity).to eq 5
end
end
context "when the customer does not have a user associated with it" do
before do
standing_order.customer.update_attribute(:user_id, nil)
end
it "initialises the order without a user_id" do
expect{ proxy_order.initialise_order! }.to change{Spree::Order.count}.by(1)
expect(proxy_order.reload.order).to be_a Spree::Order
order = proxy_order.order
expect(order.user).to be nil
end
end
end
context "when the order has already been initialised" do