diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2016-02-22 17:20:37 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2016-02-22 21:22:29 -0300 |
commit | a087cf4312c1ec01f3bb021a6791ac3a6ef1cec3 (patch) | |
tree | 847d9cf9d8e4c6f17e0fc391273edb80e1992f15 | |
parent | 97ed810cfc15725a0856227fa9f9eb26930f16c8 (diff) | |
download | rails-a087cf4312c1ec01f3bb021a6791ac3a6ef1cec3.tar.gz rails-a087cf4312c1ec01f3bb021a6791ac3a6ef1cec3.tar.bz2 rails-a087cf4312c1ec01f3bb021a6791ac3a6ef1cec3.zip |
Transform the mime object to symbol when registering the parsers
This will keep our current API working without having the users to
change their codebases.
-rw-r--r-- | actionpack/lib/action_dispatch/http/parameters.rb | 17 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/params_parser.rb | 1 | ||||
-rw-r--r-- | actionpack/test/controller/webservice_test.rb | 2 |
3 files changed, 15 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb index bcb818d38c..ff5031d7d5 100644 --- a/actionpack/lib/action_dispatch/http/parameters.rb +++ b/actionpack/lib/action_dispatch/http/parameters.rb @@ -1,6 +1,8 @@ module ActionDispatch module Http module Parameters + extend ActiveSupport::Concern + PARAMETERS_KEY = 'action_dispatch.request.path_parameters' DEFAULT_PARSERS = { @@ -10,13 +12,20 @@ module ActionDispatch } } - def self.included(klass) - class << klass - attr_accessor :parameter_parsers + included do + class << self + attr_reader :parameter_parsers end - klass.parameter_parsers = DEFAULT_PARSERS + self.parameter_parsers = DEFAULT_PARSERS end + + module ClassMethods + def parameter_parsers=(parsers) # :nodoc: + @parameter_parsers = parsers.transform_keys { |key| key.respond_to?(:symbol) ? key.symbol : key } + end + end + # Returns both GET and POST \parameters in a single hash. def parameters params = get_header("action_dispatch.request.parameters") diff --git a/actionpack/lib/action_dispatch/middleware/params_parser.rb b/actionpack/lib/action_dispatch/middleware/params_parser.rb index c2a4f46e67..5841c978af 100644 --- a/actionpack/lib/action_dispatch/middleware/params_parser.rb +++ b/actionpack/lib/action_dispatch/middleware/params_parser.rb @@ -37,6 +37,7 @@ module ActionDispatch # The +parsers+ argument can take Hash of parsers where key is identifying # content mime type, and value is a lambda that is going to process data. def self.new(app, parsers = {}) + parsers = parsers.transform_keys { |key| key.respond_to?(:symbol) ? key.symbol : key } ActionDispatch::Request.parameter_parsers = ActionDispatch::Request::DEFAULT_PARSERS.merge(parsers) app end diff --git a/actionpack/test/controller/webservice_test.rb b/actionpack/test/controller/webservice_test.rb index f02898e10c..daf17558aa 100644 --- a/actionpack/test/controller/webservice_test.rb +++ b/actionpack/test/controller/webservice_test.rb @@ -65,7 +65,7 @@ class WebServiceTest < ActionDispatch::IntegrationTest def test_register_and_use_json_simple with_test_route_set do - with_params_parsers json: Proc.new { |data| ActiveSupport::JSON.decode(data)['request'].with_indifferent_access } do + with_params_parsers Mime[:json] => Proc.new { |data| ActiveSupport::JSON.decode(data)['request'].with_indifferent_access } do post "/", params: '{"request":{"summary":"content...","title":"JSON"}}', headers: { 'CONTENT_TYPE' => 'application/json' } |