diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/railtie.rb | 4 | ||||
-rw-r--r-- | railties/test/railties/railtie_test.rb | 17 |
2 files changed, 21 insertions, 0 deletions
diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 37c802fb60..be5d4ff260 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -32,6 +32,10 @@ module Rails subclasses.map { |p| p.railtie_name } end + def named(name) + subclasses.detect { |r| r.railtie_name == name } + end + def log_subscriber(log_subscriber) Rails::LogSubscriber.add(railtie_name, log_subscriber) end diff --git a/railties/test/railties/railtie_test.rb b/railties/test/railties/railtie_test.rb index 9fefb285b4..22fb0a2ec3 100644 --- a/railties/test/railties/railtie_test.rb +++ b/railties/test/railties/railtie_test.rb @@ -15,6 +15,23 @@ module RailtiesTest @app ||= Rails.application end + test "can find railtie by name" do + class TieA < Rails::Railtie; railtie_name :railtie_a; end + class TieB < Rails::Railtie; railtie_name :railtie_b; end + class EngineA < Rails::Engine; engine_name :engine_a; end + class EngineB < Rails::Engine; engine_name :engine_b; end + + assert_equal TieA, Rails::Railtie.named(:railtie_a) + assert_equal TieB, Rails::Railtie.named(:railtie_b) + assert_nil Rails::Railtie.named(:railtie_x) + assert_nil Rails::Railtie.named(:engine_a) + + assert_equal EngineA, Rails::Engine.named(:engine_a) + assert_equal EngineB, Rails::Engine.named(:engine_b) + assert_nil Rails::Engine.named(:engine_x) + assert_nil Rails::Engine.named(:railtie_a) + end + test "Rails::Railtie itself does not respond to config" do assert !Rails::Railtie.respond_to?(:config) end |