@@ -17,7 +17,10 @@ def teardown
17
17
end
18
18
19
19
test "show exceptions middleware filter backtrace before logging" do
20
- controller :foo , <<-RUBY
20
+ routes <<~'RUBY'
21
+ get "/foo" => "foo#index"
22
+ RUBY
23
+ controller :foo , <<~'RUBY'
21
24
class FooController < ActionController::Base
22
25
def index
23
26
raise 'oops'
@@ -35,7 +38,10 @@ def index
35
38
end
36
39
37
40
test "renders active record exceptions as 404" do
38
- controller :foo , <<-RUBY
41
+ routes <<~'RUBY'
42
+ get "/foo" => "foo#index"
43
+ RUBY
44
+ controller :foo , <<~'RUBY'
39
45
class FooController < ActionController::Base
40
46
def index
41
47
raise ActiveRecord::RecordNotFound
@@ -53,10 +59,7 @@ def index
53
59
end
54
60
55
61
test "renders unknown http methods as 405 when routes are used as the custom exceptions app" do
56
- app_file "config/routes.rb" , <<-RUBY
57
- Rails.application.routes.draw do
58
- end
59
- RUBY
62
+ routes ""
60
63
61
64
add_to_config "config.exceptions_app = self.routes"
62
65
@@ -67,7 +70,7 @@ def index
67
70
end
68
71
69
72
test "renders unknown http formats as 406 when routes are used as the custom exceptions app" do
70
- controller :foo , <<- RUBY
73
+ controller :foo , <<~' RUBY'
71
74
class FooController < ActionController::Base
72
75
def index
73
76
render plain: "rendering index!"
@@ -79,12 +82,10 @@ def not_acceptable
79
82
end
80
83
RUBY
81
84
82
- app_file "config/routes.rb" , <<-RUBY
83
- Rails.application.routes.draw do
84
- get "/foo", to: "foo#index"
85
- post "/foo", to: "foo#index"
86
- match "/406", to: "foo#not_acceptable", via: :all
87
- end
85
+ routes <<~'RUBY'
86
+ get "/foo", to: "foo#index"
87
+ post "/foo", to: "foo#index"
88
+ match "/406", to: "foo#not_acceptable", via: :all
88
89
RUBY
89
90
90
91
add_to_config "config.exceptions_app = self.routes"
@@ -109,7 +110,7 @@ def not_acceptable
109
110
end
110
111
111
112
test "uses custom exceptions app" do
112
- add_to_config <<- RUBY
113
+ add_to_config <<~' RUBY'
113
114
config.exceptions_app = lambda do |env|
114
115
[404, { "Content-Type" => "text/plain" }, ["YOU FAILED"]]
115
116
end
@@ -123,7 +124,10 @@ def not_acceptable
123
124
end
124
125
125
126
test "URL generation error when action_dispatch.show_exceptions is set raises an exception" do
126
- controller :foo , <<-RUBY
127
+ routes <<~'RUBY'
128
+ get "/foo" => "foo#index"
129
+ RUBY
130
+ controller :foo , <<~'RUBY'
127
131
class FooController < ActionController::Base
128
132
def index
129
133
raise ActionController::UrlGenerationError
@@ -141,7 +145,7 @@ def index
141
145
app . config . action_dispatch . show_exceptions = :none
142
146
143
147
assert_raise ( ActionController ::RoutingError ) do
144
- get ( "/foo " , { } , "HTTPS" => "on" )
148
+ get ( "/does-not-exist " , { } , "HTTPS" => "on" )
145
149
end
146
150
end
147
151
@@ -165,10 +169,8 @@ def index
165
169
end
166
170
167
171
test "routing to a nonexistent controller when action_dispatch.show_exceptions and consider_all_requests_local are set shows diagnostics" do
168
- app_file "config/routes.rb" , <<-RUBY
169
- Rails.application.routes.draw do
170
- resources :articles
171
- end
172
+ routes <<~'RUBY'
173
+ resources :articles
172
174
RUBY
173
175
174
176
app . config . action_dispatch . show_exceptions = :all
@@ -179,7 +181,10 @@ def index
179
181
end
180
182
181
183
test "displays diagnostics message when exception raised in template that contains UTF-8" do
182
- controller :foo , <<-RUBY
184
+ routes <<~'RUBY'
185
+ get "/foo" => "foo#index"
186
+ RUBY
187
+ controller :foo , <<~'RUBY'
183
188
class FooController < ActionController::Base
184
189
def index
185
190
end
@@ -200,7 +205,11 @@ def index
200
205
end
201
206
202
207
test "displays diagnostics message when malformed query parameters are provided" do
203
- controller :foo , <<-RUBY
208
+ routes <<~'RUBY'
209
+ get "/foo" => "foo#index"
210
+ RUBY
211
+
212
+ controller :foo , <<~'RUBY'
204
213
class FooController < ActionController::Base
205
214
def index
206
215
end
@@ -216,7 +225,10 @@ def index
216
225
end
217
226
218
227
test "displays diagnostics message when too deep query parameters are provided" do
219
- controller :foo , <<-RUBY
228
+ routes <<~'RUBY'
229
+ get "/foo" => "foo#index"
230
+ RUBY
231
+ controller :foo , <<~'RUBY'
220
232
class FooController < ActionController::Base
221
233
def index
222
234
end
@@ -235,7 +247,10 @@ def index
235
247
end
236
248
237
249
test "displays statement invalid template correctly" do
238
- controller :foo , <<-RUBY
250
+ routes <<~'RUBY'
251
+ get "/foo" => "foo#index"
252
+ RUBY
253
+ controller :foo , <<~'RUBY'
239
254
class FooController < ActionController::Base
240
255
def index
241
256
raise ActiveRecord::StatementInvalid
@@ -258,7 +273,10 @@ def index
258
273
end
259
274
260
275
test "show_exceptions :rescuable with a rescuable error" do
261
- controller :foo , <<-RUBY
276
+ routes <<~'RUBY'
277
+ get "/foo" => "foo#index"
278
+ RUBY
279
+ controller :foo , <<~'RUBY'
262
280
class FooController < ActionController::Base
263
281
def index
264
282
raise AbstractController::ActionNotFound
@@ -273,7 +291,10 @@ def index
273
291
end
274
292
275
293
test "show_exceptions :rescuable with a non-rescuable error" do
276
- controller :foo , <<-RUBY
294
+ routes <<~'RUBY'
295
+ get "/foo" => "foo#index"
296
+ RUBY
297
+ controller :foo , <<~'RUBY'
277
298
class FooController < ActionController::Base
278
299
def index
279
300
raise 'oops'
0 commit comments