forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor button_to helper to use token_tag method
- Loading branch information
1 parent
423b262
commit 0470979
Showing
4 changed files
with
34 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,9 @@ class UrlHelperTest < ActiveSupport::TestCase | |
# In those cases, we'll set up a simple mock | ||
attr_accessor :controller, :request | ||
|
||
cattr_accessor :request_forgery | ||
self.request_forgery = false | ||
|
||
routes = ActionDispatch::Routing::RouteSet.new | ||
routes.draw do | ||
match "/" => "foo#bar" | ||
|
@@ -49,11 +52,22 @@ def test_url_for_with_back_and_no_referer | |
assert_equal 'javascript:history.back()', url_for(:back) | ||
end | ||
|
||
# todo: missing test cases | ||
# TODO: missing test cases | ||
def test_button_to_with_straight_url | ||
assert_dom_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_straight_url_and_request_forgery | ||
self.request_forgery = true | ||
|
||
assert_dom_equal( | ||
%{<form method="post" action="http://www.example.com" class="button_to"><div><input type="submit" value="Hello" /><input name="form_token" type="hidden" value="secret" /></div></form>}, | ||
button_to("Hello", "http://www.example.com") | ||
) | ||
ensure | ||
self.request_forgery = false | ||
end | ||
|
||
def test_button_to_with_form_class | ||
assert_dom_equal "<form method=\"post\" action=\"http://www.example.com\" class=\"custom-class\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com", :form_class => 'custom-class') | ||
end | ||
|
@@ -435,9 +449,16 @@ def test_mail_to_returns_html_safe_string | |
assert mail_to("[email protected]", "My email", :encode => "hex").html_safe? | ||
end | ||
|
||
# TODO: button_to looks at this ... why? | ||
def protect_against_forgery? | ||
false | ||
self.request_forgery | ||
end | ||
|
||
def form_authenticity_token | ||
"secret" | ||
end | ||
|
||
def request_forgery_protection_token | ||
"form_token" | ||
end | ||
|
||
private | ||
|