diff options
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/metal/strong_parameters.rb | 28 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/testing/integration.rb | 7 |
2 files changed, 34 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index 26794c67b7..f101c7b836 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -7,6 +7,7 @@ require 'action_dispatch/http/upload' require 'rack/test' require 'stringio' require 'set' +require 'yaml' module ActionController # Raised when a required parameter is missing. @@ -591,6 +592,33 @@ module ActionController "<#{self.class} #{@parameters} permitted: #{@permitted}>" end + def self.hook_into_yaml_loading # :nodoc: + # Wire up YAML format compatibility with Rails 4.2 and Psych 2.0.8 and 2.0.9+. + # Makes the YAML parser call `init_with` when it encounters the keys below + # instead of trying its own parsing routines. + YAML.load_tags['!ruby/hash-with-ivars:ActionController::Parameters'] = name + YAML.load_tags['!ruby/hash:ActionController::Parameters'] = name + end + hook_into_yaml_loading + + def init_with(coder) # :nodoc: + case coder.tag + when '!ruby/hash:ActionController::Parameters' + # YAML 2.0.8's format where hash instance variables weren't stored. + @parameters = coder.map.with_indifferent_access + @permitted = false + when '!ruby/hash-with-ivars:ActionController::Parameters' + # YAML 2.0.9's Hash subclass format where keys and values + # were stored under an elements hash and `permitted` within an ivars hash. + @parameters = coder.map['elements'].with_indifferent_access + @permitted = coder.map['ivars'][:@permitted] + when '!ruby/object:ActionController::Parameters' + # YAML's Object format. Only needed because of the format + # backwardscompability above, otherwise equivalent to YAML's initialization. + @parameters, @permitted = coder.map['parameters'], coder.map['permitted'] + end + end + def method_missing(method_sym, *args, &block) if @parameters.respond_to?(method_sym) message = <<-DEPRECATE.squish diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 9a76b68ae1..c8ad8cee68 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -327,6 +327,12 @@ module ActionDispatch # Performs the actual request. def process(method, path, params: nil, headers: nil, env: nil, xhr: false, as: nil) request_encoder = RequestEncoder.encoder(as) + headers ||= {} + + if method == :get && as == :json && params + headers['X-Http-Method-Override'] = 'GET' + method = :post + end if path =~ %r{://} path = build_expanded_path(path, request_encoder) do |location| @@ -361,7 +367,6 @@ module ActionDispatch } if xhr - headers ||= {} headers['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' headers['HTTP_ACCEPT'] ||= [Mime[:js], Mime[:html], Mime[:xml], 'text/xml', '*/*'].join(', ') end |