diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-10-10 17:15:11 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-10-10 17:15:11 +0100 |
commit | 66ee2654ff243f03595a402fa15e1eea1b5b45be (patch) | |
tree | 3f1055e03082f0c767719e8cba5155e4207779e0 /railties/test/initializable_test.rb | |
parent | dd2779e1b83b4d867d47dd286ec0c919f5df12a9 (diff) | |
parent | b9ce8216fa849a47ad0b0f99fa510e226a23c12e (diff) | |
download | rails-66ee2654ff243f03595a402fa15e1eea1b5b45be.tar.gz rails-66ee2654ff243f03595a402fa15e1eea1b5b45be.tar.bz2 rails-66ee2654ff243f03595a402fa15e1eea1b5b45be.zip |
Merge commit 'mainstream/master'
Diffstat (limited to 'railties/test/initializable_test.rb')
-rw-r--r-- | railties/test/initializable_test.rb | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb new file mode 100644 index 0000000000..7c8aed00c9 --- /dev/null +++ b/railties/test/initializable_test.rb @@ -0,0 +1,68 @@ +require 'abstract_unit' +require 'rails/initializable' + +module InitializableTests + + class Foo + extend Rails::Initializable + + class << self + attr_accessor :foo, :bar + end + + initializer :omg do + @foo ||= 0 + @foo += 1 + end + end + + class Bar < Foo + initializer :bar do + @bar ||= 0 + @bar += 1 + end + end + + module Word + extend Rails::Initializable + + initializer :word do + $word = "bird" + end + end + + class Basic < ActiveSupport::TestCase + include ActiveSupport::Testing::Isolation + + test "initializers run" do + Foo.initializers.run + assert_equal 1, Foo.foo + end + + test "initializers are inherited" do + Bar.initializers.run + assert_equal [1, 1], [Bar.foo, Bar.bar] + end + + test "initializers only get run once" do + Foo.initializers.run + Foo.initializers.run + assert_equal 1, Foo.foo + end + + test "running initializers on children does not effect the parent" do + Bar.initializers.run + assert_nil Foo.foo + assert_nil Foo.bar + end + + test "inherited initializers are the same objects" do + assert Foo.initializers[:foo].eql?(Bar.initializers[:foo]) + end + + test "initializing with modules" do + Word.initializers.run + assert_equal "bird", $word + end + end +end
\ No newline at end of file |