ar_after_transaction 0.2.6 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
data/Gemfile.lock CHANGED
@@ -1,22 +1,22 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ar_after_transaction (0.2.6)
4
+ ar_after_transaction (0.3.0)
5
5
  activerecord
6
6
 
7
7
  GEM
8
- remote: http://rubygems.org/
8
+ remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (3.2.9)
11
- activesupport (= 3.2.9)
10
+ activemodel (3.2.13)
11
+ activesupport (= 3.2.13)
12
12
  builder (~> 3.0.0)
13
- activerecord (3.2.9)
14
- activemodel (= 3.2.9)
15
- activesupport (= 3.2.9)
13
+ activerecord (3.2.13)
14
+ activemodel (= 3.2.13)
15
+ activesupport (= 3.2.13)
16
16
  arel (~> 3.0.2)
17
17
  tzinfo (~> 0.3.29)
18
- activesupport (3.2.9)
19
- i18n (~> 0.6)
18
+ activesupport (3.2.13)
19
+ i18n (= 0.6.1)
20
20
  multi_json (~> 1.0)
21
21
  appraisal (0.5.1)
22
22
  bundler
@@ -26,7 +26,7 @@ GEM
26
26
  bump (0.3.5)
27
27
  diff-lcs (1.1.3)
28
28
  i18n (0.6.1)
29
- multi_json (1.3.7)
29
+ multi_json (1.7.3)
30
30
  rake (10.0.2)
31
31
  rspec (2.12.0)
32
32
  rspec-core (~> 2.12.0)
@@ -37,7 +37,7 @@ GEM
37
37
  diff-lcs (~> 1.1.3)
38
38
  rspec-mocks (2.12.0)
39
39
  sqlite3 (1.3.6)
40
- tzinfo (0.3.35)
40
+ tzinfo (0.3.37)
41
41
 
42
42
  PLATFORMS
43
43
  ruby
