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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4165447ab4b683699ba7c83f00f146dfc2b16d7
4
- data.tar.gz: 551149649de9ba7f7048e1f86b111f3698d0d756
3
+ metadata.gz: 5d37205f04fd9dab8a6f219b2ff9ab0760b953d2
4
+ data.tar.gz: '058120cf8588254d3ce383837752aaf0d575d5cc'
5
5
  SHA512:
6
- metadata.gz: e46f1ff9660d8e0467251a1f3571de9895fa184bd132249f102e57bb36c33256b0b5aa31ffd0c5e1ccd36a2b96cba04f3234ed090a10731f87e78cf1ffb34ce3
7
- data.tar.gz: 68d74ffaca0ad4cbdf7911266c7e8dbd85d02eabe271b8f4951580e0d035a1a7af6116a77c40be4fa6f833152888030c1278da3b961e7672521a5043a06a477d
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
- def _transaction_test_mode?
32
- defined?(TestAfterCommit)
33
- end
31
+ if ActiveRecord.version < Gem::Version.new('5')
32
+ def _transaction_test_mode?
33
+ defined?(TestAfterCommit)
34
+ end
34
35
 
35
- def _in_transaction_for_callbacks?
36
- txn = _transaction_test_mode? ? _test_open_transactions : open_transactions
37
- txn > 0
38
- end
36
+ def _in_transaction_for_callbacks?
37
+ txn = _transaction_test_mode? ? _test_open_transactions : open_transactions
38
+ txn > 0
39
+ end
39
40
 
40
- def _test_open_transactions
41
- @test_open_transactions || 0
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
- def rollback_records
4
- super
5
- if self.is_a?(ActiveRecord::ConnectionAdapters::RealTransaction) ||
6
- (connection.send(:_transaction_test_mode?) && connection.send(:_test_open_transactions) == 0)
7
- connection.send(:_remove_after_transaction_commit_callbacks)
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
 
@@ -1,3 +1,3 @@
1
1
  module AfterTransactionCommit
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -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 } }
@@ -7,7 +7,7 @@ GIT
7
7
  activerecord (>= 3.2)
8
8
 
9
9
  PATH
10
- remote: ../../
10
+ remote: ../..
11
11
  specs:
12
12
  after_transaction_commit (1.1.0)
13
13
  activerecord (>= 4.0)
@@ -71,4 +71,4 @@ DEPENDENCIES
71
71
  wwtd
72
72
 
73
73
  BUNDLED WITH
74
- 1.12.5
74
+ 1.14.3
@@ -7,7 +7,7 @@ GIT
7
7
  activerecord (>= 3.2)
8
8
 
9
9
  PATH
10
- remote: ../../
10
+ remote: ../..
11
11
  specs:
12
12
  after_transaction_commit (1.1.0)
13
13
  activerecord (>= 4.0)
@@ -70,4 +70,4 @@ DEPENDENCIES
70
70
  wwtd
71
71
 
72
72
  BUNDLED WITH
73
- 1.12.5
73
+ 1.14.3
@@ -7,7 +7,7 @@ GIT
7
7
  activerecord (>= 3.2)
8
8
 
9
9
  PATH
10
- remote: ../../
10
+ remote: ../..
11
11
  specs:
12
12
  after_transaction_commit (1.1.0)
13
13
  activerecord (>= 4.0)
@@ -70,4 +70,4 @@ DEPENDENCIES
70
70
  wwtd
71
71
 
72
72
  BUNDLED WITH
73
- 1.12.5
73
+ 1.14.3
@@ -7,7 +7,7 @@ GIT
7
7
  activerecord (>= 3.2)
8
8
 
9
9
  PATH
10
- remote: ../../
10
+ remote: ../..
11
11
  specs:
12
12
  after_transaction_commit (1.1.0)
13
13
  activerecord (>= 4.0)
@@ -67,4 +67,4 @@ DEPENDENCIES
67
67
  wwtd
68
68
 
69
69
  BUNDLED WITH
70
- 1.12.5
70
+ 1.14.3
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.0
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: 2016-10-10 00:00:00.000000000 Z
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.5.1
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: