paper_trail-association_tracking 2.3.0 → 2.4.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
2
  SHA256:
3
- metadata.gz: 5a94904cbcb068a832c7aee7d04d63750631a0dddc282da68665c98cf053baed
4
- data.tar.gz: bfb10257058405a0b4e99a555724d53b01cc050d18c6f00fb27979f8c415ded9
3
+ metadata.gz: 53355e19e486ebed17b18112e6f20a118b98dc5a3777ba8fd2bb5dfd42864be3
4
+ data.tar.gz: 3aa942c6ab92e50d27bcaf8092153d3fb997922cb9a4266cbe372e0433e0be0f
5
5
  SHA512:
6
- metadata.gz: e52ddb1d136efd024b7b138dd5e2bb4676ec1f77fd6f20aeb54048e7d886e560681bac88fec4fbf1216af7aa27dc7eb485e02f5b6623a402b903de6a91cbcd8a
7
- data.tar.gz: 5a2b6bbc604f5637ffa8758411874af0ac8c1c4a6b80f5d4f595e2c01e41399d64b69b608a1e83c6137c78373123a2078aa137749b5b24b8ef72d6d201f0dbbf
6
+ metadata.gz: 198d8abfe3e63c3d73b850fce97c5ffaf8291b7e8bb99385301e03585e064e0c9a61781b421219beaefd1d4d2f925deb0b0690a42a0f7065347531c5bf5c59b4
7
+ data.tar.gz: 60045bcaccabb01aae1567187d4978cd0fd84f3cc354fa06bc60630d5809850e33b5107533c8482ea69af1bbdd4d3ad54bfa6805b04d27588754dfdbc4bf1b2a
data/CHANGELOG.md CHANGED
@@ -1,8 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
- ### Unreleased - [View Diff](https://github.com/westonganger/paper_trail-association_tracking/compare/v2.3.0...master)
3
+ ### Unreleased - [View Diff](https://github.com/westonganger/paper_trail-association_tracking/compare/v2.4.0...master)
4
4
  - Nothing yet
5
5
 
