Skip to content
This repository
Browse code

find railties and engines by name [4264 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 7b8399b80cfff58cfe2313187ca3c803de8c8955 1 parent 5176b28
Josh Susser joshsusser authored josevalim committed
4 railties/lib/rails/railtie.rb
@@ -32,6 +32,10 @@ def railtie_names
32 32 subclasses.map { |p| p.railtie_name }
33 33 end
34 34
  35 + def named(name)
  36 + subclasses.detect { |r| r.railtie_name == name }
  37 + end
  38 +
35 39 def log_subscriber(log_subscriber)
36 40 Rails::LogSubscriber.add(railtie_name, log_subscriber)
37 41 end
17 railties/test/railties/railtie_test.rb
@@ -15,6 +15,23 @@ def app
15 15 @app ||= Rails.application
16 16 end
17 17
  18 + test "can find railtie by name" do
  19 + class TieA < Rails::Railtie; railtie_name :railtie_a; end
  20 + class TieB < Rails::Railtie; railtie_name :railtie_b; end
  21 + class EngineA < Rails::Engine; engine_name :engine_a; end
  22 + class EngineB < Rails::Engine; engine_name :engine_b; end
  23 +
  24 + assert_equal TieA, Rails::Railtie.named(:railtie_a)
  25 + assert_equal TieB, Rails::Railtie.named(:railtie_b)
  26 + assert_nil Rails::Railtie.named(:railtie_x)
  27 + assert_nil Rails::Railtie.named(:engine_a)
  28 +
  29 + assert_equal EngineA, Rails::Engine.named(:engine_a)
  30 + assert_equal EngineB, Rails::Engine.named(:engine_b)
  31 + assert_nil Rails::Engine.named(:engine_x)
  32 + assert_nil Rails::Engine.named(:railtie_a)
  33 + end
  34 +
18 35 test "Rails::Railtie itself does not respond to config" do
19 36 assert !Rails::Railtie.respond_to?(:config)
20 37 end

0 comments on commit 7b8399b

Please sign in to comment.
Something went wrong with that request. Please try again.