aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test/assert_select_email_test.rb
diff options
context:
space:
mode:
authorTimm <kaspth@gmail.com>2013-10-10 22:11:44 +0200
committerTimm <kaspth@gmail.com>2014-06-16 21:04:17 +0200
commit94ca27b1905b7865a520030e7601b2e5d1bc72cb (patch)
tree91fbc5a24eb1f703a0b68f1f735d932d7af2a11d /actionmailer/test/assert_select_email_test.rb
parentfa916af69626ac405e0f71bd4edf9c64159e61a3 (diff)
downloadrails-94ca27b1905b7865a520030e7601b2e5d1bc72cb.tar.gz
rails-94ca27b1905b7865a520030e7601b2e5d1bc72cb.tar.bz2
rails-94ca27b1905b7865a520030e7601b2e5d1bc72cb.zip
Added rails-dom-testing and rails-html-sanitizer to Gemfile. Added tests for assert_select_email.
Diffstat (limited to 'actionmailer/test/assert_select_email_test.rb')
-rw-r--r--actionmailer/test/assert_select_email_test.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/actionmailer/test/assert_select_email_test.rb b/actionmailer/test/assert_select_email_test.rb
new file mode 100644
index 0000000000..c1a03ac5a3
--- /dev/null
+++ b/actionmailer/test/assert_select_email_test.rb
@@ -0,0 +1,63 @@
+require 'abstract_unit'
+require 'rails-dom-testing'
+
+class AssertSelectEmailTest < ActionMailer::TestCase
+ Assertion = ActiveSupport::TestCase::Assertion
+
+ 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 setup
+ @response = FakeResponse.new(:html, 'some body text')
+ end
+
+ def test_assert_select_email
+ assert_raise(Assertion) { assert_select_email {} }
+ 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
+
+ protected
+
+ class FakeResponse
+ attr_accessor :content_type, :body
+
+ def initialize(content_type, body)
+ @content_type, @body = content_type, body
+ end
+ end
+end \ No newline at end of file