From fefe37aefd770cec39671f4be3e97f4e0f23c76c Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Fri, 21 Jan 2022 00:16:52 -0500 Subject: [PATCH 01/13] Release 12.2.0 --- CHANGELOG.md | 14 ++++++++++++++ README.md | 2 +- lib/paper_trail/version_number.rb | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7541e3fa..1d91ea33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,20 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/). ### Added +- None + +### Fixed + +- None + +## 12.2.0 (2022-01-21) + +### Breaking Changes + +- None + +### Added + - [#1365](https://github.com/paper-trail-gem/paper_trail/pull/1365) - Support Rails 7.0 - [#1349](https://github.com/paper-trail-gem/paper_trail/pull/1349) - diff --git a/README.md b/README.md index 9a5cdc26..627fec76 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ This is the _user guide_. See also, the Choose version: [Unreleased](https://github.com/paper-trail-gem/paper_trail/blob/master/README.md), -[12.1](https://github.com/paper-trail-gem/paper_trail/blob/v12.1.0/README.md), +[12.2](https://github.com/paper-trail-gem/paper_trail/blob/v12.2.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), diff --git a/lib/paper_trail/version_number.rb b/lib/paper_trail/version_number.rb index 97a5be13..0b24f405 100644 --- a/lib/paper_trail/version_number.rb +++ b/lib/paper_trail/version_number.rb @@ -8,7 +8,7 @@ module PaperTrail # People are encouraged to use `PaperTrail.gem_version` instead. module VERSION MAJOR = 12 - MINOR = 1 + MINOR = 2 TINY = 0 # Set PRE to nil unless it's a pre-release (beta, rc, etc.) From 05c7b3f14d2814d9faf25f1225ce84b965b40fd4 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Fri, 21 Jan 2022 00:31:59 -0500 Subject: [PATCH 02/13] Doc: update compat table [ci skip] --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 627fec76..a36d4ac4 100644 --- a/README.md +++ b/README.md @@ -88,9 +88,9 @@ Choose version: ### 1.a. Compatibility | paper_trail | branch | ruby | activerecord | -| -------------- | ---------- | -------- | ------------- | -| unreleased | master | >= 2.5.0 | >= 5.2, < 6.2 | -| 12 | 12-stable | >= 2.5.0 | >= 5.2, < 6.2 | +| -------------- | ---------- | -------- |---------------| +| unreleased | master | >= 2.5.0 | >= 5.2, < 7.1 | +| 12 | 12-stable | >= 2.5.0 | >= 5.2, < 7.1 | | 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 | From 0e7cf5dd92d3a037e5101593bea05a3975012e98 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Fri, 21 Jan 2022 00:37:30 -0500 Subject: [PATCH 03/13] Doc: update compat table (again, doh) [ci skip] --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a36d4ac4..627b1669 100644 --- a/README.md +++ b/README.md @@ -88,9 +88,9 @@ Choose version: ### 1.a. Compatibility | paper_trail | branch | ruby | activerecord | -| -------------- | ---------- | -------- |---------------| -| unreleased | master | >= 2.5.0 | >= 5.2, < 7.1 | -| 12 | 12-stable | >= 2.5.0 | >= 5.2, < 7.1 | +| -------------- | ---------- |----------|---------------| +| unreleased | master | >= 2.6.0 | >= 5.2, < 7.1 | +| 12 | 12-stable | >= 2.6.0 | >= 5.2, < 7.1 | | 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 | From f0e1bbbb5979adb0c1bfa50cee3e95cbfc256a6e Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Fri, 21 Jan 2022 09:58:56 +0100 Subject: [PATCH 04/13] CI: Use bundler-cache I didn't change the Lint job, since it gave me weird issues in CI, not locally, with gems not in this project showing up as being required, and not existing. --- .github/workflows/test.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c260fdd0..e90b688b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -79,10 +79,7 @@ jobs: uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - - name: Bundle - run: | - gem install bundler - bundle install --jobs 4 --retry 3 + bundler-cache: true # 'bundle install' and cache env: BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile From ee644c4c4b1c8d4108f2782806d7f7fe1ba84c8f Mon Sep 17 00:00:00 2001 From: Mathieu Jobin Date: Mon, 24 Jan 2022 18:04:50 +0900 Subject: [PATCH 05/13] run tests agains rails 7.0 --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e90b688b..18ec7b99 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -56,7 +56,7 @@ jobs: # have set this up with each database as a separate job, but then we'd be # duplicating the matrix configuration three times. matrix: - gemfile: [ 'rails_5.2', 'rails_6.0', 'rails_6.1' ] + gemfile: [ 'rails_5.2', 'rails_6.0', 'rails_6.1', 'rails_7.0' ] # To keep matrix size down, only test highest and lowest rubies. # Ruby 3.0 is an exception. For now, let's continue to test against 2.7 @@ -72,6 +72,9 @@ jobs: gemfile: 'rails_5.2' - ruby: '3.1' gemfile: 'rails_5.2' + # rails 7 requires ruby > 2.7 + - ruby: '2.6' + gemfile: 'rails_7.0' steps: - name: Checkout source uses: actions/checkout@v2 From 97bf1e72a9b68d70e7dccd3432758d8fae9f798d Mon Sep 17 00:00:00 2001 From: denisahearn Date: Mon, 31 Jan 2022 11:01:07 -0600 Subject: [PATCH 06/13] Added in_after_callback argument to save_with_version --- .rubocop_todo.yml | 1 + CHANGELOG.md | 4 ++++ lib/paper_trail/record_trail.rb | 8 +++++--- spec/models/not_on_update_spec.rb | 10 ++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a83dd96a..8cb88f81 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -50,6 +50,7 @@ Security/YAMLLoad: - 'spec/models/book_spec.rb' - 'spec/models/gadget_spec.rb' - 'spec/models/no_object_spec.rb' + - 'spec/models/not_on_update_spec.rb' - 'spec/models/person_spec.rb' - 'spec/models/version_spec.rb' - 'spec/paper_trail/events/destroy_spec.rb' diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d91ea33..3f3f660f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/). ## Unreleased +- Added `in_after_callback` argument to `PaperTrail::RecordTrail#save_with_version`, + to allow the caller to indicate if this method is being called during an `after` + callback. Defaults to `false`. + ### Breaking Changes - None diff --git a/lib/paper_trail/record_trail.rb b/lib/paper_trail/record_trail.rb index c29348d4..66c52896 100644 --- a/lib/paper_trail/record_trail.rb +++ b/lib/paper_trail/record_trail.rb @@ -194,15 +194,17 @@ module PaperTrail # Save, and create a version record regardless of options such as `:on`, # `:if`, or `:unless`. # - # Arguments are passed to `save`. + # `in_after_callback`: Indicates if this method is being called within an + # `after` callback. Defaults to `false`. + # `options`: Optional arguments passed to `save`. # # This is an "update" event. That is, we record the same data we would in # the case of a normal AR `update`. - def save_with_version(**options) + def save_with_version(in_after_callback: false, **options) ::PaperTrail.request(enabled: false) do @record.save(**options) end - record_update(force: true, in_after_callback: false, is_touch: false) + record_update(force: true, in_after_callback: in_after_callback, is_touch: false) end # Like the `update_column` method from `ActiveRecord::Persistence`, but also diff --git a/spec/models/not_on_update_spec.rb b/spec/models/not_on_update_spec.rb index 2ab15d72..dd9231d1 100644 --- a/spec/models/not_on_update_spec.rb +++ b/spec/models/not_on_update_spec.rb @@ -11,5 +11,15 @@ RSpec.describe NotOnUpdate, type: :model do PaperTrail::Version.count }.by(+1) end + + it "captures changes when in_after_callback is true" do + now = DateTime.now + record.updated_at = now + record.paper_trail.save_with_version(in_after_callback: true) + as_stored_in_version = HashWithIndifferentAccess[ + YAML.load(record.versions.last.object_changes) + ] + expect(as_stored_in_version[:updated_at].last).to(eq(now)) + end end end From 643e4747eed9bc847b6a02c049d3063ef1dd0c83 Mon Sep 17 00:00:00 2001 From: denisahearn Date: Tue, 1 Feb 2022 08:25:44 -0600 Subject: [PATCH 07/13] Use name attribute for NotOnUpdate test --- .../db/migrate/20110208155312_set_up_test_tables.rb | 1 + spec/models/not_on_update_spec.rb | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/dummy_app/db/migrate/20110208155312_set_up_test_tables.rb b/spec/dummy_app/db/migrate/20110208155312_set_up_test_tables.rb index 377889ad..e61f84a5 100644 --- a/spec/dummy_app/db/migrate/20110208155312_set_up_test_tables.rb +++ b/spec/dummy_app/db/migrate/20110208155312_set_up_test_tables.rb @@ -144,6 +144,7 @@ class SetUpTestTables < ::ActiveRecord::Migration::Current end create_table :not_on_updates, force: true do |t| + t.string :name t.timestamps null: true, limit: 6 end diff --git a/spec/models/not_on_update_spec.rb b/spec/models/not_on_update_spec.rb index dd9231d1..85dbe6e0 100644 --- a/spec/models/not_on_update_spec.rb +++ b/spec/models/not_on_update_spec.rb @@ -13,13 +13,12 @@ RSpec.describe NotOnUpdate, type: :model do end it "captures changes when in_after_callback is true" do - now = DateTime.now - record.updated_at = now + record.name = "test" record.paper_trail.save_with_version(in_after_callback: true) as_stored_in_version = HashWithIndifferentAccess[ YAML.load(record.versions.last.object_changes) ] - expect(as_stored_in_version[:updated_at].last).to(eq(now)) + expect(as_stored_in_version[:name].last).to(eq("test")) end end end From 12976d5489e8991e2891444d947ac6c5e0fd1490 Mon Sep 17 00:00:00 2001 From: denisahearn Date: Tue, 1 Feb 2022 08:40:46 -0600 Subject: [PATCH 08/13] Changed NotOnUpdate test to use record.versions.last.changeset --- .rubocop_todo.yml | 1 - spec/models/not_on_update_spec.rb | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8cb88f81..a83dd96a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -50,7 +50,6 @@ Security/YAMLLoad: - 'spec/models/book_spec.rb' - 'spec/models/gadget_spec.rb' - 'spec/models/no_object_spec.rb' - - 'spec/models/not_on_update_spec.rb' - 'spec/models/person_spec.rb' - 'spec/models/version_spec.rb' - 'spec/paper_trail/events/destroy_spec.rb' diff --git a/spec/models/not_on_update_spec.rb b/spec/models/not_on_update_spec.rb index 85dbe6e0..c811c56c 100644 --- a/spec/models/not_on_update_spec.rb +++ b/spec/models/not_on_update_spec.rb @@ -15,10 +15,8 @@ RSpec.describe NotOnUpdate, type: :model do it "captures changes when in_after_callback is true" do record.name = "test" record.paper_trail.save_with_version(in_after_callback: true) - as_stored_in_version = HashWithIndifferentAccess[ - YAML.load(record.versions.last.object_changes) - ] - expect(as_stored_in_version[:name].last).to(eq("test")) + changeset = record.versions.last.changeset + expect(changeset[:name]).to eq([nil, "test"]) end end end From f5652ea79e0b3031301edc273a47cf362260eea7 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Tue, 1 Mar 2022 13:06:48 +0900 Subject: [PATCH 09/13] Try to create a version record when associated object is touched Before #1285, a version record was created when associated object is touched. But because of Rails don't track implicit touch mutation[1], now PaperTail don't create a version record was created when associated object is touched. This patch try to keep creating a version record in that case by doing checking an event and changed value. Fixes #1339. [1]: https://github.com/rails/rails/commit/dcb825902d79d0f6baba956f7c6ec5767611353e --- CHANGELOG.md | 4 +++- lib/paper_trail/events/update.rb | 14 ++++++++++++++ spec/dummy_app/app/models/order.rb | 2 +- .../migrate/20110208155312_set_up_test_tables.rb | 1 + spec/models/order_spec.rb | 15 +++++++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 spec/models/order_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d91ea33..b98df971 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,9 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/). ### Fixed -- None +- [#1376](https://github.com/paper-trail-gem/paper_trail/pull/1376) - + Create a version record when associated object was changed the same as + PaperTrail < v12.1.0. ## 12.2.0 (2022-01-21) diff --git a/lib/paper_trail/events/update.rb b/lib/paper_trail/events/update.rb index 89407226..5c9123d7 100644 --- a/lib/paper_trail/events/update.rb +++ b/lib/paper_trail/events/update.rb @@ -40,6 +40,20 @@ module PaperTrail merge_metadata_into(data) end + # If it is a touch event, and changed are empty, it is assumed to be + # implicit `touch` mutation, and will a version is created. + # + # See https://github.com/rails/rails/commit/dcb825902d79d0f6baba956f7c6ec5767611353e + # + # @api private + def changed_notably? + if @is_touch && changes_in_latest_version.empty? + true + else + super + end + end + private # @api private diff --git a/spec/dummy_app/app/models/order.rb b/spec/dummy_app/app/models/order.rb index f272874d..d8913768 100644 --- a/spec/dummy_app/app/models/order.rb +++ b/spec/dummy_app/app/models/order.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class Order < ActiveRecord::Base - belongs_to :customer + belongs_to :customer, touch: :touched_at has_many :line_items has_paper_trail end diff --git a/spec/dummy_app/db/migrate/20110208155312_set_up_test_tables.rb b/spec/dummy_app/db/migrate/20110208155312_set_up_test_tables.rb index 377889ad..90245e31 100644 --- a/spec/dummy_app/db/migrate/20110208155312_set_up_test_tables.rb +++ b/spec/dummy_app/db/migrate/20110208155312_set_up_test_tables.rb @@ -267,6 +267,7 @@ class SetUpTestTables < ::ActiveRecord::Migration::Current create_table :customers, force: true do |t| t.string :name + t.datetime :touched_at, limit: 6 end create_table :orders, force: true do |t| diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb new file mode 100644 index 00000000..99665acc --- /dev/null +++ b/spec/models/order_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe Order, type: :model, versioning: true do + context "when the record destroyed" do + it "creates a version record for association" do + customer = Customer.create! + described_class.create!(customer: customer) + described_class.destroy_all + + expect(customer.versions.count).to(eq(3)) + end + end +end From 83b894648cd4e32f51a9be3668f73e9d21aeb46d Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Tue, 8 Mar 2022 23:15:24 -0500 Subject: [PATCH 10/13] Doc: bundle install [Closes #1370] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 627b1669..d078deb0 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ Experts: to install incompatible versions of activerecord, see ### 1.b. Installation -1. Add PaperTrail to your `Gemfile`. +1. Add PaperTrail to your `Gemfile` and run [`bundle`][57]. `gem 'paper_trail'` @@ -1772,3 +1772,4 @@ Released under the MIT licence. [54]: https://rubygems.org/gems/paper_trail [55]: https://api.dependabot.com/badges/compatibility_score?dependency-name=paper_trail&package-manager=bundler&version-scheme=semver [56]: https://dependabot.com/compatibility-score.html?dependency-name=paper_trail&package-manager=bundler&version-scheme=semver +[57]: https://bundler.io/v2.3/man/bundle-install.1.html From 81f935fb79f804ec7d89746105876e348e3ee223 Mon Sep 17 00:00:00 2001 From: Nuzair Rasheed <38219313+Nuzair46@users.noreply.github.com> Date: Wed, 9 Mar 2022 23:29:19 +0530 Subject: [PATCH 11/13] Added ability to set uuid as item_id type while generating migration (#1374) * Added ability to set uuid as item_id type while generating migration * added changelog * changed uuid to string * Revert "added changelog" This reverts commit 47b074e1444cb99c27e02ae87de1c57dbc855e10. * Made suggested changed * Added changelog * Updated readme with installation instructions. * Added fixed issue to changelog --- CHANGELOG.md | 4 ++++ README.md | 6 +++++ .../paper_trail/install/install_generator.rb | 14 +++++++++++- .../install/templates/create_versions.rb.erb | 2 +- .../paper_trail/install_generator_spec.rb | 22 +++++++++++++++++++ 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d997c30c..be3b4fd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/). ## Unreleased +- Added option `--uuid` when generating new migration. This can be used to set the type of item_id column to uuid for use with paper_trail on a database that uses uuid as primary key. + - Added `in_after_callback` argument to `PaperTrail::RecordTrail#save_with_version`, to allow the caller to indicate if this method is being called during an `after` callback. Defaults to `false`. @@ -19,6 +21,8 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/). ### Fixed +- [#1373](https://github.com/paper-trail-gem/paper_trail/issues/1373) - Add instruction to use uuid type for item_id in migration. + - [#1376](https://github.com/paper-trail-gem/paper_trail/pull/1376) - Create a version record when associated object was changed the same as PaperTrail < v12.1.0. diff --git a/README.md b/README.md index d078deb0..e9961a42 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,11 @@ Experts: to install incompatible versions of activerecord, see ``` bundle exec rails generate paper_trail:install [--with-changes] ``` + + If tables in your project use `uuid` instead of `integers` for `id`, then use: + ``` + bundle exec rails generate paper_trail:install [--uuid] + ``` See [section 5.c. Generators](#5c-generators) for details. @@ -1135,6 +1140,7 @@ Usage: Options: [--with-changes], [--no-with-changes] # Store changeset (diff) with each version + [--uuid] # To use paper_trail with projects using uuid for id Runtime options: -f, [--force] # Overwrite files that already exist diff --git a/lib/generators/paper_trail/install/install_generator.rb b/lib/generators/paper_trail/install/install_generator.rb index 6fc82fe7..4fa90364 100644 --- a/lib/generators/paper_trail/install/install_generator.rb +++ b/lib/generators/paper_trail/install/install_generator.rb @@ -20,6 +20,12 @@ module PaperTrail default: false, desc: "Store changeset (diff) with each version" ) + class_option( + :uuid, + type: :boolean, + default: false, + desc: "Use uuid instead of bigint for item_id type (use only if tables use UUIDs)" + ) desc "Generates (but does not run) a migration to add a versions table." \ " See section 5.c. Generators in README.md for more information." @@ -28,7 +34,8 @@ module PaperTrail add_paper_trail_migration( "create_versions", item_type_options: item_type_options, - versions_table_options: versions_table_options + versions_table_options: versions_table_options, + item_id_type_options: item_id_type_options ) if options.with_changes? add_paper_trail_migration("add_object_changes_to_versions") @@ -37,6 +44,11 @@ module PaperTrail private + # To use uuid instead of integer for primary key + def item_id_type_options + options.uuid? ? "string" : "bigint" + end + # MySQL 5.6 utf8mb4 limit is 191 chars for keys used in indexes. # See https://github.com/paper-trail-gem/paper_trail/issues/651 def item_type_options diff --git a/lib/generators/paper_trail/install/templates/create_versions.rb.erb b/lib/generators/paper_trail/install/templates/create_versions.rb.erb index 677d1b73..a5dc710f 100644 --- a/lib/generators/paper_trail/install/templates/create_versions.rb.erb +++ b/lib/generators/paper_trail/install/templates/create_versions.rb.erb @@ -11,7 +11,7 @@ class CreateVersions < ActiveRecord::Migration<%= migration_version %> def change create_table :versions<%= versions_table_options %> do |t| t.string :item_type<%= item_type_options %> - t.bigint :item_id, null: false + t.<%= item_id_type_options %> :item_id, null: false t.string :event, null: false t.string :whodunnit t.text :object, limit: TEXT_BYTES diff --git a/spec/generators/paper_trail/install_generator_spec.rb b/spec/generators/paper_trail/install_generator_spec.rb index 10365b2a..9fccc48b 100644 --- a/spec/generators/paper_trail/install_generator_spec.rb +++ b/spec/generators/paper_trail/install_generator_spec.rb @@ -102,4 +102,26 @@ RSpec.describe PaperTrail::InstallGenerator, type: :generator do ) end end + + describe "`--uuid` option set to `true`" do + before do + prepare_destination + run_generator %w[--uuid] + end + + it "generates a migration for creating the 'versions' table with item_id type uuid" do + expected_item_id_type = "string" + expect(destination_root).to( + have_structure { + directory("db") { + directory("migrate") { + migration("create_versions") { + contains "t.#{expected_item_id_type} :item_id, null: false" + } + } + } + } + ) + end + end end From 3b8f55b3d13e2af5aa0aa5ceaf373aa16c06c12d Mon Sep 17 00:00:00 2001 From: Joey Tepperman Date: Wed, 9 Mar 2022 17:09:46 -0500 Subject: [PATCH 12/13] Fix `create_versions` migration to support Ruby3 (#1366) * Fix `create_versions` migration to support Ruby3 * Update changelog --- CHANGELOG.md | 3 ++- lib/generators/paper_trail/install/install_generator.rb | 4 ++-- spec/generators/paper_trail/install_generator_spec.rb | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be3b4fd4..677c6898 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,7 +42,8 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/). ### Fixed -- None +- [#1366](https://github.com/paper-trail-gem/paper_trail/pull/1366) - + Fixed a bug where the `create_versions` migration lead to a broken `db/schema.rb` for Ruby 3 ### Dependencies diff --git a/lib/generators/paper_trail/install/install_generator.rb b/lib/generators/paper_trail/install/install_generator.rb index 4fa90364..13786636 100644 --- a/lib/generators/paper_trail/install/install_generator.rb +++ b/lib/generators/paper_trail/install/install_generator.rb @@ -53,9 +53,9 @@ module PaperTrail # See https://github.com/paper-trail-gem/paper_trail/issues/651 def item_type_options if mysql? - ", { null: false, limit: 191 }" + ", null: false, limit: 191" else - ", { null: false }" + ", null: false" end end diff --git a/spec/generators/paper_trail/install_generator_spec.rb b/spec/generators/paper_trail/install_generator_spec.rb index 9fccc48b..34f1386c 100644 --- a/spec/generators/paper_trail/install_generator_spec.rb +++ b/spec/generators/paper_trail/install_generator_spec.rb @@ -33,9 +33,9 @@ RSpec.describe PaperTrail::InstallGenerator, type: :generator do }.call expected_item_type_options = lambda { if described_class::MYSQL_ADAPTERS.include?(ActiveRecord::Base.connection.class.name) - ", { null: false, limit: 191 }" + ", null: false, limit: 191" else - ", { null: false }" + ", null: false" end }.call expect(destination_root).to( From 9d0f7bd854507479a348468167117cd0dd6d7755 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 13 Mar 2022 15:44:33 -0400 Subject: [PATCH 13/13] Doc: changelog [ci skip] --- CHANGELOG.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 677c6898..9550da69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,26 +5,27 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/). ## Unreleased -- Added option `--uuid` when generating new migration. This can be used to set the type of item_id column to uuid for use with paper_trail on a database that uses uuid as primary key. - -- Added `in_after_callback` argument to `PaperTrail::RecordTrail#save_with_version`, - to allow the caller to indicate if this method is being called during an `after` - callback. Defaults to `false`. - ### Breaking Changes - None ### Added -- None +- [#1371](https://github.com/paper-trail-gem/paper_trail/pull/1371) - Added + `in_after_callback` argument to `PaperTrail::RecordTrail#save_with_version`, + to allow the caller to indicate if this method is being called during an + `after` callback. Defaults to `false`. +- [#1374](https://github.com/paper-trail-gem/paper_trail/pull/1374) - Added + option `--uuid` when generating new migration. This can be used to set the + type of item_id column to uuid for use with paper_trail on a database that + uses uuid as primary key. ### Fixed -- [#1373](https://github.com/paper-trail-gem/paper_trail/issues/1373) - Add instruction to use uuid type for item_id in migration. - -- [#1376](https://github.com/paper-trail-gem/paper_trail/pull/1376) - - Create a version record when associated object was changed the same as +- [#1373](https://github.com/paper-trail-gem/paper_trail/issues/1373) - Add + CLI option to use uuid type for item_id when generating migration. +- [#1376](https://github.com/paper-trail-gem/paper_trail/pull/1376) - Create a + version record when associated object is touched. Restores the behavior of PaperTrail < v12.1.0. ## 12.2.0 (2022-01-21)