Merge pull request #52303 from Shopify/routing_source_locations_in_command

Only enable routing source locations when using routes command
This commit is contained in:
Gannon McGibbon 2024-07-15 11:39:39 -05:00 committed by GitHub
commit 099776069c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 14 additions and 2 deletions

@ -68,8 +68,6 @@ class Railtie < Rails::Railtie # :nodoc:
config.action_dispatch.always_write_cookie = Rails.env.development? if config.action_dispatch.always_write_cookie.nil?
ActionDispatch::Cookies::CookieJar.always_write_cookie = config.action_dispatch.always_write_cookie
ActionDispatch::Routing::Mapper.route_source_locations = Rails.env.development?
ActionDispatch::Http::Cache::Request.strict_freshness = app.config.action_dispatch.strict_freshness
ActionDispatch.test_app = app
end

@ -6,6 +6,7 @@
require "active_support/core_ext/enumerable"
require "active_support/core_ext/array/extract_options"
require "active_support/core_ext/regexp"
require "action_dispatch/routing"
require "action_dispatch/routing/redirection"
require "action_dispatch/routing/endpoint"

@ -1,3 +1,8 @@
* Enable tracking route source locations only when using routes command. Previously,
it was enabled in development mode, but is only needed for `bin/rails routes -E`.
*Gannon McGibbon*
* Deprecate `bin/rake stats` in favor of `bin/rails stats`.
*Juan Vásquez*

@ -22,6 +22,8 @@ def invoke_command(*)
desc "routes", "List all the defined routes"
def perform(*)
require "action_dispatch/routing/mapper"
ActionDispatch::Routing::Mapper.route_source_locations = true
boot_application!
require "action_dispatch/routing/inspector"

@ -403,6 +403,12 @@ class Rails::Command::RoutesTest < ActiveSupport::TestCase
assert_includes(output, "No unused routes found.")
end
test "route source locations aren't included when booted normally" do
output = rails "runner", "print !!ActionDispatch::Routing::Mapper.route_source_locations"
assert_equal("false", output)
end
private
def run_routes_command(args = [])
rails "routes", args