Commit cb2be3ce0ab27ac9aa25f0c3eb59047ad5a0153a
1 parent
560b1ac5
Exists in
master
and in
4 other branches
Don't email omniauth created users
Showing
2 changed files
with
13 additions
and
4 deletions
Show diff stats
app/observers/user_observer.rb
| 1 | 1 | class UserObserver < ActiveRecord::Observer |
| 2 | 2 | def after_create(user) |
| 3 | 3 | log_info("User \"#{user.name}\" (#{user.email}) was created") |
| 4 | - | |
| 5 | - Notify.new_user_email(user.id, user.password).deliver | |
| 4 | + unless user.extern_uid? | |
| 5 | + Notify.new_user_email(user.id, user.password).deliver | |
| 6 | + end | |
| 6 | 7 | end |
| 7 | 8 | |
| 8 | 9 | def after_destroy user | ... | ... |
spec/observers/user_observer_spec.rb
| ... | ... | @@ -13,17 +13,25 @@ describe UserObserver do |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | 15 | context 'when a new user is created' do |
| 16 | - let(:user) { double(:user, id: 42, password: 'P@ssword!', name: 'John', email: 'u@mail.local') } | |
| 17 | 16 | let(:notification) { double :notification } |
| 18 | 17 | |
| 19 | - it 'sends an email' do | |
| 18 | + it 'sends an email unless external' do | |
| 19 | + user = double(:user, id: 42, password: 'P@ssword!', name: 'John', email: 'u@mail.local', extern_uid?: false) | |
| 20 | 20 | notification.should_receive(:deliver) |
| 21 | 21 | Notify.should_receive(:new_user_email).with(user.id, user.password).and_return(notification) |
| 22 | 22 | |
| 23 | 23 | subject.after_create(user) |
| 24 | 24 | end |
| 25 | 25 | |
| 26 | + it 'no email for external' do | |
| 27 | + user = double(:user, id: 42, password: 'P@ssword!', name: 'John', email: 'u@mail.local', extern_uid?: true) | |
| 28 | + Notify.should_not_receive(:new_user_email) | |
| 29 | + | |
| 30 | + subject.after_create(user) | |
| 31 | + end | |
| 32 | + | |
| 26 | 33 | it 'trigger logger' do |
| 34 | + user = double(:user, id: 42, password: 'P@ssword!', name: 'John', email: 'u@mail.local', extern_uid?: false) | |
| 27 | 35 | Gitlab::AppLogger.should_receive(:info) |
| 28 | 36 | subject.after_create(user) |
| 29 | 37 | end | ... | ... |