From b185d157fe5c14ecac348558d0c0b42658de7097 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 19 Apr 2008 11:59:01 -0500 Subject: Module#synchronize: Add testcase to ensure that singleton methods can be wrapped --- .../test/core_ext/module/synchronization_test.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'activesupport/test/core_ext/module') diff --git a/activesupport/test/core_ext/module/synchronization_test.rb b/activesupport/test/core_ext/module/synchronization_test.rb index fe0f3b1a3b..b1d4bc5e06 100644 --- a/activesupport/test/core_ext/module/synchronization_test.rb +++ b/activesupport/test/core_ext/module/synchronization_test.rb @@ -40,7 +40,7 @@ class SynchronizationTest < Test::Unit::TestCase end end - def test_mutex_is_entered_during_method_call + def dummy_sync dummy = Object.new def dummy.synchronize @sync_count ||= 0 @@ -48,11 +48,15 @@ class SynchronizationTest < Test::Unit::TestCase yield end def dummy.sync_count; @sync_count; end - @target.mutex = dummy + dummy + end + + def test_mutex_is_entered_during_method_call + @target.mutex = dummy_sync @target.synchronize :to_s, :with => :mutex @instance.to_s @instance.to_s - assert_equal 2, dummy.sync_count + assert_equal 2, @target.mutex.sync_count end def test_can_synchronize_method_with_punctuation @@ -68,4 +72,14 @@ class SynchronizationTest < Test::Unit::TestCase @instance.dangerous! assert @instance.dangerous? end + + def test_can_synchronize_singleton_methods + @target.mutex = dummy_sync + class << @target + synchronize :to_s, :with => :mutex + end + assert @target.respond_to?(:to_s_without_synchronization) + assert_nothing_raised { @target.to_s; @target.to_s } + assert_equal 2, @target.mutex.sync_count + end end \ No newline at end of file -- cgit v1.2.3