提交 60d358b2 编写于 作者: A Andrew Kaspick

fix assert_select_email to work on non-multipart emails as well as converting...

fix assert_select_email to work on non-multipart emails as well as converting the Mail::Body to a string to prevent errors.
上级 e6fdfd0f
...@@ -415,9 +415,9 @@ def assert_select_email(&block) ...@@ -415,9 +415,9 @@ def assert_select_email(&block)
assert !deliveries.empty?, "No e-mail in delivery list" assert !deliveries.empty?, "No e-mail in delivery list"
for delivery in deliveries for delivery in deliveries
for part in delivery.parts for part in (delivery.parts.empty? ? [delivery] : delivery.parts)
if part["Content-Type"].to_s =~ /^text\/html\W/ if part["Content-Type"].to_s =~ /^text\/html\W/
root = HTML::Document.new(part.body).root root = HTML::Document.new(part.body.to_s).root
assert_select root, ":root", &block assert_select root, ":root", &block
end end
end end
......
...@@ -20,6 +20,15 @@ def test(html) ...@@ -20,6 +20,15 @@ def test(html)
end end
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
class AssertSelectController < ActionController::Base class AssertSelectController < ActionController::Base
def response_with=(content) def response_with=(content)
@content = content @content = content
...@@ -313,6 +322,16 @@ def test_assert_select_email ...@@ -313,6 +322,16 @@ def test_assert_select_email
end 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 protected
def render_html(html) def render_html(html)
@controller.response_with = html @controller.response_with = html
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册