Skip to content
This repository
Browse code

Deprecate link_to_function and button_to_function helpers

  • Loading branch information...
commit 9dc57fe9c4807fc0ad4b1590a931891d9faa3164 1 parent 6b8a3a0
Rafael Mendonça França authored April 21, 2012
4  actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -82,6 +82,8 @@ def javascript_cdata_section(content) #:nodoc:
82 82
       #   # => <input class="ok" onclick="alert('Hello world!');" type="button" value="Greeting" />
83 83
       #
84 84
       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
+
85 87
         onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function};"
86 88
 
87 89
         tag(:input, html_options.merge(:type => 'button', :value => name, :onclick => onclick))
@@ -100,6 +102,8 @@ def button_to_function(name, function=nil, html_options={})
100 102
       #   # => <a class="nav_link" href="#" onclick="alert('Hello world!'); return false;">Greeting</a>
101 103
       #
102 104
       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
+
103 107
         onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;"
104 108
         href = html_options[:href] || '#'
105 109
 
36  actionpack/test/template/javascript_helper_test.rb
@@ -46,33 +46,45 @@ def test_escape_javascript_with_safebuffer
46 46
   end
47 47
 
48 48
   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
51 53
   end
52 54
 
53 55
   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
56 60
   end
57 61
 
58 62
   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
61 67
   end
62 68
 
63 69
   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
66 74
   end
67 75
 
68 76
   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
71 81
   end
72 82
 
73 83
   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
76 88
   end
77 89
 
78 90
   def test_javascript_tag

0 notes on commit 9dc57fe

Please sign in to comment.
Something went wrong with that request. Please try again.