paper_trail 4.2.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/{CONTRIBUTING.md → .github/CONTRIBUTING.md} +28 -9
  3. data/.github/ISSUE_TEMPLATE.md +13 -0
  4. data/.gitignore +2 -1
  5. data/.rubocop.yml +100 -0
  6. data/.rubocop_todo.yml +14 -0
  7. data/.travis.yml +8 -9
  8. data/Appraisals +41 -0
  9. data/CHANGELOG.md +49 -9
  10. data/Gemfile +1 -1
  11. data/README.md +130 -109
  12. data/Rakefile +19 -19
  13. data/doc/bug_report_template.rb +20 -14
  14. data/gemfiles/ar3.gemfile +10 -53
  15. data/gemfiles/ar4.gemfile +7 -0
  16. data/gemfiles/ar5.gemfile +13 -0
  17. data/lib/generators/paper_trail/install_generator.rb +26 -18
  18. data/lib/generators/paper_trail/templates/add_object_changes_to_versions.rb +4 -2
  19. data/lib/generators/paper_trail/templates/add_transaction_id_column_to_versions.rb +2 -0
  20. data/lib/generators/paper_trail/templates/create_version_associations.rb +9 -4
  21. data/lib/generators/paper_trail/templates/create_versions.rb +39 -5
  22. data/lib/paper_trail.rb +169 -146
  23. data/lib/paper_trail/attributes_serialization.rb +89 -17
  24. data/lib/paper_trail/cleaner.rb +15 -9
  25. data/lib/paper_trail/config.rb +28 -11
  26. data/lib/paper_trail/frameworks/active_record.rb +4 -0
  27. data/lib/paper_trail/frameworks/active_record/models/paper_trail/version.rb +5 -1
  28. data/lib/paper_trail/frameworks/active_record/models/paper_trail/version_association.rb +6 -2
  29. data/lib/paper_trail/frameworks/cucumber.rb +1 -0
  30. data/lib/paper_trail/frameworks/rails.rb +2 -7
  31. data/lib/paper_trail/frameworks/rails/controller.rb +29 -9
  32. data/lib/paper_trail/frameworks/rails/engine.rb +7 -1
  33. data/lib/paper_trail/frameworks/rspec.rb +5 -5
  34. data/lib/paper_trail/frameworks/rspec/helpers.rb +3 -1
  35. data/lib/paper_trail/frameworks/sinatra.rb +6 -4
  36. data/lib/paper_trail/has_paper_trail.rb +199 -106
  37. data/lib/paper_trail/record_history.rb +1 -3
  38. data/lib/paper_trail/reifier.rb +297 -118
  39. data/lib/paper_trail/serializers/json.rb +3 -3
  40. data/lib/paper_trail/serializers/yaml.rb +27 -8
  41. data/lib/paper_trail/version_association_concern.rb +3 -1
  42. data/lib/paper_trail/version_concern.rb +75 -35
  43. data/lib/paper_trail/version_number.rb +6 -9
  44. data/paper_trail.gemspec +44 -51
  45. data/spec/generators/install_generator_spec.rb +24 -25
  46. data/spec/generators/paper_trail/templates/create_versions_spec.rb +51 -0
  47. data/spec/models/animal_spec.rb +12 -12
  48. data/spec/models/boolit_spec.rb +8 -8
  49. data/spec/models/callback_modifier_spec.rb +47 -47
  50. data/spec/models/car_spec.rb +13 -0
  51. data/spec/models/fluxor_spec.rb +3 -3
  52. data/spec/models/gadget_spec.rb +19 -19
  53. data/spec/models/joined_version_spec.rb +3 -3
  54. data/spec/models/json_version_spec.rb +23 -24
  55. data/spec/models/kitchen/banana_spec.rb +3 -3
  56. data/spec/models/not_on_update_spec.rb +7 -4
  57. data/spec/models/post_with_status_spec.rb +13 -3
  58. data/spec/models/skipper_spec.rb +10 -10
  59. data/spec/models/thing_spec.rb +4 -4
  60. data/spec/models/truck_spec.rb +5 -0
  61. data/spec/models/vehicle_spec.rb +5 -0
  62. data/spec/models/version_spec.rb +103 -59
  63. data/spec/models/widget_spec.rb +82 -52
  64. data/spec/modules/paper_trail_spec.rb +2 -2
  65. data/spec/modules/version_concern_spec.rb +11 -12
  66. data/spec/modules/version_number_spec.rb +2 -4
  67. data/spec/paper_trail/config_spec.rb +10 -29
  68. data/spec/paper_trail_spec.rb +16 -14
  69. data/spec/rails_helper.rb +10 -9
  70. data/spec/requests/articles_spec.rb +11 -7
  71. data/spec/spec_helper.rb +41 -22
  72. data/spec/support/alt_db_init.rb +8 -13
  73. data/test/custom_json_serializer.rb +3 -3
  74. data/test/dummy/Rakefile +2 -2
  75. data/test/dummy/app/controllers/application_controller.rb +21 -8
  76. data/test/dummy/app/controllers/articles_controller.rb +11 -8
  77. data/test/dummy/app/controllers/widgets_controller.rb +13 -12
  78. data/test/dummy/app/models/animal.rb +1 -1
  79. data/test/dummy/app/models/article.rb +19 -11
  80. data/test/dummy/app/models/authorship.rb +1 -1
  81. data/test/dummy/app/models/bar_habtm.rb +4 -0
  82. data/test/dummy/app/models/book.rb +4 -4
  83. data/test/dummy/app/models/boolit.rb +1 -1
  84. data/test/dummy/app/models/callback_modifier.rb +6 -6
  85. data/test/dummy/app/models/car.rb +3 -0
  86. data/test/dummy/app/models/chapter.rb +4 -4
  87. data/test/dummy/app/models/customer.rb +1 -1
  88. data/test/dummy/app/models/document.rb +2 -2
  89. data/test/dummy/app/models/editor.rb +1 -1
  90. data/test/dummy/app/models/foo_habtm.rb +4 -0
  91. data/test/dummy/app/models/fruit.rb +2 -2
  92. data/test/dummy/app/models/gadget.rb +1 -1
  93. data/test/dummy/app/models/kitchen/banana.rb +1 -1
  94. data/test/dummy/app/models/legacy_widget.rb +2 -2
  95. data/test/dummy/app/models/line_item.rb +1 -1
  96. data/test/dummy/app/models/not_on_update.rb +1 -1
  97. data/test/dummy/app/models/person.rb +6 -6
  98. data/test/dummy/app/models/post.rb +1 -1
  99. data/test/dummy/app/models/post_with_status.rb +1 -1
  100. data/test/dummy/app/models/quotation.rb +1 -1
  101. data/test/dummy/app/models/section.rb +1 -1
  102. data/test/dummy/app/models/skipper.rb +2 -2
  103. data/test/dummy/app/models/song.rb +13 -4
  104. data/test/dummy/app/models/thing.rb +2 -2
  105. data/test/dummy/app/models/translation.rb +2 -2
  106. data/test/dummy/app/models/truck.rb +4 -0
  107. data/test/dummy/app/models/vehicle.rb +4 -0
  108. data/test/dummy/app/models/whatchamajigger.rb +1 -1
  109. data/test/dummy/app/models/widget.rb +7 -6
  110. data/test/dummy/app/versions/joined_version.rb +4 -3
  111. data/test/dummy/app/versions/json_version.rb +1 -1
  112. data/test/dummy/app/versions/kitchen/banana_version.rb +1 -1
  113. data/test/dummy/app/versions/post_version.rb +2 -2
  114. data/test/dummy/config.ru +1 -1
  115. data/test/dummy/config/application.rb +20 -9
  116. data/test/dummy/config/boot.rb +5 -5
  117. data/test/dummy/config/environment.rb +1 -1
  118. data/test/dummy/config/environments/development.rb +4 -3
  119. data/test/dummy/config/environments/production.rb +3 -2
  120. data/test/dummy/config/environments/test.rb +15 -5
  121. data/test/dummy/config/initializers/backtrace_silencers.rb +4 -2
  122. data/test/dummy/config/initializers/paper_trail.rb +1 -2
  123. data/test/dummy/config/initializers/secret_token.rb +3 -1
  124. data/test/dummy/config/initializers/session_store.rb +1 -1
  125. data/test/dummy/config/routes.rb +2 -2
  126. data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +120 -74
  127. data/test/dummy/db/schema.rb +29 -6
  128. data/test/dummy/script/rails +6 -4
  129. data/test/functional/controller_test.rb +34 -35
  130. data/test/functional/enabled_for_controller_test.rb +6 -7
  131. data/test/functional/modular_sinatra_test.rb +43 -38
  132. data/test/functional/sinatra_test.rb +49 -40
  133. data/test/functional/thread_safety_test.rb +4 -6
  134. data/test/paper_trail_test.rb +15 -14
  135. data/test/test_helper.rb +68 -44
  136. data/test/time_travel_helper.rb +1 -15
  137. data/test/unit/associations_test.rb +517 -251
  138. data/test/unit/cleaner_test.rb +66 -60
  139. data/test/unit/inheritance_column_test.rb +17 -17
  140. data/test/unit/model_test.rb +611 -504
  141. data/test/unit/protected_attrs_test.rb +16 -12
  142. data/test/unit/serializer_test.rb +44 -43
  143. data/test/unit/serializers/json_test.rb +17 -18
  144. data/test/unit/serializers/mixin_json_test.rb +15 -14
  145. data/test/unit/serializers/mixin_yaml_test.rb +20 -16
  146. data/test/unit/serializers/yaml_test.rb +12 -13
  147. data/test/unit/timestamp_test.rb +10 -12
  148. data/test/unit/version_test.rb +7 -7
  149. metadata +92 -40
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7937d44654d4f77422ffe61d4bc2d81b7ed4026
4
- data.tar.gz: 9ec1f8bc013795818775e58e1cd9c33e5dd36499
3
+ metadata.gz: a998b8383ac675662fac129fce0617b3c2f13351
4
+ data.tar.gz: c431eeedc5dec2b6882775a95ea6ef79df63f2a9
5
5
  SHA512:
