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