Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #2918 from akaspick/assert_select_email_fix_3_0

assert_select_email fix for 3-0-stable
  • Loading branch information...
commit 3a3344a456bf988c8b61d0a02a3296726b82c6d2 2 parents 9ef9f98 + c7f3429
Jon Leighton jonleighton authored
7 actionpack/CHANGELOG
View
@@ -1,4 +1,9 @@
-*Rails 3.0.10 (unreleased)*
+*Rails 3.0.11 (unreleased)*
+
+* Fix assert_select_email to work on multipart and non-multipart emails as the method stopped working correctly in Rails 3.x due to changes in the new mail gem.
+
+
+*Rails 3.0.10 (August 31, 2011)*
* Fixes an issue where cache sweepers with only after filters would have no
controller object, it would raise undefined method controller_name for nil [jeroenj]
4 actionpack/lib/action_dispatch/testing/assertions/selector.rb
View
@@ -569,9 +569,9 @@ def assert_select_email(&block)
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
19 actionpack/test/controller/assert_select_test.rb
View
@@ -22,6 +22,15 @@ def test(html)
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
@@ -724,6 +733,16 @@ def test_assert_select_email
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
Please sign in to comment.
Something went wrong with that request. Please try again.