mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #29630 from kirs/fallback-tos_parameters
Fallback Parameters#to_s to Hash#to_s
This commit is contained in:
commit
de011ac624
3 changed files with 19 additions and 1 deletions
|
@ -179,6 +179,13 @@ module ActionController
|
|||
#
|
||||
# Returns a new array of the keys of the parameters.
|
||||
|
||||
##
|
||||
# :method: to_s
|
||||
#
|
||||
# :call-seq:
|
||||
# to_s()
|
||||
# Returns the content of the parameters as a string.
|
||||
|
||||
##
|
||||
# :method: value?
|
||||
#
|
||||
|
@ -195,7 +202,7 @@ module ActionController
|
|||
#
|
||||
# Returns a new array of the values of the parameters.
|
||||
delegate :keys, :key?, :has_key?, :values, :has_value?, :value?, :empty?, :include?,
|
||||
:as_json, to: :@parameters
|
||||
:as_json, :to_s, to: :@parameters
|
||||
|
||||
# By default, never raise an UnpermittedParameters exception if these
|
||||
# params are present. The default includes both 'controller' and 'action'
|
||||
|
|
|
@ -35,6 +35,11 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
|
|||
assert @params.as_json.key? "person"
|
||||
end
|
||||
|
||||
test "to_s returns the string representation of the parameters hash" do
|
||||
assert_equal '{"person"=>{"age"=>"32", "name"=>{"first"=>"David", "last"=>"Heinemeier Hansson"}, ' \
|
||||
'"addresses"=>[{"city"=>"Chicago", "state"=>"Illinois"}]}}', @params.to_s
|
||||
end
|
||||
|
||||
test "each carries permitted status" do
|
||||
@params.permit!
|
||||
@params.each { |key, value| assert(value.permitted?) if key == "person" }
|
||||
|
|
|
@ -345,6 +345,12 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
||||
def test_text_field_tag_with_ac_parameters
|
||||
actual = text_field_tag "title", ActionController::Parameters.new(key: "value")
|
||||
expected = %(<input id="title" name="title" type="text" value="{"key"=>"value"}" />)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
||||
def test_text_field_tag_size_string
|
||||
actual = text_field_tag "title", "Hello!", "size" => "75"
|
||||
expected = %(<input id="title" name="title" size="75" type="text" value="Hello!" />)
|
||||
|
|
Loading…
Reference in a new issue