diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-08-16 15:46:51 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-16 15:46:51 -0400 |
commit | 02c25c3cd419e93fc3882155611a4f8aa757ff3a (patch) | |
tree | cb5926049512a7a8b74386edce9ef1b2ea9bba62 | |
parent | e183dc195a965371b1edc3ea18c54910758c32e3 (diff) | |
parent | e15583c32e292acdd595dbf137d1c7cb0ea73e58 (diff) | |
download | rails-02c25c3cd419e93fc3882155611a4f8aa757ff3a.tar.gz rails-02c25c3cd419e93fc3882155611a4f8aa757ff3a.tar.bz2 rails-02c25c3cd419e93fc3882155611a4f8aa757ff3a.zip |
Merge pull request #30285 from albertoalmagro/pass-missing-name-attribute
Pass missing name attribute to execute_hook
-rw-r--r-- | activesupport/lib/active_support/lazy_load_hooks.rb | 6 | ||||
-rw-r--r-- | activesupport/test/lazy_load_hooks_test.rb | 13 |
2 files changed, 12 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/lazy_load_hooks.rb b/activesupport/lib/active_support/lazy_load_hooks.rb index c124416595..dc8080c469 100644 --- a/activesupport/lib/active_support/lazy_load_hooks.rb +++ b/activesupport/lib/active_support/lazy_load_hooks.rb @@ -40,7 +40,7 @@ module ActiveSupport # * <tt>:run_once</tt> - Given +block+ will run only once. def on_load(name, options = {}, &block) @loaded[name].each do |base| - execute_hook(base, options, block) + execute_hook(name, base, options, block) end @load_hooks[name] << [block, options] @@ -49,7 +49,7 @@ module ActiveSupport def run_load_hooks(name, base = Object) @loaded[name] << base @load_hooks[name].each do |hook, options| - execute_hook(base, options, hook) + execute_hook(name, base, options, hook) end end @@ -63,7 +63,7 @@ module ActiveSupport end end - def execute_hook(base, options, block) + def execute_hook(name, base, options, block) with_execution_control(name, block, options[:run_once]) do if options[:yield] block.call(base) diff --git a/activesupport/test/lazy_load_hooks_test.rb b/activesupport/test/lazy_load_hooks_test.rb index c161005100..721d44d0c1 100644 --- a/activesupport/test/lazy_load_hooks_test.rb +++ b/activesupport/test/lazy_load_hooks_test.rb @@ -22,14 +22,19 @@ class LazyLoadHooksTest < ActiveSupport::TestCase def test_basic_hook_with_two_registrations_only_once i = 0 - ActiveSupport.on_load(:basic_hook_with_two_once, run_once: true) do + 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 - assert_equal 0, i - ActiveSupport.run_load_hooks(:basic_hook_with_two_once, FakeContext.new(2)) + + 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 2, i + assert_equal 11, i end def test_hook_registered_after_run |