Permalink
Browse files

Merge pull request rails#29630 from kirs/fallback-tos_parameters

Fallback Parameters#to_s to Hash#to_s
  • Loading branch information...
rafaelfranca committed Jun 30, 2017
1 parent 63f9cfe commit c1014e435d26db867b2c15b74c9ef47ccff38edb
@@ -180,6 +180,13 @@ class Parameters
#
# 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?
#
@@ -196,7 +203,7 @@ class Parameters
#
# 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 @@ def test_text_field_tag_size_symbol
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="{&quot;key&quot;=&gt;&quot;value&quot;}" />)
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!" />)

0 comments on commit c1014e4

Please sign in to comment.