diff options
author | Robb Kidd <robb@thekidds.org> | 2012-06-12 22:27:03 +0400 |
---|---|---|
committer | Robb Kidd <robb@thekidds.org> | 2012-06-20 22:09:46 +0400 |
commit | dfb5da9da339096ad0a8e754f4f42ca2007b5ae6 (patch) | |
tree | 3d5464ebdcf31bd3bc3cf44a35e072aa1cde3849 /spec/requests/admin | |
parent | 5303cc285a2067b59f1e8b68f707e8dbf90fe59e (diff) |
Disable observers in specs. Enable only when observer is under test.
Used the built-in observer enable/disable feature in ActiveModel[1].
ActiveRecord::Base includes ActiveModel::Observing which provides this
behavior.
Simple wraps to enable the observer under test were added to the specs
for: ActivityObserver, IssueObserver, Admin::Users and Issues.
The spec for Project.last_activity was refactored to separate the tests
for #last_activity and #last_activity_date. Each had doubles added to
isolate the spec from the hidden dependency on the ActivityObserver
action to create an Event for the project when an Issue is created. This
ActivityObserver behavior is already tested by its spec.
[1] http://api.rubyonrails.org/classes/ActiveModel/ObserverArray.html
Diffstat (limited to 'spec/requests/admin')
-rw-r--r-- | spec/requests/admin/admin_users_spec.rb | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/spec/requests/admin/admin_users_spec.rb b/spec/requests/admin/admin_users_spec.rb index c98ed2cf6db..d9c3472d7e3 100644 --- a/spec/requests/admin/admin_users_spec.rb +++ b/spec/requests/admin/admin_users_spec.rb @@ -40,19 +40,23 @@ describe "Admin::Users" do end it "should call send mail" do - Notify.should_receive(:new_user_email).and_return(stub(:deliver => true)) - click_button "Save" + User.observers.enable :mailer_observer do + Notify.should_receive(:new_user_email).and_return(stub(:deliver => true)) + click_button "Save" + end end it "should send valid email to user with email & password" do - with_resque do - click_button "Save" + User.observers.enable :mailer_observer do + with_resque do + click_button "Save" + end + user = User.last + email = ActionMailer::Base.deliveries.last + email.subject.should have_content("Account was created") + email.body.should have_content(user.email) + email.body.should have_content(@password) end - user = User.last - email = ActionMailer::Base.deliveries.last - email.subject.should have_content("Account was created") - email.body.should have_content(user.email) - email.body.should have_content(@password) end end |