aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/lazy_load_hooks_test.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-03-06 22:04:53 +0100
committerSantiago Pastorino <santiago@wyeworks.com>2012-03-17 17:21:02 -0300
commitc0a5b8505d0fa9095cbee8b709f9aadf630a3716 (patch)
tree2ed6114ec71d3abd5fd335850ec099a66383de56 /activesupport/test/lazy_load_hooks_test.rb
parente5b46cfb6d2a4055fa25d3d3188a40cc86988b3e (diff)
downloadrails-c0a5b8505d0fa9095cbee8b709f9aadf630a3716.tar.gz
rails-c0a5b8505d0fa9095cbee8b709f9aadf630a3716.tar.bz2
rails-c0a5b8505d0fa9095cbee8b709f9aadf630a3716.zip
Ensure load hooks can be called more than once with different contexts.
Diffstat (limited to 'activesupport/test/lazy_load_hooks_test.rb')
-rw-r--r--activesupport/test/lazy_load_hooks_test.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/activesupport/test/lazy_load_hooks_test.rb b/activesupport/test/lazy_load_hooks_test.rb
index 58ccc14324..7851634dbf 100644
--- a/activesupport/test/lazy_load_hooks_test.rb
+++ b/activesupport/test/lazy_load_hooks_test.rb
@@ -8,6 +8,16 @@ class LazyLoadHooksTest < ActiveSupport::TestCase
assert_equal 1, i
end
+ def test_basic_hook_with_two_registrations
+ i = 0
+ ActiveSupport.on_load(:basic_hook_with_two) { i += incr }
+ assert_equal 0, i
+ ActiveSupport.run_load_hooks(:basic_hook_with_two, FakeContext.new(2))
+ assert_equal 2, i
+ ActiveSupport.run_load_hooks(:basic_hook_with_two, FakeContext.new(5))
+ assert_equal 7, i
+ end
+
def test_hook_registered_after_run
i = 0
ActiveSupport.run_load_hooks(:registered_after)
@@ -16,6 +26,25 @@ class LazyLoadHooksTest < ActiveSupport::TestCase
assert_equal 1, i
end
+ def test_hook_registered_after_run_with_two_registrations
+ i = 0
+ ActiveSupport.run_load_hooks(:registered_after_with_two, FakeContext.new(2))
+ ActiveSupport.run_load_hooks(:registered_after_with_two, FakeContext.new(5))
+ assert_equal 0, i
+ ActiveSupport.on_load(:registered_after_with_two) { i += incr }
+ assert_equal 7, i
+ end
+
+ def test_hook_registered_interleaved_run_with_two_registrations
+ i = 0
+ ActiveSupport.run_load_hooks(:registered_interleaved_with_two, FakeContext.new(2))
+ assert_equal 0, i
+ ActiveSupport.on_load(:registered_interleaved_with_two) { i += incr }
+ assert_equal 2, i
+ ActiveSupport.run_load_hooks(:registered_interleaved_with_two, FakeContext.new(5))
+ assert_equal 7, i
+ end
+
def test_hook_receives_a_context
i = 0
ActiveSupport.on_load(:contextual) { i += incr }