aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/integration_test.rb
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2016-08-05 14:20:21 -0400
committereileencodes <eileencodes@gmail.com>2016-08-05 15:43:39 -0400
commitaf1680f51c127c7e40019e68c01b2a693ba2640f (patch)
tree323cb7099ca25dc407bd83bfdb267c95e9b49cac /actionpack/test/controller/integration_test.rb
parent70f2f981503d4f08b48ae0a05cf0e69308e1aba0 (diff)
downloadrails-af1680f51c127c7e40019e68c01b2a693ba2640f.tar.gz
rails-af1680f51c127c7e40019e68c01b2a693ba2640f.tar.bz2
rails-af1680f51c127c7e40019e68c01b2a693ba2640f.zip
Fix GET JSON integration test request to use method override
When a `GET` request is sent `as: :json` in an integration test the test should use Rack's method override to change to a post request so the paramters are included in the postdata. Otherwise it will not encode the parameters correctly for the integration test. Because integration test sets up it's own middleware, `Rack::MethodOverride` needs to be included in the integration tests as well. `headers ||= {}` was moved so that headers are never nil. They should default to a hash. Fixes #26033 [Eileen M. Uchitelle & Aaron Patterson]
Diffstat (limited to 'actionpack/test/controller/integration_test.rb')
-rw-r--r--actionpack/test/controller/integration_test.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb
index e02b0b267d..7ad8dbb2bd 100644
--- a/actionpack/test/controller/integration_test.rb
+++ b/actionpack/test/controller/integration_test.rb
@@ -1238,6 +1238,22 @@ class IntegrationRequestEncodersTest < ActionDispatch::IntegrationTest
end
end
+ def test_get_request_with_json_uses_method_override_and_sends_a_post_request
+ with_routing do |routes|
+ routes.draw do
+ ActiveSupport::Deprecation.silence do
+ get ':action' => FooController
+ end
+ end
+
+ get '/foos_json', params: { foo: 'heyo' }, as: :json
+
+ assert_equal 'POST', request.method
+ assert_equal 'GET', request.headers['X-Http-Method-Override']
+ assert_equal({ 'foo' => 'heyo' }, response.parsed_body)
+ end
+ end
+
private
def post_to_foos(as:)
with_routing do |routes|