6
- metadata.gz: e546ad5e910cc2a08aeaaf0dca6754e05f3a89fbfb022b49a078025e09a623e359a552c2e52f3126c84662fad2cd804c34db709689211852ff43e32ff40db3a1
7
- data.tar.gz: 0ef05118041333567e076bc8407330917cc36ec5d23aec22fd6dced9367b10a466c4284eccddbb3f4d0675c4154165f24097eafe4acf0135e133c426a2b71d4b
6
+ metadata.gz: 1108f2949a0a98f6ad9e7f75eba6b2d40d21209de2beb6c856142930aa58b8f0f7c65fa1cf9fe73dd9fc3b70c22afc8886846581d992eb0ac9934504205db960
7
+ data.tar.gz: 1db8e0b3427d3801672829e014dcf1035f55ea75fecb54bebbeb5d6d54f0203d57bedce6ed5307fd5dfa8a68ebd971bc16ed4ad923fac4d9a46ff1c9f1aea0e5
@@ -3,7 +3,7 @@
3
3
  Thanks for your interest in PaperTrail!
4
4
 
5
5
  Ask usage questions on Stack Overflow:
6
- http://stackoverflow.com/tags/papertrail
6
+ https://stackoverflow.com/tags/paper-trail-gem
7
7
 
8
8
  **Please do not use github issues to ask usage questions.**
9
9
 
@@ -20,8 +20,15 @@ Please use our [bug report template][1].
20
20
 
