Skip to content

Instantly share code, notes, and snippets.

@tcaddy
Created November 18, 2011 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcaddy/1377322 to your computer and use it in GitHub Desktop.
Save tcaddy/1377322 to your computer and use it in GitHub Desktop.
assert_template in Rails3 mailer test
class SomeMailerTest < ActionMailer::TestCase
# include this so that assert_template is defined
include ActionController::TemplateAssertions
end
class SomeMailerTest < ActionMailer::TestCase
test "the mailer" do
email = SomeMailer.the_mailer.deliver
assert_template :partial=>'_the_mailer_partial'
end
private
def validate_request!
# this method is added so that assert_template will work
#
# overrides method defined in ActionDispatch::Assertions::ResponseAssertions
# even if you include that module to work around NoMethodError, it won't work b/c @response isn't
# an ActionDispatch::Request object
end
end
@tcaddy
Copy link
Author

tcaddy commented Nov 18, 2011

I had a hard time writing test coverage for a mailer that used a partial template, b/c assert_template doesn't work out-of-the-box in ActionMailer::TestCase.

I hope this saves other people some time and research.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment