Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

patch around other activerecord patches

  • Loading branch information...
commit ec1a5021acccac061801b3802131bbbb7416d583 1 parent 151085b
@michaelmwu michaelmwu authored
View
2  Gemfile
@@ -6,4 +6,4 @@ gem 'appraisal'
gem 'bump'
gem 'rake'
gem 'rspec', '~>2'
-gem 'sqlite3'
+gem 'sqlite3'
View
40 Gemfile.lock
@@ -3,10 +3,21 @@ PATH
specs:
ar_after_transaction (0.3.0)
activerecord
+ railties
GEM
remote: https://rubygems.org/
specs:
+ actionpack (3.2.13)
+ activemodel (= 3.2.13)
+ activesupport (= 3.2.13)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.4)
+ rack (~> 1.4.5)
+ rack-cache (~> 1.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.2.1)
activemodel (3.2.13)
activesupport (= 3.2.13)
builder (~> 3.0.0)
@@ -25,9 +36,29 @@ GEM
builder (3.0.4)
bump (0.3.5)
diff-lcs (1.1.3)
+ erubis (2.7.0)
+ hike (1.2.2)
i18n (0.6.1)
- multi_json (1.7.3)
+ journey (1.0.4)
+ json (1.8.0)
+ multi_json (1.7.6)
+ rack (1.4.5)
+ rack-cache (1.2)
+ rack (>= 0.4)
+ rack-ssl (1.3.3)
+ rack
+ rack-test (0.6.2)
+ rack (>= 1.0)
+ railties (3.2.13)
+ actionpack (= 3.2.13)
+ activesupport (= 3.2.13)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (>= 0.14.6, < 2.0)
rake (10.0.2)
+ rdoc (3.12.2)
+ json (~> 1.4)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
@@ -36,7 +67,14 @@ GEM
rspec-expectations (2.12.0)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.0)
+ sprockets (2.2.2)
+ hike (~> 1.2)
+ multi_json (~> 1.0)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.6)
+ thor (0.18.1)
+ tilt (1.4.1)
tzinfo (0.3.37)
PLATFORMS
View
2  Readme.md
@@ -77,7 +77,7 @@ Authors
- [Bogdan Gusiev](http://gusiev.com)
- [Benedikt Deicke](http://blog.synatic.net)
- [Tyler Rick](https://github.com/TylerRick)
- - [michaelmwu](https://github.com/michaelmwu)
+ - [Michael Wu](https://github.com/michaelmwu)
[Michael Grosser](http://grosser.it)<br/>
michael@grosser.it<br/>
View
1  ar_after_transaction.gemspec
@@ -8,5 +8,6 @@ Gem::Specification.new "ar_after_transaction", ARAfterTransaction::VERSION do |s
s.homepage = "http://github.com/grosser/ar_after_transaction"
s.files = `git ls-files`.split("\n")
s.add_runtime_dependency "activerecord"
+ s.add_runtime_dependency "railties"
s.license = "MIT"
end
View
1  gemfiles/rails2.gemfile
@@ -8,5 +8,6 @@ gem "rake"
gem "rspec", "~>2"
gem "sqlite3"
gem "activerecord", "~>2.3.14"
+gem "railties", '~> 2.3.14'
gemspec :path=>"../"
View
1  gemfiles/rails3.gemfile
@@ -8,5 +8,6 @@ gem "rake"
gem "rspec", "~>2"
gem "sqlite3"
gem "activerecord", "~>3.2.7"
+gem "railties", '~> 3.2.7'
gemspec :path=>"../"
View
13 lib/ar_after_transaction.rb
@@ -3,9 +3,18 @@
module ARAfterTransaction
module ClassMethods
- def transaction(*args)
+ def self.extended( base )
+ base.class_eval do
+ class << self
+ alias_method :transaction_without_after, :transaction
+ alias_method :transaction, :transaction_with_after
+ end
+ end
+ end
+
+ def transaction_with_after(*args)
clean = true
- super(*args) do
+ transaction_without_after(*args) do
begin
yield
rescue ActiveRecord::Rollback
View
91 spec/after_initialize_spec.rb
@@ -0,0 +1,91 @@
+require 'rails'
+require 'active_record'
+require File.expand_path '../setup_database', __FILE__
+
+module Passthrough
+ def self.extended( base )
+ base.class_eval do
+ class << self
+ alias_method :transaction_without_passthrough, :transaction
+ alias_method :transaction, :transaction_with_passthrough
+ end
+ end
+ end
+
+ def transaction_with_passthrough(*args, &block)
+ transaction_without_passthrough(*args, &block)
+ end
+end
+
+class Railtie < ::Rails::Railtie
+ config.after_initialize do
+ ActiveRecord::Base.send(:extend, Passthrough)
+ end
+end
+
+module ARAfterTransaction
+ class Application < ::Rails::Application
+ config.active_support.deprecation = :log
+
+ config.after_initialize do
+ require 'ar_after_transaction'
+ end
+ end
+end
+
+# Initialize the application
+ARAfterTransaction::Application.initialize!
+
+class AnExpectedError < Exception
+end
+
+class User
+ cattr_accessor :test_callbacks, :test_stack
+ self.test_stack = []
+ self.test_callbacks = []
+
+ after_create :do_it
+ def do_it
+ self.class.test_callbacks.map{|callback| send(callback)}.last
+ end
+
+ def do_after
+ after_transaction do
+ ActiveRecord::Base.transaction do
+ # nested transaction should not cause infinitive recursion
+ end
+ self.class.test_stack << :after
+ end
+ end
+
+ def do_normal
+ self.class.test_stack << :normal
+ end
+
+ def oops
+ raise AnExpectedError
+ end
+
+ def raise_rollback
+ raise ActiveRecord::Rollback
+ end
+end
+
+describe ARAfterTransaction do
+ before do
+ User.normally_open_transactions = nil
+ User.send(:transactions_open?).should == false
+ User.test_stack.clear
+ User.test_callbacks.clear
+ end
+
+ it "has a VERSION" do
+ ARAfterTransaction::VERSION.should =~ /^\d+\.\d+\.\d+$/
+ end
+
+ it "executes after a transaction" do
+ User.test_callbacks = [:do_after, :do_normal]
+ User.create!
+ User.test_stack.should == [:normal, :after]
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.