21
21
  Testing is a little awkward because the test suite:
22
22
 
23
- 1. contains a rails app with three databases (test, foo, and bar)
24
- 1. supports three different RDBMS': sqlite, mysql, and postgres
23
+ 1. Supports three major versions of rails: 3, 4, 5
24
+ 1. Contains a "dummy" rails app with three databases (test, foo, and bar)
25
+ 1. Supports three different RDBMS': sqlite, mysql, and postgres
26
+
27
+ Test against rails 3:
28
+
29
+ ```
30
+ bundle exec appraisal ar3 rake
31
+ ```
25
32
 
26
33
  Run tests with sqlite:
27
34
 
@@ -69,16 +76,28 @@ DB=postgres bundle exec rake prepare
69
76
  # If this is the first test run ever, create databases.
70
77
  # Unlike mysql, use create/migrate instead of setup.
71
78
  cd test/dummy
72
- RAILS_ENV=test bundle exec rake db:create
73
- RAILS_ENV=test bundle exec rake db:migrate
74
- RAILS_ENV=foo bundle exec rake db:create
75
- RAILS_ENV=foo bundle exec rake db:migrate
76
- RAILS_ENV=bar bundle exec rake db:create
77
- RAILS_ENV=bar bundle exec rake db:migrate
79
+ DB=postgres RAILS_ENV=test bundle exec rake db:create
80
+ DB=postgres RAILS_ENV=test bundle exec rake db:migrate
81
+ DB=postgres RAILS_ENV=foo bundle exec rake db:create
82
+ DB=postgres RAILS_ENV=foo bundle exec rake db:migrate
83
+ DB=postgres RAILS_ENV=bar bundle exec rake db:create
84
+ DB=postgres RAILS_ENV=bar bundle exec rake db:migrate
78
85
  cd ../..
79
86
 
80
87
  # Run tests
81
88
  DB=postgres bundle exec rake
82
89
  ```
83
90
 
91
+ ### Releases
92
+
93
+ 1. Set the version in lib/paper_trail/version_number.rb
94
+ - Set PRE to nil unless it's a pre-release (beta, rc, etc.)
95
+ 1. In the changelog, replace "Unreleased" with the date.
96
+ 1. In the readme,
97
+ - remove "unreleased" from the doc versions table
98
+ - update any other references to version number
99
+ 1. Commit and tag with `git tag -a -m "v5.0.0" "v5.0.0"`
100
+ 1. `git push --tags origin master`
101
+ 1. `gem push paper_trail`
102
+
84
103
  [1]: https://github.com/airblade/paper_trail/blob/master/doc/bug_report_template.rb
@@ -0,0 +1,13 @@
1
+ Thanks for your interest in PaperTrail! Our volunteers' time is limited, so we
2
+ can only respond on GitHub to bug reports and feature requests. Please ask
3
+ *usage questions* on StackOverflow (https://stackoverflow.com/tags/paper-trail-gem)
4
+ so that the whole community has a chance to answer your question.
5
+
6
+ Please use our template
7
+ (https://github.com/airblade/paper_trail/blob/master/doc/bug_report_template.rb)
8
+ when reporting bugs.
9
+
10
+ For other questions, please see our contributing guide.
11
+ (https://github.com/airblade/paper_trail/blob/master/.github/CONTRIBUTING.MD)
12
+
13
+ Thanks for your contribution!
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ gemfiles/*.lock
1
2
  NOTES
2
3
  test/debug.log
3
4
  test/paper_trail_plugin.sqlite3.db
@@ -12,7 +13,6 @@ pkg/*
12
13
  .bundle
13
14
  .rbenv-version
14
15
  Gemfile.lock
15
- gemfiles/*.lock
16
16
  vendor/*
17
17
  .idea
18
18
  .rvmrc
@@ -20,3 +20,4 @@ vendor/*
20
20
  .tags_sorted_by_file
21
21
  .ruby-version
22
22
  .ruby-gemset
23
+ .rbenv-gemsets
@@ -0,0 +1,100 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ # Please:
4
+ #
5
+ # - Comment any deviations from the Ruby Style Guide
6
+ # - Alphabetize cops
7
+ # - Only include permanent config; temporary goes in .rubocop_todo.yml
8
+
9
+ # We do not control `schema.rb`. Exclude it from all cops.
10
+ AllCops:
11
+ Exclude:
12
+ - test/dummy/db/schema.rb
13
+
14
+ # Migrations often contain long up/down methods, and extracting smaller methods
15
+ # from these is of questionable value.
16
+ Metrics/AbcSize:
17
+ Exclude:
18
+ - 'test/dummy/db/migrate/*'
19
+
20
+ Metrics/ClassLength:
21
+ Exclude:
22
+ - test/**/*
23
+
24
+ # The Ruby Style Guide recommends to "Limit lines to 80 characters."
25
+ # (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
26
+ # but 100 is also reasonable.
27
+ Metrics/LineLength:
28
+ Max: 100
29
+
30
+ # The number of lines in a method is not a useful metric compared to `AbcSize`.
31
+ # It's common to have very long methods (> 50 lines) which are quite simple. For
32
+ # example, a method that returns a long string with only a few interpolations.
33
+ Metrics/MethodLength:
34
+ Enabled: false
35
+
36
+ Style/AlignParameters:
37
+ EnforcedStyle: with_fixed_indentation
38
+
39
+ # Please use semantic style, e.g. `do` when there's a side-effect, else `{}`.
40
+ # The semantic style is too nuanced to lint, so the cop is disabled.
41
+ Style/BlockDelimiters:
42
+ Enabled: false
43
+
44
+ Style/DotPosition:
45
+ EnforcedStyle: trailing
46
+
47
+ # Use double negation wherever it would otherwise be impractical to convert
48
+ # a value to an actual boolean.
49
+ Style/DoubleNegation:
50
+ Enabled: false
51
+
52
+ # The decision of when to use a guard clause to improve readability is subtle,
53
+ # and it's not clear that it can be linted. Certainly, the default
54
+ # `MinBodyLength` of 1 can actually hurt readability.
55
+ Style/GuardClause:
56
+ MinBodyLength: 3
57
+
58
+ # Use postfix (modifier) conditionals for one-liners, unless doing so would
59
+ # exceed 60 characters.
60
+ Style/IfUnlessModifier:
61
+ MaxLineLength: 60
62
+
63
+ # The Ruby Style Guide says:
64
+ #
65
+ # > Use \ instead of + or << to concatenate two string literals at line end.
66
+ #
67
+ # but in my experience the `\` style is rarely used and less readable. Please
68
+ # concatenate multiline strings with `+` or use a HEREDOC.
69
+ Style/LineEndConcatenation:
70
+ Enabled: false
71
+
72
+ # Using `module_function` instead of `extend self` would make the instance
73
+ # methods in these modules private. That would be a breaking change, so these
74
+ # modules are excluded. See discussion in:
75
+ # - https://github.com/airblade/paper_trail/pull/756
76
+ # - https://github.com/bbatsov/ruby-style-guide/issues/556
77
+ Style/ModuleFunction:
78
+ Exclude:
79
+ - 'lib/paper_trail/serializers/json.rb'
80
+ - 'lib/paper_trail/serializers/yaml.rb'
81
+
82
+ Style/MultilineMethodCallIndentation:
83
+ EnforcedStyle: indented
84
+
85
+ Style/MultilineOperationIndentation:
86
+ EnforcedStyle: indented
87
+
88
+ Style/PredicateName:
89
+ NameWhitelist: has_paper_trail
90
+
91
+ # The Ruby Style Guide does not prescribe a particular quote character, only
92
+ # that a project should pick one and be consistent. The decision has no
93
+ # performance implications. Double quotes are slightly easier to read.
94
+ Style/StringLiterals:
95
+ EnforcedStyle: double_quotes
96
+
97
+ # Use exactly one space on each side of an operator. Do not align operators
98
+ # because it makes the code harder to edit, and makes lines unnecessarily long.
99
+ Style/SpaceAroundOperators:
100
+ AllowForAlignment: false
@@ -0,0 +1,14 @@
1
+ # Remove these configuration records
2
+ # one by one as the offenses are removed from the code base.
3
+
4
+ Metrics/AbcSize:
5
+ Max: 30 # Goal: 15
6
+
7
+ Metrics/CyclomaticComplexity:
8
+ Max: 13 # Goal: 6
9
+
10
+ Metrics/ModuleLength:
11
+ Max: 299
12
+
13
+ Metrics/PerceivedComplexity:
14
+ Max: 16 # Goal: 7
@@ -1,10 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
3
+ - 2.3.0
4
4
  - 1.9.3
5
- - 1.8.7
6
5
  - jruby-19mode
7
- - jruby-18mode
8
6
  env:
9
7
  global:
10
8
  - TRAVIS=true
@@ -26,16 +24,17 @@ before_script:
26
24
  - sh -c "if [ \"$DB\" = 'postgres' ]; then psql -c 'create database paper_trail_foo;' -U postgres; fi"
27
25
 
28
26
  gemfile:
29
- - Gemfile
30
27
  - gemfiles/ar3.gemfile
28
+ - gemfiles/ar4.gemfile
29
+ - gemfiles/ar5.gemfile
31
30
 
32
31
  matrix:
33
32
  fast_finish: true
34
- allow_failures:
35
- - rvm: jruby-18mode
36
- gemfile: Gemfile
37
- - rvm: 1.8.7
38
- gemfile: Gemfile
33
+ exclude:
34
+ - gemfile: gemfiles/ar5.gemfile
35
+ rvm: 1.9.3
36
+ - gemfile: gemfiles/ar5.gemfile
37
+ rvm: jruby-19mode
39
38
 
40
39
  addons:
41
40
  postgresql: "9.4"
@@ -0,0 +1,41 @@
1
+ # Specify here only version constraints that differ from
2
+ # `paper_trail.gemspec`.
3
+ #
4
+ # > The dependencies in your Appraisals file are combined with dependencies in
5
+ # > your Gemfile, so you don"t need to repeat anything that"s the same for each
6
+ # > appraisal. If something is specified in both the Gemfile and an appraisal,
7
+ # > the version from the appraisal takes precedence.
8
+ # > https://github.com/thoughtbot/appraisal
9
+
10
+ appraise "ar3" do
11
+ gem "activerecord", "~> 3.2.22"
12
+ gem "i18n", "~> 0.6.11"
13
+ gem "request_store", "~> 1.1.0"
14
+
15
+ group :development, :test do
16
+ gem 'railties', '~> 3.2.22'
17
+ gem 'test-unit', '~> 3.1.5'
18
+ platforms :ruby do
19
+ gem 'mysql2', '~> 0.3.20'
20
+ end
21
+ end
22
+ end
23
+
24
+ appraise "ar4" do
25
+ gem "activerecord", "~> 4.2"
26
+ end
27
+
28
+ appraise "ar5" do
29
+ gem "activerecord", "5.0.0.beta1"
30
+ gem "activemodel", "5.0.0.beta1"
31
+ gem "actionpack", "5.0.0.beta1"
32
+ gem "railties", "5.0.0.beta1"
33
+ gem "rspec-rails", github: "rspec/rspec-rails"
34
+ gem "rspec-core", github: "rspec/rspec-core"
35
+ gem "rspec-expectations", github: "rspec/rspec-expectations"
36
+ gem "rspec-mocks", github: "rspec/rspec-mocks"
37
+ gem "rspec-support", github: "rspec/rspec-support"
38
+ gem 'rails-controller-testing'
39
+ # Sinatra stable conflicts with AR5's rack dependency
40
+ gem 'sinatra', github: 'sinatra/sinatra'
41
+ end
@@ -1,18 +1,58 @@
1
- ## 4.2.0 (2016-05-31)
1
+ ## 5.0.0 (2016-05-02)
2
2
 
3
3
  ### Breaking Changes
4
4
 
5
- - None
5
+ - [#758](https://github.com/airblade/paper_trail/pull/758) -
6
+ `PaperTrail.config.track_associations` getter method removed,
7
+ use `track_associations?` instead.
8
+ - [#740](https://github.com/airblade/paper_trail/issues/740) -
9
+ `PaperTrail.config.track_associations?` now defaults to false
10
+ - [#723](https://github.com/airblade/paper_trail/pull/723) -
11
+ `PaperTrail.enabled=` now affects all threads
12
+ - [#556](https://github.com/airblade/paper_trail/pull/556) /
13
+ [#301](https://github.com/airblade/paper_trail/issues/301) -
14
+ If you are tracking who is responsible for changes with `whodunnit`, be aware
15
+ that PaperTrail no longer adds the `set_paper_trail_whodunnit` before_filter
16
+ for you. Please add this before_filter to your ApplicationController to
17
+ continue recording whodunnit. See the readme for an example.
18
+ - [#683](https://github.com/airblade/paper_trail/pull/683) /
19
+ [#682](https://github.com/airblade/paper_trail/issues/682) -
20
+ Destroy callback default changed to :before to accommodate ActiveRecord 5
21
+ option `belongs_to_required_by_default` and new Rails 5 default.
6
22
 
7
23
  ### Added
8
24
 
9
- - [#808](https://github.com/airblade/paper_trail/pull/808) -
10
- Warn when destroy callback is set to :after with ActiveRecord 5
11
- option `belongs_to_required_by_default` set to `true`.
25
+ - [#771](https://github.com/airblade/paper_trail/pull/771) -
26
+ Added support for has_and_belongs_to_many associations
27
+ - [#741](https://github.com/airblade/paper_trail/issues/741) /
28
+ [#681](https://github.com/airblade/paper_trail/pull/681)
29
+ MySQL unicode support in migration generator
30
+ - [#689](https://github.com/airblade/paper_trail/pull/689) -
31
+ Rails 5 compatibility
32
+ - Added a rails config option: `config.paper_trail.enabled`
33
+ - [#503](https://github.com/airblade/paper_trail/pull/730) -
34
+ Support for reifying belongs_to associations.
12
35
 
13
36
  ### Fixed
14
37
 
15
- - None
38
+ - [#777](https://github.com/airblade/paper_trail/issues/777) -
39
+ Support HMT associations with `:source` option.
40
+ - [#738](https://github.com/airblade/paper_trail/issues/738) -
41
+ Rare bug where a non-versioned STI parent caused `changeset` to
42
+ return an empty hash.
43
+ - [#731](https://github.com/airblade/paper_trail/pull/731) -
44
+ Map enums to database values before storing in `object_changes` column.
45
+ - [#715](https://github.com/airblade/paper_trail/issues/715) -
46
+ Optimize post-rollback association reset.
47
+ - [#701](https://github.com/airblade/paper_trail/pull/701) /
48
+ [#699](https://github.com/airblade/paper_trail/issues/699) -
49
+ Cleaning old versions explicitly preserves the most recent
50
+ versions instead of relying on database result ordering.
51
+ - [#635](https://github.com/airblade/paper_trail/issues/635) -
52
+ A bug where it was not possible to disable PT when using a multi-threaded
53
+ webserver.
54
+ - [#584](https://github.com/airblade/paper_trail/issues/584) -
55
+ Fixed deprecation warning for Active Record after_callback / after_commit
16
56
 
17
57
  ## 4.1.0 (2016-01-30)
18
58
 
@@ -31,7 +71,7 @@
31
71
 
32
72
  - None
33
73
 
34
- ## 4.0.2
74
+ ## 4.0.2 (2016-01-19)
35
75
 
36
76
  ### Breaking Changes
37
77
 
@@ -47,7 +87,7 @@
47
87
  [#697](https://github.com/airblade/paper_trail/pull/697)
48
88
  Bind JSON query parameters in `where_object` and `where_object_changes`.
49
89
 
50
- ## 4.0.1
90
+ ## 4.0.1 (2015-12-14)
51
91
 
52
92
  ### Breaking Changes
53
93
 
@@ -65,7 +105,7 @@
65
105
  [#588](https://github.com/airblade/paper_trail/issues/588) -
66
106
  Fixes timestamp for "create" versions
67
107
 
68
- ## 4.0.0
108
+ ## 4.0.0 (2015-07-30)
69
109
 
70
110
  This major release adds JSON column support in PostgreSQL, limited support for
71
111
  versioning associations, various new configuration options, and a year's worth
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
  gemspec
data/README.md CHANGED
@@ -10,7 +10,9 @@ has been destroyed.
10
10
 
11
11
  | Version | Documentation |
12
12
  | -------------- | ------------- |
13
- | 4 | https://github.com/airblade/paper_trail/blob/4-stable/README.md |
13
+ | 5 | https://github.com/airblade/paper_trail/blob/master/README.md |
14
+ | 4.1 | https://github.com/airblade/paper_trail/blob/4.1-stable/README.md |
15
+ | 4.0 | https://github.com/airblade/paper_trail/blob/4.0-stable/README.md |
14
16
  | 3 | https://github.com/airblade/paper_trail/blob/3.0-stable/README.md |
15
17
  | 2 | https://github.com/airblade/paper_trail/blob/2.7-stable/README.md |
16
18
  | 1 | https://github.com/airblade/paper_trail/blob/rails2/README.md |
@@ -25,7 +27,7 @@ has been destroyed.
25
27
  - [Choosing Lifecycle Events To Monitor](#choosing-lifecycle-events-to-monitor)
26
28
  - [Choosing When To Save New Versions](#choosing-when-to-save-new-versions)
27
29
  - [Choosing Attributes To Monitor](#choosing-attributes-to-monitor)
28
- - [Turning PaperTrail Off/On](#turning-papertrail-offon)
30
+ - [Turning PaperTrail Off](#turning-papertrail-off)
29
31
  - [Limiting the Number of Versions Created](#limiting-the-number-of-versions-created)
30
32
  - Working With Versions
31
33
  - [Reverting And Undeleting A Model](#reverting-and-undeleting-a-model)
@@ -38,25 +40,25 @@ has been destroyed.
38
40
  - [Storing metadata](#storing-metadata)
39
41
  - Extensibility
40
42
  - [Custom Version Classes](#custom-version-classes)
41
- - [Custom Serializer](#using-a-custom-serializer)
42
- - [SerializedAttributes support](#serializedattributes-support)
43
+ - [Custom Serializer](#custom-serializer)
43
44
  - [Testing](#testing)
44
45
  - [Sinatra](#sinatra)
45
46
 
46
47
  ## Compatibility
47
48
 
48
- | paper_trail | branch | tags | ruby | activerecord |
49
- | ----------- | ---------- | ------ | -------- | ------------ |
50
- | 4 | 4-stable | v4.x | >= 1.8.7 | >= 3.0, < 6 |
51
- | 3 | 3.0-stable | v3.x | >= 1.8.7 | >= 3.0, < 5 |
52
- | 2 | 2.7-stable | v2.x | >= 1.8.7 | >= 3.0, < 4 |
53
- | 1 | rails2 | v1.x | >= 1.8.7 | >= 2.3, < 3 |
49
+ | paper_trail | branch | tags | ruby | activerecord |
50
+ | -------------- | ---------- | ------ | -------- | ------------ |
51
+ | 5 | master | v5.x | >= 1.9.3 | >= 3.0, < 6 |
52
+ | 4 | 4.0-stable | v4.x | >= 1.8.7 | >= 3.0, < 6 |
53
+ | 3 | 3.0-stable | v3.x | >= 1.8.7 | >= 3.0, < 5 |
54
+ | 2 | 2.7-stable | v2.x | >= 1.8.7 | >= 3.0, < 4 |
55
+ | 1 | rails2 | v1.x | >= 1.8.7 | >= 2.3, < 3 |
54
56
 
55
57
  ## Installation
56
58
 
57
59
  1. Add PaperTrail to your `Gemfile`.
58
60
 
59
- `gem 'paper_trail', '~> 4.2.0'`
61
+ `gem 'paper_trail'`
60
62
 
61
63
  1. Add a `versions` table to your database.
62
64
 
@@ -65,21 +67,31 @@ has been destroyed.
65
67
  bundle exec rake db:migrate
66
68
  ```
67
69
 
70
+ If using [rails_admin][38], you must enable the experimental
71
+ [Associations](#associations) feature.
72
+
68
73
  1. Add `has_paper_trail` to the models you want to track.
69
74
 
70
- ## Basic Usage
75
+ ```ruby
76
+ class Widget < ActiveRecord::Base
77
+ has_paper_trail
78
+ end
79
+ ```
71
80
 
72
- Add `has_paper_trail` to your model to record every `create`, `update`,
73
- and `destroy`.
81
+ 1. If your controllers have a `current_user` method, you can easily [track who
82
+ is responsible for changes](#finding-out-who-was-responsible-for-a-change)
83
+ by adding a controller callback.
74
84
 
75
- ```ruby
76
- class Widget < ActiveRecord::Base
77
- has_paper_trail
78
- end
79
- ```
85
+ ```ruby
86
+ class ApplicationController
87
+ before_filter :set_paper_trail_whodunnit
88
+ end
89
+ ```
80
90
 
81
- This gives you a `versions` method which returns the "paper trail" of changes to
82
- your model.
91
+ ## Basic Usage
92
+
93
+ Your models now have a `versions` method which returns the "paper trail" of
94
+ changes to your model.
83
95
 
84
96
  ```ruby
85
97
  widget = Widget.find 42
@@ -182,7 +194,8 @@ Widget.paper_trail_enabled_for_model?
182
194
  widget.paper_trail_enabled_for_model?
183
195
  ```
184
196
 
185
- And a `PaperTrail::Version` instance has these methods:
197
+ And a `PaperTrail::Version` instance (which is just an ordinary ActiveRecord
198
+ instance, with all the usual methods) adds these methods:
186
199
 
187
200
  ```ruby
188
201
  # Returns the item restored from this version.
@@ -305,6 +318,11 @@ class Translation < ActiveRecord::Base
305
318
  end
306
319
  ```
307
320
 
321
+ ### Choosing Based on Changed Attributes
322
+
323
+ Starting with PaperTrail 4.0, versions are saved during an after-callback. If
324
+ you decide whether to save a new version based on changed attributes, please
325
+ use attribute_name_was instead of attribute_name.
308
326
 
309
327
  ## Choosing Attributes To Monitor
310
328
 
@@ -393,69 +411,30 @@ class Article < ActiveRecord::Base
393
411
  end
394
412
  ```
395
413
 
396
- ## Turning PaperTrail Off/On
414
+ ## Turning PaperTrail Off
397
415
 
398
- Sometimes you don't want to store changes. Perhaps you are only interested in
399
- changes made by your users and don't need to store changes you make yourself in,
400
- say, a migration -- or when testing your application.
416
+ PaperTrail is on by default, but sometimes you don't want to record versions.
401
417
 
402
- You can turn PaperTrail on or off in three ways: globally, per request, or per
403
- class.
418
+ ### Per Process
404
419
 
405
- ### Globally
406
-
407
- On a global level you can turn PaperTrail off like this:
420
+ Turn PaperTrail off for all threads in a `ruby` process.
408
421
 
409
422
  ```ruby
410
423
  PaperTrail.enabled = false
411
424
  ```
412
425
 
413
- For example, you might want to disable PaperTrail in your Rails application's
414
- test environment to speed up your tests. This will do it (note: this gets done
415
- automatically for `RSpec` and `Cucumber`, please see the [Testing
416
- section](#testing)):
417
-
418
- ```ruby
419
- # in config/environments/test.rb
420
- config.after_initialize do
421
- PaperTrail.enabled = false
422
- end
423
- ```
424
-
425
- If you disable PaperTrail in your test environment but want to enable it for
426
- specific tests, you can add a helper like this to your test helper:
427
-
428
- ```ruby
429
- # in test/test_helper.rb
430
- def with_versioning
431
- was_enabled = PaperTrail.enabled?
432
- was_enabled_for_controller = PaperTrail.enabled_for_controller?
433
- PaperTrail.enabled = true
434
- PaperTrail.enabled_for_controller = true
435
- begin
436
- yield
437
- ensure
438
- PaperTrail.enabled = was_enabled
439
- PaperTrail.enabled_for_controller = was_enabled_for_controller
440
- end
441
- end
442
- ```
426
+ This is commonly used to speed up tests. See [Testing](#testing) below.
443
427
 
444
- And then use it in your tests like this:
428
+ There is also a rails config option that does the same thing.
445
429
 
446
430
  ```ruby
447
- test "something that needs versioning" do
448
- with_versioning do
449
- # your test
450
- end
451
- end
431
+ # in config/environments/test.rb
432
+ config.paper_trail.enabled = false
452
433
  ```
453
434
 
454
- ### Per request
435
+ ### Per Request
455
436
 
456
- You can turn PaperTrail on or off per request by adding a
457
- `paper_trail_enabled_for_controller` method to your controller which returns
458
- `true` or `false`:
437
+ Add a `paper_trail_enabled_for_controller` method to your controller.
459
438
 
460
439
  ```ruby
461
440
  class ApplicationController < ActionController::Base
@@ -465,22 +444,14 @@ class ApplicationController < ActionController::Base
465
444
  end
466
445
  ```
467
446
 
468
- ### Per class
469
-
470
- If you are about to change some widgets and you don't want a paper trail of your
471
- changes, you can turn PaperTrail off like this:
447
+ ### Per Class
472
448
 
473
449
  ```ruby
474
450
  Widget.paper_trail_off!
475
- ```
476
-
477
- And on again like this:
478
-
479
- ```ruby
480
451
  Widget.paper_trail_on!
481
452
  ```
482
453
 
483
- ### Per method call
454
+ ### Per Method
484
455
 
485
456
  You can call a method without creating a new version using `without_versioning`.
486
457
  It takes either a method name as a symbol:
@@ -683,28 +654,35 @@ PaperTrail::Version.delete_all ["created_at < ?", 1.week.ago]
683
654
 
684
655
  ## Finding Out Who Was Responsible For A Change
685
656
 
686
- If your `ApplicationController` has a `current_user` method, PaperTrail will
687
- attempt to store the value returned by `current_user.id` in the version's
657
+ Set `PaperTrail.whodunnit=`, and that value will be stored in the version's
688
658
  `whodunnit` column.
689
659
 
690
- You may want PaperTrail to call a different method to find out who is
691
- responsible. To do so, override the `user_for_paper_trail` method in your
692
- controller like this:
660
+ ```ruby
661
+ PaperTrail.whodunnit = 'Andy Stewart'
662
+ widget.update_attributes :name => 'Wibble'
663
+ widget.versions.last.whodunnit # Andy Stewart
664
+ ```
665
+
666
+ If your controller has a `current_user` method, PaperTrail provides a
667
+ `before_filter` that will assign `current_user.id` to `PaperTrail.whodunnit`.
668
+ You can add this `before_filter` to your `ApplicationController`.
693
669
 
694
670
  ```ruby
695
671
  class ApplicationController
696
- def user_for_paper_trail
697
- logged_in? ? current_member.id : 'Public user' # or whatever
698
- end
672
+ before_filter :set_paper_trail_whodunnit
699
673
  end
700
674
  ```
701
675
 
702
- In a console session you can manually set who is responsible like this:
676
+ You may want `set_paper_trail_whodunnit` to call a different method to find out
677
+ who is responsible. To do so, override the `user_for_paper_trail` method in
678
+ your controller like this:
703
679
 
704
680
  ```ruby
705
- PaperTrail.whodunnit = 'Andy Stewart'
706
- widget.update_attributes :name => 'Wibble'
707
- widget.versions.last.whodunnit # Andy Stewart
681
+ class ApplicationController
682
+ def user_for_paper_trail
683
+ logged_in? ? current_member.id : 'Public user' # or whatever
684
+ end
685
+ end
708
686
  ```
709
687
 
710
688
  See also: [Setting whodunnit in the rails console][33]
@@ -752,6 +730,11 @@ last_version.paper_trail_originator # 'Alice'
752
730
  last_version.terminator # 'Bob'
753
731
  ```
754
732
 
733
+ ### Storing an ActiveRecord globalid in whodunnit
734
+
735
+ If you would like `whodunnit` to return an `ActiveRecord` object instead of a
736
+ string, please try the [paper_trail-globalid][37] gem.
737
+
755
738
  ## Associations
756
739
 
757
740
  **Experimental feature**, see caveats below.
@@ -770,7 +753,8 @@ the association that are created in the same transaction.
770
753
 
771
754
  To restore Has-One associations as they were at the time, pass option `:has_one
772
755
  => true` to `reify`. To restore Has-Many and Has-Many-Through associations, use
773
- option `:has_many => true`. For example:
756
+ option `:has_many => true`. To restore Belongs-To association, use
757
+ option `:belongs_to => true`. For example:
774
758
 
775
759
  ```ruby
776
760
  class Location < ActiveRecord::Base
@@ -1123,7 +1107,7 @@ Postgres. In databases without such protection, such as MySQL, a table lock may
1123
1107
  be necessary.
1124
1108
 
1125
1109
  If the above technique is too slow for your needs, and you're okay doing without
1126
- PaperTrail data temporarily, you can create the new column without a converting
1110
+ PaperTrail data temporarily, you can create the new column without converting
1127
1111
  the data.
1128
1112
 
1129
1113
  ```ruby
@@ -1181,21 +1165,57 @@ end
1181
1165
 
1182
1166
  ## Testing
1183
1167
 
1184
- You may want to turn PaperTrail off to speed up your tests. See the [Turning
1185
- PaperTrail Off/On](#turning-papertrail-offon) section above for tips on usage
1186
- with `Test::Unit`.
1168
+ You may want to turn PaperTrail off to speed up your tests. See [Turning
1169
+ PaperTrail Off](#turning-papertrail-off) above.
1187
1170
 
1188
- ### RSpec
1171
+ ### Minitest
1189
1172
 
1190
- PaperTrail provides a helper that works with [RSpec][27] to make it easier to
1191
- control when `PaperTrail` is enabled during testing.
1173
+ First, disable PT for the entire `ruby` process.
1192
1174
 
1193
- If you wish to use the helper, you will need to require it in your RSpec test
1194
- helper like so:
1175
+ ```ruby
1176
+ # in config/environments/test.rb
1177
+ config.after_initialize do
1178
+ PaperTrail.enabled = false
1179
+ end
1180
+ ```
1181
+
1182
+ Then, to enable PT for specific tests, you can add a `with_versioning` test
1183
+ helper method.
1195
1184
 
1196
1185
  ```ruby
1197
- # spec/rails_helper.rb
1186
+ # in test/test_helper.rb
1187
+ def with_versioning
1188
+ was_enabled = PaperTrail.enabled?
1189
+ was_enabled_for_controller = PaperTrail.enabled_for_controller?
1190
+ PaperTrail.enabled = true
1191
+ PaperTrail.enabled_for_controller = true
1192
+ begin
1193
+ yield
1194
+ ensure
1195
+ PaperTrail.enabled = was_enabled
1196
+ PaperTrail.enabled_for_controller = was_enabled_for_controller
1197
+ end
1198
+ end
1199
+ ```
1200
+
1201
+ Then, use the helper in your tests.
1198
1202
 
1203
+ ```ruby
1204
+ test "something that needs versioning" do
1205
+ with_versioning do
1206
+ # your test
1207
+ end
1208
+ end
1209
+ ```
1210
+
1211
+ ### RSpec
1212
+
1213
+ PaperTrail provides a helper, `paper_trail/frameworks/rspec.rb`, that works with
1214
+ [RSpec][27] to make it easier to control when `PaperTrail` is enabled during
1215
+ testing.
1216
+
1217
+ ```ruby
1218
+ # spec/rails_helper.rb
1199
1219
  ENV["RAILS_ENV"] ||= 'test'
1200
1220
  require 'spec_helper'
1201
1221
  require File.expand_path("../../config/environment", __FILE__)
@@ -1204,10 +1224,10 @@ require 'rspec/rails'
1204
1224
  require 'paper_trail/frameworks/rspec'
1205
1225
  ```
1206
1226
 
1207
- When the helper is loaded, PaperTrail will be turned off for all tests by
1208
- default. When you wish to enable PaperTrail for a test you can either wrap the
1227
+ With the helper loaded, PaperTrail will be turned off for all tests by
1228
+ default. To enable PaperTrail for a test you can either wrap the
1209
1229
  test in a `with_versioning` block, or pass in `:versioning => true` option to a
1210
- spec block, like so:
1230
+ spec block.
1211
1231
 
1212
1232
  ```ruby
1213
1233
  describe "RSpec test group" do
@@ -1377,7 +1397,7 @@ setting up your app with PaperTrail will look something like this:
1377
1397
 
1378
1398
  1. Add PaperTrail to your `Gemfile`.
1379
1399
 
1380
- `gem 'paper_trail', '~> 4.2.0'`
1400
+ `gem 'paper_trail'`
1381
1401
 
1382
1402
  2. Generate a migration to add a `versions` table to your database.
1383
1403
 
@@ -1420,7 +1440,6 @@ end
1420
1440
  [Ilya Bodrov](http://www.sitepoint.com/author/ibodrov), 10th April 2014
1421
1441
  * [Using PaperTrail to track stack traces](http://rubyrailsexpert.com/?p=36),
1422
1442
  T James Corcoran's blog, 1st October 2013.
1423
- * [RailsCast #255 - Undo with Paper Trail][3], Feb 28, 2011
1424
1443
  * [RailsCast #255 - Undo with PaperTrail](http://railscasts.com/episodes/255-undo-with-paper-trail),
1425
1444
  28th February 2011.
1426
1445
  * [Keep a Paper Trail with PaperTrail](http://www.linux-mag.com/id/7528),
@@ -1533,3 +1552,5 @@ Released under the MIT licence.
1533
1552
  [34]: https://github.com/rails/rails/blob/591a0bb87fff7583e01156696fbbf929d48d3e54/activerecord/lib/active_record/fixtures.rb#L142
1534
1553
  [35]: https://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html
1535
1554
  [36]: http://www.postgresql.org/docs/9.4/interactive/ddl.html
1555
+ [37]: https://github.com/ankit1910/paper_trail-globalid
1556
+ [38]: https://github.com/sferik/rails_admin