2012-06-20 18:29:10 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe UserObserver do
|
|
|
|
subject { UserObserver.instance }
|
|
|
|
|
|
|
|
it 'calls #after_create when new users are created' do
|
2012-11-06 04:31:55 +01:00
|
|
|
new_user = build(:user)
|
2012-06-20 18:29:10 +02:00
|
|
|
subject.should_receive(:after_create).with(new_user)
|
|
|
|
|
|
|
|
User.observers.enable :user_observer do
|
|
|
|
new_user.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a new user is created' do
|
2012-11-23 21:25:28 +01:00
|
|
|
let(:user) { double(:user, id: 42,
|
|
|
|
password: 'P@ssword!',
|
|
|
|
name: 'John',
|
|
|
|
email: 'u@mail.local',
|
|
|
|
username: 'root',
|
|
|
|
create_namespace: true) }
|
2012-06-20 18:29:10 +02:00
|
|
|
let(:notification) { double :notification }
|
|
|
|
|
|
|
|
it 'sends an email' do
|
|
|
|
notification.should_receive(:deliver)
|
|
|
|
Notify.should_receive(:new_user_email).with(user.id, user.password).and_return(notification)
|
|
|
|
|
|
|
|
subject.after_create(user)
|
|
|
|
end
|
2012-09-12 08:05:12 +02:00
|
|
|
|
|
|
|
it 'trigger logger' do
|
|
|
|
Gitlab::AppLogger.should_receive(:info)
|
|
|
|
subject.after_create(user)
|
|
|
|
end
|
2012-06-20 18:29:10 +02:00
|
|
|
end
|
|
|
|
end
|