Remove touch_with_version, was deprecated in 9.0.0

This commit is contained in:
Jared Beck 2018-08-01 22:20:33 -04:00
parent 1fd4154a67
commit 4d877a7558
10 changed files with 1 additions and 127 deletions

View File

@ -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

View File

@ -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

View File

@ -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`

View File

@ -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.
#

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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 {