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

Merge pull request #2499 from akaspick/assert_select_email_fix

Fix assert_select_email to work on non-multipart emails as well as converting the Mail::Body to a string to prevent errors.
This commit is contained in:
Jon Leighton 2011-09-07 05:51:31 -07:00
commit 16f1ce41d5
2 changed files with 21 additions and 2 deletions

View file

@ -415,9 +415,9 @@ module ActionDispatch
assert !deliveries.empty?, "No e-mail in delivery list"
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/
root = HTML::Document.new(part.body).root
root = HTML::Document.new(part.body.to_s).root
assert_select root, ":root", &block
end
end

View file

@ -20,6 +20,15 @@ class AssertSelectTest < ActionController::TestCase
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
def response_with=(content)
@content = content
@ -313,6 +322,16 @@ EOF
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
def render_html(html)
@controller.response_with = html