Skip to content

Commit 9dc57fe

Browse files
committed
Deprecate link_to_function and button_to_function helpers
1 parent 6b8a3a0 commit 9dc57fe

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

actionpack/lib/action_view/helpers/javascript_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def javascript_cdata_section(content) #:nodoc:
8282
# # => <input class="ok" onclick="alert('Hello world!');" type="button" value="Greeting" />
8383
#
8484
def button_to_function(name, function=nil, html_options={})
85+
ActiveSupport::Deprecation.warn("button_to_function is deprecated and will be removed from Rails 4.0")
86+
8587
onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function};"
8688

8789
tag(:input, html_options.merge(:type => 'button', :value => name, :onclick => onclick))
@@ -100,6 +102,8 @@ def button_to_function(name, function=nil, html_options={})
100102
# # => <a class="nav_link" href="#" onclick="alert('Hello world!'); return false;">Greeting</a>
101103
#
102104
def link_to_function(name, function, html_options={})
105+
ActiveSupport::Deprecation.warn("link_to_function is deprecated and will be removed from Rails 4.0")
106+
103107
onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;"
104108
href = html_options[:href] || '#'
105109

actionpack/test/template/javascript_helper_test.rb

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,45 @@ def test_escape_javascript_with_safebuffer
4646
end
4747

4848
def test_button_to_function
49-
assert_dom_equal %(<input type="button" onclick="alert('Hello world!');" value="Greeting" />),
50-
button_to_function("Greeting", "alert('Hello world!')")
49+
assert_deprecated "button_to_function is deprecated and will be removed from Rails 4.0" do
50+
assert_dom_equal %(<input type="button" onclick="alert('Hello world!');" value="Greeting" />),
51+
button_to_function("Greeting", "alert('Hello world!')")
52+
end
5153
end
5254

5355
def test_button_to_function_with_onclick
54-
assert_dom_equal "<input onclick=\"alert('Goodbye World :('); alert('Hello world!');\" type=\"button\" value=\"Greeting\" />",
55-
button_to_function("Greeting", "alert('Hello world!')", :onclick => "alert('Goodbye World :(')")
56+
assert_deprecated "button_to_function is deprecated and will be removed from Rails 4.0" do
57+
assert_dom_equal "<input onclick=\"alert('Goodbye World :('); alert('Hello world!');\" type=\"button\" value=\"Greeting\" />",
58+
button_to_function("Greeting", "alert('Hello world!')", :onclick => "alert('Goodbye World :(')")
59+
end
5660
end
5761

5862
def test_button_to_function_without_function
59-
assert_dom_equal "<input onclick=\";\" type=\"button\" value=\"Greeting\" />",
60-
button_to_function("Greeting")
63+
assert_deprecated "button_to_function is deprecated and will be removed from Rails 4.0" do
64+
assert_dom_equal "<input onclick=\";\" type=\"button\" value=\"Greeting\" />",
65+
button_to_function("Greeting")
66+
end
6167
end
6268

6369
def test_link_to_function
64-
assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); return false;">Greeting</a>),
65-
link_to_function("Greeting", "alert('Hello world!')")
70+
assert_deprecated "link_to_function is deprecated and will be removed from Rails 4.0" do
71+
assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); return false;">Greeting</a>),
72+
link_to_function("Greeting", "alert('Hello world!')")
73+
end
6674
end
6775

6876
def test_link_to_function_with_existing_onclick
69-
assert_dom_equal %(<a href="#" onclick="confirm('Sanity!'); alert('Hello world!'); return false;">Greeting</a>),
70-
link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')")
77+
assert_deprecated "link_to_function is deprecated and will be removed from Rails 4.0" do
78+
assert_dom_equal %(<a href="#" onclick="confirm('Sanity!'); alert('Hello world!'); return false;">Greeting</a>),
79+
link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')")
80+
end
7181
end
7282

7383
def test_function_with_href
74-
assert_dom_equal %(<a href="http://example.com/" onclick="alert('Hello world!'); return false;">Greeting</a>),
75-
link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/')
84+
assert_deprecated "link_to_function is deprecated and will be removed from Rails 4.0" do
85+
assert_dom_equal %(<a href="http://example.com/" onclick="alert('Hello world!'); return false;">Greeting</a>),
86+
link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/')
87+
end
7688
end
7789

7890
def test_javascript_tag

0 commit comments

Comments
 (0)