class IntegrationRequestEncodersTest
Public Instance Methods
test_doesnt_mangle_request_path()
click to toggle source
# File actionpack/test/controller/integration_test.rb, line 987 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
test_encoding_as_json()
click to toggle source
# File actionpack/test/controller/integration_test.rb, line 976 def test_encoding_as_json post_to_foos as: :json do assert_response :success 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
test_encoding_as_without_mime_registration()
click to toggle source
# File actionpack/test/controller/integration_test.rb, line 1003 def test_encoding_as_without_mime_registration assert_raise ArgumentError do ActionDispatch::IntegrationTest.register_encoder :wibble end end
test_get_parameters_with_as_option()
click to toggle source
# File actionpack/test/controller/integration_test.rb, line 1042 def test_get_parameters_with_as_option with_routing do |routes| routes.draw do ActiveSupport::Deprecation.silence do get ":action" => FooController end end get "/foos_json?foo=heyo", as: :json assert_equal({ "foo" => "heyo" }, response.parsed_body) end end
test_get_request_with_json_uses_method_override_and_sends_a_post_request()
click to toggle source
# File actionpack/test/controller/integration_test.rb, line 1056 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
test_parsed_body_without_as_option()
click to toggle source
# File actionpack/test/controller/integration_test.rb, line 1028 def test_parsed_body_without_as_option with_routing do |routes| routes.draw do ActiveSupport::Deprecation.silence do get ":action" => FooController end end get "/foos_json.json", params: { foo: "heyo" } assert_equal({ "foo" => "heyo" }, response.parsed_body) end end
test_registering_custom_encoder()
click to toggle source
# File actionpack/test/controller/integration_test.rb, line 1009 def test_registering_custom_encoder Mime::Type.register "text/wibble", :wibble ActionDispatch::IntegrationTest.register_encoder(:wibble, param_encoder: -> params { params }) post_to_foos as: :wibble do assert_response :success 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 ensure Mime::Type.unregister :wibble end
test_standard_json_encoding_works()
click to toggle source
# File actionpack/test/controller/integration_test.rb, line 960 def test_standard_json_encoding_works with_routing do |routes| routes.draw do ActiveSupport::Deprecation.silence do post ":action" => FooController end end post "/foos_json.json", params: { foo: "fighters" }.to_json, headers: { "Content-Type" => "application/json" } assert_response :success assert_equal({ "foo" => "fighters" }, response.parsed_body) end end
Private Instance Methods
post_to_foos(as:) { || ... }
click to toggle source
# File actionpack/test/controller/integration_test.rb, line 1073 def post_to_foos(as:) with_routing do |routes| routes.draw do ActiveSupport::Deprecation.silence do post ":action" => FooController end end post "/foos_#{as}", params: { foo: "fighters" }, as: as yield end end