diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 317e8886f6..8701806419 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -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) diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 43b8bd3535..81782a1842 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -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