Remove methods deprecated in PT 9
This commit is contained in:
parent
c145cc46c2
commit
265b3d972c
|
@ -7,7 +7,7 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
|
|||
|
||||
### Breaking Changes
|
||||
|
||||
- TODO: Remove all the deprecated methods like `MyModel.paper_trail.disable`
|
||||
- Remove all methods deprecated in PT 9
|
||||
- [#1108](https://github.com/paper-trail-gem/paper_trail/pull/1108) -
|
||||
In `versions.item_type`, we now store the subclass name instead of
|
||||
the base_class.
|
||||
|
|
|
@ -57,46 +57,6 @@ module PaperTrail
|
|||
!!PaperTrail.config.enabled
|
||||
end
|
||||
|
||||
# @deprecated
|
||||
def enabled_for_controller=(value)
|
||||
::ActiveSupport::Deprecation.warn(
|
||||
"PaperTrail.enabled_for_controller= is deprecated, " \
|
||||
"use PaperTrail.request.enabled=",
|
||||
caller(1)
|
||||
)
|
||||
request.enabled = value
|
||||
end
|
||||
|
||||
# @deprecated
|
||||
def enabled_for_controller?
|
||||
::ActiveSupport::Deprecation.warn(
|
||||
"PaperTrail.enabled_for_controller? is deprecated, " \
|
||||
"use PaperTrail.request.enabled?",
|
||||
caller(1)
|
||||
)
|
||||
request.enabled?
|
||||
end
|
||||
|
||||
# @deprecated
|
||||
def enabled_for_model(model, value)
|
||||
::ActiveSupport::Deprecation.warn(
|
||||
"PaperTrail.enabled_for_model is deprecated, " \
|
||||
"use PaperTrail.request.enabled_for_model",
|
||||
caller(1)
|
||||
)
|
||||
request.enabled_for_model(model, value)
|
||||
end
|
||||
|
||||
# @deprecated
|
||||
def enabled_for_model?(model)
|
||||
::ActiveSupport::Deprecation.warn(
|
||||
"PaperTrail.enabled_for_model? is deprecated, " \
|
||||
"use PaperTrail.request.enabled_for_model?",
|
||||
caller(1)
|
||||
)
|
||||
request.enabled_for_model?(model)
|
||||
end
|
||||
|
||||
# Returns PaperTrail's `::Gem::Version`, convenient for comparisons. This is
|
||||
# recommended over `::PaperTrail::VERSION::STRING`.
|
||||
#
|
||||
|
@ -137,53 +97,6 @@ module PaperTrail
|
|||
raise(E_TIMESTAMP_FIELD_CONFIG)
|
||||
end
|
||||
|
||||
# @deprecated
|
||||
def whodunnit=(value)
|
||||
::ActiveSupport::Deprecation.warn(
|
||||
"PaperTrail.whodunnit= is deprecated, use PaperTrail.request.whodunnit=",
|
||||
caller(1)
|
||||
)
|
||||
request.whodunnit = value
|
||||
end
|
||||
|
||||
# @deprecated
|
||||
def whodunnit(value = nil, &block)
|
||||
if value.nil?
|
||||
::ActiveSupport::Deprecation.warn(
|
||||
"PaperTrail.whodunnit is deprecated, use PaperTrail.request.whodunnit",
|
||||
caller(1)
|
||||
)
|
||||
request.whodunnit
|
||||
elsif block_given?
|
||||
::ActiveSupport::Deprecation.warn(
|
||||
"Passing a block to PaperTrail.whodunnit is deprecated, " \
|
||||
'use PaperTrail.request(whodunnit: "John") do .. end',
|
||||
caller(1)
|
||||
)
|
||||
request(whodunnit: value, &block)
|
||||
else
|
||||
raise ArgumentError, "Invalid arguments"
|
||||
end
|
||||
end
|
||||
|
||||
# @deprecated
|
||||
def controller_info=(value)
|
||||
::ActiveSupport::Deprecation.warn(
|
||||
"PaperTrail.controller_info= is deprecated, use PaperTrail.request.controller_info=",
|
||||
caller(1)
|
||||
)
|
||||
request.controller_info = value
|
||||
end
|
||||
|
||||
# @deprecated
|
||||
def controller_info
|
||||
::ActiveSupport::Deprecation.warn(
|
||||
"PaperTrail.controller_info is deprecated, use PaperTrail.request.controller_info",
|
||||
caller(1)
|
||||
)
|
||||
request.controller_info
|
||||
end
|
||||
|
||||
# Set the PaperTrail serializer. This setting affects all threads.
|
||||
# @api public
|
||||
def serializer=(value)
|
||||
|
|
|
@ -4,27 +4,6 @@ module PaperTrail
|
|||
# Configures an ActiveRecord model, mostly at application boot time, but also
|
||||
# sometimes mid-request, with methods like enable/disable.
|
||||
class ModelConfig
|
||||
DPR_DISABLE = <<-STR.squish.freeze
|
||||
MyModel.paper_trail.disable is deprecated, use
|
||||
PaperTrail.request.disable_model(MyModel). This new API makes it clear
|
||||
that only the current request is affected, not all threads. Also, all
|
||||
other request-variables now go through the same `request` method, so this
|
||||
new API is more consistent.
|
||||
STR
|
||||
DPR_ENABLE = <<-STR.squish.freeze
|
||||
MyModel.paper_trail.enable is deprecated, use
|
||||
PaperTrail.request.enable_model(MyModel). This new API makes it clear
|
||||
that only the current request is affected, not all threads. Also, all
|
||||
other request-variables now go through the same `request` method, so this
|
||||
new API is more consistent.
|
||||
STR
|
||||
DPR_ENABLED = <<-STR.squish.freeze
|
||||
MyModel.paper_trail.enabled? is deprecated, use
|
||||
PaperTrail.request.enabled_for_model?(MyModel). This new API makes it clear
|
||||
that this is a setting specific to the current request, not all threads.
|
||||
Also, all other request-variables now go through the same `request`
|
||||
method, so this new API is more consistent.
|
||||
STR
|
||||
E_CANNOT_RECORD_AFTER_DESTROY = <<-STR.strip_heredoc.freeze
|
||||
paper_trail.on_destroy(:after) is incompatible with ActiveRecord's
|
||||
belongs_to_required_by_default. Use on_destroy(:before)
|
||||
|
@ -44,24 +23,6 @@ module PaperTrail
|
|||
@model_class = model_class
|
||||
end
|
||||
|
||||
# @deprecated
|
||||
def disable
|
||||
::ActiveSupport::Deprecation.warn(DPR_DISABLE, caller(1))
|
||||
::PaperTrail.request.disable_model(@model_class)
|
||||
end
|
||||
|
||||
# @deprecated
|
||||
def enable
|
||||
::ActiveSupport::Deprecation.warn(DPR_ENABLE, caller(1))
|
||||
::PaperTrail.request.enable_model(@model_class)
|
||||
end
|
||||
|
||||
# @deprecated
|
||||
def enabled?
|
||||
::ActiveSupport::Deprecation.warn(DPR_ENABLED, caller(1))
|
||||
::PaperTrail.request.enabled_for_model?(@model_class)
|
||||
end
|
||||
|
||||
# Adds a callback that records a version after a "create" event.
|
||||
#
|
||||
# @api public
|
||||
|
|
|
@ -7,34 +7,6 @@ require "paper_trail/events/update"
|
|||
module PaperTrail
|
||||
# Represents the "paper trail" for a single record.
|
||||
class RecordTrail
|
||||
DPR_WHODUNNIT = <<-STR.squish.freeze
|
||||
my_model_instance.paper_trail.whodunnit('John') is deprecated,
|
||||
please use PaperTrail.request(whodunnit: 'John')
|
||||
STR
|
||||
DPR_WITHOUT_VERSIONING = <<-STR
|
||||
my_model_instance.paper_trail.without_versioning is deprecated, without
|
||||
an exact replacement. To disable versioning for a particular model,
|
||||
|
||||
```
|
||||
PaperTrail.request.disable_model(Banana)
|
||||
# changes to Banana model do not create versions,
|
||||
# but eg. changes to Kiwi model do.
|
||||
PaperTrail.request.enable_model(Banana)
|
||||
```
|
||||
|
||||
Or, you may want to disable all models,
|
||||
|
||||
```
|
||||
PaperTrail.request.enabled = false
|
||||
# no versions created
|
||||
PaperTrail.request.enabled = true
|
||||
|
||||
# or, with a block,
|
||||
PaperTrail.request(enabled: false) do
|
||||
# no versions created
|
||||
end
|
||||
```
|
||||
STR
|
||||
E_STI_ITEM_TYPES_NOT_UPDATED = <<~STR.squish.freeze
|
||||
It looks like %s is an STI subclass, and you have not yet updated your
|
||||
`item_type`s. Starting with
|
||||
|
@ -74,18 +46,6 @@ module PaperTrail
|
|||
PaperTrail.request.enabled_for_model?(@record.class)
|
||||
end
|
||||
|
||||
# Not sure why, but this method was mentioned in the README in the past,
|
||||
# so we need to deprecate it properly.
|
||||
# @deprecated
|
||||
def enabled_for_model?
|
||||
::ActiveSupport::Deprecation.warn(
|
||||
"MyModel#paper_trail.enabled_for_model? is deprecated, use " \
|
||||
"PaperTrail.request.enabled_for_model?(MyModel) instead.",
|
||||
caller(1)
|
||||
)
|
||||
PaperTrail.request.enabled_for_model?(@record.class)
|
||||
end
|
||||
|
||||
# Returns true if this instance is the current, live one;
|
||||
# returns false if this instance came from a previous version.
|
||||
def live?
|
||||
|
@ -309,34 +269,6 @@ module PaperTrail
|
|||
versions.collect { |version| version_at(version.created_at) }
|
||||
end
|
||||
|
||||
# Executes the given method or block without creating a new version.
|
||||
# @deprecated
|
||||
def without_versioning(method = nil)
|
||||
::ActiveSupport::Deprecation.warn(DPR_WITHOUT_VERSIONING, caller(1))
|
||||
paper_trail_was_enabled = PaperTrail.request.enabled_for_model?(@record.class)
|
||||
PaperTrail.request.disable_model(@record.class)
|
||||
if method
|
||||
if respond_to?(method)
|
||||
public_send(method)
|
||||
else
|
||||
@record.send(method)
|
||||
end
|
||||
else
|
||||
yield @record
|
||||
end
|
||||
ensure
|
||||
PaperTrail.request.enable_model(@record.class) if paper_trail_was_enabled
|
||||
end
|
||||
|
||||
# @deprecated
|
||||
def whodunnit(value)
|
||||
raise ArgumentError, "expected to receive a block" unless block_given?
|
||||
::ActiveSupport::Deprecation.warn(DPR_WHODUNNIT, caller(1))
|
||||
::PaperTrail.request(whodunnit: value) do
|
||||
yield @record
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# @api private
|
||||
|
|
|
@ -217,16 +217,6 @@ RSpec.describe Widget, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#whodunnit", versioning: true do
|
||||
it "is deprecated, delegates to Request.whodunnit" do
|
||||
allow(::ActiveSupport::Deprecation).to receive(:warn)
|
||||
allow(::PaperTrail::Request).to receive(:with)
|
||||
widget.paper_trail.whodunnit("Alex") {}
|
||||
expect(::ActiveSupport::Deprecation).to have_received(:warn).once
|
||||
expect(::PaperTrail::Request).to have_received(:with).with(whodunnit: "Alex")
|
||||
end
|
||||
end
|
||||
|
||||
describe "touch", versioning: true do
|
||||
it "creates a version" do
|
||||
expect { widget.touch }.to change {
|
||||
|
|
|
@ -15,40 +15,5 @@ module PaperTrail
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "deprecated methods" do
|
||||
let(:config) { PaperTrail::ModelConfig.new(:some_model_class) }
|
||||
|
||||
before do
|
||||
allow(ActiveSupport::Deprecation).to receive(:warn)
|
||||
end
|
||||
|
||||
describe "disable" do
|
||||
it "delegates to request" do
|
||||
allow(PaperTrail.request).to receive(:disable_model)
|
||||
config.disable
|
||||
expect(PaperTrail.request).to have_received(:disable_model).with(:some_model_class)
|
||||
expect(ActiveSupport::Deprecation).to have_received(:warn)
|
||||
end
|
||||
end
|
||||
|
||||
describe "enable" do
|
||||
it "delegates to request" do
|
||||
allow(PaperTrail.request).to receive(:enable_model)
|
||||
config.enable
|
||||
expect(PaperTrail.request).to have_received(:enable_model).with(:some_model_class)
|
||||
expect(ActiveSupport::Deprecation).to have_received(:warn)
|
||||
end
|
||||
end
|
||||
|
||||
describe "enabled?" do
|
||||
it "delegates to request" do
|
||||
allow(PaperTrail.request).to receive(:enabled_for_model?)
|
||||
config.enabled?
|
||||
expect(PaperTrail.request).to have_received(:enabled_for_model?).with(:some_model_class)
|
||||
expect(ActiveSupport::Deprecation).to have_received(:warn)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -407,15 +407,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "when destroyed \"without versioning\"" do
|
||||
it "leave paper trail off after call" do
|
||||
allow(::ActiveSupport::Deprecation).to receive(:warn)
|
||||
@widget.paper_trail.without_versioning(:destroy)
|
||||
expect(::PaperTrail.request.enabled_for_model?(Widget)).to eq(false)
|
||||
expect(::ActiveSupport::Deprecation).to have_received(:warn).once
|
||||
end
|
||||
end
|
||||
|
||||
context "and then its paper trail turned on" do
|
||||
before do
|
||||
PaperTrail.request.enable_model(Widget)
|
||||
|
@ -428,31 +419,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
expect(@widget.versions.length).to(eq((@count + 1)))
|
||||
end
|
||||
end
|
||||
|
||||
context "when updated \"without versioning\"" do
|
||||
it "does not create new version" do
|
||||
allow(::ActiveSupport::Deprecation).to receive(:warn)
|
||||
@widget.paper_trail.without_versioning do
|
||||
@widget.update_attributes(name: "Ford")
|
||||
end
|
||||
@widget.paper_trail.without_versioning do |w|
|
||||
w.update_attributes(name: "Nixon")
|
||||
end
|
||||
expect(@widget.versions.length).to(eq(@count))
|
||||
expect(PaperTrail.request.enabled_for_model?(Widget)).to eq(true)
|
||||
expect(::ActiveSupport::Deprecation).to have_received(:warn).twice
|
||||
end
|
||||
end
|
||||
|
||||
context "given a symbol, specifying a method name" do
|
||||
it "does not create a new version" do
|
||||
allow(::ActiveSupport::Deprecation).to receive(:warn)
|
||||
@widget.paper_trail.without_versioning(:touch)
|
||||
expect(::ActiveSupport::Deprecation).to have_received(:warn).once
|
||||
expect(@widget.versions.length).to(eq(@count))
|
||||
expect(::PaperTrail.request.enabled_for_model?(Widget)).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "spec_helper"
|
||||
|
||||
RSpec.describe PaperTrail do
|
||||
describe "#set_paper_trail_whodunnit" do
|
||||
it "is thread-safe" do
|
||||
blocked = true
|
||||
slow_thread = Thread.new do
|
||||
controller = TestController.new
|
||||
controller.send(:set_paper_trail_whodunnit)
|
||||
sleep(0.001) while blocked
|
||||
described_class.request.whodunnit
|
||||
end
|
||||
fast_thread = Thread.new do
|
||||
controller = TestController.new
|
||||
controller.send(:set_paper_trail_whodunnit)
|
||||
who = described_class.request.whodunnit
|
||||
blocked = false
|
||||
who
|
||||
end
|
||||
expect(fast_thread.value).not_to(eq(slow_thread.value))
|
||||
end
|
||||
end
|
||||
|
||||
describe "#without_versioning" do
|
||||
it "is thread-safe" do
|
||||
allow(::ActiveSupport::Deprecation).to receive(:warn)
|
||||
enabled = nil
|
||||
t1 = Thread.new do
|
||||
Widget.new.paper_trail.without_versioning do
|
||||
sleep(0.01)
|
||||
enabled = described_class.request.enabled_for_model?(Widget)
|
||||
sleep(0.01)
|
||||
end
|
||||
enabled
|
||||
end
|
||||
# A second thread is timed so that it runs during the first thread's
|
||||
# `without_versioning` block.
|
||||
t2 = Thread.new do
|
||||
sleep(0.005)
|
||||
described_class.request.enabled_for_model?(Widget)
|
||||
end
|
||||
expect(t1.value).to eq(false)
|
||||
expect(t2.value).to eq(true) # see? unaffected by t1
|
||||
expect(described_class.request.enabled_for_model?(Widget)).to eq(true)
|
||||
expect(::ActiveSupport::Deprecation).to have_received(:warn).once
|
||||
end
|
||||
end
|
||||
end
|
|
@ -104,55 +104,4 @@ RSpec.describe PaperTrail do
|
|||
expect(described_class.version).to eq(described_class::VERSION::STRING)
|
||||
end
|
||||
end
|
||||
|
||||
describe "deprecated methods" do
|
||||
before do
|
||||
allow(ActiveSupport::Deprecation).to receive(:warn)
|
||||
end
|
||||
|
||||
shared_examples "it delegates to request" do |method, args|
|
||||
it do
|
||||
arguments = args || [no_args]
|
||||
allow(described_class.request).to receive(method)
|
||||
described_class.public_send(method, *args)
|
||||
expect(described_class.request).to have_received(method).with(*arguments)
|
||||
expect(ActiveSupport::Deprecation).to have_received(:warn)
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like "it delegates to request", :enabled_for_model, [Widget, true]
|
||||
it_behaves_like "it delegates to request", :enabled_for_model?, [Widget]
|
||||
it_behaves_like "it delegates to request", :whodunnit=, [:some_whodunnit]
|
||||
it_behaves_like "it delegates to request", :whodunnit, nil
|
||||
it_behaves_like "it delegates to request", :controller_info=, [:some_whodunnit]
|
||||
it_behaves_like "it delegates to request", :controller_info, nil
|
||||
|
||||
describe "#enabled_for_controller=" do
|
||||
it "is deprecated" do
|
||||
allow(::PaperTrail.request).to receive(:enabled=)
|
||||
::PaperTrail.enabled_for_controller = true
|
||||
expect(::PaperTrail.request).to have_received(:enabled=).with(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe "whodunnit with block" do
|
||||
it "delegates to request" do
|
||||
allow(described_class.request).to receive(:with)
|
||||
described_class.whodunnit(:some_whodunnit) { :some_block }
|
||||
expect(ActiveSupport::Deprecation).to have_received(:warn)
|
||||
expect(described_class.request).to have_received(:with) do |*args, &block|
|
||||
expect(args).to eq([{ whodunnit: :some_whodunnit }])
|
||||
expect(block.call).to eq :some_block
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "whodunnit with invalid arguments" do
|
||||
it "raises an error" do
|
||||
expect { described_class.whodunnit(:some_whodunnit) }.to raise_error(ArgumentError) do |e|
|
||||
expect(e.message).to eq "Invalid arguments"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue