require File.join(File.dirname(__FILE__), '..', 'og', 'CONFIG.rb') require 'rubygems' require 'facets' require 'test/unit' require 'ostruct' require 'og' require 'glue/hierarchical' class TC_OgHierarchical < Test::Unit::TestCase # :nodoc: all class Comment attr_accessor :body, String attr_accessor :create_time, Time include Glue::NestedSets def initialize(body = nil) @body = body @create_time = Time.now end def to_s sprintf("%3d %3d %s", @lft, @rgt, @body) end end $og1.manage_classes Comment def test_all root = Comment.create('root') c1 = Comment.new('1') root.add_comment c1 c2 = Comment.new('1.1') c1.add_comment c2 c3 = Comment.new('1.2') c1.add_comment c3 c4 = Comment.new('1.1.1') c2.add_comment c4 c5 = Comment.new('1.2.1') c3.add_comment c5 c6 = Comment.new('1.1.1.1') c4.add_comment c6 c7 = Comment.new('2') root.add_comment c7 c8 = Comment.new('3') root.add_comment c8 c9 = Comment.new('2.1') c7.add_comment c9 c1.reload =begin Comment.all(:order => "lft, rgt").each { |c| puts sprintf("%3d %3d %s", c.lft, c.rgt, c.body) # p c } puts '--1' c1.comments(:order => "lft, rgt").each { |c| puts c.body } puts '--2' c1.full_comments(:order => "lft, rgt").each { |c| puts c.body } puts '--3' c1.direct_comments(:order => "lft, rgt").each { |c| puts c.body } =end assert_equal 6, c1.full_comments.size assert_equal 5, c1.comments.size assert_equal 2, c1.direct_comments.size c8.reload assert_equal 'root', c8.parent.body end end