Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@mperham mperham authored
Showing with 11 additions and 8 deletions.
  1. +0 −2  init.rb
  2. +6 −5 lib/deadlock_retry.rb
  3. +5 −1 test/deadlock_retry_test.rb
View
2  init.rb
@@ -1,2 +0,0 @@
-require 'deadlock_retry'
-ActiveRecord::Base.send :include, DeadlockRetry
View
11 lib/deadlock_retry.rb
@@ -19,13 +19,12 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
module DeadlockRetry
- def self.append_features(base)
- super
+
+ def self.included(base)
base.extend(ClassMethods)
base.class_eval do
- class <<self
- alias_method :transaction_without_deadlock_handling, :transaction
- alias_method :transaction, :transaction_with_deadlock_handling
+ class << self
+ alias_method_chain :transaction, :deadlock_handling
end
end
end
@@ -80,3 +79,5 @@ def log_innodb_status
end
end
+
+ActiveRecord::Base.send(:include, DeadlockRetry)
View
6 test/deadlock_retry_test.rb
@@ -1,7 +1,7 @@
require 'rubygems'
# Change the version if you want to test a different version of ActiveRecord
-gem 'activerecord', '2.1.1'
+gem 'activerecord', '2.2.2'
require 'active_record'
require 'active_record/version'
puts "Testing ActiveRecord #{ActiveRecord::VERSION::STRING}"
@@ -66,6 +66,10 @@ def test_error_if_unrecognized_error
end
end
+ def test_included_by_default
+ assert ActiveRecord::Base.respond_to?(:transaction_with_deadlock_handling)
+ end
+
def test_error_in_nested_transaction_should_retry_outermost_transaction
tries = 0
errors = 0
Please sign in to comment.
Something went wrong with that request. Please try again.