From c52dc7b898dc114baf8d2f27f499ec7ab157187f Mon Sep 17 00:00:00 2001
From: Dana Sherson <robot@dana.sh>
Date: Mon, 4 Feb 2019 17:22:53 +1100
Subject: [PATCH] Don't check #present? of ActiveRecord objects because it's
 always true

(or the variable is assigned nil and it's always false)

While the rails maintainers argue about whether it's a good idea
https://github.com/rails/rails/issues/35059

I found this because out of curiosity I ran our test suite with
ApplicationRecord#present? raising in our projects
---
 lib/closure_tree/hierarchy_maintenance.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/closure_tree/hierarchy_maintenance.rb b/lib/closure_tree/hierarchy_maintenance.rb
index e3f4ee46..9476901d 100644
--- a/lib/closure_tree/hierarchy_maintenance.rb
+++ b/lib/closure_tree/hierarchy_maintenance.rb
@@ -23,7 +23,7 @@ def _ct_validate
       if !(defined? @_ct_skip_cycle_detection) &&
         !new_record? && # don't validate for cycles if we're a new record
         changes[_ct.parent_column_name] && # don't validate for cycles if we didn't change our parent
-        parent.present? && # don't validate if we're root
+        parent && # don't validate if we're root
         parent.self_and_ancestors.include?(self) # < this is expensive :\
         errors.add(_ct.parent_column_sym, I18n.t('closure_tree.loop_error', default: 'You cannot add an ancestor as a descendant'))
       end