1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionmailer/test/assert_select_email_test.rb

48 lines
1.3 KiB
Ruby
Raw Normal View History

require 'abstract_unit'
class AssertSelectEmailTest < ActionMailer::TestCase
class AssertSelectMailer < ActionMailer::Base
def test(html)
2014-05-28 05:20:15 -04:00
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)
2014-05-28 05:20:15 -04:00
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
2014-05-28 05:38:22 -04:00
assert_raise ActiveSupport::TestCase::Assertion do
assert_select_email {}
end
AssertSelectMailer.test("<div><p>foo</p><p>bar</p></div>").deliver_now
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_now
assert_select_email do
assert_select "div:root" do
assert_select "p:first-child", "foo"
assert_select "p:last-child", "bar"
end
end
end
2014-05-28 05:20:38 -04:00
end