From 125326438273c2092b6806c6faa9b68fa7712f51 Mon Sep 17 00:00:00 2001 From: Shivam Kumar <76581658+shivamkb17@users.noreply.github.com> Date: Wed, 27 Mar 2024 07:28:45 +0530 Subject: [PATCH] fix: Avoid duplicate invitation emails when adding an agent (#9131) Co-authored-by: Sojan Co-authored-by: Shivam Mishra Co-authored-by: Pranav --- app/builders/agent_builder.rb | 6 ------ spec/builders/agent_builder_spec.rb | 16 ---------------- 2 files changed, 22 deletions(-) diff --git a/app/builders/agent_builder.rb b/app/builders/agent_builder.rb index 07b0e7345..54f478920 100644 --- a/app/builders/agent_builder.rb +++ b/app/builders/agent_builder.rb @@ -16,7 +16,6 @@ class AgentBuilder def perform ActiveRecord::Base.transaction do @user = find_or_create_user - send_confirmation_if_required create_account_user end @user @@ -34,11 +33,6 @@ class AgentBuilder User.create!(email: email, name: name, password: temp_password, password_confirmation: temp_password) end - # Sends confirmation instructions if the user is persisted and not confirmed. - def send_confirmation_if_required - @user.send_confirmation_instructions if user_needs_confirmation? - end - # Checks if the user needs confirmation. # @return [Boolean] true if the user is persisted and not confirmed, false otherwise. def user_needs_confirmation? diff --git a/spec/builders/agent_builder_spec.rb b/spec/builders/agent_builder_spec.rb index 9d7667306..ac8a3229a 100644 --- a/spec/builders/agent_builder_spec.rb +++ b/spec/builders/agent_builder_spec.rb @@ -67,21 +67,5 @@ RSpec.describe AgentBuilder, type: :model do expect(user.encrypted_password).not_to be_empty end end - - context 'with confirmation required' do - let(:unconfirmed_user) { create(:user, email: email) } - - before do - unconfirmed_user.confirmed_at = nil - unconfirmed_user.save(validate: false) - allow(unconfirmed_user).to receive(:confirmed?).and_return(false) - end - - it 'sends confirmation instructions' do - user = agent_builder.perform - expect(user).to receive(:send_confirmation_instructions) - agent_builder.send(:send_confirmation_if_required) - end - end end end