Merge pull request #51933 from zzak/51910

Handle case where script_name is a blank string
This commit is contained in:
Jean Boussier 2024-05-31 11:12:29 +02:00 committed by GitHub
commit bc56661a3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 68 additions and 1 deletions

@ -714,7 +714,7 @@ def define_generate_prefix(app, name)
def optimize_routes_generation?; false; end
define_method :find_script_name do |options|
if options.key? :script_name
if options.key?(:script_name) && options[:script_name].present?
super(options)
else
script_namer.call(options)

@ -1070,6 +1070,73 @@ def index
assert_equal "ok", last_response.body
end
test "nested isolated engines should set correct route module prefix" do
app = File.readlines("#{app_path}/config/application.rb")
app.insert(6, "require \"bukkits/awesome\"")
File.open("#{app_path}/config/application.rb", "r+") do |f|
f.puts app
end
@plugin.write "lib/bukkits.rb", <<-RUBY
module Bukkits
class Engine < ::Rails::Engine
isolate_namespace Bukkits
end
end
RUBY
@plugin.write "lib/bukkits/awesome.rb", <<-RUBY
module Bukkits
module Awesome
class Engine < ::Rails::Engine
isolate_namespace Bukkits::Awesome
end
end
end
RUBY
app_file "config/routes.rb", <<-RUBY
Rails.application.routes.draw do
mount Bukkits::Engine, at: "/bukkits"
end
Bukkits::Engine.routes.draw do
get "/foo" => "foo#index"
mount Bukkits::Awesome::Engine, at: "/awesome"
end
Bukkits::Awesome::Engine.routes.draw do
get "/bar", as: :bar, to: "bar#index"
end
RUBY
@plugin.write "app/controllers/bukkits/foo_controller.rb", <<-RUBY
class Bukkits::FooController < ActionController::Base
def index
render plain: bukkits_awesome.bar_path
end
end
RUBY
@plugin.write "app/controllers/bukkits/awesome/bar_controller.rb", <<-RUBY
class Bukkits::Awesome::BarController < ActionController::Base
def index
render plain: "ok"
end
end
RUBY
add_to_config("config.action_dispatch.show_exceptions = :none")
boot_rails
get("/bukkits/foo")
assert_equal "/bukkits/awesome/bar", last_response.body
get("/bukkits/awesome/bar")
assert_equal "ok", last_response.body
end
test "loading seed data" do
@plugin.write "db/seeds.rb", <<-RUBY
Bukkits::Engine.config.bukkits_seeds_loaded = true