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