From cb2be3ce0ab27ac9aa25f0c3eb59047ad5a0153a Mon Sep 17 00:00:00 2001 From: Gabor Liptak Date: Wed, 19 Sep 2012 13:36:00 -0500 Subject: [PATCH 1/2] Don't email omniauth created users --- app/observers/user_observer.rb | 5 +++-- spec/observers/user_observer_spec.rb | 12 ++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/observers/user_observer.rb b/app/observers/user_observer.rb index 654621f7..aed320f6 100644 --- a/app/observers/user_observer.rb +++ b/app/observers/user_observer.rb @@ -1,8 +1,9 @@ class UserObserver < ActiveRecord::Observer def after_create(user) log_info("User \"#{user.name}\" (#{user.email}) was created") - - Notify.new_user_email(user.id, user.password).deliver + unless user.extern_uid? + Notify.new_user_email(user.id, user.password).deliver + end end def after_destroy user diff --git a/spec/observers/user_observer_spec.rb b/spec/observers/user_observer_spec.rb index 0420a250..8ce0b577 100644 --- a/spec/observers/user_observer_spec.rb +++ b/spec/observers/user_observer_spec.rb @@ -13,17 +13,25 @@ describe UserObserver do end context 'when a new user is created' do - let(:user) { double(:user, id: 42, password: 'P@ssword!', name: 'John', email: 'u@mail.local') } let(:notification) { double :notification } - it 'sends an email' do + it 'sends an email unless external' do + user = double(:user, id: 42, password: 'P@ssword!', name: 'John', email: 'u@mail.local', extern_uid?: false) notification.should_receive(:deliver) Notify.should_receive(:new_user_email).with(user.id, user.password).and_return(notification) subject.after_create(user) end + it 'no email for external' do + user = double(:user, id: 42, password: 'P@ssword!', name: 'John', email: 'u@mail.local', extern_uid?: true) + Notify.should_not_receive(:new_user_email) + + subject.after_create(user) + end + it 'trigger logger' do + user = double(:user, id: 42, password: 'P@ssword!', name: 'John', email: 'u@mail.local', extern_uid?: false) Gitlab::AppLogger.should_receive(:info) subject.after_create(user) end From 2d2a235c06fea4a1dba50da19eb3a98d9ea975a2 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 5 Mar 2013 16:50:37 +0200 Subject: [PATCH 2/2] fixed omniauth email spec --- spec/observers/user_observer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/observers/user_observer_spec.rb b/spec/observers/user_observer_spec.rb index dd7d88fa..b58c5647 100644 --- a/spec/observers/user_observer_spec.rb +++ b/spec/observers/user_observer_spec.rb @@ -16,7 +16,7 @@ describe UserObserver do end it 'no email for external' do - Notify.should_receive(:new_user_email) + Notify.should_not_receive(:new_user_email) create(:user, extern_uid: '32442eEfsafada') end