From a007800a552a9ab31c21134c2e716222268a1276 Mon Sep 17 00:00:00 2001 From: stopdropandrew Date: Sat, 2 Mar 2013 15:50:41 -0800 Subject: [PATCH] ActiveSupport::Notifications::Instrumenter#instrument should yield its payload the same way that ActiveSupport::Notifications does. Fix spelling in test name. --- activesupport/CHANGELOG.md | 7 ++++++- .../lib/active_support/notifications/instrumenter.rb | 2 +- activesupport/test/notifications/instrumenter_test.rb | 8 ++++++++ activesupport/test/notifications_test.rb | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index c47cb75274..de6d3324eb 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,7 +1,12 @@ ## Rails 4.0.0 (unreleased) ## +* `ActiveSupport::Notifications::Instrumenter#instrument` should yield + its payload. + + *stopdropandrew* + * Fix deletion of empty directories in ActiveSupport::Cache::FileStore. - + *Charles Jones* ## Rails 4.0.0.beta1 (February 25, 2013) ## diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 1ee7ca06bb..e0ae60e61f 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -17,7 +17,7 @@ module ActiveSupport def instrument(name, payload={}) start name, payload begin - yield + yield payload rescue Exception => e payload[:exception] = [e.class.name, e.message] raise e diff --git a/activesupport/test/notifications/instrumenter_test.rb b/activesupport/test/notifications/instrumenter_test.rb index 62a9b61464..f46e96f636 100644 --- a/activesupport/test/notifications/instrumenter_test.rb +++ b/activesupport/test/notifications/instrumenter_test.rb @@ -34,6 +34,14 @@ module ActiveSupport assert called end + def test_instrument_yields_the_payload_for_further_modification + assert_equal 2, instrumenter.instrument("awesome") { |p| p[:result] = 1 + 1 } + assert_equal 1, notifier.finishes.size + name, _, payload = notifier.finishes.first + assert_equal "awesome", name + assert_equal Hash[:result => 2], payload + end + def test_start instrumenter.start("foo", payload) assert_equal [["foo", instrumenter.id, payload]], notifier.starts diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index bcb393c7bc..d63c59883a 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -157,7 +157,7 @@ module Notifications assert_equal 2, instrument(:awesome) { 1 + 1 } end - def test_instrument_yields_the_paylod_for_further_modification + def test_instrument_yields_the_payload_for_further_modification assert_equal 2, instrument(:awesome) { |p| p[:result] = 1 + 1 } assert_equal 1, @events.size assert_equal :awesome, @events.first.name