Skip to content

Commit 524faa9

Browse files
committed
Add test for after_routes_loaded
Related to rails#50720.
1 parent 2c873b8 commit 524faa9

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

railties/test/application/loading_test.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,46 @@ class User
292292
assert_equal "7", last_response.body
293293
end
294294

295+
296+
test "routes reloading triggers after_routes_loaded" do
297+
add_to_config <<-RUBY
298+
config.enable_reloading = true
299+
RUBY
300+
301+
app_file "config/routes.rb", <<-RUBY
302+
$counter ||= 1
303+
$counter *= 2
304+
Rails.application.routes.draw do
305+
get '/c', to: lambda { |env| User.name; [200, {"Content-Type" => "text/plain"}, [$counter.to_s]] }
306+
end
307+
RUBY
308+
309+
app_file "config/initializers/after_routes_loaded.rb", <<-RUBY
310+
Rails.configuration.after_routes_loaded do
311+
$counter *= 3
312+
end
313+
RUBY
314+
315+
app_file "app/models/user.rb", <<-MODEL
316+
class User
317+
$counter += 1
318+
end
319+
MODEL
320+
321+
require "rack/test"
322+
extend Rack::Test::Methods
323+
324+
require "#{rails_root}/config/environment"
325+
326+
get "/c"
327+
assert_equal "3", last_response.body
328+
329+
app_file "db/schema.rb", ""
330+
331+
get "/c"
332+
assert_equal "19", last_response.body
333+
end
334+
295335
test "routes are only loaded once on boot" do
296336
add_to_config <<-RUBY
297337
config.enable_reloading = true

0 commit comments

Comments
 (0)