From 7bde1b7ed1ad7dcb2b8fe21b19c52b8f01c5bb3b Mon Sep 17 00:00:00 2001 From: Charles Pence Date: Tue, 11 Apr 2017 11:29:07 -0500 Subject: [PATCH] Fix ActiveSupport 5.1 deprecation warnings. --- lib/closure_tree/hierarchy_maintenance.rb | 7 +++++-- lib/closure_tree/numeric_deterministic_ordering.rb | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/closure_tree/hierarchy_maintenance.rb b/lib/closure_tree/hierarchy_maintenance.rb index b114ec3a..e9fe761e 100644 --- a/lib/closure_tree/hierarchy_maintenance.rb +++ b/lib/closure_tree/hierarchy_maintenance.rb @@ -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 + + 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 diff --git a/lib/closure_tree/numeric_deterministic_ordering.rb b/lib/closure_tree/numeric_deterministic_ordering.rb index 8a6535cd..f5a98200 100644 --- a/lib/closure_tree/numeric_deterministic_ordering.rb +++ b/lib/closure_tree/numeric_deterministic_ordering.rb @@ -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