after_transaction_commit 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/after_transaction_commit/database_statements.rb +15 -9
- data/lib/after_transaction_commit/transaction.rb +14 -5
- data/lib/after_transaction_commit/version.rb +1 -1
- data/spec/after_transaction_commit_spec.rb +24 -0
- data/spec/gemfiles/40.gemfile.lock +2 -2
- data/spec/gemfiles/41.gemfile.lock +2 -2
- data/spec/gemfiles/42.gemfile.lock +2 -2
- data/spec/gemfiles/50.gemfile.lock +2 -2
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d37205f04fd9dab8a6f219b2ff9ab0760b953d2
|
4
|
+
data.tar.gz: '058120cf8588254d3ce383837752aaf0d575d5cc'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 692045eb18c6ec174083466cb7d5e02b84a8eeca2c03ddb023238dad14ee4067b70946e5870899f86718577d3efbce1a0801986c2c8d57ce2b991a4db958df3f
|
7
|
+
data.tar.gz: cb79f79c415901f0b4b2fec1875795fae2f515fe08aed3d015f0e31b277b4b21e57ccccd5f889985c5e9a67e21f1470ed2293c175e2b24500a2a152304b5b960
|
@@ -28,16 +28,22 @@ ActiveRecord::ConnectionAdapters::DatabaseStatements.class_eval do
|
|
28
28
|
@after_transaction_commit = [] if @after_transaction_commit
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
if ActiveRecord.version < Gem::Version.new('5')
|
32
|
+
def _transaction_test_mode?
|
33
|
+
defined?(TestAfterCommit)
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
def _in_transaction_for_callbacks?
|
37
|
+
txn = _transaction_test_mode? ? _test_open_transactions : open_transactions
|
38
|
+
txn > 0
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
def _test_open_transactions
|
42
|
+
@test_open_transactions || 0
|
43
|
+
end
|
44
|
+
else
|
45
|
+
def _in_transaction_for_callbacks?
|
46
|
+
current_transaction.joinable?
|
47
|
+
end
|
42
48
|
end
|
43
49
|
end
|
@@ -1,10 +1,19 @@
|
|
1
1
|
module AfterTransactionCommit
|
2
2
|
module Transaction
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
if ActiveRecord.version < Gem::Version.new('5')
|
4
|
+
def rollback_records
|
5
|
+
super
|
6
|
+
if self.is_a?(ActiveRecord::ConnectionAdapters::RealTransaction) ||
|
7
|
+
(connection.send(:_transaction_test_mode?) && connection.send(:_test_open_transactions) == 0)
|
8
|
+
connection.send(:_remove_after_transaction_commit_callbacks)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
else
|
12
|
+
def rollback_records
|
13
|
+
super
|
14
|
+
unless connection.current_transaction.joinable?
|
15
|
+
connection.send(:_remove_after_transaction_commit_callbacks)
|
16
|
+
end
|
8
17
|
end
|
9
18
|
end
|
10
19
|
|
@@ -20,6 +20,29 @@ describe AfterTransactionCommit do
|
|
20
20
|
expect(a).to eql 1
|
21
21
|
end
|
22
22
|
|
23
|
+
it "immediately executes the callback when in a non-joinable transaction" do
|
24
|
+
skip "Rails 5 only" if ActiveRecord.version < Gem::Version.new('5')
|
25
|
+
a = 0
|
26
|
+
User.connection.transaction(joinable: false) do
|
27
|
+
User.connection.after_transaction_commit { a += 1 }
|
28
|
+
expect(a).to eql 1
|
29
|
+
end
|
30
|
+
expect(a).to eql 1
|
31
|
+
end
|
32
|
+
|
33
|
+
it "executes the callback when a nested transaction commits within a non-joinable transaction" do
|
34
|
+
skip "Rails 5 only" if ActiveRecord.version < Gem::Version.new('5')
|
35
|
+
a = 0
|
36
|
+
User.connection.transaction(joinable: false) do
|
37
|
+
User.connection.transaction do
|
38
|
+
User.connection.after_transaction_commit { a += 1 }
|
39
|
+
expect(a).to eql 0
|
40
|
+
end
|
41
|
+
expect(a).to eql 1
|
42
|
+
end
|
43
|
+
expect(a).to eql 1
|
44
|
+
end
|
45
|
+
|
23
46
|
it "should not execute the callbacks on rollback" do
|
24
47
|
a = 0
|
25
48
|
User.connection.transaction do
|
@@ -44,6 +67,7 @@ describe AfterTransactionCommit do
|
|
44
67
|
end
|
45
68
|
|
46
69
|
it "should execute the callback immediately if created during commit callback" do
|
70
|
+
skip "Pre-Rails 5 only" if !ENV['REAL'] && ActiveRecord.version >= Gem::Version.new('5')
|
47
71
|
a = 0
|
48
72
|
User.connection.transaction do
|
49
73
|
User.connection.after_transaction_commit { User.connection.after_transaction_commit { a += 1 } }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: after_transaction_commit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Palmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
version: '0'
|
160
160
|
requirements: []
|
161
161
|
rubyforge_project:
|
162
|
-
rubygems_version: 2.
|
162
|
+
rubygems_version: 2.6.10
|
163
163
|
signing_key:
|
164
164
|
specification_version: 4
|
165
165
|
summary: ActiveRecord::Base.connection.after_transaction_commit { ... }
|
@@ -175,4 +175,3 @@ test_files:
|
|
175
175
|
- spec/gemfiles/50.gemfile
|
176
176
|
- spec/gemfiles/50.gemfile.lock
|
177
177
|
- spec/spec_helper.rb
|
178
|
-
has_rdoc:
|