提交 a6234426 编写于 作者: B Benjamin Quorning

Implement ActionController::Parameters#inspect

Now that AC::Parameters is no longer a Hash, it shouldn't look like a hash.
上级 39b1dd1c
......@@ -109,7 +109,7 @@ class Parameters
cattr_accessor :permit_all_parameters, instance_accessor: false
cattr_accessor :action_on_unpermitted_parameters, instance_accessor: false
delegate :keys, :key?, :has_key?, :values, :has_value?, :value?, :empty?, :include?, :inspect,
delegate :keys, :key?, :has_key?, :values, :has_value?, :value?, :empty?, :include?,
:as_json, to: :@parameters
# By default, never raise an UnpermittedParameters exception if these
......@@ -574,6 +574,10 @@ def stringify_keys # :nodoc:
dup
end
def inspect
"<#{self.class} #{@parameters}>"
end
def method_missing(method_sym, *args, &block)
if @parameters.respond_to?(method_sym)
message = <<-DEPRECATE.squish
......
......@@ -134,4 +134,13 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
params1 = ActionController::Parameters.new(hash1)
assert(params1 == hash1)
end
test "inspect shows both class name and parameters" do
assert_equal(
'<ActionController::Parameters {"person"=>{"age"=>"32", '\
'"name"=>{"first"=>"David", "last"=>"Heinemeier Hansson"}, ' \
'"addresses"=>[{"city"=>"Chicago", "state"=>"Illinois"}]}}>',
@params.inspect
)
end
end
......@@ -988,7 +988,7 @@ def create
app 'development'
post "/posts.json", '{ "title": "foo", "name": "bar" }', "CONTENT_TYPE" => "application/json"
assert_equal '{"title"=>"foo"}', last_response.body
assert_equal '<ActionController::Parameters {"title"=>"foo"}>', last_response.body
end
test "config.action_controller.permit_all_parameters = true" do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册