aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick <nick@nicksieger.com>2008-04-19 11:59:01 -0500
committerNick Sieger <nick@nicksieger.com>2008-08-29 14:12:09 -0500
commitb185d157fe5c14ecac348558d0c0b42658de7097 (patch)
tree20a687e0dc14b0f3e5e43dad7b6f277ad97cbebc
parent9dc4f6611043d032e576d93430cd29efc8864bc4 (diff)
downloadrails-b185d157fe5c14ecac348558d0c0b42658de7097.tar.gz
rails-b185d157fe5c14ecac348558d0c0b42658de7097.tar.bz2
rails-b185d157fe5c14ecac348558d0c0b42658de7097.zip
Module#synchronize: Add testcase to ensure that singleton methods can be wrapped
-rw-r--r--activesupport/lib/active_support/core_ext/module/synchronization.rb1
-rw-r--r--activesupport/test/core_ext/module/synchronization_test.rb20
2 files changed, 17 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/synchronization.rb b/activesupport/lib/active_support/core_ext/module/synchronization.rb
index c55a3f07ee..7d54d496ab 100644
--- a/activesupport/lib/active_support/core_ext/module/synchronization.rb
+++ b/activesupport/lib/active_support/core_ext/module/synchronization.rb
@@ -20,7 +20,6 @@ class Module
methods.each do |method|
aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
-
if instance_methods.include?("#{aliased_method}_without_synchronization#{punctuation}")
raise ArgumentError, "#{method} is already synchronized. Double synchronization is not currently supported."
end
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