Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert_select_email fix for 3-0-stable #2918

Merged
merged 3 commits into from
Sep 7, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion actionpack/CHANGELOG
Original file line number Original file line Diff line number Diff line change
@@ -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 * 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] controller object, it would raise undefined method controller_name for nil [jeroenj]
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/testing/assertions/selector.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -569,9 +569,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be split into two lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could, but this has already been pulled into master with the current style and I don't see much point in deviating from the other branches if it's not really necessary.

I assume you're looking for something like...
parts = delivery.parts.empty? ? [delivery] : delivery.parts
for part in parts...

If this really needs to be changed, then I'll make another commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it would be better assigned to an ivar on a separate line, but I don't find it so offensive that I think it's worth deviating given I already applied to master.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But please feel free to refactor on master :)

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
Expand Down
19 changes: 19 additions & 0 deletions actionpack/test/controller/assert_select_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,6 +22,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
Expand Down Expand Up @@ -724,6 +733,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
Expand Down