summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorRobb Kidd <robb@thekidds.org>2012-06-20 12:29:10 -0400
committerRobb Kidd <robb@thekidds.org>2012-06-20 14:09:46 -0400
commit88964132edaec721e256449579c032ca731781bc (patch)
tree0c45a6ebb3bfe74f3f5b711974353541b9c2dccf /spec
parent97ca4f5ddadd9f6880e238e85af00a82dcd8807f (diff)
downloadgitlab-ce-88964132edaec721e256449579c032ca731781bc.tar.gz
Extract observation of User to a UserObserver
Diffstat (limited to 'spec')
-rw-r--r--spec/models/user_observer_spec.rb26
-rw-r--r--spec/requests/admin/admin_users_spec.rb7
2 files changed, 30 insertions, 3 deletions
diff --git a/spec/models/user_observer_spec.rb b/spec/models/user_observer_spec.rb
new file mode 100644
index 00000000000..23dac98bb74
--- /dev/null
+++ b/spec/models/user_observer_spec.rb
@@ -0,0 +1,26 @@
+require 'spec_helper'
+
+describe UserObserver do
+ subject { UserObserver.instance }
+
+ it 'calls #after_create when new users are created' do
+ new_user = Factory.new(:user)
+ 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
+ let(:user) { double(:user, id: 42, password: 'P@ssword!') }
+ 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
+ end
+end
diff --git a/spec/requests/admin/admin_users_spec.rb b/spec/requests/admin/admin_users_spec.rb
index d9c3472d7e3..ba6831e3d8b 100644
--- a/spec/requests/admin/admin_users_spec.rb
+++ b/spec/requests/admin/admin_users_spec.rb
@@ -40,14 +40,15 @@ describe "Admin::Users" do
end
it "should call send mail" do
- User.observers.enable :mailer_observer do
- Notify.should_receive(:new_user_email).and_return(stub(:deliver => true))
+ Notify.should_receive(:new_user_email).and_return(stub(:deliver => true))
+
+ User.observers.enable :user_observer do
click_button "Save"
end
end
it "should send valid email to user with email & password" do
- User.observers.enable :mailer_observer do
+ User.observers.enable :user_observer do
with_resque do
click_button "Save"
end