Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove methods deprecated in PT 9 #1132

Merged
merged 1 commit into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
87 changes: 0 additions & 87 deletions lib/paper_trail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,46 +57,6 @@ def enabled?
!!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`.
#
Expand Down Expand Up @@ -137,53 +97,6 @@ def timestamp_field=(_field_name)
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)
Expand Down
39 changes: 0 additions & 39 deletions lib/paper_trail/model_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -44,24 +23,6 @@ def initialize(model_class)
@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
Expand Down
68 changes: 0 additions & 68 deletions lib/paper_trail/record_trail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,6 @@
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
Expand Down Expand Up @@ -74,18 +46,6 @@ def enabled?
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?
Expand Down Expand Up @@ -309,34 +269,6 @@ def versions_between(start_time, end_time)
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
Expand Down
10 changes: 0 additions & 10 deletions spec/models/widget_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,6 @@
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 {
Expand Down
35 changes: 0 additions & 35 deletions spec/paper_trail/model_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,5 @@ class MisconfiguredCVC < ActiveRecord::Base
)
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
34 changes: 0 additions & 34 deletions spec/paper_trail/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,6 @@
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)
Expand All @@ -428,31 +419,6 @@
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
Expand Down
Loading