Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #9523 from stopdropandrew/Instrumenter#instrument-…
Browse files Browse the repository at this point in the history
…yields-payload

ActiveSupport::Notifications::Instrumenter#instrument should yield

Conflicts:
	activesupport/CHANGELOG.md
  • Loading branch information
rafaelfranca committed Mar 27, 2013
2 parents d684de4 + a007800 commit 57fbcc5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions activesupport/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ##

* `ActiveSupport::Notifications::Instrumenter#instrument` should yield
its payload.

*stopdropandrew*

* `ActiveSupport::TimeWithZone` raises `NoMethodError` in proper context.
Fixes #9772.

Expand All @@ -9,6 +14,7 @@

*Charles Jones*


## Rails 4.0.0.beta1 (February 25, 2013) ##

* Improve singularizing a singular for multiple cases.
Expand Down
Expand Up @@ -17,7 +17,7 @@ def initialize(notifier)
def instrument(name, payload={})
start name, payload
begin
yield
yield payload
rescue Exception => e
payload[:exception] = [e.class.name, e.message]
raise e
Expand Down
8 changes: 8 additions & 0 deletions activesupport/test/notifications/instrumenter_test.rb
Expand Up @@ -34,6 +34,14 @@ def test_instrument
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
Expand Down
2 changes: 1 addition & 1 deletion activesupport/test/notifications_test.rb
Expand Up @@ -157,7 +157,7 @@ def test_instrument_returns_block_result
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
Expand Down

0 comments on commit 57fbcc5

Please sign in to comment.