ar_transaction_changes 1.1.10 → 1.1.11

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
2
  SHA256:
3
- metadata.gz: 714d24f3fc939b5ab4170bd5863573aea0b5f9f918d3494f51656096579d0cc6
4
- data.tar.gz: 62d4814dccd3e3f5623958e1182ba8654eca9d37cc01bf986cfa09527fc5b6b5
3
+ metadata.gz: c1ad6773a9205c5481c708ac6685c0f0609018fb0bc03845b57db109a32bd6b3
4
+ data.tar.gz: a4df65cd09d591fefb68fa9c3b1ccf311fbffcafb42e7ac7192622d747e05d49
5
5
  SHA512:
6
- metadata.gz: 1a77baf0fd44d182e407c79ae17499933aa0a85aa1a9d2c7be3c4b1df2a0a6bee34a4d18d10bb82a5aea3b45aaa65dfde4d6254bf49b5aa8abb2dd293900b6ac
7
- data.tar.gz: ab7fd9f52be45e78f6911159cb7c472ac9d78151891b1968bfcf1629ee97e65a944ef71178c5b5411f935b680d5a460f99f6884c3d8ce08aad6274b882b175f5
6
+ metadata.gz: f51346e32137f229013ccaf2f201e6d2ec2c60a806fb92f452818c1cf8d553a13f45744d17b0a0b8bff33496455611451443aa81f7f780826fa4b546fb91394e
7
+ data.tar.gz: 4c7200f2d0dcbe341fda292fe71a916dd072c52a617c992c5140abb203765d4ce1b456efa67a20bf8ba3c310ea1038c90486424fce9b6e1844c91920c5910fbf
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ArTransactionChanges
4
- VERSION = "1.1.10"
4
+ VERSION = "1.1.11"
5
5
  end
@@ -4,37 +4,37 @@ require "ar_transaction_changes/version"
4
4
  require "active_record"
5
5
 
6
6
  module ArTransactionChanges
7
- def self.included(base)
8
- if base.respond_to?(:_commit_callbacks) && base.respond_to?(:_rollback_callbacks)
9
- if !base._commit_callbacks.empty? || !base._rollback_callbacks.empty?
10
- raise "ArTransactionChanges must be included before defining any after_commit or after_rollback callbacks"
11
- end
12
- end
13
- end
14
-
15
- if ActiveRecord.version >= Gem::Version.new('8.1.0.alpha')
16
- def _run_commit_callbacks!
7
+ if ActiveRecord.version >= Gem::Version.new('7.1')
8
+ def run_callbacks(kind, type = nil)
17
9
  super
18
10
  ensure
19
- @transaction_changed_attributes = nil
11
+ if kind == :commit || kind == :rollback
12
+ @transaction_changed_attributes = nil
13
+ end
20
14
  end
21
15
 
22
- def _run_rollback_callbacks!
23
- super
24
- ensure
25
- @transaction_changed_attributes = nil
16
+ if ActiveRecord.version >= Gem::Version.new('8.1.0.alpha')
17
+ # We should reset @transaction_changed_attributes in the no-op version of the method.
18
+ # Even if there are no callbacks registered, attributes should be reset on commit/rollback.
19
+ def _run_commit_callbacks
20
+ super
21
+ ensure
22
+ @transaction_changed_attributes = nil
23
+ end
24
+
25
+ def _run_rollback_callbacks
26
+ super
27
+ ensure
28
+ @transaction_changed_attributes = nil
29
+ end
26
30
  end
27
31
  else
28
- def _run_commit_callbacks
32
+ def run_callbacks(kind)
29
33
  super
30
34
  ensure
31
- @transaction_changed_attributes = nil
32
- end
33
-
34
- def _run_rollback_callbacks
35
- super
36
- ensure
37
- @transaction_changed_attributes = nil
35
+ if kind == :commit || kind == :rollback
36
+ @transaction_changed_attributes = nil
37
+ end
38
38
  end
39
39
  end
40
40
 
@@ -174,28 +174,4 @@ class TransactionChangesTest < Minitest::Test
174
174
 
175
175
  assert_equal [[], ['a', 'b']], @user.stored_transaction_changes['notes']
176
176
  end
177
-
178
- def test_do_not_allow_adding_this_gem_to_a_model_after_commit_callbacks_are_defined
179
- assert_raises(RuntimeError) do
180
- Class.new(ActiveRecord::Base) do
181
- after_commit :some_method
182
-
183
- include ArTransactionChanges
184
-
185
- def some_method; end
186
- end
187
- end
188
- end
189
-
190
- def test_do_not_allow_adding_this_gem_to_a_model_after_rollback_callbacks_are_defined
191
- assert_raises(RuntimeError) do
192
- Class.new(ActiveRecord::Base) do
193
- after_rollback :some_method
194
-
195
- include ArTransactionChanges
196
-
197
- def some_method; end
198
- end
199
- end
200
- end
201
177
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_transaction_changes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.10
4
+ version: 1.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Thacker-Smith