Find customers by user id as well as email

Also fixing up a spec which became brittle due to too much mocking.
This commit is contained in:
Maikel Linke
2022-09-14 15:44:45 +10:00
committed by Konrad
parent cf634d8d9b
commit 9dbba35019
3 changed files with 4 additions and 5 deletions

View File

@@ -718,7 +718,8 @@ module Spree
end
def find_customer
Customer.of(distributor).find_by(email: email_for_customer)
user&.customers&.of(distributor)&.first ||
Customer.of(distributor).find_by(email: email_for_customer)
end
def create_customer

View File

@@ -21,10 +21,10 @@ describe Spree::Order do
context "#save" do
context "when associated with a registered user" do
let(:user) { double(:user, email: "test@example.com") }
let(:user) { Spree::User.new(email: "test@example.com") }
before do
allow(order).to receive_messages user: user
order.user = user
end
it "should assign the email address of the user" do

View File

@@ -975,8 +975,6 @@ describe Spree::Order do
end
it "recognises users with changed email address" do
pending "#9002"
order.update!(state: "complete")
# Change email instantly without confirmation via Devise: