user_observer_spec.rb 998 Bytes
Newer Older
1 2 3 4 5 6
require 'spec_helper'

describe UserObserver do
  subject { UserObserver.instance }

  it 'calls #after_create when new users are created' do
7
    new_user = build(:user)
8 9 10 11 12 13 14 15
    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
16 17 18 19 20 21
    let(:user) { double(:user, id: 42,
                        password: 'P@ssword!',
                        name: 'John',
                        email: 'u@mail.local',
                        username: 'root',
                        create_namespace: true) }
22 23 24 25 26 27 28 29
    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
randx's avatar
randx committed
30 31 32 33 34

    it 'trigger logger' do
      Gitlab::AppLogger.should_receive(:info)
      subject.after_create(user)
    end
35 36
  end
end