2
2
3
3
class ShowExceptionsTest < ActionDispatch ::IntegrationTest
4
4
5
- Boomer = lambda do |env |
6
- req = ActionDispatch ::Request . new ( env )
7
- case req . path
8
- when "/not_found"
9
- raise ActionController ::UnknownAction
10
- when "/runtime_error"
11
- raise RuntimeError
12
- when "/method_not_allowed"
13
- raise ActionController ::MethodNotAllowed
14
- when "/not_implemented"
15
- raise ActionController ::NotImplemented
16
- when "/unprocessable_entity"
17
- raise ActionController ::InvalidAuthenticityToken
18
- when "/not_found_original_exception"
19
- raise ActionView ::Template ::Error . new ( 'template' , { } , AbstractController ::ActionNotFound . new )
20
- else
21
- raise "puke!"
5
+ class Boomer
6
+ def initialize ( detailed = false )
7
+ @detailed = detailed
8
+ end
9
+
10
+ def call ( env )
11
+ env [ 'action_dispatch.show_detailed_exceptions' ] = @detailed
12
+ req = ActionDispatch ::Request . new ( env )
13
+ case req . path
14
+ when "/not_found"
15
+ raise ActionController ::UnknownAction
16
+ when "/runtime_error"
17
+ raise RuntimeError
18
+ when "/method_not_allowed"
19
+ raise ActionController ::MethodNotAllowed
20
+ when "/not_implemented"
21
+ raise ActionController ::NotImplemented
22
+ when "/unprocessable_entity"
23
+ raise ActionController ::InvalidAuthenticityToken
24
+ when "/not_found_original_exception"
25
+ raise ActionView ::Template ::Error . new ( 'template' , { } , AbstractController ::ActionNotFound . new )
26
+ else
27
+ raise "puke!"
28
+ end
22
29
end
23
30
end
24
31
25
- ProductionApp = ActionDispatch ::ShowExceptions . new ( Boomer , false )
26
- DevelopmentApp = ActionDispatch ::ShowExceptions . new ( Boomer , true )
32
+ ProductionApp = ActionDispatch ::ShowExceptions . new ( Boomer . new ( false ) )
33
+ DevelopmentApp = ActionDispatch ::ShowExceptions . new ( Boomer . new ( true ) )
27
34
28
- test "rescue in public from a remote ip " do
35
+ test "rescue with error page when show_exceptions is false " do
29
36
@app = ProductionApp
30
- self . remote_addr = '208.77.188.166'
31
37
32
38
get "/" , { } , { 'action_dispatch.show_exceptions' => true }
33
39
assert_response 500
@@ -42,32 +48,28 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest
42
48
assert_equal "" , body
43
49
end
44
50
45
- test "rescue locally from a local request" do
46
- @app = ProductionApp
47
- [ '127.0.0.1' , '127.0.0.127' , '::1' , '0:0:0:0:0:0:0:1' , '0:0:0:0:0:0:0:1%0' ] . each do |ip_address |
48
- self . remote_addr = ip_address
51
+ test "rescue with diagnostics message when show_exceptions is true" do
52
+ @app = DevelopmentApp
49
53
50
- get "/" , { } , { 'action_dispatch.show_exceptions' => true }
51
- assert_response 500
52
- assert_match ( /puke/ , body )
54
+ get "/" , { } , { 'action_dispatch.show_exceptions' => true }
55
+ assert_response 500
56
+ assert_match ( /puke/ , body )
53
57
54
- get "/not_found" , { } , { 'action_dispatch.show_exceptions' => true }
55
- assert_response 404
56
- assert_match ( /#{ ActionController ::UnknownAction . name } / , body )
58
+ get "/not_found" , { } , { 'action_dispatch.show_exceptions' => true }
59
+ assert_response 404
60
+ assert_match ( /#{ ActionController ::UnknownAction . name } / , body )
57
61
58
- get "/method_not_allowed" , { } , { 'action_dispatch.show_exceptions' => true }
59
- assert_response 405
60
- assert_match ( /ActionController::MethodNotAllowed/ , body )
61
- end
62
+ get "/method_not_allowed" , { } , { 'action_dispatch.show_exceptions' => true }
63
+ assert_response 405
64
+ assert_match ( /ActionController::MethodNotAllowed/ , body )
62
65
end
63
66
64
- test "localize public rescue message " do
67
+ test "localize rescue error page " do
65
68
# Change locale
66
69
old_locale , I18n . locale = I18n . locale , :da
67
70
68
71
begin
69
72
@app = ProductionApp
70
- self . remote_addr = '208.77.188.166'
71
73
72
74
get "/" , { } , { 'action_dispatch.show_exceptions' => true }
73
75
assert_response 500
@@ -81,23 +83,6 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest
81
83
end
82
84
end
83
85
84
- test "always rescue locally in development mode" do
85
- @app = DevelopmentApp
86
- self . remote_addr = '208.77.188.166'
87
-
88
- get "/" , { } , { 'action_dispatch.show_exceptions' => true }
89
- assert_response 500
90
- assert_match ( /puke/ , body )
91
-
92
- get "/not_found" , { } , { 'action_dispatch.show_exceptions' => true }
93
- assert_response 404
94
- assert_match ( /#{ ActionController ::UnknownAction . name } / , body )
95
-
96
- get "/method_not_allowed" , { } , { 'action_dispatch.show_exceptions' => true }
97
- assert_response 405
98
- assert_match ( /ActionController::MethodNotAllowed/ , body )
99
- end
100
-
101
86
test "does not show filtered parameters" do
102
87
@app = DevelopmentApp
103
88
@@ -107,16 +92,15 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest
107
92
assert_match ( ""foo"=>"[FILTERED]"" , body )
108
93
end
109
94
110
- test "show registered original exception for wrapped exceptions when consider_all_requests_local is false" do
95
+ test "show registered original exception for wrapped exceptions when show_exceptions is false" do
111
96
@app = ProductionApp
112
- self . remote_addr = '208.77.188.166'
113
97
114
98
get "/not_found_original_exception" , { } , { 'action_dispatch.show_exceptions' => true }
115
99
assert_response 404
116
100
assert_match ( /404 error/ , body )
117
101
end
118
102
119
- test "show registered original exception for wrapped exceptions when consider_all_requests_local is true" do
103
+ test "show registered original exception for wrapped exceptions when show_exceptions is true" do
120
104
@app = DevelopmentApp
121
105
122
106
get "/not_found_original_exception" , { } , { 'action_dispatch.show_exceptions' => true }
@@ -125,7 +109,7 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest
125
109
end
126
110
127
111
test "show the controller name in the diagnostics template when controller name is present" do
128
- @app = ProductionApp
112
+ @app = DevelopmentApp
129
113
get ( "/runtime_error" , { } , {
130
114
'action_dispatch.show_exceptions' => true ,
131
115
'action_dispatch.request.parameters' => {
0 commit comments