mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Do not overwrite _railtie method on namespace while creating isolated engine or application.
In order to run Engine as standalone application, you will need Rails::Application instance in the same namespace that engine one. It's very important to leave _railtie bound to whatever used "namespace" method first.
This commit is contained in:
parent
69f97f4697
commit
74598fe7e9
2 changed files with 33 additions and 12 deletions
|
@ -333,8 +333,12 @@ module Rails
|
|||
def namespace(mod)
|
||||
engine_name(generate_railtie_name(mod))
|
||||
|
||||
_railtie = self
|
||||
name = engine_name
|
||||
self.routes.default_scope = {:module => name}
|
||||
self.namespaced = true
|
||||
|
||||
unless mod.respond_to?(:_railtie)
|
||||
_railtie = self
|
||||
mod.singleton_class.instance_eval do
|
||||
define_method(:_railtie) do
|
||||
_railtie
|
||||
|
@ -344,10 +348,7 @@ module Rails
|
|||
"#{name}_"
|
||||
end
|
||||
end
|
||||
|
||||
self.routes.default_scope = {:module => name}
|
||||
|
||||
self.namespaced = true
|
||||
end
|
||||
end
|
||||
|
||||
def namespaced?
|
||||
|
|
|
@ -643,5 +643,25 @@ module RailtiesTest
|
|||
Bukkits::Engine.load_seed
|
||||
assert Bukkits::Engine.config.bukkits_seeds_loaded
|
||||
end
|
||||
|
||||
test "using namespace more than once on one module should not overwrite _railtie method" do
|
||||
@plugin.write "lib/bukkits.rb", <<-RUBY
|
||||
module AppTemplate
|
||||
class Engine < ::Rails::Engine
|
||||
namespace(AppTemplate)
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
|
||||
add_to_config "namespace AppTemplate"
|
||||
|
||||
app_file "config/routes.rb", <<-RUBY
|
||||
AppTemplate::Application.routes.draw do end
|
||||
RUBY
|
||||
|
||||
boot_rails
|
||||
|
||||
assert_equal AppTemplate._railtie, AppTemplate::Engine
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue