diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-06-16 06:17:51 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-06-16 06:17:51 +0000 |
commit | 43c470fae468ef63e0d5c3dc1e202925685fd47b (patch) | |
tree | 6d18896eb8a8bf0eeb7286259568558dcdcb23e1 /actionpack/test | |
parent | 70757cb2730b5e28085e97101d0f7a7538fac799 (diff) | |
download | rails-43c470fae468ef63e0d5c3dc1e202925685fd47b.tar.gz rails-43c470fae468ef63e0d5c3dc1e202925685fd47b.tar.bz2 rails-43c470fae468ef63e0d5c3dc1e202925685fd47b.zip |
Added button_to as a form-based solution to deal with harmful actions that should be hidden behind POSTs. This makes it just as easy as link_to to create a safe trigger for actions like destroy, although it's limited by being a block element, the fixed look, and a no-no inside other forms. #1371 [tom@moertel.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1437 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/template/url_helper_test.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index b1f2dd65e9..f208466118 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -21,6 +21,28 @@ class UrlHelperTest < Test::Unit::TestCase end # todo: missing test cases + def test_button_to_with_straight_url + assert_equal "<form method=\"post\" action=\"http://www.example.com\" class=\"button-to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com") + end + + def test_button_to_with_javascript_confirm + assert_equal( + "<form method=\"post\" action=\"http://www.example.com\" class=\"button-to\"><div><input onclick=\"return confirm('Are you sure?');\" type=\"submit\" value=\"Hello\" /></div></form>", + button_to("Hello", "http://www.example.com", :confirm => "Are you sure?") + ) + end + + def test_button_to_enabled_disabled + assert_equal( + "<form method=\"post\" action=\"http://www.example.com\" class=\"button-to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", + button_to("Hello", "http://www.example.com", :disabled => false) + ) + assert_equal( + "<form method=\"post\" action=\"http://www.example.com\" class=\"button-to\"><div><input disabled=\"disabled\" type=\"submit\" value=\"Hello\" /></div></form>", + button_to("Hello", "http://www.example.com", :disabled => true) + ) + end + def test_link_tag_with_straight_url assert_equal "<a href=\"http://www.example.com\">Hello</a>", link_to("Hello", "http://www.example.com") end |