1
0
Fork 0
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:
Piotr Sarnacki 2010-09-25 19:02:14 +02:00
parent 69f97f4697
commit 74598fe7e9
2 changed files with 33 additions and 12 deletions

View file

@ -333,21 +333,22 @@ module Rails
def namespace(mod) def namespace(mod)
engine_name(generate_railtie_name(mod)) engine_name(generate_railtie_name(mod))
_railtie = self
name = engine_name name = engine_name
mod.singleton_class.instance_eval do
define_method(:_railtie) do
_railtie
end
define_method(:table_name_prefix) do
"#{name}_"
end
end
self.routes.default_scope = {:module => name} self.routes.default_scope = {:module => name}
self.namespaced = true self.namespaced = true
unless mod.respond_to?(:_railtie)
_railtie = self
mod.singleton_class.instance_eval do
define_method(:_railtie) do
_railtie
end
define_method(:table_name_prefix) do
"#{name}_"
end
end
end
end end
def namespaced? def namespaced?

View file

@ -643,5 +643,25 @@ module RailtiesTest
Bukkits::Engine.load_seed Bukkits::Engine.load_seed
assert Bukkits::Engine.config.bukkits_seeds_loaded assert Bukkits::Engine.config.bukkits_seeds_loaded
end 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
end end