diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 61506421b..990bd335a 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -2,6 +2,11 @@ class Users::RegistrationsController < Devise::RegistrationsController # before_filter :configure_sign_up_params, only: [:create] # before_filter :configure_account_update_params, only: [:update] + def after_sign_up_path_for(resource_or_scope) + WelcomeMailer.welcome_email(User.last).deliver_now! + super + end + # GET /resource/sign_up # def new # super @@ -9,9 +14,7 @@ class Users::RegistrationsController < Devise::RegistrationsController # POST /resource def create - retour = super - WelcomeMailer.welcome_email(User.last).deliver_now! - retour + super end # GET /resource/edit diff --git a/spec/controllers/users/registrations_controller_spec.rb b/spec/controllers/users/registrations_controller_spec.rb index fe1f70b5d..cca9d229e 100644 --- a/spec/controllers/users/registrations_controller_spec.rb +++ b/spec/controllers/users/registrations_controller_spec.rb @@ -5,7 +5,7 @@ describe Users::RegistrationsController, type: :controller do let(:email) { 'test@octo.com' } let(:password) { 'password' } - let(:user) { { email: email, password: password, password_confirmation: password } } + let(:user) { {email: email, password: password, password_confirmation: password} } before do @request.env["devise.mapping"] = Devise.mappings[:user] @@ -14,13 +14,25 @@ describe Users::RegistrationsController, type: :controller do describe '.create' do subject { post :create, user: user } - it { expect(described_class).to be < Devise::RegistrationsController } + context 'when user is correct' do + it { expect(described_class).to be < Devise::RegistrationsController } - it 'welcome email is send' do - expect(WelcomeMailer).to receive(:welcome_email).and_return(WelcomeMailer) - expect(WelcomeMailer).to receive(:deliver_now!) + it 'welcome email is send' do + expect(WelcomeMailer).to receive(:welcome_email).and_return(WelcomeMailer) + expect(WelcomeMailer).to receive(:deliver_now!) - subject + subject + end + end + + context 'when user is not correct' do + let(:user) { {email: '', password: password, password_confirmation: password} } + + it 'welcome email is not send' do + expect(WelcomeMailer).not_to receive(:welcome_email) + + subject + end end end end