From 060f109ecbbf14ceb54348b3731a97963eb89288 Mon Sep 17 00:00:00 2001
From: Andrew Hacking <ahacking@gmail.com>
Date: Mon, 26 Aug 2013 10:25:58 +1000
Subject: [PATCH 1/2] Fix attr_accessible handling

---
 lib/closure_tree/support.rb       | 6 ++----
 lib/closure_tree/support_flags.rb | 2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/lib/closure_tree/support.rb b/lib/closure_tree/support.rb
index 8fd257b1..7724ae58 100644
--- a/lib/closure_tree/support.rb
+++ b/lib/closure_tree/support.rb
@@ -27,13 +27,11 @@ def initialize(model_class, options)
 
     def hierarchy_class_for_model
       hierarchy_class = model_class.parent.const_set(short_hierarchy_class_name, Class.new(ActiveRecord::Base))
-      use_attr_accessible = use_attr_accessible?
-      include_forbidden_attributes_protection = include_forbidden_attributes_protection?
       hierarchy_class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
-        include ActiveModel::ForbiddenAttributesProtection if include_forbidden_attributes_protection
+        include ActiveModel::ForbiddenAttributesProtection if #{include_forbidden_attributes_protection?}
         belongs_to :ancestor, :class_name => "#{model_class}"
         belongs_to :descendant, :class_name => "#{model_class}"
-        attr_accessible :ancestor, :descendant, :generations if use_attr_accessible
+        attr_accessible :ancestor, :descendant, :generations if #{use_attr_accessible?}
         def ==(other)
           self.class == other.class && ancestor_id == other.ancestor_id && descendant_id == other.descendant_id
         end
diff --git a/lib/closure_tree/support_flags.rb b/lib/closure_tree/support_flags.rb
index 78d771eb..dbec2c63 100644
--- a/lib/closure_tree/support_flags.rb
+++ b/lib/closure_tree/support_flags.rb
@@ -4,7 +4,7 @@ module SupportFlags
     def use_attr_accessible?
       defined?(ActiveModel::MassAssignmentSecurity) &&
         model_class.respond_to?(:accessible_attributes) &&
-        model_class.accessible_attributes.present?
+        ! model_class.accessible_attributes.nil?
     end
 
     def include_forbidden_attributes_protection?

From 88aa434e66d84740ad8f22a8f23eb47423b67c66 Mon Sep 17 00:00:00 2001
From: Andrew Hacking <ahacking@gmail.com>
Date: Tue, 27 Aug 2013 23:16:36 +1000
Subject: [PATCH 2/2] Undo buggy change

---
 lib/closure_tree/support.rb | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/closure_tree/support.rb b/lib/closure_tree/support.rb
index 7724ae58..e88201fe 100644
--- a/lib/closure_tree/support.rb
+++ b/lib/closure_tree/support.rb
@@ -24,14 +24,15 @@ def initialize(model_class, options)
         extend NumericOrderSupport.adapter_for_connection(connection)
       end
     end
-
     def hierarchy_class_for_model
       hierarchy_class = model_class.parent.const_set(short_hierarchy_class_name, Class.new(ActiveRecord::Base))
+      use_attr_accessible = use_attr_accessible?
+      include_forbidden_attributes_protection = include_forbidden_attributes_protection?
       hierarchy_class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
-        include ActiveModel::ForbiddenAttributesProtection if #{include_forbidden_attributes_protection?}
+        include ActiveModel::ForbiddenAttributesProtection if include_forbidden_attributes_protection
         belongs_to :ancestor, :class_name => "#{model_class}"
         belongs_to :descendant, :class_name => "#{model_class}"
-        attr_accessible :ancestor, :descendant, :generations if #{use_attr_accessible?}
+        attr_accessible :ancestor, :descendant, :generations if use_attr_accessible
         def ==(other)
           self.class == other.class && ancestor_id == other.ancestor_id && descendant_id == other.descendant_id
         end