]> git.openstreetmap.org Git - rails.git/blob - test/controllers/errors_controller_test.rb
Merge remote-tracking branch 'upstream/pull/7634'
[rails.git] / test / controllers / errors_controller_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class ErrorsControllerTest < ActionDispatch::IntegrationTest
6   def test_routes
7     assert_routing(
8       { :path => "/400", :method => :get },
9       { :controller => "errors", :action => "bad_request" }
10     )
11     assert_routing(
12       { :path => "/403", :method => :get },
13       { :controller => "errors", :action => "forbidden" }
14     )
15     assert_routing(
16       { :path => "/404", :method => :get },
17       { :controller => "errors", :action => "not_found" }
18     )
19     assert_routing(
20       { :path => "/500", :method => :get },
21       { :controller => "errors", :action => "internal_server_error" }
22     )
23   end
24
25   def test_bad_request
26     get "/400"
27     assert_response :bad_request
28   end
29
30   def test_forbidden
31     get "/403"
32     assert_response :forbidden
33   end
34
35   def test_not_found
36     get "/404"
37     assert_response :not_found
38   end
39
40   def test_internal_server_error
41     get "/500"
42     assert_response :internal_server_error
43     assert_template "errors/internal_server_error"
44   end
45
46   ##
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"]
55   end
56
57   ##
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"
66   end
67 end