1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove run_initializers from class methods.

This commit is contained in:
José Valim 2010-06-24 11:39:37 +02:00
parent 5eb3b4d9a7
commit e061a12a15
2 changed files with 14 additions and 33 deletions

View file

@ -79,14 +79,6 @@ module Rails
opts[:after] ||= initializers.last.name unless initializers.empty? || initializers.find { |i| i.name == opts[:before] } opts[:after] ||= initializers.last.name unless initializers.empty? || initializers.find { |i| i.name == opts[:before] }
initializers << Initializer.new(name, nil, opts, &blk) initializers << Initializer.new(name, nil, opts, &blk)
end 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 end
end end

View file

@ -5,10 +5,7 @@ module InitializableTests
class Foo class Foo
include Rails::Initializable include Rails::Initializable
attr_accessor :foo, :bar
class << self
attr_accessor :foo, :bar
end
initializer :start do initializer :start do
@foo ||= 0 @foo ||= 0
@ -158,30 +155,22 @@ module InitializableTests
include ActiveSupport::Testing::Isolation include ActiveSupport::Testing::Isolation
test "initializers run" do test "initializers run" do
Foo.run_initializers foo = Foo.new
assert_equal 1, Foo.foo foo.run_initializers
assert_equal 1, foo.foo
end end
test "initializers are inherited" do test "initializers are inherited" do
Bar.run_initializers bar = Bar.new
assert_equal [1, 1], [Bar.foo, Bar.bar] bar.run_initializers
assert_equal [1, 1], [bar.foo, bar.bar]
end end
test "initializers only get run once" do test "initializers only get run once" do
Foo.run_initializers foo = Foo.new
Foo.run_initializers foo.run_initializers
assert_equal 1, Foo.foo foo.run_initializers
end assert_equal 1, foo.foo
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
end end
test "creating initializer without a block raises an error" do test "creating initializer without a block raises an error" do
@ -198,19 +187,19 @@ module InitializableTests
class BeforeAfter < ActiveSupport::TestCase class BeforeAfter < ActiveSupport::TestCase
test "running on parent" do test "running on parent" do
$arr = [] $arr = []
Parent.run_initializers Parent.new.run_initializers
assert_equal [5, 1, 2], $arr assert_equal [5, 1, 2], $arr
end end
test "running on child" do test "running on child" do
$arr = [] $arr = []
Child.run_initializers Child.new.run_initializers
assert_equal [5, 3, 1, 4, 2], $arr assert_equal [5, 3, 1, 4, 2], $arr
end end
test "handles dependencies introduced before all initializers are loaded" do test "handles dependencies introduced before all initializers are loaded" do
$arr = [] $arr = []
Interdependent::Application.run_initializers Interdependent::Application.new.run_initializers
assert_equal [1, 2, 3, 4], $arr assert_equal [1, 2, 3, 4], $arr
end end
end end