Chris@1296: class Note < ActiveRecord::Base Chris@1296: acts_as_nested_set :scope => [:notable_id, :notable_type] Chris@1296: end Chris@1296: Chris@1296: class Default < ActiveRecord::Base Chris@1296: self.table_name = 'categories' Chris@1296: acts_as_nested_set Chris@1296: end Chris@1296: Chris@1296: class ScopedCategory < ActiveRecord::Base Chris@1296: self.table_name = 'categories' Chris@1296: acts_as_nested_set :scope => :organization Chris@1296: end Chris@1296: Chris@1296: class RenamedColumns < ActiveRecord::Base Chris@1296: acts_as_nested_set :parent_column => 'mother_id', :left_column => 'red', :right_column => 'black' Chris@1296: end Chris@1296: Chris@1296: class Category < ActiveRecord::Base Chris@1296: acts_as_nested_set Chris@1296: Chris@1296: validates_presence_of :name Chris@1296: Chris@1296: # Setup a callback that we can switch to true or false per-test Chris@1296: set_callback :move, :before, :custom_before_move Chris@1296: cattr_accessor :test_allows_move Chris@1296: @@test_allows_move = true Chris@1296: def custom_before_move Chris@1296: @@test_allows_move Chris@1296: end Chris@1296: Chris@1296: def to_s Chris@1296: name Chris@1296: end Chris@1296: Chris@1296: def recurse &block Chris@1296: block.call self, lambda{ Chris@1296: self.children.each do |child| Chris@1296: child.recurse &block Chris@1296: end Chris@1296: } Chris@1296: end Chris@1296: end Chris@1296: Chris@1296: class Thing < ActiveRecord::Base Chris@1296: acts_as_nested_set :counter_cache => 'children_count' Chris@1296: end Chris@1296: Chris@1296: class DefaultWithCallbacks < ActiveRecord::Base Chris@1296: Chris@1296: self.table_name = 'categories' Chris@1296: Chris@1296: attr_accessor :before_add, :after_add, :before_remove, :after_remove Chris@1296: Chris@1296: acts_as_nested_set :before_add => :do_before_add_stuff, Chris@1296: :after_add => :do_after_add_stuff, Chris@1296: :before_remove => :do_before_remove_stuff, Chris@1296: :after_remove => :do_after_remove_stuff Chris@1296: Chris@1296: private Chris@1296: Chris@1296: [ :before_add, :after_add, :before_remove, :after_remove ].each do |hook_name| Chris@1296: define_method "do_#{hook_name}_stuff" do |child_node| Chris@1296: self.send("#{hook_name}=", child_node) Chris@1296: end Chris@1296: end Chris@1296: Chris@1296: end Chris@1296: Chris@1296: class Broken < ActiveRecord::Base Chris@1296: acts_as_nested_set Chris@1296: end