mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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.
This commit is contained in:
parent
239126385f
commit
f71b075d6c
2 changed files with 12 additions and 1 deletions
|
@ -180,7 +180,11 @@ module ActionView
|
|||
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 @@ class UrlHelperTest < ActiveSupport::TestCase
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue