diff options
-rw-r--r-- | railties/lib/rails/engine.rb | 2 | ||||
-rw-r--r-- | railties/test/railties/railtie_test.rb | 16 |
2 files changed, 18 insertions, 0 deletions
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 6b1e21a798..de16c55990 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -166,6 +166,7 @@ module Rails class << self attr_accessor :called_from + alias :engine_name :railtie_name def inherited(base) unless base.abstract_railtie? @@ -201,6 +202,7 @@ module Rails end delegate :middleware, :root, :paths, :to => :config + delegate :engine_name, :to => "self.class" def load_tasks super diff --git a/railties/test/railties/railtie_test.rb b/railties/test/railties/railtie_test.rb index 6715003d3d..406d5d764f 100644 --- a/railties/test/railties/railtie_test.rb +++ b/railties/test/railties/railtie_test.rb @@ -19,6 +19,22 @@ module RailtiesTest assert !Rails::Railtie.respond_to?(:config) end + test "Railtie provides railtie_name" do + begin + class ::Foo < Rails::Railtie ; end + assert_equal "foo", ::Foo.railtie_name + ensure + Object.send(:remove_const, :"Foo") + end + end + + test "railtie_name can be set manualy" do + class Foo < Rails::Railtie + railtie_name "bar" + end + assert_equal "bar", Foo.railtie_name + end + test "cannot inherit from a railtie" do class Foo < Rails::Railtie ; end assert_raise RuntimeError do |