6
+ ### v2.4.0 - 2026-09-16 - [View Diff](https://github.com/westonganger/paper_trail-association_tracking/compare/v2.3.0...v2.4.0)
7
+ - [#59](https://github.com/westonganger/paper_trail-association_tracking/pull/59) - Pass the version object when saving `belongs_to` association rows, so `VersionAssociation` no longer loads the parent version before each INSERT under `belongs_to_required_by_default`
8
+ - [#56](https://github.com/westonganger/paper_trail-association_tracking/pull/56) - Defer inclusion until after active record has fully loaded
9
+ - [#54](https://github.com/westonganger/paper_trail-association_tracking/pull/54) - Change migration for `versions.transaction_id` to BIGINT
10
+
6
11
  ### v2.3.0 - 2025-04-17 - [View Diff](https://github.com/westonganger/paper_trail-association_tracking/compare/v2.2.1...v2.3.0)
7
12
  - [#46](https://github.com/westonganger/paper_trail-association_tracking/pull/46) - Add support for custom version association class with separate database connection
8
13
  - [#49](https://github.com/westonganger/paper_trail-association_tracking/pull/49) - Fix has_many though associations when the through association is singular
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  <a href='https://github.com/westonganger/paper_trail-association_tracking/actions' target='_blank'><img src="https://github.com/westonganger/paper_trail-association_tracking/actions/workflows/test.yml/badge.svg?branch=master" style="max-width:100%;" height='21' style='border:0px;height:21px;' border='0' alt="CI Status"></a>
5
5
  <a href='https://rubygems.org/gems/paper_trail-association_tracking' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://img.shields.io/gem/dt/paper_trail-association_tracking?color=brightgreen&label=Rubygems%20Downloads' border='0' alt='RubyGems Downloads' /></a>
6
6
 
7
- Plugin for the [PaperTrail](https://github.com/paper-trail-gem/paper_trail.git) gem to track and reify associations. This gem was extracted from PaperTrail for v9.2.0 to simplify things in PaperTrail and association tracking separately.
7
+ Plugin for the [PaperTrail](https://github.com/paper-trail-gem/paper_trail.git) gem to track and reify associations. This gem was extracted from PaperTrail core.
8
8
 
9
9
  **PR's will happily be accepted**
10
10
 
@@ -2,7 +2,7 @@
2
2
  # schema for tracking associations.
3
3
  class AddTransactionIdColumnToVersions < ActiveRecord::Migration<%= migration_version %>
4
4
  def self.up
5
- add_column :versions, :transaction_id, :integer
5
+ add_column :versions, :transaction_id, :bigint
6
6
  add_index :versions, [:transaction_id]
7
7
  end
8
8
 
@@ -7,14 +7,14 @@ require "paper_trail_association_tracking/reifier"
7
7
  require "paper_trail_association_tracking/record_trail"
8
8
  require "paper_trail_association_tracking/request"
9
9
  require "paper_trail_association_tracking/paper_trail"
10
- require "paper_trail_association_tracking/version_concern"
11
10
 
12
11
  if defined?(Rails)
13
- require "paper_trail/frameworks/active_record"
14
- require "paper_trail_association_tracking/frameworks/rails"
15
- elsif defined?(ActiveRecord)
16
- require "paper_trail/frameworks/active_record"
17
- require "paper_trail_association_tracking/frameworks/active_record"
12
+ require "paper_trail_association_tracking/frameworks/rails/railtie"
13
+ else
14
+ ActiveSupport.on_load(:active_record) do
15
+ require "paper_trail/frameworks/active_record"
16
+ require "paper_trail_association_tracking/frameworks/active_record"
17
+ end
18
18
  end
19
19
 
20
20
  module PaperTrailAssociationTracking
@@ -1,3 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "paper_trail_association_tracking/frameworks/active_record/models/paper_trail/version_association"
4
+
5
+ require "paper_trail_association_tracking/version_concern"
@@ -5,13 +5,10 @@ module PaperTrailAssociationTracking
5
5
 
6
6
  initializer "paper_trail_association_tracking", after: "paper_trail" do
7
7
  ActiveSupport.on_load(:active_record) do
8
+ require "paper_trail/frameworks/active_record"
8
9
  require "paper_trail_association_tracking/frameworks/active_record"
9
10
  end
10
11
  end
11
12
 
12
- config.to_prepare do
13
- ::PaperTrail::Version.include(::PaperTrailAssociationTracking::VersionConcern)
14
- end
15
-
16
13
  end
17
14
  end
@@ -163,10 +163,9 @@ module PaperTrailAssociationTracking
163
163
  # Save a single `belongs_to` association.
164
164
  # @api private
165
165
  def save_bt_association(assoc, version)
166
- assoc_version_args = {
167
- version_id: version.id,
166
+ assoc_version_args = version_association_version_args(version).merge(
168
167
  foreign_key_name: assoc.foreign_key
169
- }
168
+ )
170
169
 
171
170
  if assoc.options[:polymorphic]
172
171
  foreign_type = @record.send(assoc.foreign_type)
@@ -184,6 +183,22 @@ module PaperTrailAssociationTracking
184
183
  end
185
184
  end
186
185
 
186
+ # Handing over the version object lets a required `belongs_to :version`
187
+ # validate presence from the loaded target instead of reloading the row it
188
+ # just wrote. Fall back to the id when the association class expects a
189
+ # different version class, so custom version classes keep working.
190
+ # @api private
191
+ def version_association_version_args(version)
192
+ reflection = @record.class.paper_trail.version_association_class.reflect_on_association(:version)
193
+ if reflection && version.persisted? && version.is_a?(reflection.klass)
194
+ { version: version }
195
+ else
196
+ { version_id: version.id }
197
+ end
198
+ rescue NameError
199
+ { version_id: version.id }
200
+ end
201
+
187
202
  # Returns true if the given HABTM association should be saved.
188
203
  # @api private
189
204
  def save_habtm_association?(assoc)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PaperTrailAssociationTracking
4
- VERSION = "2.3.0".freeze
4
+ VERSION = "2.4.0".freeze
5
5
  end
@@ -16,3 +16,5 @@ module PaperTrailAssociationTracking
16
16
  end
17
17
  end
18
18
  end
19
+
20
+ PaperTrail::Version.include(PaperTrailAssociationTracking::VersionConcern)
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paper_trail-association_tracking
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Weston Ganger
8
8
  - Jared Beck
9
9
  - Ben Atkins
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2025-04-17 00:00:00.000000000 Z
12
+ date: 1980-01-02 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: paper_trail
@@ -101,7 +100,6 @@ files:
101
100
  - lib/paper_trail_association_tracking/config.rb
102
101
  - lib/paper_trail_association_tracking/frameworks/active_record.rb
103
102
  - lib/paper_trail_association_tracking/frameworks/active_record/models/paper_trail/version_association.rb
104
- - lib/paper_trail_association_tracking/frameworks/rails.rb
105
103
  - lib/paper_trail_association_tracking/frameworks/rails/railtie.rb
106
104
  - lib/paper_trail_association_tracking/model_config.rb
107
105
  - lib/paper_trail_association_tracking/paper_trail.rb
@@ -120,7 +118,6 @@ homepage: https://github.com/westonganger/paper_trail-association_tracking
120
118
  licenses:
121
119
  - MIT
122
120
  metadata: {}
123
- post_install_message:
124
121
  rdoc_options: []
125
122
  require_paths:
126
123
  - lib
@@ -135,8 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
132
  - !ruby/object:Gem::Version
136
133
  version: '0'
137
134
  requirements: []
138
- rubygems_version: 3.4.22
139
- signing_key:
135
+ rubygems_version: 4.0.3
140
136
  specification_version: 4
141
137
  summary: Plugin for the PaperTrail gem to track and reify associations
142
138
  test_files: []
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "paper_trail_association_tracking/frameworks/rails/railtie"