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

Warn if paper_trail_on_destroy(:after) is combined with ActiveRecord belongs_to_required_by_default #808

Merged
merged 1 commit into from
May 31, 2016
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 4.2.0 (Unreleased)

### Added

- [#808](https://github.com/airblade/paper_trail/pull/808) -
Warn when destroy callback is set to :after with ActiveRecord 5
option `belongs_to_required_by_default` set to `true`.

## 4.1.0

### Breaking Changes
Expand Down
15 changes: 12 additions & 3 deletions lib/paper_trail/has_paper_trail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,18 @@ def paper_trail_on_destroy(recording_order = 'after')
fail ArgumentError, 'recording order can only be "after" or "before"'
end

send "#{recording_order}_destroy",
:record_destroy,
:if => :save_version?
if recording_order.to_s == 'after' and
Copy link
Contributor Author

@md5 md5 May 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, I changed this from recording_order == 'after' to recording_order.to_s == 'after' to ensure that the warning is still issued when the :after symbol is used. This fix should probably be made on master as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

This fix should probably be made on master as well.

Please do, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #813

I added a spec to test that the warning is actually being issued and it's not passing for some reason. We can discuss on the PR.

Gem::Version.new(ActiveRecord::VERSION::STRING).release >= Gem::Version.new("5")
if ::ActiveRecord::Base.belongs_to_required_by_default
::ActiveSupport::Deprecation.warn(
"paper_trail_on_destroy(:after) is incompatible with ActiveRecord " +
"belongs_to_required_by_default and has no effect. Please use :before " +
"or disable belongs_to_required_by_default."
)
end
end

send "#{recording_order}_destroy", :record_destroy, :if => :save_version?

return if paper_trail_options[:on].include?(:destroy)
paper_trail_options[:on] << :destroy
Expand Down