user_observer_spec.rb 776 Bytes
Newer Older
1 2 3
require 'spec_helper'

describe UserObserver do
4
  before(:each) { enable_observers }
5
  after(:each) {disable_observers}
6
  subject { UserObserver.instance }
7
  before { subject.stub(notification: mock('NotificationService').as_null_object) }
8 9

  it 'calls #after_create when new users are created' do
10
    new_user = build(:user)
11
    subject.should_receive(:after_create).with(new_user)
12
    new_user.save
13 14 15 16
  end

  context 'when a new user is created' do
    it 'sends an email' do
17
      subject.should_receive(:notification)
18
      create(:user)
19
    end
randx's avatar
randx committed
20 21

    it 'trigger logger' do
22
      user = double(:user, id: 42, password: 'P@ssword!', name: 'John', email: 'u@mail.local', extern_uid?: false)
randx's avatar
randx committed
23
      Gitlab::AppLogger.should_receive(:info)
24
      create(:user)
randx's avatar
randx committed
25
    end
26 27
  end
end