paper_trail 7.0.2 → 7.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CONTRIBUTING.md +1 -1
- data/.rubocop_todo.yml +10 -0
- data/.travis.yml +4 -4
- data/Appraisals +3 -5
- data/CHANGELOG.md +16 -1
- data/README.md +70 -119
- data/Rakefile +6 -1
- data/doc/bug_report_template.rb +4 -2
- data/doc/warning_about_not_setting_whodunnit.md +6 -5
- data/gemfiles/ar_4.0.gemfile +1 -1
- data/gemfiles/ar_4.2.gemfile +1 -1
- data/gemfiles/ar_5.0.gemfile +2 -3
- data/gemfiles/ar_5.1.gemfile +8 -0
- data/gemfiles/ar_master.gemfile +2 -2
- data/lib/generators/paper_trail/templates/add_object_changes_to_versions.rb.erb +1 -1
- data/lib/generators/paper_trail/templates/add_transaction_id_column_to_versions.rb.erb +1 -1
- data/lib/generators/paper_trail/templates/create_version_associations.rb.erb +1 -1
- data/lib/paper_trail/model_config.rb +4 -4
- data/lib/paper_trail/version_concern.rb +4 -4
- data/lib/paper_trail/version_number.rb +1 -1
- data/paper_trail.gemspec +5 -5
- data/spec/controllers/articles_controller_spec.rb +1 -1
- data/spec/generators/install_generator_spec.rb +2 -2
- data/spec/models/animal_spec.rb +5 -5
- data/spec/models/boolit_spec.rb +2 -2
- data/spec/models/callback_modifier_spec.rb +2 -2
- data/spec/models/car_spec.rb +2 -2
- data/spec/models/custom_primary_key_record_spec.rb +2 -2
- data/spec/models/document_spec.rb +2 -2
- data/spec/models/gadget_spec.rb +2 -2
- data/spec/models/joined_version_spec.rb +1 -1
- data/spec/models/json_version_spec.rb +4 -4
- data/spec/models/kitchen/banana_spec.rb +2 -2
- data/spec/models/not_on_update_spec.rb +2 -2
- data/spec/models/post_with_status_spec.rb +4 -4
- data/spec/models/skipper_spec.rb +1 -1
- data/spec/models/thing_spec.rb +2 -2
- data/spec/models/vehicle_spec.rb +2 -2
- data/spec/models/version_spec.rb +26 -5
- data/spec/models/widget_spec.rb +10 -2
- data/spec/modules/paper_trail_spec.rb +2 -2
- data/spec/modules/version_concern_spec.rb +2 -2
- data/spec/modules/version_number_spec.rb +1 -1
- data/spec/paper_trail/associations_spec.rb +965 -0
- data/spec/paper_trail/cleaner_spec.rb +2 -2
- data/spec/paper_trail/config_spec.rb +2 -2
- data/spec/paper_trail/model_spec.rb +1421 -0
- data/spec/paper_trail/serializer_spec.rb +85 -0
- data/spec/paper_trail/serializers/custom_yaml_serializer_spec.rb +1 -1
- data/spec/paper_trail/serializers/json_spec.rb +2 -2
- data/spec/paper_trail/serializers/yaml_spec.rb +42 -0
- data/spec/paper_trail/version_limit_spec.rb +2 -2
- data/spec/paper_trail/version_spec.rb +96 -0
- data/spec/paper_trail_spec.rb +1 -1
- data/spec/requests/articles_spec.rb +2 -2
- data/spec/spec_helper.rb +47 -79
- data/{test → spec/support}/custom_json_serializer.rb +0 -0
- data/test/dummy/app/models/document.rb +1 -1
- data/test/dummy/app/models/not_on_update.rb +1 -1
- data/test/dummy/app/models/widget.rb +1 -1
- data/test/dummy/config/routes.rb +1 -1
- data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +18 -9
- data/test/dummy/db/schema.rb +64 -64
- data/test/test_helper.rb +1 -33
- data/test/unit/serializers/mixin_json_test.rb +1 -1
- metadata +27 -32
- data/spec/models/truck_spec.rb +0 -5
- data/spec/rails_helper.rb +0 -34
- data/test/time_travel_helper.rb +0 -1
- data/test/unit/associations_test.rb +0 -1032
- data/test/unit/model_test.rb +0 -1416
- data/test/unit/serializer_test.rb +0 -107
- data/test/unit/serializers/yaml_test.rb +0 -50
- data/test/unit/version_test.rb +0 -112
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11a429887d7b9272fd54814535da3c8d5beff4f0
|
4
|
+
data.tar.gz: 2d58e73069b0b929789382f3119bcdfa42c651ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b8bc23a333b80008c006bca40968f587ac40c71231326c4f8b1f3ef460e09fe3c4ad00085de912ce1991fa1007d2e50c04596a64181c4fae2ef8b7c18d51baa
|
7
|
+
data.tar.gz: 0c3ba5b7dfaaf2a448efa2a59dc2a4afbc15eb6a57cec024a536853172f561678afadf738320f01d212b6fa541053029982baadb9449a4fef0587e21ca7d2a8f
|
data/.github/CONTRIBUTING.md
CHANGED
@@ -128,7 +128,7 @@ After editing `test/dummy/db/migrate/20110208155312_set_up_test_tables.rb` ..
|
|
128
128
|
|
129
129
|
```
|
130
130
|
cd test/dummy
|
131
|
-
export BUNDLE_GEMFILE=../../gemfiles/ar_5.
|
131
|
+
export BUNDLE_GEMFILE=../../gemfiles/ar_5.1.gemfile
|
132
132
|
RAILS_ENV=test bundle exec rake db:environment:set db:drop db:create db:migrate
|
133
133
|
RAILS_ENV=foo bundle exec rake db:environment:set db:drop db:create db:migrate
|
134
134
|
RAILS_ENV=bar bundle exec rake db:environment:set db:drop db:create db:migrate
|
data/.rubocop_todo.yml
CHANGED
@@ -21,11 +21,21 @@ RSpec/BeforeAfterAll:
|
|
21
21
|
RSpec/FilePath:
|
22
22
|
Enabled: false
|
23
23
|
|
24
|
+
RSpec/InstanceVariable:
|
25
|
+
Exclude:
|
26
|
+
- spec/paper_trail/associations_spec.rb
|
27
|
+
- spec/paper_trail/model_spec.rb
|
28
|
+
|
24
29
|
RSpec/MessageSpies:
|
25
30
|
Enabled: false
|
26
31
|
|
27
32
|
RSpec/NamedSubject:
|
28
33
|
Enabled: false
|
29
34
|
|
35
|
+
RSpec/NestedGroups:
|
36
|
+
Exclude:
|
37
|
+
- spec/paper_trail/associations_spec.rb
|
38
|
+
- spec/paper_trail/model_spec.rb
|
39
|
+
|
30
40
|
Security/YAMLLoad:
|
31
41
|
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
3
|
rvm:
|
4
|
-
- 2.3.
|
4
|
+
- 2.3.4
|
5
5
|
- 2.1.10
|
6
6
|
env:
|
7
7
|
global:
|
@@ -27,15 +27,15 @@ gemfile:
|
|
27
27
|
- gemfiles/ar_4.0.gemfile
|
28
28
|
- gemfiles/ar_4.2.gemfile
|
29
29
|
- gemfiles/ar_5.0.gemfile
|
30
|
-
- gemfiles/
|
30
|
+
- gemfiles/ar_5.1.gemfile
|
31
31
|
|
32
32
|
matrix:
|
33
33
|
fast_finish: true
|
34
34
|
exclude:
|
35
35
|
- gemfile: gemfiles/ar_5.0.gemfile
|
36
36
|
rvm: 2.1.10
|
37
|
-
|
38
|
-
|
37
|
+
- gemfile: gemfiles/ar_5.1.gemfile
|
38
|
+
rvm: 2.1.10
|
39
39
|
|
40
40
|
addons:
|
41
41
|
postgresql: "9.4"
|
data/Appraisals
CHANGED
@@ -16,13 +16,11 @@ appraise "ar-4.2" do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
appraise "ar-5.0" do
|
19
|
-
gem "activerecord", "~> 5.0.
|
20
|
-
gem "rspec-rails", "~> 3.5.1"
|
19
|
+
gem "activerecord", "~> 5.0.3"
|
21
20
|
gem "rails-controller-testing"
|
22
21
|
end
|
23
22
|
|
24
|
-
appraise "
|
25
|
-
gem "rails",
|
26
|
-
gem "rspec-rails", "~> 3.5.1"
|
23
|
+
appraise "ar-5.1" do
|
24
|
+
gem "rails", "5.1.1"
|
27
25
|
gem "rails-controller-testing"
|
28
26
|
end
|
data/CHANGELOG.md
CHANGED
@@ -17,6 +17,21 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
|
|
17
17
|
|
18
18
|
- None
|
19
19
|
|
20
|
+
## 7.0.3 (2017-06-01)
|
21
|
+
|
22
|
+
### Breaking Changes
|
23
|
+
|
24
|
+
- None
|
25
|
+
|
26
|
+
### Added
|
27
|
+
|
28
|
+
- None
|
29
|
+
|
30
|
+
### Fixed
|
31
|
+
|
32
|
+
- [#959](https://github.com/airblade/paper_trail/pull/959) -
|
33
|
+
Add migration version (eg. `[5.1]`) to all migration generators.
|
34
|
+
|
20
35
|
## 7.0.2 (2017-04-26)
|
21
36
|
|
22
37
|
### Breaking Changes
|
@@ -31,7 +46,7 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
|
|
31
46
|
### Fixed
|
32
47
|
|
33
48
|
- [#956](https://github.com/airblade/paper_trail/pull/956) -
|
34
|
-
Fix ActiveRecord >= 5.1 version check
|
49
|
+
Fix ActiveRecord >= 5.1 version check
|
35
50
|
|
36
51
|
## 7.0.1 (2017-04-10)
|
37
52
|
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ has been destroyed.
|
|
11
11
|
| Version | Documentation |
|
12
12
|
| -------------- | ------------- |
|
13
13
|
| Unreleased | https://github.com/airblade/paper_trail/blob/master/README.md |
|
14
|
-
| 7.0.
|
14
|
+
| 7.0.3 | https://github.com/airblade/paper_trail/blob/v7.0.3/README.md |
|
15
15
|
| 6.0.2 | https://github.com/airblade/paper_trail/blob/v6.0.2/README.md |
|
16
16
|
| 5.2.3 | https://github.com/airblade/paper_trail/blob/v5.2.3/README.md |
|
17
17
|
| 4.2.0 | https://github.com/airblade/paper_trail/blob/v4.2.0/README.md |
|
@@ -57,7 +57,7 @@ has been destroyed.
|
|
57
57
|
- [7.c Cucumber](#7c-cucumber)
|
58
58
|
- [7.d Spork](#7d-spork)
|
59
59
|
- [7.e Zeus or Spring](#7e-zeus-or-spring)
|
60
|
-
- [8.
|
60
|
+
- [8. Integration with Other Libraries](#8-integration-with-other-libraries)
|
61
61
|
|
62
62
|
## 1. Introduction
|
63
63
|
|
@@ -88,7 +88,7 @@ has been destroyed.
|
|
88
88
|
```
|
89
89
|
|
90
90
|
If using [rails_admin][38], you must enable the experimental
|
91
|
-
[Associations](#associations) feature. For more information on this
|
91
|
+
[Associations](#4b-associations) feature. For more information on this
|
92
92
|
generator, see [section 5.c. Generators](#5c-generators).
|
93
93
|
|
94
94
|
1. Add `has_paper_trail` to the models you want to track.
|
@@ -145,7 +145,7 @@ widget.name # 'Doobly'
|
|
145
145
|
# Add has_paper_trail to Widget model.
|
146
146
|
|
147
147
|
widget.versions # []
|
148
|
-
widget.update_attributes :
|
148
|
+
widget.update_attributes name: 'Wotsit'
|
149
149
|
widget.versions.last.reify.name # 'Doobly'
|
150
150
|
widget.versions.last.event # 'update'
|
151
151
|
```
|
@@ -286,7 +286,7 @@ ignore `create` events:
|
|
286
286
|
|
287
287
|
```ruby
|
288
288
|
class Article < ActiveRecord::Base
|
289
|
-
has_paper_trail :
|
289
|
+
has_paper_trail on: [:update, :destroy]
|
290
290
|
end
|
291
291
|
```
|
292
292
|
|
@@ -305,11 +305,11 @@ a = Article.create
|
|
305
305
|
a.versions.size # 1
|
306
306
|
a.versions.last.event # 'create'
|
307
307
|
a.paper_trail_event = 'update title'
|
308
|
-
a.update_attributes :
|
308
|
+
a.update_attributes title: 'My Title'
|
309
309
|
a.versions.size # 2
|
310
310
|
a.versions.last.event # 'update title'
|
311
311
|
a.paper_trail_event = nil
|
312
|
-
a.update_attributes :
|
312
|
+
a.update_attributes title: 'Alternate'
|
313
313
|
a.versions.size # 3
|
314
314
|
a.versions.last.event # 'update'
|
315
315
|
```
|
@@ -324,7 +324,7 @@ class Article < ActiveRecord::Base
|
|
324
324
|
|
325
325
|
# Include PaperTrail, but do not add any callbacks yet. Passing the
|
326
326
|
# empty array to `:on` omits callbacks.
|
327
|
-
has_paper_trail :
|
327
|
+
has_paper_trail on: []
|
328
328
|
|
329
329
|
# Add callbacks in the order you need.
|
330
330
|
paper_trail.on_destroy # add destroy callback
|
@@ -346,8 +346,8 @@ translations:
|
|
346
346
|
|
347
347
|
```ruby
|
348
348
|
class Translation < ActiveRecord::Base
|
349
|
-
has_paper_trail :
|
350
|
-
:
|
349
|
+
has_paper_trail if: Proc.new { |t| t.language_code == 'US' },
|
350
|
+
unless: Proc.new { |t| t.type == 'DRAFT' }
|
351
351
|
end
|
352
352
|
```
|
353
353
|
|
@@ -444,7 +444,7 @@ persisted.
|
|
444
444
|
|
445
445
|
```ruby
|
446
446
|
class Article < ActiveRecord::Base
|
447
|
-
has_paper_trail :
|
447
|
+
has_paper_trail skip: [:file_upload]
|
448
448
|
end
|
449
449
|
```
|
450
450
|
|
@@ -501,7 +501,7 @@ Or a block:
|
|
501
501
|
|
502
502
|
```ruby
|
503
503
|
@widget.paper_trail.without_versioning do
|
504
|
-
@widget.update_attributes :
|
504
|
+
@widget.update_attributes name: 'Ford'
|
505
505
|
end
|
506
506
|
```
|
507
507
|
|
@@ -528,7 +528,7 @@ PaperTrail makes reverting to a previous version easy:
|
|
528
528
|
|
529
529
|
```ruby
|
530
530
|
widget = Widget.find 42
|
531
|
-
widget.update_attributes :
|
531
|
+
widget.update_attributes name: 'Blah blah'
|
532
532
|
# Time passes....
|
533
533
|
widget = widget.paper_trail.previous_version # the widget as it was before the update
|
534
534
|
widget.save # reverted
|
@@ -613,7 +613,7 @@ And you can perform `WHERE` queries for object versions based on attributes:
|
|
613
613
|
|
614
614
|
```ruby
|
615
615
|
# All versions that meet these criteria.
|
616
|
-
PaperTrail::Version.where_object(content:
|
616
|
+
PaperTrail::Version.where_object(content: 'Hello', title: 'Article')
|
617
617
|
```
|
618
618
|
|
619
619
|
### 3.c. Diffing Versions
|
@@ -629,7 +629,7 @@ attributes PaperTrail is ignoring) in each `update` version. You can use the
|
|
629
629
|
`version.changeset` method to retrieve it. For example:
|
630
630
|
|
631
631
|
```ruby
|
632
|
-
widget = Widget.create :
|
632
|
+
widget = Widget.create name: 'Bob'
|
633
633
|
widget.versions.last.changeset
|
634
634
|
# {
|
635
635
|
# "name"=>[nil, "Bob"],
|
@@ -637,7 +637,7 @@ widget.versions.last.changeset
|
|
637
637
|
# "updated_at"=>[nil, 2015-08-10 04:10:40 UTC],
|
638
638
|
# "id"=>[nil, 1]
|
639
639
|
# }
|
640
|
-
widget.update_attributes :
|
640
|
+
widget.update_attributes name: 'Robert'
|
641
641
|
widget.versions.last.changeset
|
642
642
|
# {
|
643
643
|
# "name"=>["Bob", "Robert"],
|
@@ -678,7 +678,7 @@ For diffing two ActiveRecord objects:
|
|
678
678
|
to specify which columns to compare.
|
679
679
|
|
680
680
|
If you want to selectively record changes for some models but not others you
|
681
|
-
can opt out of recording changes by passing
|
681
|
+
can opt out of recording changes by passing `save_changes: false` to your
|
682
682
|
`has_paper_trail` method declaration.
|
683
683
|
|
684
684
|
### 3.d. Deleting Old Versions
|
@@ -692,7 +692,7 @@ sql> delete from versions where created_at < 2010-06-01;
|
|
692
692
|
```
|
693
693
|
|
694
694
|
```ruby
|
695
|
-
PaperTrail::Version.delete_all [
|
695
|
+
PaperTrail::Version.delete_all ['created_at < ?', 1.week.ago]
|
696
696
|
```
|
697
697
|
|
698
698
|
## 4. Saving More Information About Versions
|
@@ -704,15 +704,15 @@ Set `PaperTrail.whodunnit=`, and that value will be stored in the version's
|
|
704
704
|
|
705
705
|
```ruby
|
706
706
|
PaperTrail.whodunnit = 'Andy Stewart'
|
707
|
-
widget.update_attributes :
|
707
|
+
widget.update_attributes name: 'Wibble'
|
708
708
|
widget.versions.last.whodunnit # Andy Stewart
|
709
709
|
```
|
710
710
|
|
711
711
|
`whodunnit` also accepts a block, a convenient way to temporarily set the value.
|
712
712
|
|
713
713
|
```ruby
|
714
|
-
PaperTrail.whodunnit(
|
715
|
-
widget.update_attributes :
|
714
|
+
PaperTrail.whodunnit('Dorian Marié') do
|
715
|
+
widget.update_attributes name: 'Wibble'
|
716
716
|
end
|
717
717
|
```
|
718
718
|
|
@@ -747,10 +747,10 @@ the `whodunnit` value for an operation inside a block like this:
|
|
747
747
|
```ruby
|
748
748
|
PaperTrail.whodunnit = 'Andy Stewart'
|
749
749
|
widget.paper_trail.whodunnit('Lucas Souza') do
|
750
|
-
widget.update_attributes :
|
750
|
+
widget.update_attributes name: 'Wibble'
|
751
751
|
end
|
752
752
|
widget.versions.last.whodunnit # Lucas Souza
|
753
|
-
widget.update_attributes :
|
753
|
+
widget.update_attributes name: 'Clair'
|
754
754
|
widget.versions.last.whodunnit # Andy Stewart
|
755
755
|
```
|
756
756
|
|
@@ -767,10 +767,10 @@ like it does, call `paper_trail_originator` on the object.
|
|
767
767
|
```ruby
|
768
768
|
widget = Widget.find 153 # assume widget has 0 versions
|
769
769
|
PaperTrail.whodunnit = 'Alice'
|
770
|
-
widget.update_attributes :
|
770
|
+
widget.update_attributes name: 'Yankee'
|
771
771
|
widget.paper_trail.originator # 'Alice'
|
772
772
|
PaperTrail.whodunnit = 'Bob'
|
773
|
-
widget.update_attributes :
|
773
|
+
widget.update_attributes name: 'Zulu'
|
774
774
|
widget.paper_trail.originator # 'Bob'
|
775
775
|
first_version, last_version = widget.versions.first, widget.versions.last
|
776
776
|
first_version.whodunnit # 'Alice'
|
@@ -813,10 +813,10 @@ association and reify it. The `transaction_id` is a unique id for version record
|
|
813
813
|
created in the same transaction. It is used to associate the version of the model
|
814
814
|
and the version of the association that are created in the same transaction.
|
815
815
|
|
816
|
-
To restore Has-One associations as they were at the time, pass option
|
817
|
-
|
818
|
-
option
|
819
|
-
option
|
816
|
+
To restore Has-One associations as they were at the time, pass option `has_one:
|
817
|
+
true` to `reify`. To restore Has-Many and Has-Many-Through associations, use
|
818
|
+
option `has_many: true`. To restore Belongs-To association, use
|
819
|
+
option `belongs_to: true`. For example:
|
820
820
|
|
821
821
|
```ruby
|
822
822
|
class Location < ActiveRecord::Base
|
@@ -832,10 +832,10 @@ end
|
|
832
832
|
treasure.amount # 100
|
833
833
|
treasure.location.latitude # 12.345
|
834
834
|
|
835
|
-
treasure.update_attributes :
|
836
|
-
treasure.location.update_attributes :
|
835
|
+
treasure.update_attributes amount: 153
|
836
|
+
treasure.location.update_attributes latitude: 54.321
|
837
837
|
|
838
|
-
t = treasure.versions.last.reify(:
|
838
|
+
t = treasure.versions.last.reify(has_one: true)
|
839
839
|
t.amount # 100
|
840
840
|
t.location.latitude # 12.345
|
841
841
|
```
|
@@ -849,11 +849,11 @@ treasure.amount # 100
|
|
849
849
|
treasure.location.latitude # 12.345
|
850
850
|
|
851
851
|
Treasure.transaction do
|
852
|
-
treasure.location.update_attributes :
|
853
|
-
treasure.update_attributes :
|
852
|
+
treasure.location.update_attributes latitude: 54.321
|
853
|
+
treasure.update_attributes amount: 153
|
854
854
|
end
|
855
855
|
|
856
|
-
t = treasure.versions.last.reify(:
|
856
|
+
t = treasure.versions.last.reify(has_one: true)
|
857
857
|
t.amount # 100
|
858
858
|
t.location.latitude # 12.345, instead of 54.321
|
859
859
|
```
|
@@ -862,7 +862,7 @@ By default, PaperTrail excludes an associated record from the reified parent
|
|
862
862
|
model if the associated record exists in the live model but did not exist as at
|
863
863
|
the time the version was created. This is usually what you want if you just want
|
864
864
|
to look at the reified version. But if you want to persist it, it would be
|
865
|
-
better to pass in option
|
865
|
+
better to pass in option `mark_for_destruction: true` so that the associated
|
866
866
|
record is included and marked for destruction. Note that `mark_for_destruction`
|
867
867
|
only has [an effect on associations marked with `autosave: true`][32].
|
868
868
|
|
@@ -877,14 +877,14 @@ class Wotsit < ActiveRecord::Base
|
|
877
877
|
belongs_to :widget
|
878
878
|
end
|
879
879
|
|
880
|
-
widget = Widget.create(:
|
881
|
-
widget.update_attributes(:
|
882
|
-
widget.create_wotsit(:
|
880
|
+
widget = Widget.create(name: 'widget_0')
|
881
|
+
widget.update_attributes(name: 'widget_1')
|
882
|
+
widget.create_wotsit(name: 'wotsit')
|
883
883
|
|
884
|
-
widget_0 = widget.versions.last.reify(:
|
884
|
+
widget_0 = widget.versions.last.reify(has_one: true)
|
885
885
|
widget_0.wotsit # nil
|
886
886
|
|
887
|
-
widget_0 = widget.versions.last.reify(:
|
887
|
+
widget_0 = widget.versions.last.reify(has_one: true, mark_for_destruction: true)
|
888
888
|
widget_0.wotsit.marked_for_destruction? # true
|
889
889
|
widget_0.save!
|
890
890
|
widget.reload.wotsit # nil
|
@@ -919,8 +919,8 @@ Given these models:
|
|
919
919
|
|
920
920
|
```ruby
|
921
921
|
class Book < ActiveRecord::Base
|
922
|
-
has_many :authorships, :
|
923
|
-
has_many :authors, :
|
922
|
+
has_many :authorships, dependent: :destroy
|
923
|
+
has_many :authors, through: :authorships, source: :person
|
924
924
|
has_paper_trail
|
925
925
|
end
|
926
926
|
|
@@ -931,8 +931,8 @@ class Authorship < ActiveRecord::Base
|
|
931
931
|
end
|
932
932
|
|
933
933
|
class Person < ActiveRecord::Base
|
934
|
-
has_many :authorships, :
|
935
|
-
has_many :books, :
|
934
|
+
has_many :authorships, dependent: :destroy
|
935
|
+
has_many :books, through: :authorships
|
936
936
|
has_paper_trail
|
937
937
|
end
|
938
938
|
```
|
@@ -941,7 +941,7 @@ Then each of the following will store authorship versions:
|
|
941
941
|
|
942
942
|
```ruby
|
943
943
|
@book.authors << @dostoyevsky
|
944
|
-
@book.authors.create :
|
944
|
+
@book.authors.create name: 'Tolstoy'
|
945
945
|
@book.authorships.last.destroy
|
946
946
|
@book.authorships.clear
|
947
947
|
@book.author_ids = [@solzhenistyn.id, @dostoyevsky.id]
|
@@ -984,9 +984,9 @@ You can store arbitrary model-level metadata alongside each version like this:
|
|
984
984
|
```ruby
|
985
985
|
class Article < ActiveRecord::Base
|
986
986
|
belongs_to :author
|
987
|
-
has_paper_trail :
|
988
|
-
|
989
|
-
|
987
|
+
has_paper_trail meta: { author_id: :author_id,
|
988
|
+
word_count: :count_words,
|
989
|
+
answer: 42 }
|
990
990
|
def count_words
|
991
991
|
153
|
992
992
|
end
|
@@ -1008,7 +1008,7 @@ question. Clearly this is inefficient. Using the metadata you can find just
|
|
1008
1008
|
those versions you want:
|
1009
1009
|
|
1010
1010
|
```ruby
|
1011
|
-
PaperTrail::Version.where(:
|
1011
|
+
PaperTrail::Version.where(author_id: author_id)
|
1012
1012
|
```
|
1013
1013
|
|
1014
1014
|
#### Metadata from Controllers
|
@@ -1020,7 +1020,7 @@ correspond to columns in your `versions` table.
|
|
1020
1020
|
```ruby
|
1021
1021
|
class ApplicationController
|
1022
1022
|
def info_for_paper_trail
|
1023
|
-
{ :
|
1023
|
+
{ ip: request.remote_ip, user_agent: request.user_agent }
|
1024
1024
|
end
|
1025
1025
|
end
|
1026
1026
|
```
|
@@ -1105,7 +1105,7 @@ class PostVersion < PaperTrail::Version
|
|
1105
1105
|
end
|
1106
1106
|
|
1107
1107
|
class Post < ActiveRecord::Base
|
1108
|
-
has_paper_trail :
|
1108
|
+
has_paper_trail class_name: 'PostVersion'
|
1109
1109
|
end
|
1110
1110
|
```
|
1111
1111
|
|
@@ -1151,8 +1151,8 @@ model. For example:
|
|
1151
1151
|
|
1152
1152
|
```ruby
|
1153
1153
|
class Post < ActiveRecord::Base
|
1154
|
-
has_paper_trail :
|
1155
|
-
:
|
1154
|
+
has_paper_trail versions: :paper_trail_versions,
|
1155
|
+
version: :paper_trail_version
|
1156
1156
|
|
1157
1157
|
# Existing versions method. We don't want to clash.
|
1158
1158
|
def versions
|
@@ -1318,7 +1318,7 @@ end
|
|
1318
1318
|
Then, use the helper in your tests.
|
1319
1319
|
|
1320
1320
|
```ruby
|
1321
|
-
test
|
1321
|
+
test 'something that needs versioning' do
|
1322
1322
|
with_versioning do
|
1323
1323
|
# your test
|
1324
1324
|
end
|
@@ -1347,7 +1347,7 @@ test in a `with_versioning` block, or pass in `versioning: true` option to a
|
|
1347
1347
|
spec block.
|
1348
1348
|
|
1349
1349
|
```ruby
|
1350
|
-
describe
|
1350
|
+
describe 'RSpec test group' do
|
1351
1351
|
it 'by default, PaperTrail will be turned off' do
|
1352
1352
|
expect(PaperTrail).to_not be_enabled
|
1353
1353
|
end
|
@@ -1377,18 +1377,18 @@ class Widget < ActiveRecord::Base
|
|
1377
1377
|
end
|
1378
1378
|
|
1379
1379
|
describe Widget do
|
1380
|
-
it
|
1380
|
+
it 'is not versioned by default' do
|
1381
1381
|
is_expected.to_not be_versioned
|
1382
1382
|
end
|
1383
1383
|
|
1384
|
-
describe
|
1384
|
+
describe 'add versioning to the `Widget` class' do
|
1385
1385
|
before(:all) do
|
1386
1386
|
class Widget < ActiveRecord::Base
|
1387
1387
|
has_paper_trail
|
1388
1388
|
end
|
1389
1389
|
end
|
1390
1390
|
|
1391
|
-
it
|
1391
|
+
it 'enables paper trail' do
|
1392
1392
|
is_expected.to be_versioned
|
1393
1393
|
end
|
1394
1394
|
end
|
@@ -1402,7 +1402,7 @@ The `have_a_version_with` matcher makes assertions about versions using
|
|
1402
1402
|
|
1403
1403
|
```ruby
|
1404
1404
|
describe '`have_a_version_with` matcher' do
|
1405
|
-
it
|
1405
|
+
it 'is possible to do assertions on version attributes' do
|
1406
1406
|
widget.update_attributes!(name: 'Leonard', an_integer: 1)
|
1407
1407
|
widget.update_attributes!(name: 'Tom')
|
1408
1408
|
widget.update_attributes!(name: 'Bob')
|
@@ -1419,7 +1419,7 @@ The `have_a_version_with_changes` matcher makes assertions about versions using
|
|
1419
1419
|
|
1420
1420
|
```ruby
|
1421
1421
|
describe '`have_a_version_with_changes` matcher' do
|
1422
|
-
it
|
1422
|
+
it 'is possible to do assertions on version changes' do
|
1423
1423
|
widget.update_attributes!(name: 'Leonard', an_integer: 1)
|
1424
1424
|
widget.update_attributes!(name: 'Tom')
|
1425
1425
|
widget.update_attributes!(name: 'Bob')
|
@@ -1442,7 +1442,7 @@ helper like so:
|
|
1442
1442
|
```ruby
|
1443
1443
|
# features/support/env.rb
|
1444
1444
|
|
1445
|
-
ENV["RAILS_ENV"] ||=
|
1445
|
+
ENV["RAILS_ENV"] ||= 'cucumber'
|
1446
1446
|
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
|
1447
1447
|
# ...
|
1448
1448
|
require 'paper_trail/frameworks/cucumber'
|
@@ -1505,9 +1505,10 @@ require 'rspec/rails'
|
|
1505
1505
|
require 'paper_trail/frameworks/rspec'
|
1506
1506
|
```
|
1507
1507
|
|
1508
|
-
## 8.
|
1508
|
+
## 8. Integration with Other Libraries
|
1509
1509
|
|
1510
|
-
|
1510
|
+
- [ActiveAdmin][42]
|
1511
|
+
- Sinatra - [paper_trail-sinatra][41]
|
1511
1512
|
|
1512
1513
|
## Articles
|
1513
1514
|
|
@@ -1528,61 +1529,10 @@ Please use GitHub's [issue tracker](http://github.com/airblade/paper_trail/issue
|
|
1528
1529
|
|
1529
1530
|
## Contributors
|
1530
1531
|
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
* [Zachery Hostens](http://github.com/zacheryph)
|
1536
|
-
* [Jeremy Weiskotten](http://github.com/jeremyw)
|
1537
|
-
* [Phan Le](http://github.com/revo)
|
1538
|
-
* [jdrucza](http://github.com/jdrucza)
|
1539
|
-
* [conickal](http://github.com/conickal)
|
1540
|
-
* [Thibaud Guillaume-Gentil](http://github.com/thibaudgg)
|
1541
|
-
* Danny Trelogan
|
1542
|
-
* [Mikl Kurkov](http://github.com/mkurkov)
|
1543
|
-
* [Franco Catena](https://github.com/francocatena)
|
1544
|
-
* [Emmanuel Gomez](https://github.com/emmanuel)
|
1545
|
-
* [Matthew MacLeod](https://github.com/mattmacleod)
|
1546
|
-
* [benzittlau](https://github.com/benzittlau)
|
1547
|
-
* [Tom Derks](https://github.com/EgoH)
|
1548
|
-
* [Jonas Hoglund](https://github.com/jhoglund)
|
1549
|
-
* [Stefan Huber](https://github.com/MSNexploder)
|
1550
|
-
* [thinkcast](https://github.com/thinkcast)
|
1551
|
-
* [Dominik Sander](https://github.com/dsander)
|
1552
|
-
* [Burke Libbey](https://github.com/burke)
|
1553
|
-
* [6twenty](https://github.com/6twenty)
|
1554
|
-
* [nir0](https://github.com/nir0)
|
1555
|
-
* [Eduard Tsech](https://github.com/edtsech)
|
1556
|
-
* [Mathieu Arnold](https://github.com/mat813)
|
1557
|
-
* [Nicholas Thrower](https://github.com/throwern)
|
1558
|
-
* [Benjamin Curtis](https://github.com/stympy)
|
1559
|
-
* [Peter Harkins](https://github.com/pushcx)
|
1560
|
-
* [Mohd Amree](https://github.com/amree)
|
1561
|
-
* [Nikita Cernovs](https://github.com/nikitachernov)
|
1562
|
-
* [Jason Noble](https://github.com/jasonnoble)
|
1563
|
-
* [Jared Mehle](https://github.com/jrmehle)
|
1564
|
-
* [Eric Schwartz](https://github.com/emschwar)
|
1565
|
-
* [Ben Woosley](https://github.com/Empact)
|
1566
|
-
* [Philip Arndt](https://github.com/parndt)
|
1567
|
-
* [Daniel Vydra](https://github.com/dvydra)
|
1568
|
-
* [Byron Bowerman](https://github.com/BM5k)
|
1569
|
-
* [Nicolas Buduroi](https://github.com/budu)
|
1570
|
-
* [Pikender Sharma](https://github.com/pikender)
|
1571
|
-
* [Paul Brannan](https://github.com/cout)
|
1572
|
-
* [Ben Morrall](https://github.com/bmorrall)
|
1573
|
-
* [Yves Senn](https://github.com/senny)
|
1574
|
-
* [Ben Atkins](https://github.com/fullbridge-batkins)
|
1575
|
-
* [Tyler Rick](https://github.com/TylerRick)
|
1576
|
-
* [Bradley Priest](https://github.com/bradleypriest)
|
1577
|
-
* [David Butler](https://github.com/dwbutler)
|
1578
|
-
* [Paul Belt](https://github.com/belt)
|
1579
|
-
* [Vlad Bokov](https://github.com/razum2um)
|
1580
|
-
* [Sean Marcia](https://github.com/SeanMarcia)
|
1581
|
-
* [Chulki Lee](https://github.com/chulkilee)
|
1582
|
-
* [Lucas Souza](https://github.com/lucasas)
|
1583
|
-
* [Russell Osborne](https://github.com/rposborne)
|
1584
|
-
* [Ben Li](https://github.com/bli)
|
1585
|
-
* [Felix Liu](https://github.com/lyfeyaj)
|
1532
|
+
Created by Andy Stewart in 2010, maintained since 2012 by Ben Atkins, since 2015
|
1533
|
+
by Jared Beck, with contributions by over 150 people.
|
1534
|
+
|
1535
|
+
https://github.com/airblade/paper_trail/graphs/contributors
|
1586
1536
|
|
1587
1537
|
## Inspirations
|
1588
1538
|
|
@@ -1631,3 +1581,4 @@ Released under the MIT licence.
|
|
1631
1581
|
[39]: http://api.rubyonrails.org/classes/ActiveRecord/Base.html#class-ActiveRecord::Base-label-Single+table+inheritance
|
1632
1582
|
[40]: http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Polymorphic+Associations
|
1633
1583
|
[41]: https://github.com/jaredbeck/paper_trail-sinatra
|
1584
|
+
[42]: https://github.com/activeadmin/activeadmin/wiki/Auditing-via-paper_trail-%28change-history%29
|