From 45462c5e41a77e600878f7b8b2e41babeef8fe8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 4 Jan 2010 22:22:21 +0100 Subject: Expose Instrumenter id in Notifications. --- activesupport/test/notifications_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 3ba77ae135..ef6e6d8d22 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -86,6 +86,10 @@ module Notifications assert_equal 2, @notifier.instrument(:awesome) { 1 + 1 } end + def test_instrumenter_exposes_its_id + assert_equal 20, ActiveSupport::Notifications::Instrumenter.new(@notifier).id.size + end + def test_nested_events_can_be_instrumented @notifier.instrument(:awesome, :payload => "notifications") do @notifier.instrument(:wot, :payload => "child") do -- cgit v1.2.3 From 2601a16ede92566c651c06942294250ea653bd85 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 4 Jan 2010 16:22:39 -0600 Subject: Autoload AS test case --- activesupport/test/abstract_unit.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index dda139372e..d91e0415c4 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -13,7 +13,6 @@ require 'mocha' ENV['NO_RELOAD'] = '1' require 'active_support' -require 'active_support/test_case' # Include shims until we get off 1.8.6 require 'active_support/ruby/shim' -- cgit v1.2.3 From 74f6ccea201d778e020f8c758013d90ea8a5c8a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 6 Jan 2010 22:23:29 +0100 Subject: instrumenter should be accessible from ActiveSupport::Notifications. --- activesupport/test/notifications_test.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index ef6e6d8d22..62849c3d04 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -5,7 +5,8 @@ module Notifications def setup Thread.abort_on_exception = true - @notifier = ActiveSupport::Notifications::Notifier.new + ActiveSupport::Notifications.notifier = nil + @notifier = ActiveSupport::Notifications.notifier @events = [] @notifier.subscribe { |*args| @events << event(*args) } end @@ -82,17 +83,19 @@ module Notifications end class InstrumentationTest < TestCase + delegate :instrument, :to => ActiveSupport::Notifications + def test_instrument_returns_block_result - assert_equal 2, @notifier.instrument(:awesome) { 1 + 1 } + assert_equal 2, instrument(:awesome) { 1 + 1 } end def test_instrumenter_exposes_its_id - assert_equal 20, ActiveSupport::Notifications::Instrumenter.new(@notifier).id.size + assert_equal 20, ActiveSupport::Notifications.instrumenter.id.size end def test_nested_events_can_be_instrumented - @notifier.instrument(:awesome, :payload => "notifications") do - @notifier.instrument(:wot, :payload => "child") do + instrument(:awesome, :payload => "notifications") do + instrument(:wot, :payload => "child") do 1 + 1 end @@ -112,7 +115,7 @@ module Notifications def test_instrument_publishes_when_exception_is_raised begin - @notifier.instrument(:awesome, :payload => "notifications") do + instrument(:awesome, :payload => "notifications") do raise "OMG" end flunk @@ -127,7 +130,7 @@ module Notifications end def test_event_is_pushed_even_without_block - @notifier.instrument(:awesome, :payload => "notifications") + instrument(:awesome, :payload => "notifications") drain assert_equal 1, @events.size -- cgit v1.2.3 From a323b83acfe6e02812ec3b7b4ce912b07c85220e Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 7 Jan 2010 00:05:06 -0800 Subject: Remove unneeded reliance on super -> method_missing quirk --- activesupport/test/core_ext/duration_test.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index 42b4f10172..6530de1ef4 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -2,6 +2,31 @@ require 'abstract_unit' require 'active_support/time' class DurationTest < ActiveSupport::TestCase + def test_is_a + d = 1.day + assert d.is_a?(ActiveSupport::Duration) + assert d.is_a?(Numeric) + assert d.is_a?(Fixnum) + assert !d.is_a?(Hash) + + k = Class.new + class << k; undef_method :== end + assert !d.is_a?(k) + end + + def test_threequals + assert ActiveSupport::Duration === 1.day + assert !(ActiveSupport::Duration === 1.day.to_i) + assert !(ActiveSupport::Duration === 'foo') + assert !(ActiveSupport::Duration === ActiveSupport::BasicObject.new) + end + + def test_equals + assert 1.day == 1.day + assert 1.day == 1.day.to_i + assert !(1.day == 'foo') + end + def test_inspect assert_equal '0 seconds', 0.seconds.inspect assert_equal '1 month', 1.month.inspect -- cgit v1.2.3 From 4704af763f47362135b644302b8666e36a58fb34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 12 Jan 2010 13:07:04 +0100 Subject: Do not send notifications when instrumentation raise an error. --- activesupport/test/notifications_test.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 62849c3d04..226e12ff75 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -113,20 +113,17 @@ module Notifications assert_equal Hash[:payload => "notifications"], @events.last.payload end - def test_instrument_publishes_when_exception_is_raised + def test_instrument_does_not_publish_when_exception_is_raised begin instrument(:awesome, :payload => "notifications") do raise "OMG" end - flunk - rescue + rescue RuntimeError => e + assert_equal "OMG", e.message end drain - - assert_equal 1, @events.size - assert_equal :awesome, @events.last.name - assert_equal Hash[:payload => "notifications"], @events.last.payload + assert_equal 0, @events.size end def test_event_is_pushed_even_without_block -- cgit v1.2.3 From 7c3573f32757e9c4c6b6140499a3e7dfe2d335b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 13 Jan 2010 22:28:18 +0100 Subject: Add instrument! to notifications which adds the result to the payload. --- activesupport/test/notifications_test.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 226e12ff75..3690d723fa 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -83,10 +83,20 @@ module Notifications end class InstrumentationTest < TestCase - delegate :instrument, :to => ActiveSupport::Notifications + delegate :instrument, :instrument!, :to => ActiveSupport::Notifications def test_instrument_returns_block_result assert_equal 2, instrument(:awesome) { 1 + 1 } + drain + end + + def test_instrument_with_band_adds_result_to_payload + assert_equal 2, instrument!(:awesome) { 1 + 1 } + drain + + assert_equal 1, @events.size + assert_equal :awesome, @events.first.name + assert_equal Hash[:result => 2], @events.first.payload end def test_instrumenter_exposes_its_id -- cgit v1.2.3 From 7f4d8e3fbd704cf1005a46309e3795192b114013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 15 Jan 2010 11:01:37 +0100 Subject: Yield the payload notifications for further modification (like adding the result). --- activesupport/test/notifications_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 3690d723fa..c3eb1a4eb5 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -90,8 +90,8 @@ module Notifications drain end - def test_instrument_with_band_adds_result_to_payload - assert_equal 2, instrument!(:awesome) { 1 + 1 } + def test_instrument_yields_the_paylod_for_further_modification + assert_equal 2, instrument(:awesome) { |p| p[:result] = 1 + 1 } drain assert_equal 1, @events.size -- cgit v1.2.3