Skip to content

Commit bc56661

Browse files
authored
Merge pull request rails#51933 from zzak/51910
Handle case where script_name is a blank string
2 parents f6666de + 234191c commit bc56661

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

actionpack/lib/action_dispatch/routing/mapper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ def define_generate_prefix(app, name)
714714
def optimize_routes_generation?; false; end
715715

716716
define_method :find_script_name do |options|
717-
if options.key? :script_name
717+
if options.key?(:script_name) && options[:script_name].present?
718718
super(options)
719719
else
720720
script_namer.call(options)

railties/test/railties/engine_test.rb

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,73 @@ def index
10701070
assert_equal "ok", last_response.body
10711071
end
10721072

1073+
test "nested isolated engines should set correct route module prefix" do
1074+
app = File.readlines("#{app_path}/config/application.rb")
1075+
app.insert(6, "require \"bukkits/awesome\"")
1076+
File.open("#{app_path}/config/application.rb", "r+") do |f|
1077+
f.puts app
1078+
end
1079+
1080+
@plugin.write "lib/bukkits.rb", <<-RUBY
1081+
module Bukkits
1082+
class Engine < ::Rails::Engine
1083+
isolate_namespace Bukkits
1084+
end
1085+
end
1086+
RUBY
1087+
1088+
@plugin.write "lib/bukkits/awesome.rb", <<-RUBY
1089+
module Bukkits
1090+
module Awesome
1091+
class Engine < ::Rails::Engine
1092+
isolate_namespace Bukkits::Awesome
1093+
end
1094+
end
1095+
end
1096+
RUBY
1097+
1098+
app_file "config/routes.rb", <<-RUBY
1099+
Rails.application.routes.draw do
1100+
mount Bukkits::Engine, at: "/bukkits"
1101+
end
1102+
1103+
Bukkits::Engine.routes.draw do
1104+
get "/foo" => "foo#index"
1105+
1106+
mount Bukkits::Awesome::Engine, at: "/awesome"
1107+
end
1108+
1109+
Bukkits::Awesome::Engine.routes.draw do
1110+
get "/bar", as: :bar, to: "bar#index"
1111+
end
1112+
RUBY
1113+
1114+
@plugin.write "app/controllers/bukkits/foo_controller.rb", <<-RUBY
1115+
class Bukkits::FooController < ActionController::Base
1116+
def index
1117+
render plain: bukkits_awesome.bar_path
1118+
end
1119+
end
1120+
RUBY
1121+
1122+
@plugin.write "app/controllers/bukkits/awesome/bar_controller.rb", <<-RUBY
1123+
class Bukkits::Awesome::BarController < ActionController::Base
1124+
def index
1125+
render plain: "ok"
1126+
end
1127+
end
1128+
RUBY
1129+
1130+
add_to_config("config.action_dispatch.show_exceptions = :none")
1131+
1132+
boot_rails
1133+
1134+
get("/bukkits/foo")
1135+
assert_equal "/bukkits/awesome/bar", last_response.body
1136+
get("/bukkits/awesome/bar")
1137+
assert_equal "ok", last_response.body
1138+
end
1139+
10731140
test "loading seed data" do
10741141
@plugin.write "db/seeds.rb", <<-RUBY
10751142
Bukkits::Engine.config.bukkits_seeds_loaded = true

0 commit comments

Comments
 (0)