From 2a43c9593c2b28a4da9ef28f4a14eb609cd20391 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Tue, 13 Sep 2011 13:55:23 +0800 Subject: [PATCH] Tracked down a difficult bug with sending emails from a rake task. ActionMailer::Base.smtp_settings needed to be set, not Errbit::Application.config.action_mailer.smtp_settings. --- config/environments/development.rb | 3 ++- config/initializers/_load_config.rb | 3 ++- spec/mailers/mailer_spec.rb | 11 +++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 4a01584..6d118a1 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -15,9 +15,10 @@ Errbit::Application.configure do config.action_controller.perform_caching = false # Don't care if the mailer can't send - config.action_mailer.raise_delivery_errors = false + config.action_mailer.raise_delivery_errors = true config.action_mailer.default_url_options = { :host => 'localhost:3000' } # Print deprecation notices to the Rails logger config.active_support.deprecation = :log end + diff --git a/config/initializers/_load_config.rb b/config/initializers/_load_config.rb index afde4f6..50bee9e 100644 --- a/config/initializers/_load_config.rb +++ b/config/initializers/_load_config.rb @@ -43,7 +43,8 @@ end # Set SMTP settings if given. if smtp = Errbit::Config.smtp_settings - Errbit::Application.config.action_mailer.smtp_settings = smtp + ActionMailer::Base.delivery_method = :smtp + ActionMailer::Base.smtp_settings = smtp end # Set config specific values diff --git a/spec/mailers/mailer_spec.rb b/spec/mailers/mailer_spec.rb index d435da0..a67f5ce 100644 --- a/spec/mailers/mailer_spec.rb +++ b/spec/mailers/mailer_spec.rb @@ -4,16 +4,23 @@ describe Mailer do context "Err Notification" do include EmailSpec::Helpers include EmailSpec::Matchers - Mailer.send :helper, ActionMailer::InlineCssHelper before do @notice = Factory(:notice, :message => "class < ActionController::Base") - @email = Mailer.err_notification(@notice) + @email = Mailer.err_notification(@notice).deliver + end + + it "should send the email" do + ActionMailer::Base.deliveries.size.should == 1 end it "should html-escape the notice's message for the html part" do @email.should have_body_text("class < ActionController::Base") end + + it "should have inline css" do + @email.should have_body_text('