diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/initializable.rb | 8 | ||||
-rw-r--r-- | railties/test/initializable_test.rb | 39 |
2 files changed, 14 insertions, 33 deletions
diff --git a/railties/lib/rails/initializable.rb b/railties/lib/rails/initializable.rb index fba3ad2c85..686a2dc0cb 100644 --- a/railties/lib/rails/initializable.rb +++ b/railties/lib/rails/initializable.rb @@ -79,14 +79,6 @@ module Rails opts[:after] ||= initializers.last.name unless initializers.empty? || initializers.find { |i| i.name == opts[:before] } initializers << Initializer.new(name, nil, opts, &blk) end - - def run_initializers(*args) - return if @ran - initializers_chain.tsort.each do |initializer| - instance_exec(*args, &initializer.block) - end - @ran = true - end end end end diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb index 74301a5dc5..72c35879c5 100644 --- a/railties/test/initializable_test.rb +++ b/railties/test/initializable_test.rb @@ -5,10 +5,7 @@ module InitializableTests class Foo include Rails::Initializable - - class << self - attr_accessor :foo, :bar - end + attr_accessor :foo, :bar initializer :start do @foo ||= 0 @@ -158,30 +155,22 @@ module InitializableTests include ActiveSupport::Testing::Isolation test "initializers run" do - Foo.run_initializers - assert_equal 1, Foo.foo + foo = Foo.new + foo.run_initializers + assert_equal 1, foo.foo end test "initializers are inherited" do - Bar.run_initializers - assert_equal [1, 1], [Bar.foo, Bar.bar] + bar = Bar.new + bar.run_initializers + assert_equal [1, 1], [bar.foo, bar.bar] end test "initializers only get run once" do - Foo.run_initializers - Foo.run_initializers - assert_equal 1, Foo.foo - end - - test "running initializers on children does not effect the parent" do - Bar.run_initializers - assert_nil Foo.foo - assert_nil Foo.bar - end - - test "initializing with modules" do - Word.run_initializers - assert_equal "bird", $word + foo = Foo.new + foo.run_initializers + foo.run_initializers + assert_equal 1, foo.foo end test "creating initializer without a block raises an error" do @@ -198,19 +187,19 @@ module InitializableTests class BeforeAfter < ActiveSupport::TestCase test "running on parent" do $arr = [] - Parent.run_initializers + Parent.new.run_initializers assert_equal [5, 1, 2], $arr end test "running on child" do $arr = [] - Child.run_initializers + Child.new.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 + Interdependent::Application.new.run_initializers assert_equal [1, 2, 3, 4], $arr end end |