diff --git a/CHANGELOG.md b/CHANGELOG.md index 334dd816..f7e035e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/). See [5.c. Generators][2] for instructions. - This change fixes a long-standing issue with reification of STI subclasses, [#594](https://github.com/paper-trail-gem/paper_trail/issues/594) +- Removed `touch_with_version`, was deprecated in 9.0.0 ### Added diff --git a/README.md b/README.md index c76e97bf..16b2ce13 100644 --- a/README.md +++ b/README.md @@ -362,10 +362,6 @@ the record has not changed. my_model.paper_trail.save_with_version ``` -There is a similar method, `touch_with_version`, which was deprecated in -9.0.0 and will be removed. `save_with_version` serves a similar purpose, but -it's a save, not a touch. - ### 2.c. Choosing Attributes To Monitor #### Ignore diff --git a/lib/paper_trail/events/base.rb b/lib/paper_trail/events/base.rb index 461c2cf4..8fb49279 100644 --- a/lib/paper_trail/events/base.rb +++ b/lib/paper_trail/events/base.rb @@ -11,7 +11,6 @@ module PaperTrail # - `after_update` we call `RecordTrail#record_update` # - `after_touch` we call `RecordTrail#record_update` # - `RecordTrail#save_with_version` calls `RecordTrail#record_update` - # - `RecordTrail#touch_with_version` (deprecated) calls `RecordTrail#record_update` # - `RecordTrail#update_columns` is also referred to as an update, though # it uses `RecordTrail#record_update_columns` rather than # `RecordTrail#record_update` diff --git a/lib/paper_trail/events/update.rb b/lib/paper_trail/events/update.rb index 4a3a99c2..a22d144b 100644 --- a/lib/paper_trail/events/update.rb +++ b/lib/paper_trail/events/update.rb @@ -10,7 +10,6 @@ module PaperTrail class Update < Base # - is_touch - [boolean] - Used in the two situations that are touch-like: # - `after_touch` we call `RecordTrail#record_update` - # - `RecordTrail#touch_with_version` (deprecated) calls `RecordTrail#record_update` # - force_changes - [Hash] - Only used by `RecordTrail#update_columns`, # because there dirty tracking is off, so it has to track its own changes. # diff --git a/lib/paper_trail/record_trail.rb b/lib/paper_trail/record_trail.rb index a2537741..0526ee5e 100644 --- a/lib/paper_trail/record_trail.rb +++ b/lib/paper_trail/record_trail.rb @@ -7,12 +7,6 @@ require "paper_trail/events/update" module PaperTrail # Represents the "paper trail" for a single record. class RecordTrail - DPR_TOUCH_WITH_VERSION = <<-STR.squish.freeze - my_model.paper_trail.touch_with_version is deprecated, please use - my_model.paper_trail.save_with_version, which is slightly different. It's - a save, not a touch, so make sure you understand the difference by reading - the ActiveRecord documentation for both. - STR DPR_WHODUNNIT = <<-STR.squish.freeze my_model_instance.paper_trail.whodunnit('John') is deprecated, please use PaperTrail.request(whodunnit: 'John') @@ -249,38 +243,6 @@ module PaperTrail version end - # Mimics the `touch` method from `ActiveRecord::Persistence` (without - # actually calling `touch`), but also creates a version. - # - # A version is created regardless of options such as `:on`, `:if`, or - # `:unless`. - # - # This is an "update" event. That is, we record the same data we would in - # the case of a normal AR `update`. - # - # Some advanced PT users disable all callbacks (eg. `has_paper_trail(on: - # [])`) and use only this method, giving them complete control over when - # version records are inserted. It's unclear under which specific - # circumstances this technique should be adopted. - # - # @deprecated - def touch_with_version(name = nil) - ::ActiveSupport::Deprecation.warn(DPR_TOUCH_WITH_VERSION, caller(1)) - unless @record.persisted? - raise ::ActiveRecord::ActiveRecordError, "can not touch on a new record object" - end - attributes = @record.send :timestamp_attributes_for_update_in_model - attributes << name if name - current_time = @record.send :current_time_from_proper_timezone - attributes.each { |column| - @record.send(:write_attribute, column, current_time) - } - ::PaperTrail.request(enabled: false) do - @record.save!(validate: false) - end - record_update(force: true, in_after_callback: false, is_touch: false) - end - # Save, and create a version record regardless of options such as `:on`, # `:if`, or `:unless`. # @@ -288,12 +250,6 @@ module PaperTrail # # This is an "update" event. That is, we record the same data we would in # the case of a normal AR `update`. - # - # In older versions of PaperTrail, a method named `touch_with_version` was - # used for this purpose. `save_with_version` is not exactly the same. - # First, the arguments are different. It passes all arguments to `save`. - # Second, it doesn't set any timestamp attributes prior to the `save` the - # way `touch_with_version` did. def save_with_version(*args) ::PaperTrail.request(enabled: false) do @record.save(*args) diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 73e412fb..b0641983 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -185,16 +185,4 @@ RSpec.describe Article, type: :model, versioning: true do expect(article.versions.map(&:event)).to(match_array(%w[create destroy])) end end - - describe "#touch_with_version" do - it "creates a version, ignoring the :only option" do - article = described_class.create - - allow(::ActiveSupport::Deprecation).to receive(:warn) - expect { article.paper_trail.touch_with_version }.to change { - ::PaperTrail::Version.count - }.by(+1) - expect(::ActiveSupport::Deprecation).to have_received(:warn).once - end - end end diff --git a/spec/models/not_on_update_spec.rb b/spec/models/not_on_update_spec.rb index 744d21a0..2ab15d72 100644 --- a/spec/models/not_on_update_spec.rb +++ b/spec/models/not_on_update_spec.rb @@ -12,24 +12,4 @@ RSpec.describe NotOnUpdate, type: :model do }.by(+1) end end - - describe "#touch_with_version", versioning: true do - let!(:record) { described_class.create! } - - it "creates a version, regardless" do - allow(::ActiveSupport::Deprecation).to receive(:warn) - expect { record.paper_trail.touch_with_version }.to change { - PaperTrail::Version.count - }.by(+1) - expect(::ActiveSupport::Deprecation).to have_received(:warn).once - end - - it "increments the `:updated_at` timestamp" do - before = record.updated_at - allow(::ActiveSupport::Deprecation).to receive(:warn) - record.paper_trail.touch_with_version - expect(::ActiveSupport::Deprecation).to have_received(:warn).once - expect(record.updated_at).to be > before - end - end end diff --git a/spec/models/on/empty_array_spec.rb b/spec/models/on/empty_array_spec.rb index ac772fe0..b9236336 100644 --- a/spec/models/on/empty_array_spec.rb +++ b/spec/models/on/empty_array_spec.rb @@ -12,19 +12,6 @@ module On end end - describe "#touch_with_version" do - it "creates a version record" do - record = described_class.create(name: "Alice") - allow(::ActiveSupport::Deprecation).to receive(:warn) - record.paper_trail.touch_with_version - expect(::ActiveSupport::Deprecation).to have_received(:warn).once - expect(record.versions.length).to(eq(1)) - v = record.versions.first - expect(v.event).to(eq("update")) - expect(v.object_deserialized.fetch("name")).to eq("Alice") - end - end - describe ".paper_trail.update_columns" do it "creates a version record" do widget = Widget.create diff --git a/spec/models/post_with_status_spec.rb b/spec/models/post_with_status_spec.rb index 08305fdb..21504e34 100644 --- a/spec/models/post_with_status_spec.rb +++ b/spec/models/post_with_status_spec.rb @@ -31,20 +31,6 @@ RSpec.describe PostWithStatus, type: :model do end end - describe "#touch_with_version" do - it "preserves the enum value (and all other attributes)" do - post = described_class.create(status: :draft) - expect(post.versions.count).to eq(1) - expect(post.status).to eq("draft") - allow(::ActiveSupport::Deprecation).to receive(:warn) - post.paper_trail.touch_with_version - expect(::ActiveSupport::Deprecation).to have_received(:warn).once - expect(post.versions.count).to eq(2) - expect(post.versions.last[:object]).to include("status: 0") - expect(post.paper_trail.previous_version.status).to eq("draft") - end - end - describe "#save_with_version" do it "preserves the enum value (and all other attributes)" do post = described_class.create(status: :draft) diff --git a/spec/models/widget_spec.rb b/spec/models/widget_spec.rb index 4f29dea9..e4ffcf94 100644 --- a/spec/models/widget_spec.rb +++ b/spec/models/widget_spec.rb @@ -227,24 +227,6 @@ RSpec.describe Widget, type: :model do end end - describe "#touch_with_version", versioning: true do - it "creates a version" do - allow(::ActiveSupport::Deprecation).to receive(:warn) - count = widget.versions.size - widget.paper_trail.touch_with_version - expect(widget.versions.size).to eq(count + 1) - expect(::ActiveSupport::Deprecation).to have_received(:warn).once - end - - it "increments the `:updated_at` timestamp" do - allow(::ActiveSupport::Deprecation).to receive(:warn) - time_was = widget.updated_at - widget.paper_trail.touch_with_version - expect(widget.updated_at).to be > time_was - expect(::ActiveSupport::Deprecation).to have_received(:warn).once - end - end - describe "touch", versioning: true do it "creates a version" do expect { widget.touch }.to change {