Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix ActiveSupport 5.1 deprecation warnings #262

Merged
merged 1 commit into from
Apr 14, 2017
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
7 changes: 5 additions & 2 deletions lib/closure_tree/hierarchy_maintenance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ def _ct_before_save
end

def _ct_after_save
if changes[_ct.parent_column_name] || @was_new_record
as_5_1 = ActiveSupport.version >= Gem::Version.new('5.1.0')
changes_method = as_5_1 ? :saved_changes : :changes
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wow, that's pretty horrible that Rails is making us do this. Bummer.

I can't think of a more elegant way to do it though. Thanks for this PR.

Choose a reason for hiding this comment

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

Maybe this is a little less ugly?

changes_method = respond_to?(:saved_changes) ? :saved_changes : :changes

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, maybe? I guess I'm just frustrated by the rails team for making changes like this. Over and over again. If you think the other way is better, I'll merge your PR.

Copy link

Choose a reason for hiding this comment

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

I'm just frustrated by the rails team for making changes like this.

For the record, this change was not "oh this is better this way". The change in behavior of these methods was required to fix dozens of bugs, and significantly simplify the implementation of associations (weeding out even more bugs). It's not something that was taken lightly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@sgrif not meant as a personal affront--just a recognition of seven years of API churn.

Copy link

Choose a reason for hiding this comment

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

For sure. There have been a lot of needless changes that hurt gems over the years.


if public_send(changes_method)[_ct.parent_column_name] || @was_new_record
rebuild!
end
if changes[_ct.parent_column_name] && !@was_new_record
if public_send(changes_method)[_ct.parent_column_name] && !@was_new_record
# Resetting the ancestral collections addresses
# https://github.com/mceachen/closure_tree/issues/68
ancestor_hierarchies.reload
Expand Down
9 changes: 7 additions & 2 deletions lib/closure_tree/numeric_deterministic_ordering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ module NumericDeterministicOrdering
end

def _ct_reorder_prior_siblings_if_parent_changed
if attribute_changed?(_ct.parent_column_name) && !@was_new_record
was_parent_id = attribute_was(_ct.parent_column_name)
as_5_1 = ActiveSupport.version >= Gem::Version.new('5.1.0')
change_method = as_5_1 ? :saved_change_to_attribute? : :attribute_changed?

if public_send(change_method, _ct.parent_column_name) && !@was_new_record
attribute_method = as_5_1 ? :attribute_before_last_save : :attribute_was

was_parent_id = public_send(attribute_method, _ct.parent_column_name)
_ct.reorder_with_parent_id(was_parent_id)
end
end
Expand Down