after_transaction_commit 2.0.0 → 2.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 63f1cd01dccbe67715506366d7614ab1a3c371c9
4
- data.tar.gz: b5680b26a3c4dc8598e9e77bb22de844138889c2
2
+ SHA256:
3
+ metadata.gz: 20d35571092e0e740743873aa021004cc975761ece8ec9b09ca6032e129f3ae6
4
+ data.tar.gz: 605ca6c85f2bb022af1293e2a3628f7835c8cdd7a2019af97f701adbbc896e5e
5
5
  SHA512:
6
- metadata.gz: e9842667116d5471a281863ddd689aa7357f28010e144a3ed3341d6907319ac09cee50445c7735f060000938a82ed3eb38ddff2228401c53be8e481be7f1e368
7
- data.tar.gz: a05ca303f7121c54fbdd3d6776d1668a6b7677bc8864fc76af4d3a5506454dd61d4f8ad96ec277314e1f8efa62ed351368f0983dfbd89d1679057e4b12d96693
6
+ metadata.gz: 4f4596c9ca8547334cfdcce3e223e975852ccae179138f213bcd37fe638f0b80b0db05648fb3aed942fe4e1b82da488b75488d7d4b54338b3cae30390333a210
7
+ data.tar.gz: 90a1974ab88def8e409fbc7b3e7f39d7ddd43a9d2de99297ce6aa908feab9e050b23eefb1ab7ada7ee60770d6f076c976d51219baa3c1b492a51f21b937d8847
@@ -8,4 +8,3 @@ require "after_transaction_commit/transaction"
8
8
  # force autoloading if necessary
9
9
  ActiveRecord::ConnectionAdapters::RealTransaction
10
10
  ActiveRecord::ConnectionAdapters::Transaction.prepend(AfterTransactionCommit::Transaction)
11
- ActiveRecord::ConnectionAdapters::TransactionManager.include(AfterTransactionCommit::TransactionManager)
@@ -2,8 +2,8 @@
2
2
  # classes, so if we include into it, the other classes won't get this method
3
3
  ActiveRecord::ConnectionAdapters::DatabaseStatements.class_eval do
4
4
  def after_transaction_commit(&block)
5
- transaction = transaction_manager.outermost_joinable_transaction
6
- return block.call unless transaction
7
- transaction.after_transaction_commit(&block)
5
+ transaction = transaction_manager.current_transaction
6
+ return block.call unless transaction.joinable?
7
+ transaction.add_after_commit(block)
8
8
  end
9
9
  end
@@ -1,24 +1,21 @@
1
1
  module AfterTransactionCommit
2
2
  module Transaction
3
- def after_transaction_commit(&block)
4
- @after_transaction_commit ||= []
5
- @after_transaction_commit << block
3
+ def initialize(*)
4
+ super
5
+ @after_commit_blocks = []
6
6
  end
7
7
 
8
- def commit_records
9
- super
10
- @after_transaction_commit.each(&:call) if @after_transaction_commit.present?
8
+ def add_after_commit(block)
9
+ @after_commit_blocks << block
11
10
  end
12
- end
13
11
 
14
- module TransactionManager
15
- def outermost_joinable_transaction
16
- last_t = nil
17
- @stack.reverse_each do |t|
18
- return last_t unless t.joinable?
19
- last_t = t
12
+ def commit_records
13
+ super
14
+ if @run_commit_callbacks
15
+ @after_commit_blocks.each(&:call)
16
+ else
17
+ connection.current_transaction.instance_variable_get(:@after_commit_blocks).concat(@after_commit_blocks)
20
18
  end
21
- last_t if last_t&.joinable?
22
19
  end
23
20
  end
24
21
  end
@@ -1,3 +1,3 @@
1
1
  module AfterTransactionCommit
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -82,6 +82,19 @@ describe AfterTransactionCommit do
82
82
  expect(a).to eql 1
83
83
  end
84
84
 
85
+ it "doesn't execute the callback if an intermediate transaction rolls back" do
86
+ a = 0
87
+ User.connection.transaction do
88
+ User.connection.transaction(requires_new: true) do
89
+ User.connection.transaction(requires_new: true) do
90
+ User.connection.after_transaction_commit { a += 1 }
91
+ end
92
+ raise ActiveRecord::Rollback
93
+ end
94
+ end
95
+ expect(a).to eql 0
96
+ end
97
+
85
98
  it "doesn't lose a callback inside a callback inside a nested non-joinable transaction" do
86
99
  a = 0
87
100
  User.connection.transaction do
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: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Palmer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-14 00:00:00.000000000 Z
11
+ date: 2020-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -122,7 +122,7 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- description:
125
+ description:
126
126
  email:
127
127
  - brianp@instructure.com
128
128
  executables: []
@@ -151,7 +151,7 @@ homepage: https://github.com/instructure/after_transaction_commit
151
151
  licenses:
152
152
  - MIT
153
153
  metadata: {}
154
- post_install_message:
154
+ post_install_message:
155
155
  rdoc_options: []
156
156
  require_paths:
157
157
  - lib
@@ -166,9 +166,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
168
  requirements: []
169
- rubyforge_project:
170
- rubygems_version: 2.6.11
171
- signing_key:
169
+ rubygems_version: 3.1.2
170
+ signing_key:
172
171
  specification_version: 4
173
172
  summary: ActiveRecord::Base.connection.after_transaction_commit { ... }
174
173
  test_files: