paper_trail-association_tracking 2.1.3 → 2.2.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 +4 -4
- data/CHANGELOG.md +8 -4
- data/README.md +16 -4
- data/Rakefile +1 -4
- data/lib/paper_trail-association_tracking.rb +8 -16
- data/lib/paper_trail_association_tracking/frameworks/active_record.rb +0 -2
- data/lib/paper_trail_association_tracking/frameworks/rails/railtie.rb +17 -0
- data/lib/paper_trail_association_tracking/frameworks/rails.rb +1 -1
- data/lib/paper_trail_association_tracking/model_config.rb +28 -9
- data/lib/paper_trail_association_tracking/version.rb +1 -1
- data/lib/paper_trail_association_tracking/version_concern.rb +1 -20
- metadata +10 -39
- data/lib/paper_trail_association_tracking/frameworks/rails/engine.rb +0 -10
- data/lib/paper_trail_association_tracking/frameworks/rspec.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9af07695b14d97e4ca838054a2764188521584545338887289e9c56f91cdb22b
|
4
|
+
data.tar.gz: cb80d2ce702c4d2178cbd82c3191a3b9a81a72e7d7349447fe517b21d65e6e6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2723be9c0afe1f2ffcdec97638ac073a7074ece8d78a67f42a8fe986fa56533e4a9d8306293cd7df1eedde7bfbee5dd3aa29990fb273db41f5dae9cc4a4b4d70
|
7
|
+
data.tar.gz: 27a332d6d0a2aa9b810f2c493f9b48f4c4567b9e8ca1280a64e25206771168ad9982f99c75a6b53cfa1d20a670c2e3f395c16cf30bdab3fafa39f2d2ef2cec51
|
data/CHANGELOG.md
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
### Unreleased - [View Diff](https://github.com/westonganger/paper_trail-association_tracking/compare/v2.
|
4
|
-
|
3
|
+
### Unreleased - [View Diff](https://github.com/westonganger/paper_trail-association_tracking/compare/v2.2.0...master)
|
5
4
|
- Nothing yet
|
6
5
|
|
6
|
+
### v2.2.0 - [View Diff](https://github.com/westonganger/paper_trail-association_tracking/compare/v2.1.3...v2.2.0)
|
7
|
+
|
8
|
+
- [PR #36](https://github.com/westonganger/paper_trail-association_tracking/pull/36) - Fix load order for paper_trail v12+
|
9
|
+
- Drop support for Ruby 2.5
|
10
|
+
- Add Github Actions CI supporting multiple version of Ruby, Rails and multiple databases types
|
11
|
+
|
7
12
|
### 2.1.3 - [View Diff](https://github.com/westonganger/paper_trail-association_tracking/compare/v2.1.1...v2.1.3)
|
8
13
|
|
9
14
|
- [PR #24](https://github.com/westonganger/paper_trail-association_tracking/pull/24) - Fix reification on STI models that have parent child relationships
|
10
|
-
- Last version that is compatible with `paper_trail` due to the change in the loading mechanism
|
11
15
|
|
12
16
|
### 2.1.2
|
13
17
|
|
14
|
-
- Release yanked, had bug preventing installation
|
18
|
+
- A late night oopsies, Release yanked immediately, had bug preventing installation.
|
15
19
|
|
16
20
|
### 2.1.1 - 2020-10-21 - [View Diff](https://github.com/westonganger/paper_trail-association_tracking/compare/v2.1.0...v2.1.1)
|
17
21
|
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# PaperTrail-AssociationTracking
|
2
2
|
|
3
3
|
<a href="https://badge.fury.io/rb/paper_trail-association_tracking" target="_blank"><img height="21" style='border:0px;height:21px;' border='0' src="https://badge.fury.io/rb/paper_trail-association_tracking.svg" alt="Gem Version"></a>
|
4
|
-
<a href='https://
|
4
|
+
<a href='https://github.com/westonganger/paper_trail-association_tracking/actions' target='_blank'><img src="https://github.com/westonganger/paper_trail-association_tracking/workflows/Tests/badge.svg" 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://ruby-gem-downloads-badge.herokuapp.com/paper_trail-association_tracking?label=rubygems&type=total&total_label=downloads&color=brightgreen' border='0' alt='RubyGems Downloads' /></a>
|
6
6
|
|
7
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.
|
@@ -23,17 +23,23 @@ It will store in the `version_associations` table additional information to corr
|
|
23
23
|
- [Known Issues](#known-issues)
|
24
24
|
- [Contributing](#contributing)
|
25
25
|
- [Credits](#credits)
|
26
|
+
- [Alternative Solution](#alternative-solution)
|
26
27
|
|
27
28
|
|
28
29
|
# Install
|
29
30
|
|
30
31
|
```ruby
|
31
|
-
|
32
|
-
|
33
|
-
gem 'paper_trail' # Minimum required version is v9.2.0
|
32
|
+
gem 'paper_trail'
|
34
33
|
gem 'paper_trail-association_tracking'
|
35
34
|
```
|
36
35
|
|
36
|
+
For PT v9.2 to v11.x you must use PT-AT v2
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
gem 'paper_trail'#, ">=9.2.0", "< 12.0"
|
40
|
+
gem 'paper_trail-association_tracking', "<= 2.1.3"
|
41
|
+
```
|
42
|
+
|
37
43
|
Then run `rails generate paper_trail_association_tracking:install` which will do the following two things for you:
|
38
44
|
|
39
45
|
1. Create a `version_associations` table
|
@@ -182,3 +188,9 @@ Maintained by [Weston Ganger](https://westonganger.com) - [@westonganger](https:
|
|
182
188
|
Plugin authored by [Weston Ganger](https://westonganger.com) - [@westonganger](https://github.com/westonganger)
|
183
189
|
|
184
190
|
Associations code originally contributed by Ben Atkins, Jared Beck, Andy Stewart & more
|
191
|
+
|
192
|
+
# Alternative Solution
|
193
|
+
|
194
|
+
Model Versioning and Restoration require concious thought, design, and understanding. You should understand your versioning and restoration process completely. Because PT-AT it is mostly a blackbox solution which encourages you to set it up and then assume its "Just Working". This can make for major data problems later.
|
195
|
+
|
196
|
+
Instead I recommend a newer gem that I have created for handling snapshots of records and associations called [active_snapshot](https://github.com/westonganger/active_snapshot). This gem does not utilize `paper_trail` at all. The focus of this gem is to have a simple and fully understandable design is easy to customize and know inside and out for your projects needs.
|
data/Rakefile
CHANGED
@@ -17,9 +17,6 @@ Rake::TestTask.new(:test) do |t|
|
|
17
17
|
t.libs << "test"
|
18
18
|
t.pattern = "test/**/*_test.rb"
|
19
19
|
t.verbose = false
|
20
|
-
|
21
|
-
### Enabling ruby interpreter warnings (-w) is, sadly, impractical.
|
22
|
-
### There are too many noisy warnings that we have no control over, e.g. caused by libs we depend on.
|
23
20
|
t.warning = false
|
24
21
|
end
|
25
22
|
|
@@ -27,7 +24,7 @@ require "rspec/core/rake_task"
|
|
27
24
|
desc "Run tests on PaperTrail with RSpec"
|
28
25
|
task(:spec).clear
|
29
26
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
30
|
-
t.verbose = false # hide list of specs
|
27
|
+
t.verbose = false # hide list of specs
|
31
28
|
end
|
32
29
|
|
33
30
|
desc "Default: run all available test suites"
|
@@ -9,6 +9,14 @@ require "paper_trail_association_tracking/request"
|
|
9
9
|
require "paper_trail_association_tracking/paper_trail"
|
10
10
|
require "paper_trail_association_tracking/version_concern"
|
11
11
|
|
12
|
+
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"
|
18
|
+
end
|
19
|
+
|
12
20
|
module PaperTrailAssociationTracking
|
13
21
|
def self.version
|
14
22
|
VERSION
|
@@ -47,20 +55,4 @@ module PaperTrail
|
|
47
55
|
prepend ::PaperTrailAssociationTracking::Request::ClassMethods
|
48
56
|
end
|
49
57
|
end
|
50
|
-
|
51
|
-
module VersionConcern
|
52
|
-
include ::PaperTrailAssociationTracking::VersionConcern
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# Require frameworks
|
57
|
-
if defined?(::Rails)
|
58
|
-
# Rails module is sometimes defined by gems like rails-html-sanitizer so we check for presence of Rails.application.
|
59
|
-
if defined?(::Rails.application)
|
60
|
-
require "paper_trail_association_tracking/frameworks/rails"
|
61
|
-
else
|
62
|
-
::Kernel.warn('PaperTrail has been loaded too early, before rails is loaded. This can happen when another gem defines the ::Rails namespace, then PT is loaded, all before rails is loaded. You may want to reorder your Gemfile, or defer the loading of PT by using `require: false` and a manual require elsewhere.')
|
63
|
-
end
|
64
|
-
else
|
65
|
-
require "paper_trail_association_tracking/frameworks/active_record"
|
66
58
|
end
|
@@ -1,5 +1,3 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# This file only needs to be loaded if the gem is being used outside of Rails,
|
4
|
-
# since otherwise the model(s) will get loaded in via the `Rails::Engine`.
|
5
3
|
require "paper_trail_association_tracking/frameworks/active_record/models/paper_trail/version_association"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PaperTrailAssociationTracking
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
|
6
|
+
initializer "paper_trail_association_tracking", after: "paper_trail" do
|
7
|
+
ActiveSupport.on_load(:active_record) do
|
8
|
+
require "paper_trail_association_tracking/frameworks/active_record"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
config.to_prepare do
|
13
|
+
::PaperTrail::Version.include(::PaperTrailAssociationTracking::VersionConcern)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -38,15 +38,34 @@ module PaperTrailAssociationTracking
|
|
38
38
|
habtm_assocs_not_skipped.each(&method(:setup_habtm_change_callbacks))
|
39
39
|
end
|
40
40
|
|
41
|
-
def setup_habtm_change_callbacks(
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
def setup_habtm_change_callbacks(association)
|
42
|
+
association_name = association.name
|
43
|
+
|
44
|
+
if ActiveRecord::VERSION::MAJOR >= 7
|
45
|
+
### https://github.com/westonganger/paper_trail-association_tracking/pull/37#issuecomment-1067146121
|
46
|
+
|
47
|
+
before_add_callback = lambda do |*args|
|
48
|
+
update_habtm_state(association_name, :before_add, args[-2], args.last)
|
49
|
+
end
|
50
|
+
|
51
|
+
before_remove_callback = lambda do |*args|
|
52
|
+
update_habtm_state(association_name, :before_remove, args[-2], args.last)
|
53
|
+
end
|
54
|
+
|
55
|
+
assoc_opts = association.options.merge(before_add: before_add_callback, before_remove: before_remove_callback)
|
56
|
+
|
57
|
+
association.instance_variable_set(:@options, **assoc_opts)
|
58
|
+
|
59
|
+
::ActiveRecord::Associations::Builder::CollectionAssociation.send(:define_callbacks, @model_class, association)
|
60
|
+
else
|
61
|
+
%w[add remove].each do |verb|
|
62
|
+
@model_class.send("before_#{verb}_for_#{association_name}").send(
|
63
|
+
:<<,
|
64
|
+
lambda do |*args|
|
65
|
+
update_habtm_state(association_name, :"before_#{verb}", args[-2], args.last)
|
66
|
+
end
|
67
|
+
)
|
68
|
+
end
|
50
69
|
end
|
51
70
|
end
|
52
71
|
|
@@ -1,10 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module PaperTrailAssociationTracking
|
4
|
-
# Originally, PaperTrail did not provide this module, and all of this
|
5
|
-
# functionality was in `PaperTrail::Version`. That model still exists (and is
|
6
|
-
# used by most apps) but by moving the functionality to this module, people
|
7
|
-
# can include this concern instead of sub-classing the `Version` model.
|
8
4
|
module VersionConcern
|
9
5
|
extend ::ActiveSupport::Concern
|
10
6
|
|
@@ -16,22 +12,7 @@ module PaperTrailAssociationTracking
|
|
16
12
|
has_many :version_associations, dependent: :destroy
|
17
13
|
end
|
18
14
|
|
19
|
-
scope
|
15
|
+
scope :within_transaction, ->(id) { where(transaction_id: id) }
|
20
16
|
end
|
21
|
-
|
22
|
-
# Restore the item from this version.
|
23
|
-
#
|
24
|
-
# In addition to the options provided by PaperTrail core. This Plugin provides the following Options:
|
25
|
-
#
|
26
|
-
# - :has_one
|
27
|
-
# - `true` - Also reify has_one associations.
|
28
|
-
# - `false - Default.
|
29
|
-
# - :has_many
|
30
|
-
# - `true` - Also reify has_many and has_many :through associations.
|
31
|
-
# - `false` - Default.
|
32
|
-
#
|
33
|
-
#def reify(options = {})
|
34
|
-
# super
|
35
|
-
#end
|
36
17
|
end
|
37
18
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paper_trail-association_tracking
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Weston Ganger
|
8
8
|
- Jared Beck
|
9
9
|
- Ben Atkins
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2022-03-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: paper_trail
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - "
|
19
|
+
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '12.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- - "
|
26
|
+
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '12.0'
|
29
29
|
- !ruby/object:Gem::Dependency
|
@@ -82,34 +82,6 @@ dependencies:
|
|
82
82
|
- - ">="
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
|
-
- !ruby/object:Gem::Dependency
|
86
|
-
name: mysql2
|
87
|
-
requirement: !ruby/object:Gem::Requirement
|
88
|
-
requirements:
|
89
|
-
- - ">="
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
version: '0'
|
92
|
-
type: :development
|
93
|
-
prerelease: false
|
94
|
-
version_requirements: !ruby/object:Gem::Requirement
|
95
|
-
requirements:
|
96
|
-
- - ">="
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
version: '0'
|
99
|
-
- !ruby/object:Gem::Dependency
|
100
|
-
name: pg
|
101
|
-
requirement: !ruby/object:Gem::Requirement
|
102
|
-
requirements:
|
103
|
-
- - ">="
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
version: '0'
|
106
|
-
type: :development
|
107
|
-
prerelease: false
|
108
|
-
version_requirements: !ruby/object:Gem::Requirement
|
109
|
-
requirements:
|
110
|
-
- - ">="
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
version: '0'
|
113
85
|
- !ruby/object:Gem::Dependency
|
114
86
|
name: rack-test
|
115
87
|
requirement: !ruby/object:Gem::Requirement
|
@@ -200,8 +172,7 @@ files:
|
|
200
172
|
- lib/paper_trail_association_tracking/frameworks/active_record.rb
|
201
173
|
- lib/paper_trail_association_tracking/frameworks/active_record/models/paper_trail/version_association.rb
|
202
174
|
- lib/paper_trail_association_tracking/frameworks/rails.rb
|
203
|
-
- lib/paper_trail_association_tracking/frameworks/rails/
|
204
|
-
- lib/paper_trail_association_tracking/frameworks/rspec.rb
|
175
|
+
- lib/paper_trail_association_tracking/frameworks/rails/railtie.rb
|
205
176
|
- lib/paper_trail_association_tracking/model_config.rb
|
206
177
|
- lib/paper_trail_association_tracking/paper_trail.rb
|
207
178
|
- lib/paper_trail_association_tracking/record_trail.rb
|
@@ -219,7 +190,7 @@ homepage: https://github.com/westonganger/paper_trail-association_tracking
|
|
219
190
|
licenses:
|
220
191
|
- MIT
|
221
192
|
metadata: {}
|
222
|
-
post_install_message:
|
193
|
+
post_install_message:
|
223
194
|
rdoc_options: []
|
224
195
|
require_paths:
|
225
196
|
- lib
|
@@ -227,15 +198,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
227
198
|
requirements:
|
228
199
|
- - ">="
|
229
200
|
- !ruby/object:Gem::Version
|
230
|
-
version: 2.
|
201
|
+
version: 2.6.0
|
231
202
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
232
203
|
requirements:
|
233
204
|
- - ">="
|
234
205
|
- !ruby/object:Gem::Version
|
235
206
|
version: '0'
|
236
207
|
requirements: []
|
237
|
-
rubygems_version: 3.
|
238
|
-
signing_key:
|
208
|
+
rubygems_version: 3.2.32
|
209
|
+
signing_key:
|
239
210
|
specification_version: 4
|
240
211
|
summary: Plugin for the PaperTrail gem to track and reify associations
|
241
212
|
test_files: []
|
@@ -1,10 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module PaperTrailAssociationTracking
|
4
|
-
module Rails
|
5
|
-
# See http://guides.rubyonrails.org/engines.html
|
6
|
-
class Engine < ::Rails::Engine
|
7
|
-
paths["app/models"] << "lib/paper_trail_association_tracking/frameworks/active_record/models"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rspec/core"
|
4
|
-
require "rspec/matchers"
|
5
|
-
|
6
|
-
RSpec::Matchers.define :have_a_version_with do |attributes|
|
7
|
-
# check if the model has a version with the specified attributes
|
8
|
-
match do |actual|
|
9
|
-
versions_association = actual.class.versions_association_name
|
10
|
-
actual.send(versions_association).where_object(attributes).any?
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
RSpec::Matchers.define :have_a_version_with_changes do |attributes|
|
15
|
-
# check if the model has a version changes with the specified attributes
|
16
|
-
match do |actual|
|
17
|
-
versions_association = actual.class.versions_association_name
|
18
|
-
actual.send(versions_association).where_object_changes(attributes).any?
|
19
|
-
end
|
20
|
-
end
|