2017-07-23 11:17:16 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:03:39 -04:00
|
|
|
require "abstract_unit"
|
2013-10-10 16:11:44 -04:00
|
|
|
|
|
|
|
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>"
|
2013-10-10 16:11:44 -04:00
|
|
|
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|
|
2016-05-21 08:49:38 -04:00
|
|
|
format.text { render plain: options[:text] }
|
|
|
|
format.html { render plain: options[:html] }
|
2013-10-10 16:11:44 -04:00
|
|
|
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
|
2018-09-25 13:18:20 -04:00
|
|
|
assert_select_email { }
|
2014-05-28 05:38:22 -04:00
|
|
|
end
|
|
|
|
|
2014-08-20 04:34:57 -04:00
|
|
|
AssertSelectMailer.test("<div><p>foo</p><p>bar</p></div>").deliver_now
|
2013-10-10 16:11:44 -04:00
|
|
|
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
|
2016-08-06 13:03:39 -04:00
|
|
|
AssertMultipartSelectMailer.test(html: "<div><p>foo</p><p>bar</p></div>", text: "foo bar").deliver_now
|
2013-10-10 16:11:44 -04:00
|
|
|
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
|