diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2016-02-10 17:46:14 +0100 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2016-02-10 17:46:14 +0100 |
commit | 688996da7b25080a1a2ef74f5b4789f3e5eb670d (patch) | |
tree | 1e0c972435bcc11ed691d9aa0950fc40ff9c9333 /actionpack/test | |
parent | b07970883d87e310696b0e7d8653cfdfc5fd4e9c (diff) | |
parent | 52bb2d36d3141dcd8217221065d9b5fa2b12deba (diff) | |
download | rails-688996da7b25080a1a2ef74f5b4789f3e5eb670d.tar.gz rails-688996da7b25080a1a2ef74f5b4789f3e5eb670d.tar.bz2 rails-688996da7b25080a1a2ef74f5b4789f3e5eb670d.zip |
Merge pull request #21671 from kaspth/integration-request-encoding-helpers
Add `as` to encode a request as a specific mime type.
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/controller/integration_test.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index d0a1d1285f..296bc1baad 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -1126,3 +1126,46 @@ class IntegrationRequestsWithSessionSetup < ActionDispatch::IntegrationTest assert_equal({"user_name"=>"david"}, cookies.to_hash) end end + +class IntegrationRequestEncodersTest < ActionDispatch::IntegrationTest + class FooController < ActionController::Base + def foos + render plain: 'ok' + end + end + + def test_encoding_as_json + assert_encoded_as :json, content_type: 'application/json' + end + + def test_encoding_as_without_mime_registration + assert_raise ArgumentError do + ActionDispatch::IntegrationTest.register_encoder :wibble + end + end + + def test_registering_custom_encoder + Mime::Type.register 'text/wibble', :wibble + + ActionDispatch::IntegrationTest.register_encoder(:wibble, &:itself) + + assert_encoded_as :wibble, content_type: 'text/wibble', + parsed_parameters: Hash.new # Unregistered MIME Type can't be parsed + ensure + Mime::Type.unregister :wibble + end + + private + def assert_encoded_as(format, content_type:, parsed_parameters: { 'foo' => 'fighters' }) + with_routing do |routes| + routes.draw { post ':action' => FooController } + + post '/foos', params: { foo: 'fighters' }, as: format + + assert_response :success + assert_match "foos.#{format}", request.path + assert_equal content_type, request.content_type + assert_equal parsed_parameters, request.request_parameters + end + end +end |