diff options
author | Jon Moss <me@jonathanmoss.me> | 2016-10-17 21:16:54 -0400 |
---|---|---|
committer | Jon Moss <me@jonathanmoss.me> | 2016-10-17 21:16:54 -0400 |
commit | 4aae8bfe4dc6da1722e7f0f1722cf1f7ef472c19 (patch) | |
tree | 32d119bb4aa9228b4d0e37e0f7504f0592b95ec3 /actionview/test/template | |
parent | 8e76f6959efc44c8575b721fdf53d06ea9430fed (diff) | |
download | rails-4aae8bfe4dc6da1722e7f0f1722cf1f7ef472c19.tar.gz rails-4aae8bfe4dc6da1722e7f0f1722cf1f7ef472c19.tar.bz2 rails-4aae8bfe4dc6da1722e7f0f1722cf1f7ef472c19.zip |
Convert ActionController::Parameters to a hash in button_to
Before, an error would be raised saying that the method `to_param` was
undefined on the instance of `ActionController::Parameters`. Now, we are
checking to see if the `params` object being passed to `button_to`
responds to the `permitted?` method, and if so, we will call `to_h` on it. If it
does not respond to `permitted?`, then the `params` will remain
unchanged.
[Jon Moss, Rafael Mendonça França]
Diffstat (limited to 'actionview/test/template')
-rw-r--r-- | actionview/test/template/url_helper_test.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb index 2ef2be65d2..4f73241f52 100644 --- a/actionview/test/template/url_helper_test.rb +++ b/actionview/test/template/url_helper_test.rb @@ -221,6 +221,22 @@ class UrlHelperTest < ActiveSupport::TestCase ) end + class FakeParams + def permitted? + end + + def to_h + { foo: :bar, baz: "quux" } + end + end + + def test_button_to_with_strong_params + assert_dom_equal( + %{<form action="http://www.example.com" class="button_to" method="post"><input type="submit" value="Hello" /><input type="hidden" name="baz" value="quux" /><input type="hidden" name="foo" value="bar" /></form>}, + button_to("Hello", "http://www.example.com", params: FakeParams.new) + ) + end + def test_button_to_with_nested_hash_params assert_dom_equal( %{<form action="http://www.example.com" class="button_to" method="post"><input type="submit" value="Hello" /><input type="hidden" name="foo[bar]" value="baz" /></form>}, |