1 # frozen_string_literal: true
5 class ErrorsControllerTest < ActionDispatch::IntegrationTest
8 { :path => "/400", :method => :get },
9 { :controller => "errors", :action => "bad_request" }
12 { :path => "/403", :method => :get },
13 { :controller => "errors", :action => "forbidden" }
16 { :path => "/404", :method => :get },
17 { :controller => "errors", :action => "not_found" }
20 { :path => "/500", :method => :get },
21 { :controller => "errors", :action => "internal_server_error" }
27 assert_response :bad_request
32 assert_response :forbidden
37 assert_response :not_found
40 def test_internal_server_error
42 assert_response :internal_server_error
43 assert_template "errors/internal_server_error"
47 # rails sets action_dispatch.original_path to the path of the request
48 # that failed when it calls this controller to render the error
49 def test_internal_server_error_api
50 get "/500", :env => { "action_dispatch.original_path" => "/api/0.6/node/1" }
51 assert_response :internal_server_error
52 assert_equal "text/plain", @response.media_type
53 assert_equal "Internal Server Error", @response.body
54 assert_equal "Internal Server Error", @response.headers["Error"]
58 # errors requested with the X-Error-Format header are returned with a
59 # 200 status, with the real status in the body
60 def test_internal_server_error_api_error_format_xml
61 get "/500", :headers => { "X-Error-Format" => "xml" }, :env => { "action_dispatch.original_path" => "/api/0.6/node/1" }
62 assert_response :success
63 assert_equal "application/xml", @response.media_type
64 assert_dom "osmError > status", :text => /\A500\b/
65 assert_dom "osmError > message", :text => "Internal Server Error"