paper_trail 7.0.3 → 7.1.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/.github/CONTRIBUTING.md +21 -27
- data/.gitignore +4 -4
- data/.rubocop.yml +2 -2
- data/CHANGELOG.md +17 -0
- data/README.md +31 -2
- data/Rakefile +4 -1
- data/lib/paper_trail.rb +2 -0
- data/lib/paper_trail/serializers/json.rb +9 -0
- data/lib/paper_trail/version_concern.rb +1 -1
- data/lib/paper_trail/version_number.rb +2 -2
- data/paper_trail.gemspec +2 -3
- data/spec/controllers/widgets_controller_spec.rb +85 -0
- data/{test/dummy → spec/dummy_app}/Rakefile +0 -0
- data/{test/dummy → spec/dummy_app}/app/controllers/application_controller.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/controllers/articles_controller.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/controllers/test_controller.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/controllers/widgets_controller.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/animal.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/article.rb +1 -0
- data/{test/dummy → spec/dummy_app}/app/models/authorship.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/bar_habtm.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/book.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/boolit.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/callback_modifier.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/car.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/cat.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/chapter.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/citation.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/custom_primary_key_record.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/customer.rb +0 -0
- data/spec/dummy_app/app/models/document.rb +8 -0
- data/{test/dummy → spec/dummy_app}/app/models/dog.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/editor.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/editorship.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/elephant.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/fluxor.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/foo_habtm.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/foo_widget.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/fruit.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/gadget.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/kitchen/banana.rb +0 -0
- data/spec/dummy_app/app/models/legacy_widget.rb +6 -0
- data/{test/dummy → spec/dummy_app}/app/models/line_item.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/not_on_update.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/on/create.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/on/destroy.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/on/empty_array.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/on/update.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/order.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/paragraph.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/person.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/post.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/post_with_status.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/quotation.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/section.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/skipper.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/song.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/thing.rb +0 -0
- data/spec/dummy_app/app/models/translation.rb +11 -0
- data/{test/dummy → spec/dummy_app}/app/models/truck.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/vehicle.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/whatchamajigger.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/widget.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/models/wotsit.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/versions/custom_primary_key_record_version.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/versions/joined_version.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/versions/json_version.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/versions/kitchen/banana_version.rb +0 -0
- data/{test/dummy → spec/dummy_app}/app/versions/post_version.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config.ru +0 -0
- data/{test/dummy → spec/dummy_app}/config/application.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/boot.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/database.mysql.yml +0 -0
- data/{test/dummy → spec/dummy_app}/config/database.postgres.yml +0 -0
- data/{test/dummy → spec/dummy_app}/config/database.sqlite.yml +0 -0
- data/{test/dummy → spec/dummy_app}/config/environment.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/environments/development.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/environments/production.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/environments/test.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/initializers/backtrace_silencers.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/initializers/inflections.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/initializers/mime_types.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/initializers/paper_trail.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/initializers/secret_token.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/initializers/session_store.rb +0 -0
- data/{test/dummy → spec/dummy_app}/config/locales/en.yml +0 -0
- data/{test/dummy → spec/dummy_app}/config/routes.rb +0 -0
- data/{test/dummy → spec/dummy_app}/db/migrate/20110208155312_set_up_test_tables.rb +0 -0
- data/{test/dummy → spec/dummy_app}/db/schema.rb +0 -0
- data/spec/models/article_spec.rb +186 -0
- data/spec/models/document_spec.rb +41 -5
- data/spec/models/legacy_widget_spec.rb +40 -0
- data/spec/models/on/create_spec.rb +27 -0
- data/spec/models/on/destroy_spec.rb +27 -0
- data/spec/models/on/empty_array_spec.rb +30 -0
- data/spec/models/on/update_spec.rb +27 -0
- data/spec/models/translation_spec.rb +70 -0
- data/spec/models/version_spec.rb +7 -3
- data/spec/paper_trail/config_spec.rb +12 -0
- data/spec/paper_trail/model_spec.rb +0 -429
- data/spec/paper_trail/serializers/custom_json_serializer_spec.rb +18 -0
- data/spec/paper_trail/thread_safety_spec.rb +44 -0
- data/spec/paper_trail_spec.rb +9 -0
- data/spec/spec_helper.rb +6 -10
- metadata +178 -179
- data/test/dummy/app/models/document.rb +0 -6
- data/test/dummy/app/models/legacy_widget.rb +0 -3
- data/test/dummy/app/models/translation.rb +0 -6
- data/test/functional/controller_test.rb +0 -90
- data/test/functional/thread_safety_test.rb +0 -46
- data/test/test_helper.rb +0 -68
- data/test/unit/serializers/mixin_json_test.rb +0 -39
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '022806af0ea91aee393c67adb08dcf4a322c7652'
|
|
4
|
+
data.tar.gz: 50d52e94b4a93c6f89de10638cb3ddcad73a8312
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5282396646c7f8174d2cd866e5ee0d64f394e1f967a8c4ab979b593f772f0360f825f7312418edba016622f6088fb2cdae1264142c9b83fb2310309cd3868ff4
|
|
7
|
+
data.tar.gz: 48ab8574011657bcb0e4d2dbe60a78a53187ca79cef2d3a8770992bc0cf2ce179a144c821cbae194d8dc54e6a7cb4a0b44968ff513f60a16788dc2729efcff86
|
data/.github/CONTRIBUTING.md
CHANGED
|
@@ -7,10 +7,7 @@ https://stackoverflow.com/tags/paper-trail-gem
|
|
|
7
7
|
|
|
8
8
|
**Please do not use github issues to ask usage questions.**
|
|
9
9
|
|
|
10
|
-
On github, we appreciate bug reports, feature
|
|
11
|
-
suggestions, and especially pull requests.
|
|
12
|
-
|
|
13
|
-
Thanks, and happy (paper) trails :)
|
|
10
|
+
On github, we appreciate bug reports, feature suggestions, and pull requests.
|
|
14
11
|
|
|
15
12
|
## Reporting Bugs
|
|
16
13
|
|
|
@@ -18,9 +15,7 @@ Please use our [bug report template][1].
|
|
|
18
15
|
|
|
19
16
|
## Development
|
|
20
17
|
|
|
21
|
-
Install gems with `bundle exec appraisal install`.
|
|
22
|
-
(It is still possible to run the `ar-4.2` gemfile locally on ruby 1.9.3, but
|
|
23
|
-
not the `ar-5.0` gemfile.)
|
|
18
|
+
Install gems with `bundle exec appraisal install`.
|
|
24
19
|
|
|
25
20
|
Testing is a little awkward because the test suite:
|
|
26
21
|
|
|
@@ -32,13 +27,13 @@ Testing is a little awkward because the test suite:
|
|
|
32
27
|
|
|
33
28
|
```
|
|
34
29
|
# Create the appropriate database config. file
|
|
35
|
-
rm
|
|
30
|
+
rm spec/dummy_app/config/database.yml
|
|
36
31
|
DB=sqlite bundle exec rake prepare
|
|
37
32
|
|
|
38
33
|
# If this is the first test run ever, create databases.
|
|
39
|
-
# We can't use `appraisal` inside the
|
|
40
|
-
# See
|
|
41
|
-
cd
|
|
34
|
+
# We can't use `appraisal` inside the dummy app, so we must set `BUNDLE_GEMFILE`.
|
|
35
|
+
# See spec/dummy_app/config/boot.rb for a complete explanation.
|
|
36
|
+
cd spec/dummy_app
|
|
42
37
|
export BUNDLE_GEMFILE=../../gemfiles/ar_4.2.gemfile
|
|
43
38
|
RAILS_ENV=test bundle exec rake db:setup
|
|
44
39
|
RAILS_ENV=foo bundle exec rake db:setup
|
|
@@ -49,8 +44,7 @@ cd ../..
|
|
|
49
44
|
# Run tests
|
|
50
45
|
DB=sqlite bundle exec appraisal ar-4.2 rake
|
|
51
46
|
|
|
52
|
-
# Run a single test
|
|
53
|
-
DB=sqlite bundle exec appraisal ar-4.2 ruby -I test test/unit/associations_test.rb
|
|
47
|
+
# Run a single test
|
|
54
48
|
DB=sqlite bundle exec appraisal ar-4.2 rspec spec/paper_trail/serializers/json_spec.rb
|
|
55
49
|
```
|
|
56
50
|
|
|
@@ -58,13 +52,13 @@ DB=sqlite bundle exec appraisal ar-4.2 rspec spec/paper_trail/serializers/json_s
|
|
|
58
52
|
|
|
59
53
|
```
|
|
60
54
|
# Create the appropriate database config. file
|
|
61
|
-
rm
|
|
55
|
+
rm spec/dummy_app/config/database.yml
|
|
62
56
|
DB=sqlite bundle exec rake prepare
|
|
63
57
|
|
|
64
58
|
# If this is the first test run ever, create databases.
|
|
65
|
-
# We can't use `appraisal` inside the
|
|
66
|
-
# See
|
|
67
|
-
cd
|
|
59
|
+
# We can't use `appraisal` inside the dummy app, so we must set `BUNDLE_GEMFILE`.
|
|
60
|
+
# See spec/dummy_app/config/boot.rb for a complete explanation.
|
|
61
|
+
cd spec/dummy_app
|
|
68
62
|
export BUNDLE_GEMFILE=../../gemfiles/ar_5.0.gemfile
|
|
69
63
|
RAILS_ENV=test bundle exec rake db:environment:set db:setup
|
|
70
64
|
RAILS_ENV=foo bundle exec rake db:environment:set db:setup
|
|
@@ -80,13 +74,13 @@ DB=sqlite bundle exec appraisal ar-5.0 rake
|
|
|
80
74
|
|
|
81
75
|
```
|
|
82
76
|
# Create the appropriate database config. file
|
|
83
|
-
rm
|
|
77
|
+
rm spec/dummy_app/config/database.yml
|
|
84
78
|
DB=mysql bundle exec rake prepare
|
|
85
79
|
|
|
86
80
|
# If this is the first test run ever, create databases.
|
|
87
|
-
# We can't use `appraisal` inside the
|
|
88
|
-
# See
|
|
89
|
-
cd
|
|
81
|
+
# We can't use `appraisal` inside the dummy app, so we must set `BUNDLE_GEMFILE`.
|
|
82
|
+
# See spec/dummy_app/config/boot.rb for a complete explanation.
|
|
83
|
+
cd spec/dummy_app
|
|
90
84
|
export BUNDLE_GEMFILE=../../gemfiles/ar_5.0.gemfile
|
|
91
85
|
RAILS_ENV=test bundle exec rake db:environment:set db:setup
|
|
92
86
|
RAILS_ENV=foo bundle exec rake db:environment:set db:setup
|
|
@@ -102,14 +96,14 @@ DB=mysql bundle exec appraisal ar-5.0 rake
|
|
|
102
96
|
|
|
103
97
|
```
|
|
104
98
|
# Create the appropriate database config. file
|
|
105
|
-
rm
|
|
99
|
+
rm spec/dummy_app/config/database.yml
|
|
106
100
|
DB=postgres bundle exec rake prepare
|
|
107
101
|
|
|
108
102
|
# If this is the first test run ever, create databases.
|
|
109
103
|
# Unlike mysql, use create/migrate instead of setup.
|
|
110
|
-
# We can't use `appraisal` inside the
|
|
111
|
-
# See
|
|
112
|
-
cd
|
|
104
|
+
# We can't use `appraisal` inside the dummy app, so we must set `BUNDLE_GEMFILE`.
|
|
105
|
+
# See spec/dummy_app/config/boot.rb for a complete explanation.
|
|
106
|
+
cd spec/dummy_app
|
|
113
107
|
export BUNDLE_GEMFILE=../../gemfiles/ar_5.0.gemfile
|
|
114
108
|
DB=postgres RAILS_ENV=test bundle exec rake db:drop db:create db:migrate
|
|
115
109
|
DB=postgres RAILS_ENV=foo bundle exec rake db:drop db:create db:migrate
|
|
@@ -124,10 +118,10 @@ DB=postgres bundle exec appraisal ar-5.0 rake
|
|
|
124
118
|
|
|
125
119
|
## Editing the migration
|
|
126
120
|
|
|
127
|
-
After editing `
|
|
121
|
+
After editing `spec/dummy_app/db/migrate/20110208155312_set_up_test_tables.rb` ..
|
|
128
122
|
|
|
129
123
|
```
|
|
130
|
-
cd
|
|
124
|
+
cd spec/dummy_app
|
|
131
125
|
export BUNDLE_GEMFILE=../../gemfiles/ar_5.1.gemfile
|
|
132
126
|
RAILS_ENV=test bundle exec rake db:environment:set db:drop db:create db:migrate
|
|
133
127
|
RAILS_ENV=foo bundle exec rake db:environment:set db:drop db:create db:migrate
|
data/.gitignore
CHANGED
|
@@ -2,10 +2,10 @@ gemfiles/*.lock
|
|
|
2
2
|
NOTES
|
|
3
3
|
test/debug.log
|
|
4
4
|
test/paper_trail_plugin.sqlite3.db
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
spec/dummy_app/config/database.yml
|
|
6
|
+
spec/dummy_app/db/*.sqlite3
|
|
7
|
+
spec/dummy_app/log/*
|
|
8
|
+
spec/dummy_app/tmp/*
|
|
9
9
|
spec/dummy/
|
|
10
10
|
coverage
|
|
11
11
|
pkg/*
|
data/.rubocop.yml
CHANGED
|
@@ -12,7 +12,7 @@ inherit_from: .rubocop_todo.yml
|
|
|
12
12
|
AllCops:
|
|
13
13
|
Exclude:
|
|
14
14
|
- gemfiles/vendor/bundle/**/* # This dir only shows up on travis ¯\_(ツ)_/¯
|
|
15
|
-
-
|
|
15
|
+
- spec/dummy_app/db/schema.rb # Generated, out of our control
|
|
16
16
|
|
|
17
17
|
# Set to lowest supported version
|
|
18
18
|
TargetRubyVersion: 2.1
|
|
@@ -21,7 +21,7 @@ AllCops:
|
|
|
21
21
|
# from these is of questionable value.
|
|
22
22
|
Metrics/AbcSize:
|
|
23
23
|
Exclude:
|
|
24
|
-
- '
|
|
24
|
+
- 'spec/dummy_app/db/migrate/*'
|
|
25
25
|
|
|
26
26
|
# Not a useful metric compared to, e.g. `AbcSize`.
|
|
27
27
|
Metrics/BlockLength:
|
data/CHANGELOG.md
CHANGED
|
@@ -17,6 +17,23 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
|
|
|
17
17
|
|
|
18
18
|
- None
|
|
19
19
|
|
|
20
|
+
## 7.1.0 (2017-07-09)
|
|
21
|
+
|
|
22
|
+
### Breaking Changes
|
|
23
|
+
|
|
24
|
+
- None
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- [#803](https://github.com/airblade/paper_trail/issues/803)
|
|
29
|
+
Deprecate `where_object_changes` when reading json from a text column
|
|
30
|
+
- [#976](https://github.com/airblade/paper_trail/pull/976)
|
|
31
|
+
`PaperTrail.whodunnit` accepts a `Proc`
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
|
|
35
|
+
- None
|
|
36
|
+
|
|
20
37
|
## 7.0.3 (2017-06-01)
|
|
21
38
|
|
|
22
39
|
### Breaking Changes
|
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.1.0 | https://github.com/airblade/paper_trail/blob/v7.1.0/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 |
|
|
@@ -716,6 +716,14 @@ PaperTrail.whodunnit('Dorian Marié') do
|
|
|
716
716
|
end
|
|
717
717
|
```
|
|
718
718
|
|
|
719
|
+
`whodunnit` also accepts a `Proc`.
|
|
720
|
+
|
|
721
|
+
```ruby
|
|
722
|
+
PaperTrail.whodunnit = proc do
|
|
723
|
+
caller.first{ |c| c.starts_with? Rails.root.to_s }
|
|
724
|
+
end
|
|
725
|
+
```
|
|
726
|
+
|
|
719
727
|
If your controller has a `current_user` method, PaperTrail provides a
|
|
720
728
|
`before_action` that will assign `current_user.id` to `PaperTrail.whodunnit`.
|
|
721
729
|
You can add this `before_action` to your `ApplicationController`.
|
|
@@ -1090,7 +1098,23 @@ Generates (but does not run) a migration to add a versions table. Also generate
|
|
|
1090
1098
|
|
|
1091
1099
|
As of version 6, PT no longer supports rails 3 or the [protected_attributes][17]
|
|
1092
1100
|
gem. If you are still using them, you may use PT 5 or lower. We recommend
|
|
1093
|
-
upgrading to [strong_parameters][18] as soon as possible.
|
|
1101
|
+
upgrading to [strong_parameters][18] as soon as possible.
|
|
1102
|
+
|
|
1103
|
+
If you must use [protected_attributes][17] for now, and want to use PT > 5, you
|
|
1104
|
+
can reopen `PaperTrail::Version` and add the following `attr_accessible` fields:
|
|
1105
|
+
|
|
1106
|
+
```ruby
|
|
1107
|
+
# app/models/paper_trail/version.rb
|
|
1108
|
+
module PaperTrail
|
|
1109
|
+
class Version < ActiveRecord::Base
|
|
1110
|
+
include PaperTrail::VersionConcern
|
|
1111
|
+
attr_accessible :item_type, :item_id, :event, :whodunnit, :object, :object_changes, :created_at
|
|
1112
|
+
end
|
|
1113
|
+
end
|
|
1114
|
+
```
|
|
1115
|
+
|
|
1116
|
+
This unsupported workaround has been tested with protected_attributes 1.0.9 /
|
|
1117
|
+
rails 4.2.8 / paper_trail 7.0.3.
|
|
1094
1118
|
|
|
1095
1119
|
## 6. Extensibility
|
|
1096
1120
|
|
|
@@ -1534,6 +1558,10 @@ by Jared Beck, with contributions by over 150 people.
|
|
|
1534
1558
|
|
|
1535
1559
|
https://github.com/airblade/paper_trail/graphs/contributors
|
|
1536
1560
|
|
|
1561
|
+
## Contributing
|
|
1562
|
+
|
|
1563
|
+
See our [contribution guidelines][43]
|
|
1564
|
+
|
|
1537
1565
|
## Inspirations
|
|
1538
1566
|
|
|
1539
1567
|
* [Simply Versioned](http://github.com/github/simply_versioned)
|
|
@@ -1582,3 +1610,4 @@ Released under the MIT licence.
|
|
|
1582
1610
|
[40]: http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Polymorphic+Associations
|
|
1583
1611
|
[41]: https://github.com/jaredbeck/paper_trail-sinatra
|
|
1584
1612
|
[42]: https://github.com/activeadmin/activeadmin/wiki/Auditing-via-paper_trail-%28change-history%29
|
|
1613
|
+
[43]: https://github.com/airblade/paper_trail/blob/master/.github/CONTRIBUTING.md
|
data/Rakefile
CHANGED
|
@@ -4,7 +4,10 @@ Bundler::GemHelper.install_tasks
|
|
|
4
4
|
desc "Set a relevant database.yml for testing"
|
|
5
5
|
task :prepare do
|
|
6
6
|
ENV["DB"] ||= "sqlite"
|
|
7
|
-
FileUtils.cp
|
|
7
|
+
FileUtils.cp(
|
|
8
|
+
"spec/dummy_app/config/database.#{ENV['DB']}.yml",
|
|
9
|
+
"spec/dummy_app/config/database.yml"
|
|
10
|
+
)
|
|
8
11
|
end
|
|
9
12
|
|
|
10
13
|
require "rake/testtask"
|
data/lib/paper_trail.rb
CHANGED
|
@@ -4,6 +4,13 @@ module PaperTrail
|
|
|
4
4
|
module Serializers
|
|
5
5
|
# An alternate serializer for, e.g. `versions.object`.
|
|
6
6
|
module JSON
|
|
7
|
+
E_WHERE_OBJ_CHANGES = <<-STR.squish.freeze
|
|
8
|
+
where_object_changes has a known issue. When reading json from a text
|
|
9
|
+
column, it may return more records than expected. Instead of a warning,
|
|
10
|
+
this method may raise an error in the future. Please join the discussion
|
|
11
|
+
at https://github.com/airblade/paper_trail/issues/803
|
|
12
|
+
STR
|
|
13
|
+
|
|
7
14
|
extend self # makes all instance methods become module methods as well
|
|
8
15
|
|
|
9
16
|
def load(string)
|
|
@@ -35,6 +42,8 @@ module PaperTrail
|
|
|
35
42
|
# Returns a SQL LIKE condition to be used to match the given field and
|
|
36
43
|
# value in the serialized `object_changes`.
|
|
37
44
|
def where_object_changes_condition(arel_field, field, value)
|
|
45
|
+
::ActiveSupport::Deprecation.warn(E_WHERE_OBJ_CHANGES)
|
|
46
|
+
|
|
38
47
|
# Convert to JSON to handle strings and nulls correctly.
|
|
39
48
|
json_value = value.to_json
|
|
40
49
|
|
|
@@ -17,7 +17,7 @@ module PaperTrail
|
|
|
17
17
|
# Since the test suite has test coverage for this, we want to declare
|
|
18
18
|
# the association when the test suite is running. This makes it pass when
|
|
19
19
|
# DB is not initialized prior to test runs such as when we run on Travis
|
|
20
|
-
# CI (there won't be a db in `
|
|
20
|
+
# CI (there won't be a db in `spec/dummy_app/db/`).
|
|
21
21
|
if PaperTrail.config.track_associations?
|
|
22
22
|
has_many :version_associations, dependent: :destroy
|
|
23
23
|
end
|
data/paper_trail.gemspec
CHANGED
|
@@ -12,7 +12,7 @@ at any stage in its lifecycle, revert it to any version, or restore it after it
|
|
|
12
12
|
has been destroyed.
|
|
13
13
|
EOS
|
|
14
14
|
s.homepage = "https://github.com/airblade/paper_trail"
|
|
15
|
-
s.authors = ["Andy Stewart", "Ben Atkins"]
|
|
15
|
+
s.authors = ["Andy Stewart", "Ben Atkins", "Jared Beck"]
|
|
16
16
|
s.email = "batkinz@gmail.com"
|
|
17
17
|
s.license = "MIT"
|
|
18
18
|
|
|
@@ -30,10 +30,9 @@ has been destroyed.
|
|
|
30
30
|
|
|
31
31
|
s.add_development_dependency "appraisal", "~> 2.1"
|
|
32
32
|
s.add_development_dependency "rake", "~> 12.0"
|
|
33
|
-
s.add_development_dependency "shoulda", "~> 3.5"
|
|
34
33
|
s.add_development_dependency "ffaker", "~> 2.5"
|
|
35
34
|
|
|
36
|
-
# Why `railties`? Possibly used by `
|
|
35
|
+
# Why `railties`? Possibly used by `spec/dummy_app` boot up?
|
|
37
36
|
s.add_development_dependency "railties", [">= 4.0", "< 5.2"]
|
|
38
37
|
|
|
39
38
|
s.add_development_dependency "rack-test", "~> 0.6.3"
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
RSpec.describe WidgetsController, type: :controller, versioning: true do
|
|
4
|
+
before { request.env["REMOTE_ADDR"] = "127.0.0.1" }
|
|
5
|
+
after { RequestStore.store[:paper_trail] = nil }
|
|
6
|
+
|
|
7
|
+
describe "#create" do
|
|
8
|
+
context "PT enabled" do
|
|
9
|
+
it "stores information like IP address in version" do
|
|
10
|
+
post(:create, params_wrapper(widget: { name: "Flugel" }))
|
|
11
|
+
widget = assigns(:widget)
|
|
12
|
+
expect(widget.versions.length).to(eq(1))
|
|
13
|
+
expect(widget.versions.last.whodunnit.to_i).to(eq(153))
|
|
14
|
+
expect(widget.versions.last.ip).to(eq("127.0.0.1"))
|
|
15
|
+
expect(widget.versions.last.user_agent).to(eq("Rails Testing"))
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "controller metadata methods should get evaluated" do
|
|
19
|
+
request.env["HTTP_USER_AGENT"] = "User-Agent"
|
|
20
|
+
post :create, params_wrapper(widget: { name: "Flugel" })
|
|
21
|
+
expect(PaperTrail.enabled_for_controller?).to(eq(true))
|
|
22
|
+
expect(PaperTrail.whodunnit).to(eq(153))
|
|
23
|
+
expect(PaperTrail.controller_info.present?).to(eq(true))
|
|
24
|
+
expect(PaperTrail.controller_info.keys.include?(:ip)).to(eq(true))
|
|
25
|
+
expect(PaperTrail.controller_info.keys.include?(:user_agent)).to(eq(true))
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context "PT disabled" do
|
|
30
|
+
it "does not save a version, and metadata is not set" do
|
|
31
|
+
request.env["HTTP_USER_AGENT"] = "Disable User-Agent"
|
|
32
|
+
post :create, params_wrapper(widget: { name: "Flugel" })
|
|
33
|
+
expect(assigns(:widget).versions.length).to(eq(0))
|
|
34
|
+
expect(PaperTrail).not_to be_enabled_for_controller
|
|
35
|
+
expect(PaperTrail.whodunnit).to be_nil
|
|
36
|
+
expect(PaperTrail.controller_info).to eq({})
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe "#destroy" do
|
|
42
|
+
it "can be disabled" do
|
|
43
|
+
request.env["HTTP_USER_AGENT"] = "Disable User-Agent"
|
|
44
|
+
post(:create, params_wrapper(widget: { name: "Flugel" }))
|
|
45
|
+
w = assigns(:widget)
|
|
46
|
+
expect(w.versions.length).to(eq(0))
|
|
47
|
+
delete(:destroy, params_wrapper(id: w.id))
|
|
48
|
+
expect(PaperTrail::Version.with_item_keys("Widget", w.id).size).to(eq(0))
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "stores information like IP address in version" do
|
|
52
|
+
w = Widget.create(name: "Roundel")
|
|
53
|
+
expect(w.versions.length).to(eq(1))
|
|
54
|
+
delete(:destroy, params_wrapper(id: w.id))
|
|
55
|
+
widget = assigns(:widget)
|
|
56
|
+
expect(widget.versions.length).to(eq(2))
|
|
57
|
+
expect(widget.versions.last.ip).to(eq("127.0.0.1"))
|
|
58
|
+
expect(widget.versions.last.user_agent).to(eq("Rails Testing"))
|
|
59
|
+
expect(widget.versions.last.whodunnit.to_i).to(eq(153))
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe "#update" do
|
|
64
|
+
it "stores information like IP address in version" do
|
|
65
|
+
w = Widget.create(name: "Duvel")
|
|
66
|
+
expect(w.versions.length).to(eq(1))
|
|
67
|
+
put(:update, params_wrapper(id: w.id, widget: { name: "Bugle" }))
|
|
68
|
+
widget = assigns(:widget)
|
|
69
|
+
expect(widget.versions.length).to(eq(2))
|
|
70
|
+
expect(widget.versions.last.whodunnit.to_i).to(eq(153))
|
|
71
|
+
expect(widget.versions.last.ip).to(eq("127.0.0.1"))
|
|
72
|
+
expect(widget.versions.last.user_agent).to(eq("Rails Testing"))
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "can be disabled" do
|
|
76
|
+
request.env["HTTP_USER_AGENT"] = "Disable User-Agent"
|
|
77
|
+
post(:create, params_wrapper(widget: { name: "Flugel" }))
|
|
78
|
+
w = assigns(:widget)
|
|
79
|
+
expect(w.versions.length).to(eq(0))
|
|
80
|
+
put(:update, params_wrapper(id: w.id, widget: { name: "Bugle" }))
|
|
81
|
+
widget = assigns(:widget)
|
|
82
|
+
expect(widget.versions.length).to(eq(0))
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|