spec/support/models.rb in closure_tree-4.0.1 vs spec/support/models.rb in closure_tree-4.1.0

- old
+ new

@@ -1,24 +1,45 @@ require 'uuidtools' class Tag < ActiveRecord::Base acts_as_tree :dependent => :destroy, :order => "name" before_destroy :add_destroyed_tag - attr_accessible :name + attr_accessible :name if _ct.use_attr_accessible? + def to_s + name + end + def add_destroyed_tag + # Proof for the tests that the destroy rather than the delete method was called: + DestroyedTag.create(:name => name) + end +end +class UUIDTag < ActiveRecord::Base + self.primary_key = :uuid + before_create :set_uuid + acts_as_tree :dependent => :destroy, :order => 'name', :parent_column_name => 'parent_uuid' + before_destroy :add_destroyed_tag + attr_accessible :name if _ct.use_attr_accessible? + + def set_uuid + self.uuid = UUIDTools::UUID.timestamp_create.to_s + end + def to_s name end def add_destroyed_tag # Proof for the tests that the destroy rather than the delete method was called: DestroyedTag.create(:name => name) end end +USE_ATTR_ACCESSIBLE = Tag._ct.use_attr_accessible? + class DestroyedTag < ActiveRecord::Base - attr_accessible :name + attr_accessible :name if USE_ATTR_ACCESSIBLE end class User < ActiveRecord::Base acts_as_tree :parent_column_name => "referrer_id", :name_column => 'email', @@ -29,11 +50,11 @@ def indirect_contracts Contract.where(:user_id => descendant_ids) end - attr_accessible :email, :referrer + attr_accessible :email, :referrer if USE_ATTR_ACCESSIBLE def to_s email end end @@ -41,11 +62,12 @@ class Contract < ActiveRecord::Base belongs_to :user end class Label < ActiveRecord::Base - attr_accessible :name # <- make sure order doesn't matter + # make sure order doesn't matter + attr_accessible :name if USE_ATTR_ACCESSIBLE acts_as_tree :order => :sort_order, # <- LOOK IT IS A SYMBOL OMG :parent_column_name => "mother_id", :dependent => :destroy def to_s @@ -67,8 +89,8 @@ end module Namespace class Type < ActiveRecord::Base acts_as_tree :dependent => :destroy - attr_accessible :name + attr_accessible :name if _ct.use_attr_accessible? end end