aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-07-10 16:52:00 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-07-10 16:52:00 -0300
commit3229eda00c2a38526787fddb6cc307cfee5c5ac6 (patch)
tree9b45bf0c52e5b20ab403a5ac0025b9b1b18a5ce3 /actionmailer
parent6e76031e8f1f815b390f966cb21e25c66e5ded50 (diff)
parentff1b7e75357eb7797f25aeab33994765130db67f (diff)
downloadrails-3229eda00c2a38526787fddb6cc307cfee5c5ac6.tar.gz
rails-3229eda00c2a38526787fddb6cc307cfee5c5ac6.tar.bz2
rails-3229eda00c2a38526787fddb6cc307cfee5c5ac6.zip
Merge pull request #11218 from kaspth/loofah-integration
Loofah-integration Conflicts: actionpack/CHANGELOG.md actionview/CHANGELOG.md
Diffstat (limited to 'actionmailer')
-rw-r--r--actionmailer/lib/action_mailer/test_case.rb5
-rw-r--r--actionmailer/test/assert_select_email_test.rb50
2 files changed, 52 insertions, 3 deletions
diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb
index a5442c0316..9207c1bc56 100644
--- a/actionmailer/lib/action_mailer/test_case.rb
+++ b/actionmailer/lib/action_mailer/test_case.rb
@@ -55,14 +55,13 @@ module ActionMailer
protected
def initialize_test_deliveries
- @old_delivery_method = ActionMailer::Base.delivery_method
+ set_delivery_method :test
@old_perform_deliveries = ActionMailer::Base.perform_deliveries
- ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
end
def restore_test_deliveries
- ActionMailer::Base.delivery_method = @old_delivery_method
+ restore_delivery_method
ActionMailer::Base.perform_deliveries = @old_perform_deliveries
ActionMailer::Base.deliveries.clear
end
diff --git a/actionmailer/test/assert_select_email_test.rb b/actionmailer/test/assert_select_email_test.rb
new file mode 100644
index 0000000000..376d97bdd7
--- /dev/null
+++ b/actionmailer/test/assert_select_email_test.rb
@@ -0,0 +1,50 @@
+require 'abstract_unit'
+require 'rails-dom-testing'
+
+class AssertSelectEmailTest < ActionMailer::TestCase
+ include Rails::Dom::Testing::Assertions::SelectorAssertions
+
+ class AssertSelectMailer < ActionMailer::Base
+ def test(html)
+ mail body: html, content_type: "text/html",
+ subject: "Test e-mail", from: "test@test.host", to: "test <test@test.host>"
+ end
+ end
+
+ class AssertMultipartSelectMailer < ActionMailer::Base
+ def test(options)
+ mail subject: "Test e-mail", from: "test@test.host", to: "test <test@test.host>" do |format|
+ format.text { render text: options[:text] }
+ format.html { render text: options[:html] }
+ end
+ end
+ end
+
+ #
+ # Test assert_select_email
+ #
+
+ def test_assert_select_email
+ assert_raise ActiveSupport::TestCase::Assertion do
+ assert_select_email {}
+ end
+
+ AssertSelectMailer.test("<div><p>foo</p><p>bar</p></div>").deliver
+ assert_select_email do
+ assert_select "div:root" do
+ assert_select "p:first-child", "foo"
+ assert_select "p:last-child", "bar"
+ end
+ end
+ end
+
+ def test_assert_select_email_multipart
+ AssertMultipartSelectMailer.test(html: "<div><p>foo</p><p>bar</p></div>", text: 'foo bar').deliver
+ assert_select_email do
+ assert_select "div:root" do
+ assert_select "p:first-child", "foo"
+ assert_select "p:last-child", "bar"
+ end
+ end
+ end
+end