diff options
author | kp <keith.j.payne@gmail.com> | 2016-02-10 17:44:54 +0000 |
---|---|---|
committer | kp <keith.j.payne@gmail.com> | 2016-02-10 17:44:54 +0000 |
commit | ec4ae308a76bd86fb6eaf7fa8ee025af0063ee30 (patch) | |
tree | 741019b3fbf474ff4cdeefdbeb6ff1f598ffcdfc /actionpack/test/controller/integration_test.rb | |
parent | 8641de93eb98d4ebdb0db2530c8c79c0c4e2f95e (diff) | |
parent | 688996da7b25080a1a2ef74f5b4789f3e5eb670d (diff) | |
download | rails-ec4ae308a76bd86fb6eaf7fa8ee025af0063ee30.tar.gz rails-ec4ae308a76bd86fb6eaf7fa8ee025af0063ee30.tar.bz2 rails-ec4ae308a76bd86fb6eaf7fa8ee025af0063ee30.zip |
Merge remote-tracking branch 'origin/master' into actioncable_logging
Diffstat (limited to 'actionpack/test/controller/integration_test.rb')
-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 |