mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Ensure created users are associated with customers
When a user is created with the same email as existing customers Then the user is associated with these customers So that the user can access the private shops where he has been invited to before signup
This commit is contained in:
@@ -19,6 +19,7 @@ Spree.user_class.class_eval do
|
||||
accepts_nested_attributes_for :ship_address
|
||||
|
||||
attr_accessible :enterprise_ids, :enterprise_roles_attributes, :enterprise_limit, :locale, :bill_address_attributes, :ship_address_attributes
|
||||
after_create :associate_customers
|
||||
|
||||
validate :limit_owned_enterprises
|
||||
|
||||
@@ -64,6 +65,10 @@ Spree.user_class.class_eval do
|
||||
Delayed::Job.enqueue ConfirmSignupJob.new(id)
|
||||
end
|
||||
|
||||
def associate_customers
|
||||
self.customers = Customer.where(email: email)
|
||||
end
|
||||
|
||||
def can_own_more_enterprises?
|
||||
owned_enterprises(:reload).size < enterprise_limit
|
||||
end
|
||||
|
||||
@@ -77,6 +77,17 @@ describe Spree.user_class do
|
||||
end.to enqueue_job Delayed::PerformableMethod
|
||||
expect(Delayed::Job.last.payload_object.method_name).to eq(:send_on_create_confirmation_instructions_without_delay)
|
||||
end
|
||||
|
||||
context "with the the same email as existing customers" do
|
||||
let(:email) { Faker::Internet.email }
|
||||
let!(:customer1) { create(:customer, user: nil, email: email) }
|
||||
let!(:customer2) { create(:customer, user: nil, email: email) }
|
||||
let!(:user) { create(:user, email: email) }
|
||||
|
||||
it "should associate these customers with the created user" do
|
||||
expect(user.customers.reload).to include customer1, customer2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "confirming email" do
|
||||
|
||||
Reference in New Issue
Block a user