data/Readme.md CHANGED
@@ -77,6 +77,7 @@ Authors
77
77
  - [Bogdan Gusiev](http://gusiev.com)
78
78
  - [Benedikt Deicke](http://blog.synatic.net)
79
79
  - [Tyler Rick](https://github.com/TylerRick)
80
+ - [michaelmwu](https://github.com/michaelmwu)
80
81
 
81
82
  [Michael Grosser](http://grosser.it)<br/>
82
83
  michael@grosser.it<br/>
@@ -1,6 +1,6 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source :rubygems
3
+ source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
6
  gem "bump"
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: /Users/mgrosser/code/tools/ar_after_transaction
3
3
  specs:
4
- ar_after_transaction (0.2.5)
4
+ ar_after_transaction (0.2.6)
5
5
  activerecord
6
6
 
7
7
  GEM
8
- remote: http://rubygems.org/
8
+ remote: https://rubygems.org/
9
9
  specs:
10
10
  activerecord (2.3.14)
11
11
  activesupport (= 2.3.14)
@@ -1,6 +1,6 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source :rubygems
3
+ source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
6
  gem "bump"
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: /Users/mgrosser/code/tools/ar_after_transaction
3
3
  specs:
4
- ar_after_transaction (0.2.5)
4
+ ar_after_transaction (0.2.6)
5
5
  activerecord
6
6
 
7
7
  GEM
8
- remote: http://rubygems.org/
8
+ remote: https://rubygems.org/
9
9
  specs:
10
10
  activemodel (3.2.8)
11
11
  activesupport (= 3.2.8)
@@ -3,11 +3,16 @@ require 'ar_after_transaction/version'
3
3
 
4
4
  module ARAfterTransaction
5
5
  module ClassMethods
6
- @@after_transaction_callbacks = []
7
-
8
- def transaction(*args, &block)
6
+ def transaction(*args)
9
7
  clean = true
10
- super
8
+ super(*args) do
9
+ begin
10
+ yield
11
+ rescue ActiveRecord::Rollback
12
+ clean = false
13
+ raise
14
+ end
15
+ end
11
16
  rescue Exception
12
17
  clean = false
13
18
  raise
@@ -20,7 +25,8 @@ module ARAfterTransaction
20
25
 
21
26
  def after_transaction(&block)
22
27
  if transactions_open?
23
- @@after_transaction_callbacks << block
28
+ connection.after_transaction_callbacks ||= []
29
+ connection.after_transaction_callbacks << block
24
30
  else
25
31
  yield
26
32
  end
@@ -41,8 +47,8 @@ module ARAfterTransaction
41
47
  end
42
48
 
43
49
  def delete_after_transaction_callbacks
44
- result = @@after_transaction_callbacks
45
- @@after_transaction_callbacks = []
50
+ result = connection.after_transaction_callbacks || []
51
+ connection.after_transaction_callbacks = []
46
52
  result
47
53
  end
48
54
  end
@@ -54,5 +60,15 @@ module ARAfterTransaction
54
60
  end
55
61
  end
56
62
 
63
+ module ARAfterTransactionConnection
64
+ def self.included(base)
65
+ base.class_eval do
66
+ attr_accessor :normally_open_transactions
67
+ attr_accessor :after_transaction_callbacks
68
+ end
69
+ end
70
+ end
71
+
57
72
  ActiveRecord::Base.send(:extend, ARAfterTransaction::ClassMethods)
58
73
  ActiveRecord::Base.send(:include, ARAfterTransaction::InstanceMethods)
74
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, ARAfterTransactionConnection)
@@ -1,3 +1,3 @@
1
1
  module ARAfterTransaction
2
- VERSION = Version = '0.2.6'
2
+ VERSION = Version = '0.3.0'
3
3
  end
@@ -29,6 +29,10 @@ class User
29
29
  def oops
30
30
  raise AnExpectedError
31
31
  end
32
+
33
+ def raise_rollback
34
+ raise ActiveRecord::Rollback
35
+ end
32
36
  end
33
37
 
34
38
  describe ARAfterTransaction do
@@ -57,7 +61,23 @@ describe ARAfterTransaction do
57
61
  User.test_stack.should == [:normal]
58
62
  end
59
63
 
60
- it "clears transation callbacks when transaction fails" do
64
+ it "does not execute when transaction gets rolled back by ActiveRecord::Rollback raised in an after_create callback" do
65
+ User.test_callbacks = [:do_after, :do_normal, :raise_rollback]
66
+ user = User.create!
67
+ User.test_stack.should == [:normal]
68
+ end
69
+
70
+ it "does not execute when transaction gets rolled back by ActiveRecord::Rollback outside of the model" do
71
+ User.test_callbacks = [:do_after, :do_normal]
72
+ user = nil
73
+ ActiveRecord::Base.transaction do
74
+ user = User.create!
75
+ raise ActiveRecord::Rollback
76
+ end
77
+ User.test_stack.should == [:normal]
78
+ end
79
+
80
+ it "clears transaction callbacks when transaction fails" do
61
81
  User.test_callbacks = [:do_after, :do_normal, :oops]
62
82
  lambda{
63
83
  User.create!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_after_transaction
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-30 00:00:00.000000000 Z
12
+ date: 2013-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -64,7 +64,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
64
  version: '0'
65
65
  segments:
66
66
  - 0
67
- hash: 3939892965249242623
67
+ hash: -2540261946806490361
68
68
  required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  none: false
70
70
  requirements:
@@ -73,10 +73,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  version: '0'
74
74
  segments:
75
75
  - 0
76
- hash: 3939892965249242623
76
+ hash: -2540261946806490361
77
77
  requirements: []
78
78
  rubyforge_project:
79
- rubygems_version: 1.8.24
79
+ rubygems_version: 1.8.25
80
80
  signing_key:
81
81
  specification_version: 3
82
82
  summary: Execute irreversible actions only when transactions are not rolled back