diff options
author | Paul Rosania <paul.rosania@gmail.com> | 2010-01-27 01:08:50 -0500 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2010-01-29 19:25:58 -0800 |
commit | 766e857bea9bd29f27be1ccd888eec066f2e3f04 (patch) | |
tree | 8fb8934ba767997fd944c70379d01fcdbb6d6342 /railties/test | |
parent | a06c47a52b90a5d812e64309488ad5926dc583ca (diff) | |
download | rails-766e857bea9bd29f27be1ccd888eec066f2e3f04.tar.gz rails-766e857bea9bd29f27be1ccd888eec066f2e3f04.tar.bz2 rails-766e857bea9bd29f27be1ccd888eec066f2e3f04.zip |
tsort-based dependency resolution for initializers
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/initializable_test.rb | 43 | ||||
-rw-r--r-- | railties/test/railties/plugin_test.rb | 2 |
2 files changed, 42 insertions, 3 deletions
diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb index 0c7378cb64..6a7e4dcc25 100644 --- a/railties/test/initializable_test.rb +++ b/railties/test/initializable_test.rb @@ -50,7 +50,7 @@ module InitializableTests $arr << 3 end - initializer :four, :after => :one do + initializer :four, :after => :one, :before => :two do $arr << 4 end end @@ -97,7 +97,7 @@ module InitializableTests $arr << 3 end - initializer :terminate, :after => :first do + initializer :terminate, :after => :first, :before => :startup do $arr << two end @@ -121,6 +121,39 @@ module InitializableTests end end + module Interdependent + class PluginA + include Rails::Initializable + + initializer "plugin_a.startup" do + $arr << 1 + end + + initializer "plugin_a.terminate" do + $arr << 4 + end + end + + class PluginB + include Rails::Initializable + + initializer "plugin_b.startup", :after => "plugin_a.startup" do + $arr << 2 + end + + initializer "plugin_b.terminate", :before => "plugin_a.terminate" do + $arr << 3 + end + end + + class Application + include Rails::Initializable + def self.initializers + PluginB.initializers + PluginA.initializers + end + end + end + class Basic < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation @@ -174,6 +207,12 @@ module InitializableTests Child.run_initializers assert_equal [5, 3, 1, 4, 2], $arr end + + test "handles dependencies introduced before all initializers are loaded" do + $arr = [] + Interdependent::Application.run_initializers + assert_equal [1, 2, 3, 4], $arr + end end class InstanceTest < ActiveSupport::TestCase diff --git a/railties/test/railties/plugin_test.rb b/railties/test/railties/plugin_test.rb index 997b692e49..09b859dcdd 100644 --- a/railties/test/railties/plugin_test.rb +++ b/railties/test/railties/plugin_test.rb @@ -47,7 +47,7 @@ module RailtiesTest assert_equal :debug, LEVEL end - test "plugin_init_is_ran_before_application_ones" do + test "plugin_init_is_run_before_application_ones" do plugin "foo", "$foo = true" do |plugin| plugin.write "lib/foo.rb", "module Foo; end" end |