aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/integration_test.rb35
1 files changed, 24 insertions, 11 deletions
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb
index 296bc1baad..cb524bacb2 100644
--- a/actionpack/test/controller/integration_test.rb
+++ b/actionpack/test/controller/integration_test.rb
@@ -1129,13 +1129,23 @@ end
class IntegrationRequestEncodersTest < ActionDispatch::IntegrationTest
class FooController < ActionController::Base
- def foos
+ def foos_json
+ render json: params.permit(:foo)
+ end
+
+ def foos_wibble
render plain: 'ok'
end
end
def test_encoding_as_json
- assert_encoded_as :json, content_type: 'application/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({ 'foo' => 'fighters' }, request.request_parameters)
+ assert_equal({ 'foo' => 'fighters' }, response.parsed_body)
+ end
end
def test_encoding_as_without_mime_registration
@@ -1147,25 +1157,28 @@ class IntegrationRequestEncodersTest < ActionDispatch::IntegrationTest
def test_registering_custom_encoder
Mime::Type.register 'text/wibble', :wibble
- ActionDispatch::IntegrationTest.register_encoder(:wibble, &:itself)
+ ActionDispatch::IntegrationTest.register_encoder(:wibble,
+ param_encoder: -> params { params })
- assert_encoded_as :wibble, content_type: 'text/wibble',
- parsed_parameters: Hash.new # Unregistered MIME Type can't be parsed
+ post_to_foos as: :wibble do
+ assert_response :success
+ assert_match 'foos_wibble.wibble', request.path
+ assert_equal 'text/wibble', request.content_type
+ assert_equal Hash.new, request.request_parameters # Unregistered MIME Type can't be parsed.
+ assert_equal 'ok', response.parsed_body
+ end
ensure
Mime::Type.unregister :wibble
end
private
- def assert_encoded_as(format, content_type:, parsed_parameters: { 'foo' => 'fighters' })
+ def post_to_foos(as:)
with_routing do |routes|
routes.draw { post ':action' => FooController }
- post '/foos', params: { foo: 'fighters' }, as: format
+ post "/foos_#{as}", params: { foo: 'fighters' }, as: as
- assert_response :success
- assert_match "foos.#{format}", request.path
- assert_equal content_type, request.content_type
- assert_equal parsed_parameters, request.request_parameters
+ yield
end
end
end