class LazyLoadHooksTest
Public Instance Methods
test_basic_hook()
click to toggle source
# File activesupport/test/lazy_load_hooks_test.rb, line 6 def test_basic_hook i = 0 ActiveSupport.on_load(:basic_hook) { i += 1 } ActiveSupport.run_load_hooks(:basic_hook) assert_equal 1, i end
test_basic_hook_with_two_registrations()
click to toggle source
# File activesupport/test/lazy_load_hooks_test.rb, line 13 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
test_basic_hook_with_two_registrations_only_once()
click to toggle source
# File activesupport/test/lazy_load_hooks_test.rb, line 23 def test_basic_hook_with_two_registrations_only_once i = 0 block = proc { i += incr } ActiveSupport.on_load(:basic_hook_with_two_once, run_once: true, &block) ActiveSupport.on_load(:basic_hook_with_two_once) do i += incr end ActiveSupport.on_load(:different_hook, run_once: true, &block) ActiveSupport.run_load_hooks(:different_hook, FakeContext.new(2)) assert_equal 2, i ActiveSupport.run_load_hooks(:basic_hook_with_two_once, FakeContext.new(2)) assert_equal 6, i ActiveSupport.run_load_hooks(:basic_hook_with_two_once, FakeContext.new(5)) assert_equal 11, i end
test_hook_receives_a_context()
click to toggle source
# File activesupport/test/lazy_load_hooks_test.rb, line 92 def test_hook_receives_a_context i = 0 ActiveSupport.on_load(:contextual) { i += incr } assert_equal 0, i ActiveSupport.run_load_hooks(:contextual, FakeContext.new(2)) assert_equal 2, i end
test_hook_receives_a_context_afterward()
click to toggle source
# File activesupport/test/lazy_load_hooks_test.rb, line 100 def test_hook_receives_a_context_afterward i = 0 ActiveSupport.run_load_hooks(:contextual_after, FakeContext.new(2)) assert_equal 0, i ActiveSupport.on_load(:contextual_after) { i += incr } assert_equal 2, i end
test_hook_registered_after_run()
click to toggle source
# File activesupport/test/lazy_load_hooks_test.rb, line 40 def test_hook_registered_after_run i = 0 ActiveSupport.run_load_hooks(:registered_after) assert_equal 0, i ActiveSupport.on_load(:registered_after) { i += 1 } assert_equal 1, i end
test_hook_registered_after_run_with_two_registrations()
click to toggle source
# File activesupport/test/lazy_load_hooks_test.rb, line 48 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
test_hook_registered_after_run_with_two_registrations_only_once()
click to toggle source
# File activesupport/test/lazy_load_hooks_test.rb, line 57 def test_hook_registered_after_run_with_two_registrations_only_once i = 0 ActiveSupport.run_load_hooks(:registered_after_with_two_once, FakeContext.new(2)) ActiveSupport.run_load_hooks(:registered_after_with_two_once, FakeContext.new(5)) assert_equal 0, i ActiveSupport.on_load(:registered_after_with_two_once, run_once: true) { i += incr } assert_equal 2, i end
test_hook_registered_interleaved_run_with_two_registrations()
click to toggle source
# File activesupport/test/lazy_load_hooks_test.rb, line 66 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
test_hook_registered_interleaved_run_with_two_registrations_once()
click to toggle source
# File activesupport/test/lazy_load_hooks_test.rb, line 76 def test_hook_registered_interleaved_run_with_two_registrations_once i = 0 ActiveSupport .run_load_hooks(:registered_interleaved_with_two_once, FakeContext.new(2)) assert_equal 0, i ActiveSupport.on_load(:registered_interleaved_with_two_once, run_once: true) do i += incr end assert_equal 2, i ActiveSupport .run_load_hooks(:registered_interleaved_with_two_once, FakeContext.new(5)) assert_equal 2, i end
test_hook_with_yield_true()
click to toggle source
# File activesupport/test/lazy_load_hooks_test.rb, line 108 def test_hook_with_yield_true i = 0 ActiveSupport.on_load(:contextual_yield, yield: true) do |obj| i += obj.incr + incr_amt end assert_equal 0, i ActiveSupport.run_load_hooks(:contextual_yield, FakeContext.new(2)) assert_equal 7, i end
test_hook_with_yield_true_afterward()
click to toggle source
# File activesupport/test/lazy_load_hooks_test.rb, line 118 def test_hook_with_yield_true_afterward i = 0 ActiveSupport.run_load_hooks(:contextual_yield_after, FakeContext.new(2)) assert_equal 0, i ActiveSupport.on_load(:contextual_yield_after, yield: true) do |obj| i += obj.incr + incr_amt end assert_equal 7, i end
Private Instance Methods
incr_amt()
click to toggle source
# File activesupport/test/lazy_load_hooks_test.rb, line 130 def incr_amt 5 end