after_commit_changes 1.0.0 → 1.0.1

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: 69c7f5e46ca54be22ea0fecc939d4a092681e5183f3f80ef7850a7b4588aa702
4
- data.tar.gz: 03c2c226e947acab43f004a8b98bfe6f0b27f3959a1abde8b421715861324442
3
+ metadata.gz: 05d161dfd3945b94e6fb19633fd6642e7d0198e4b4df776fc069145f5830bb79
4
+ data.tar.gz: ac61c36d5f91357f4f1ee5fde7d095af3b2d06a171bfe6cbc1e2c820a679da00
5
5
  SHA512:
6
- metadata.gz: c478de53032f858476b399ec9aff94aa46b14f8ccb341a29332f7cbfcd037a6fb7b3d85244172042f88c012550c7c876ee0f664c8c6af875eeb57044720ef40b
7
- data.tar.gz: 99e87f8493b2fe465ef4d14866691e4fb6ffffefbd8e8dd5e193ae262961e51a82546a2e0d43480e8bbb0cc383dd52356963489824f8ed467ac235255843fe04
6
+ metadata.gz: a3a04e388b718d74fdaa5aac1af65186d325498dfc59a3c454427a793656fafcdddda0a5e26d941acadb1308350f90f7225da14e7579ba06dfd80ef3f5b95a1b
7
+ data.tar.gz: 4c32507ae1d63e28c22c2ed78bd293f21b094fb2ab2aaf89b90ab2e0f57f77e9b9474cf467fbe8119d370e0a2496c044b792fd5824e75224f01b6aebb997d85a
data/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## 1.0.1
8
+
9
+ ### Fixed
10
+ - Changes from rolled back transactions are no longer included in the aggregated saved changes on a subsequent save.
11
+ - Changes rolled back to a savepoint (i.e. a nested transaction with `requires_new: true`) are no longer included in the aggregated saved changes when the outer transaction commits.
12
+ - Internal state tracking saved changes is now cleared after every transaction instead of being retained on the instance after transactions with a single save.
13
+
7
14
  ## 1.0.0
8
15
 
9
16
  ### Added
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # AfterCommitChanges
2
2
 
3
3
  [![Continuous Integration](https://github.com/bdurand/after_commit_changes/actions/workflows/continuous_integration.yml/badge.svg)](https://github.com/bdurand/after_commit_changes/actions/workflows/continuous_integration.yml)
4
- [![Regression Test](https://github.com/bdurand/after_commit_changes/actions/workflows/regression_test.yml/badge.svg)](https://github.com/bdurand/after_commit_changes/actions/workflows/regression_test.yml)
5
4
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
6
5
  [![Gem Version](https://badge.fury.io/rb/after_commit_changes.svg)](https://badge.fury.io/rb/after_commit_changes)
7
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -32,5 +32,5 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.add_development_dependency "bundler"
34
34
 
35
- spec.required_ruby_version = ">= 2.5"
35
+ spec.required_ruby_version = ">= 2.6"
36
36
  end
@@ -10,19 +10,29 @@ module AfterCommitChanges
10
10
 
11
11
  base.after_save do
12
12
  @after_commit_saved_changes ||= []
13
- @after_commit_saved_changes << saved_changes
13
+ @after_commit_saved_changes << [self.class.connection.open_transactions, saved_changes]
14
+ end
15
+
16
+ base.after_rollback do
17
+ if @after_commit_saved_changes
18
+ depth = self.class.connection.open_transactions
19
+ @after_commit_saved_changes.reject! { |entry_depth, _changes| entry_depth > depth }
20
+ @after_commit_saved_changes = nil if @after_commit_saved_changes.empty?
21
+ end
14
22
  end
15
23
  end
16
24
 
17
25
  private
18
26
 
19
27
  def rollup_mutations_for_transaction!
20
- return unless @after_commit_saved_changes && @after_commit_saved_changes.size > 1
28
+ saved_changes_list = @after_commit_saved_changes
29
+ @after_commit_saved_changes = nil
30
+ return unless saved_changes_list && saved_changes_list.size > 1
21
31
 
22
32
  attributes = @_start_transaction_state[:attributes].deep_dup
23
33
  mutations = ActiveModel::AttributeMutationTracker.new(attributes)
24
34
 
25
- @after_commit_saved_changes[1, @after_commit_saved_changes.length].each do |changes|
35
+ saved_changes_list.each do |_depth, changes|
26
36
  changes.each do |attr_name, value_change|
27
37
  attribute = attributes[attr_name]
28
38
  last_value = value_change.last
@@ -32,7 +42,6 @@ module AfterCommitChanges
32
42
  end
33
43
  end
34
44
 
35
- @after_commit_saved_changes = nil
36
45
  @mutations_before_last_save = mutations
37
46
  end
38
47
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: after_commit_changes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-11-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activerecord
@@ -38,7 +37,6 @@ dependencies:
38
37
  - - ">="
39
38
  - !ruby/object:Gem::Version
40
39
  version: '0'
41
- description:
42
40
  email:
43
41
  - bbdurand@gmail.com
44
42
  executables: []
@@ -55,7 +53,6 @@ homepage: https://github.com/bdurand/after_commit_changes
55
53
  licenses:
56
54
  - MIT
57
55
  metadata: {}
58
- post_install_message:
59
56
  rdoc_options: []
60
57
  require_paths:
61
58
  - lib
@@ -63,15 +60,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
60
  requirements:
64
61
  - - ">="
65
62
  - !ruby/object:Gem::Version
66
- version: '2.5'
63
+ version: '2.6'
67
64
  required_rubygems_version: !ruby/object:Gem::Requirement
68
65
  requirements:
69
66
  - - ">="
70
67
  - !ruby/object:Gem::Version
71
68
  version: '0'
72
69
  requirements: []
73
- rubygems_version: 3.4.20
74
- signing_key:
70
+ rubygems_version: 4.0.3
75
71
  specification_version: 4
76
72
  summary: Aggregate all changes made to an ActiveRecord model inside a transaction
77
73
  into a single set of changes.