Permalink
Browse files

Fix link_to with block and url_hash

Use link_to with block and url_hash, expect block as name.
But ignore block and use url_hash as name.
3-2-stable passes this test. 4-0-stable and master fail this.
  • Loading branch information...
1 parent 2391263 commit f71b075d6c29447d08193007936f6376779d7bff @sanemat sanemat committed Jul 7, 2013
Showing with 12 additions and 1 deletion.
  1. +5 −1 actionview/lib/action_view/helpers/url_helper.rb
  2. +7 −0 actionview/test/template/url_helper_test.rb
@@ -180,7 +180,11 @@ def link_to(name = nil, options = nil, html_options = nil, &block)
url = url_for(options)
html_options['href'] ||= url
- content_tag(:a, name || url, html_options, &block)
+ if block_given?
+ content_tag(:a, capture(&block) || url, html_options)
+ else
+ content_tag(:a, name || url, html_options)
+ end
end
# Generates a form containing a single button that submits to the URL created
@@ -308,6 +308,13 @@ def test_link_tag_with_block_and_html_options
link_to('/', class: "special") { content_tag(:span, 'Example site') }
end
+ def test_link_tag_using_block_and_hash
+ assert_dom_equal(
+ %{<a href="/"><span>Example site</span></a>},
+ link_to(url_hash) { content_tag(:span, 'Example site') }
+ )
+ end
+
def test_link_tag_using_block_in_erb
out = render_erb %{<%= link_to('/') do %>Example site<% end %>}
assert_equal '<a href="/">Example site</a>', out

0 comments on commit f71b075

Please sign in to comment.