aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2016-11-22 22:22:34 +0100
committerKasper Timm Hansen <kaspth@gmail.com>2016-11-23 22:02:19 +0100
commit86754a8f7b4986323aae3be172330fbc228c27ab (patch)
treedcfaf38a44dace30b40ce9a597eed3cc2c9d4937 /actionpack/test
parent49aa974ec8b15721d53b3b6abea88bd6ba433a68 (diff)
downloadrails-86754a8f7b4986323aae3be172330fbc228c27ab.tar.gz
rails-86754a8f7b4986323aae3be172330fbc228c27ab.tar.bz2
rails-86754a8f7b4986323aae3be172330fbc228c27ab.zip
Use accept header instead of mangling request path.
Instead of appending a format to the request, it's much better to just pass a more appropriate accept header. Rails will figure out the format from that instead. This allows devs to use `:as` on routes that don't have a format. Introduce an `IdentityEncoder` to avoid `if request_encoder`, essentially a better version of the purpose of the `WWWFormEncoder`. One that makes conceptual sense on GET requests too. Fixes #27144.
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/integration_test.rb27
1 files changed, 25 insertions, 2 deletions
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb
index f89cfdb78c..d8be5d32e1 100644
--- a/actionpack/test/controller/integration_test.rb
+++ b/actionpack/test/controller/integration_test.rb
@@ -930,6 +930,10 @@ end
class IntegrationRequestEncodersTest < ActionDispatch::IntegrationTest
class FooController < ActionController::Base
+ def foos
+ render plain: "ok"
+ end
+
def foos_json
render json: params.permit(:foo)
end
@@ -958,13 +962,30 @@ class IntegrationRequestEncodersTest < ActionDispatch::IntegrationTest
def test_encoding_as_json
post_to_foos as: :json do
assert_response :success
- assert_match "foos_json.json", request.path
assert_equal "application/json", request.content_type
+ assert_equal "application/json", request.accepts.first.to_s
+ assert_equal :json, request.format.ref
assert_equal({ "foo" => "fighters" }, request.request_parameters)
assert_equal({ "foo" => "fighters" }, response.parsed_body)
end
end
+ def test_doesnt_mangle_request_path
+ with_routing do |routes|
+ routes.draw do
+ ActiveSupport::Deprecation.silence do
+ post ":action" => FooController
+ end
+ end
+
+ post "/foos"
+ assert_equal "/foos", request.path
+
+ post "/foos_json", as: :json
+ assert_equal "/foos_json", request.path
+ end
+ end
+
def test_encoding_as_without_mime_registration
assert_raise ArgumentError do
ActionDispatch::IntegrationTest.register_encoder :wibble
@@ -979,8 +1000,10 @@ class IntegrationRequestEncodersTest < ActionDispatch::IntegrationTest
post_to_foos as: :wibble do
assert_response :success
- assert_match "foos_wibble.wibble", request.path
+ assert_equal "/foos_wibble", request.path
assert_equal "text/wibble", request.content_type
+ assert_equal "text/wibble", request.accepts.first.to_s
+ assert_equal :wibble, request.format.ref
assert_equal Hash.new, request.request_parameters # Unregistered MIME Type can't be parsed.
assert_equal "ok", response.parsed_body
end