Don't email omniauth created users
This commit is contained in:
parent
560b1ac5f3
commit
cb2be3ce0a
2 changed files with 13 additions and 4 deletions
|
@ -1,9 +1,10 @@
|
||||||
class UserObserver < ActiveRecord::Observer
|
class UserObserver < ActiveRecord::Observer
|
||||||
def after_create(user)
|
def after_create(user)
|
||||||
log_info("User \"#{user.name}\" (#{user.email}) was created")
|
log_info("User \"#{user.name}\" (#{user.email}) was created")
|
||||||
|
unless user.extern_uid?
|
||||||
Notify.new_user_email(user.id, user.password).deliver
|
Notify.new_user_email(user.id, user.password).deliver
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def after_destroy user
|
def after_destroy user
|
||||||
log_info("User \"#{user.name}\" (#{user.email}) was removed")
|
log_info("User \"#{user.name}\" (#{user.email}) was removed")
|
||||||
|
|
|
@ -13,17 +13,25 @@ describe UserObserver do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when a new user is created' do
|
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 }
|
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)
|
notification.should_receive(:deliver)
|
||||||
Notify.should_receive(:new_user_email).with(user.id, user.password).and_return(notification)
|
Notify.should_receive(:new_user_email).with(user.id, user.password).and_return(notification)
|
||||||
|
|
||||||
subject.after_create(user)
|
subject.after_create(user)
|
||||||
end
|
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
|
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)
|
Gitlab::AppLogger.should_receive(:info)
|
||||||
subject.after_create(user)
|
subject.after_create(user)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue