From 5bb090281645020f85d18cfdc9c22d1c99b5d685 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Mon, 5 Apr 2021 14:28:05 -0400 Subject: [PATCH] Followup to #1285, #1291, #1292 --- .rubocop.yml | 9 ++++ .rubocop_todo.yml | 16 ------- CHANGELOG.md | 16 +++---- README.md | 48 +++++++++++-------- lib/paper_trail/model_config.rb | 7 +++ .../versions/where_attribute_changes.rb | 2 +- .../versions/where_object_changes_to.rb | 2 +- 7 files changed, 55 insertions(+), 45 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1f7d1436..05f82077 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -117,6 +117,15 @@ Naming/PredicateName: Naming/MethodParameterName: Enabled: false +# This cop has low value to begin with. Also, secondarily, it does not allow +# reasonable names like `rails_lt_6_0`. +Naming/VariableNumber: + Enabled: false + +# Good advice for rails applications, but not applicable to libraries like PT. +Rails/SkipsModelValidations: + Enabled: false + # This cop does not seem to work in rubocop-rspec 1.28.0 RSpec/DescribeClass: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 03f21de9..8e57f124 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -101,22 +101,6 @@ Rails/RedundantForeignKey: - 'spec/dummy_app/app/models/family/family_line.rb' - 'spec/dummy_app/app/models/person.rb' -# Offense count: 28 -# Configuration parameters: ForbiddenMethods, AllowedMethods. -# ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, insert, insert!, insert_all, insert_all!, toggle!, touch, touch_all, update_all, update_attribute, update_column, update_columns, update_counters, upsert, upsert_all -Rails/SkipsModelValidations: - Exclude: - - 'lib/paper_trail/record_trail.rb' - - 'spec/models/gadget_spec.rb' - - 'spec/models/on/create_spec.rb' - - 'spec/models/on/empty_array_spec.rb' - - 'spec/models/on/touch_spec.rb' - - 'spec/models/on/update_spec.rb' - - 'spec/models/widget_spec.rb' - - 'spec/paper_trail/cleaner_spec.rb' - - 'spec/paper_trail/config_spec.rb' - - 'spec/paper_trail/model_spec.rb' - # Offense count: 1 # Cop supports --auto-correct. Rails/WhereNot: diff --git a/CHANGELOG.md b/CHANGELOG.md index f308e5a8..26767f9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,12 +11,18 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/). ### Added -- `where_attribute_changes` queries for versions where the object's attribute +- [#1292](https://github.com/paper-trail-gem/paper_trail/pull/1292) - + `where_attribute_changes` queries for versions where the object's attribute changed to or from any values. +- [#1291](https://github.com/paper-trail-gem/paper_trail/pull/1291) - + `where_object_changes_to` queries for versions where the object's attributes + changed to one set of known values from any other set of values. ### Fixed -- None +- [#1285](https://github.com/paper-trail-gem/paper_trail/pull/1285) - + For ActiveRecord >= 6.0, the `touch` callback will no longer create a new + `Version` for skipped or ignored attributes. ## 12.0.0 (2021-03-29) @@ -31,8 +37,6 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/). ### Added -- `where_object_changes_to` queries for versions where the object's attributes - changed to one set of known values from any other set of values. - `where_object_changes_from` queries for versions where the object's attributes changed from one set of known values to any other set of values. @@ -43,10 +47,6 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/). - Expand kwargs passed to `save_with_version` using double splat operator - Rails 6.1 compatibility - [#1287](https://github.com/paper-trail-gem/paper_trail/issues/1287) - Fix 'rails db:migrate' error when run against an app with mysql2 adapter -- [#1285](https://github.com/paper-trail-gem/paper_trail/pull/1285) - - Touch callback does not create a new version for skipped or ignored attributes - for ActiveRecord 6.0 and higher - ### Dependencies - Drop support for ruby 2.4 (reached EoL on 2020-03-31) diff --git a/README.md b/README.md index 66c5a866..499dc79b 100644 --- a/README.md +++ b/README.md @@ -10,21 +10,23 @@ has been destroyed. ## Documentation -| Version | Documentation | -| -------------- | ------------- | -| Unreleased | https://github.com/paper-trail-gem/paper_trail/blob/master/README.md | -| 12.0.0 | https://github.com/paper-trail-gem/paper_trail/blob/v12.0.0/README.md | -| 11.1.0 | https://github.com/paper-trail-gem/paper_trail/blob/v11.1.0/README.md | -| 10.3.1 | https://github.com/paper-trail-gem/paper_trail/blob/v10.3.1/README.md | -| 9.2.0 | https://github.com/paper-trail-gem/paper_trail/blob/v9.2.0/README.md | -| 8.1.2 | https://github.com/paper-trail-gem/paper_trail/blob/v8.1.2/README.md | -| 7.1.3 | https://github.com/paper-trail-gem/paper_trail/blob/v7.1.3/README.md | -| 6.0.2 | https://github.com/paper-trail-gem/paper_trail/blob/v6.0.2/README.md | -| 5.2.3 | https://github.com/paper-trail-gem/paper_trail/blob/v5.2.3/README.md | -| 4.2.0 | https://github.com/paper-trail-gem/paper_trail/blob/v4.2.0/README.md | -| 3.0.9 | https://github.com/paper-trail-gem/paper_trail/blob/v3.0.9/README.md | -| 2.7.2 | https://github.com/paper-trail-gem/paper_trail/blob/v2.7.2/README.md | -| 1.6.5 | https://github.com/paper-trail-gem/paper_trail/blob/v1.6.5/README.md | +This is the _user guide_. See also, the +[API reference](https://www.rubydoc.info/gems/paper_trail). + +Choose version: +[Unreleased](https://github.com/paper-trail-gem/paper_trail/blob/master/README.md), +[12.0](https://github.com/paper-trail-gem/paper_trail/blob/v12.0.0/README.md), +[11.1](https://github.com/paper-trail-gem/paper_trail/blob/v11.1.0/README.md), +[10.3](https://github.com/paper-trail-gem/paper_trail/blob/v10.3.1/README.md), +[9.2](https://github.com/paper-trail-gem/paper_trail/blob/v9.2.0/README.md), +[8.1](https://github.com/paper-trail-gem/paper_trail/blob/v8.1.2/README.md), +[7.1](https://github.com/paper-trail-gem/paper_trail/blob/v7.1.3/README.md), +[6.0](https://github.com/paper-trail-gem/paper_trail/blob/v6.0.2/README.md), +[5.2](https://github.com/paper-trail-gem/paper_trail/blob/v5.2.3/README.md), +[4.2](https://github.com/paper-trail-gem/paper_trail/blob/v4.2.0/README.md), +[3.0](https://github.com/paper-trail-gem/paper_trail/blob/v3.0.9/README.md), +[2.7](https://github.com/paper-trail-gem/paper_trail/blob/v2.7.2/README.md), +[1.6](https://github.com/paper-trail-gem/paper_trail/blob/v1.6.5/README.md) ## Table of Contents @@ -85,8 +87,8 @@ has been destroyed. | paper_trail | branch | ruby | activerecord | | -------------- | ---------- | -------- | ------------- | | unreleased | master | >= 2.5.0 | >= 5.2, < 6.2 | -| 12 | master | >= 2.5.0 | >= 5.2, < 6.2 | -| 11 | master | >= 2.4.0 | >= 5.2, < 6.1 | +| 12 | 12-stable | >= 2.5.0 | >= 5.2, < 6.2 | +| 11 | 11-stable | >= 2.4.0 | >= 5.2, < 6.1 | | 10 | 10-stable | >= 2.3.0 | >= 4.2, < 6.1 | | 9 | 9-stable | >= 2.3.0 | >= 4.2, < 5.3 | | 8 | 8-stable | >= 2.2.0 | >= 4.2, < 5.2 | @@ -720,8 +722,16 @@ PaperTrail::Version.where_object(content: 'Hello', title: 'Article') PaperTrail::Version.where_object_changes(atr: 'v') ``` -Using `where_object_changes` to read YAML from a text column was deprecated in -8.1.0, and will now raise an error. +See also: + +- `where_object_changes_from` +- `where_object_changes_to` +- `where_attribute_changes` + +Using `where_object_changes*` or `where_attribute_changes` to read YAML or JSON +from a text column was deprecated in 8.1.0, and will now raise an error. Use a +`json` or `jsonb` column if possible. If you must use a `text` column, you'll +have to write a custom `object_changes_adapter`. ### 3.c. Diffing Versions diff --git a/lib/paper_trail/model_config.rb b/lib/paper_trail/model_config.rb index 903b69af..1e31c0bd 100644 --- a/lib/paper_trail/model_config.rb +++ b/lib/paper_trail/model_config.rb @@ -97,6 +97,13 @@ module PaperTrail end # Adds a callback that records a version after a "touch" event. + # + # Rails < 6.0 has a bug where dirty-tracking does not occur during + # a `touch`. (https://github.com/rails/rails/issues/33429) See also: + # https://github.com/paper-trail-gem/paper_trail/issues/1121 + # https://github.com/paper-trail-gem/paper_trail/issues/1161 + # https://github.com/paper-trail-gem/paper_trail/pull/1285 + # # @api public def on_touch @model_class.after_touch { |r| diff --git a/lib/paper_trail/queries/versions/where_attribute_changes.rb b/lib/paper_trail/queries/versions/where_attribute_changes.rb index 622a4123..d0eba465 100644 --- a/lib/paper_trail/queries/versions/where_attribute_changes.rb +++ b/lib/paper_trail/queries/versions/where_attribute_changes.rb @@ -18,7 +18,7 @@ module PaperTrail # @api private def execute - if PaperTrail.config.object_changes_adapter&.respond_to?(:where_attribute_changes) + if PaperTrail.config.object_changes_adapter.respond_to?(:where_attribute_changes) return PaperTrail.config.object_changes_adapter.where_attribute_changes( @version_model_class, @attribute ) diff --git a/lib/paper_trail/queries/versions/where_object_changes_to.rb b/lib/paper_trail/queries/versions/where_object_changes_to.rb index d7b605ab..c7b7e979 100644 --- a/lib/paper_trail/queries/versions/where_object_changes_to.rb +++ b/lib/paper_trail/queries/versions/where_object_changes_to.rb @@ -18,7 +18,7 @@ module PaperTrail # @api private def execute - if PaperTrail.config.object_changes_adapter&.respond_to?(:where_object_changes_to) + if PaperTrail.config.object_changes_adapter.respond_to?(:where_object_changes_to) return PaperTrail.config.object_changes_adapter.where_object_changes_to( @version_model_class, @attributes )