public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Module#synchronize: Add testcase to ensure that singleton methods can be wrapped
Nick (author)
Sat Apr 19 09:59:01 -0700 2008
commit  b185d157fe5c14ecac348558d0c0b42658de7097
tree    20a687e0dc14b0f3e5e43dad7b6f277ad97cbebc
parent  9dc4f6611043d032e576d93430cd29efc8864bc4
...
20
21
22
23
24
25
26
...
20
21
22
 
23
24
25
0
@@ -20,7 +20,6 @@ class Module
0
 
0
     methods.each do |method|
0
       aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
0
-      
0
       if instance_methods.include?("#{aliased_method}_without_synchronization#{punctuation}")
0
         raise ArgumentError, "#{method} is already synchronized. Double synchronization is not currently supported."
0
       end
...
40
41
42
43
 
44
45
46
...
48
49
50
51
 
 
 
 
 
52
53
54
55
 
56
57
58
...
68
69
70
 
 
 
 
 
 
 
 
 
 
71
72
...
40
41
42
 
43
44
45
46
...
48
49
50
 
51
52
53
54
55
56
57
58
 
59
60
61
62
...
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
0
@@ -40,7 +40,7 @@ class SynchronizationTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
-  def test_mutex_is_entered_during_method_call
0
+  def dummy_sync
0
     dummy = Object.new
0
     def dummy.synchronize
0
       @sync_count ||= 0
0
@@ -48,11 +48,15 @@ class SynchronizationTest < Test::Unit::TestCase
0
       yield
0
     end
0
     def dummy.sync_count; @sync_count; end
0
-    @target.mutex = dummy
0
+    dummy
0
+  end
0
+
0
+  def test_mutex_is_entered_during_method_call
0
+    @target.mutex = dummy_sync
0
     @target.synchronize :to_s, :with => :mutex
0
     @instance.to_s
0
     @instance.to_s
0
-    assert_equal 2, dummy.sync_count
0
+    assert_equal 2, @target.mutex.sync_count
0
   end
0
 
0
   def test_can_synchronize_method_with_punctuation
0
@@ -68,4 +72,14 @@ class SynchronizationTest < Test::Unit::TestCase
0
     @instance.dangerous!
0
     assert @instance.dangerous?
0
   end
0
+
0
+  def test_can_synchronize_singleton_methods
0
+    @target.mutex = dummy_sync
0
+    class << @target
0
+      synchronize :to_s, :with => :mutex
0
+    end
0
+    assert @target.respond_to?(:to_s_without_synchronization)
0
+    assert_nothing_raised { @target.to_s; @target.to_s }
0
+    assert_equal 2, @target.mutex.sync_count
0
+  end
0
 end
0
\ No newline at end of file

Comments