mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-03 02:21:33 +00:00
Create customer with default name and addresses
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user