Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Spruce up the code to more recent idioms (alias_method_chain) and

include the module in the main file so it can be run as a gem.
  • Loading branch information...
commit 144452e860d4922b3373057ebda370886dbc0610 1 parent 1984eee
Mike Perham authored February 07, 2009
2  init.rb
... ...
@@ -1,2 +0,0 @@
1  
-require 'deadlock_retry'
2  
-ActiveRecord::Base.send :include, DeadlockRetry
11  lib/deadlock_retry.rb
@@ -19,13 +19,12 @@
19 19
 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 20
 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 21
 module DeadlockRetry
22  
-  def self.append_features(base)
23  
-    super
  22
+
  23
+  def self.included(base)
24 24
     base.extend(ClassMethods)
25 25
     base.class_eval do
26  
-      class <<self
27  
-        alias_method :transaction_without_deadlock_handling, :transaction
28  
-        alias_method :transaction, :transaction_with_deadlock_handling
  26
+      class << self
  27
+        alias_method_chain :transaction, :deadlock_handling
29 28
       end
30 29
     end
31 30
   end
@@ -80,3 +79,5 @@ def log_innodb_status
80 79
 
81 80
   end
82 81
 end
  82
+
  83
+ActiveRecord::Base.send(:include, DeadlockRetry)
6  test/deadlock_retry_test.rb
... ...
@@ -1,7 +1,7 @@
1 1
 require 'rubygems'
2 2
 
3 3
 # Change the version if you want to test a different version of ActiveRecord
4  
-gem 'activerecord', '2.1.1'
  4
+gem 'activerecord', '2.2.2'
5 5
 require 'active_record'
6 6
 require 'active_record/version'
7 7
 puts "Testing ActiveRecord #{ActiveRecord::VERSION::STRING}"
@@ -66,6 +66,10 @@ def test_error_if_unrecognized_error
66 66
     end
67 67
   end
68 68
 
  69
+  def test_included_by_default
  70
+    assert ActiveRecord::Base.respond_to?(:transaction_with_deadlock_handling)
  71
+  end
  72
+
69 73
   def test_error_in_nested_transaction_should_retry_outermost_transaction
70 74
     tries = 0
71 75
     errors = 0

0 notes on commit 144452e

Please sign in to comment.
Something went wrong with that request. Please try again.