Create customer with default name and addresses

This commit is contained in:
Bing Xie
2016-08-24 15:10:40 +10:00
parent ae2357d309
commit f7523ad88c
2 changed files with 11 additions and 2 deletions

View File

@@ -289,7 +289,8 @@ Spree::Order.class_eval do
def ensure_customer
unless associate_customer
self.customer = Customer.create(enterprise: distributor, email: email_for_customer, user: user)
customer_name = bill_address.andand.full_name
self.customer = Customer.create(enterprise: distributor, email: email_for_customer, user: user, name: customer_name, bill_address: bill_address.andand.clone, ship_address: ship_address.andand.clone)
end
end
end

View File

@@ -590,10 +590,18 @@ describe Spree::Order do
end
context "and order#email_for_customer does not match any existing customers" do
it "creates a new customer" do
before {
order.bill_address = create(:address)
order.ship_address = create(:address)
}
it "creates a new customer with defaut name and addresses" do
expect(order.customer).to be_nil
expect{order.send(:ensure_customer)}.to change{Customer.count}.by 1
expect(order.customer).to be_a Customer
expect(order.customer.name).to eq order.bill_address.full_name
expect(order.customer.bill_address.same_as?(order.bill_address)).to be true
expect(order.customer.ship_address.same_as?(order.ship_address)).to be true
end
end
end