Permalink
Browse files

have_sent_email integration tests pass

  • Loading branch information...
1 parent 68ac6ae commit cf1406b9e5ef0c3c8ea4798b19bf9361391b2ae5 Chad Pytel committed Jun 11, 2010
@@ -7,6 +7,7 @@ module Unit
class TestCase
include Shoulda::ActionMailer::Assertions
include Shoulda::ActionMailer::Matchers
+ extend Shoulda::ActionMailer::Matchers
end
end
end
@@ -0,0 +1,23 @@
+# Settings specified here will take precedence over those in config/environment.rb
+
+# The test environment is used exclusively to run your application's
+# test suite. You never need to work with it otherwise. Remember that
+# your test database is "scratch space" for the test suite and is wiped
+# and recreated between test runs. Don't rely on the data there!
+config.cache_classes = true
+
+# Log error messages when you accidentally call methods on nil.
+config.whiny_nils = true
+
+# Show full error reports and disable caching
+config.action_controller.consider_all_requests_local = true
+config.action_controller.perform_caching = false
+config.action_view.cache_template_loading = true
+
+# Disable request forgery protection in test environment
+config.action_controller.allow_forgery_protection = false
+
+# Tell Action Mailer not to deliver emails to the real world.
+# The :test delivery method accumulates sent emails in the
+# ActionMailer::Base.deliveries array.
+config.action_mailer.delivery_method = :test
@@ -1,3 +1,11 @@
class Flea < ActiveRecord::Base
has_and_belongs_to_many :dogs
+
+ after_create :send_notification
+
+ private
+
+ def send_notification
+ Notifier.the_email.deliver
+ end
end
@@ -0,0 +1,8 @@
+class Notifier < ActionMailer::Base
+ def the_email
+ from "do-not-reply@example.com"
+ recipients "myself@me.com"
+ subject "This is spam"
+ body :body => "Every email is spam."
+ end
+end
@@ -0,0 +1 @@
+<%= @body %>
View
@@ -3,6 +3,12 @@
class FleaTest < ActiveSupport::TestCase
should_have_and_belong_to_many :dogs
- should have_sent_email.to('myself@me.com')
+ context "when a flea is created" do
+ setup do
+ Flea.create
+ end
+
+ should have_sent_email.to('myself@me.com')
+ end
end

0 comments on commit cf1406b

Please sign in to comment.