From 34d693b8007a3ae85d31435278dfbc2001f50342 Mon Sep 17 00:00:00 2001 From: Paco Guzman Date: Mon, 28 Jun 2010 12:15:24 +0200 Subject: [PATCH] Added data-disable-with to button_to helper --- actionpack/lib/action_view/helpers/url_helper.rb | 11 +++++++-- actionpack/test/template/url_helper_test.rb | 25 ++++++++++++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 6af11e6..23e92ee 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -601,15 +601,16 @@ module ActionView html_options['data-remote'] = 'true' end - confirm = html_options.delete("confirm") - if html_options.key?("popup") ActiveSupport::Deprecation.warn(":popup has been deprecated", caller) end - method, href = html_options.delete("method"), html_options['href'] + confirm = html_options.delete("confirm") + disable_with = html_options.delete("disable_with") + method = html_options.delete("method") add_confirm_to_attributes!(html_options, confirm) if confirm + add_disable_with_to_attributes!(html_options, disable_with) if disable_with add_method_to_attributes!(html_options, method) if method html_options @@ -619,6 +620,10 @@ module ActionView html_options["data-confirm"] = confirm if confirm end + def add_disable_with_to_attributes!(html_options, disable_with) + html_options["data-disable-with"] = disable_with if disable_with + end + def add_method_to_attributes!(html_options, method) html_options["rel"] = "nofollow" if method && method.to_s.downcase != "get" html_options["data-method"] = method if method diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 72d4897..6679f53 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -96,6 +96,13 @@ class UrlHelperTest < ActiveSupport::TestCase ) end + def test_button_to_with_javascript_disable_with + assert_dom_equal( + "
", + button_to("Hello", "http://www.example.com", :disable_with => "Greeting...") + ) + end + def test_button_to_with_remote_and_javascript_confirm assert_dom_equal( "
", @@ -103,6 +110,20 @@ class UrlHelperTest < ActiveSupport::TestCase ) end + def test_button_to_with_remote_and_javascript_disable_with + assert_dom_equal( + "
", + button_to("Hello", "http://www.example.com", :remote => true, :disable_with => "Greeting...") + ) + end + + def test_button_to_with_remote_and_javascript_confirm_and_javascript_disable_with + assert_dom_equal( + "
", + button_to("Hello", "http://www.example.com", :remote => true, :confirm => "Are you sure?", :disable_with => "Greeting...") + ) + end + def test_button_to_with_remote_false assert_dom_equal( "
", @@ -650,10 +671,10 @@ class PolymorphicControllerTest < ActionController::TestCase get :index, :workshop_id => 1 assert_equal "/workshops/1/sessions\nSession", @response.body end - + def test_existing_nested_resource @controller = SessionsController.new - + get :show, :workshop_id => 1, :id => 1 assert_equal "/workshops/1/sessions/1\nSession", @response.body end -- 1.7.0.4