require File.join(File.dirname(__FILE__), 'CONFIG.rb') require 'rubygems' require 'facets' require 'test/unit' require 'og' class TC_OgPolymorphic < Test::Unit::TestCase # :nodoc: all include Og class Foo property :name, String has_many Bar end class Bar property :name, String belongs_to Foo has_many Foobar end class Foobar property :name, String belongs_to Bar end def setup @og = Og.setup($og_config) end def test_all 2.times{|i| foo = Foo.new foo.name = "foo #{i}" foo.save } assert_equal 2, Foo.all.length 3.times{|i| bar = Bar.new bar.name = "bar #{i}" bar.save } assert_equal 3, Bar.all.length 6.times{|i| foobar = Foobar.new foobar.name = "foobar #{i}" foobar.save } assert_equal 6, Foobar.all.length foo1 = Foo[1] bar1 = Bar[1] bar1.add_foobar Foobar[1] bar1.add_foobar Foobar[2] bar1.add_foobar Foobar[3] bar1.save foo1.add_bar bar1 foo1.save foo2 = Foo[2] bar2 = Bar[2] bar3 = Bar[3] bar2.add_foobar Foobar[4] bar3.add_foobar Foobar[5] bar3.add_foobar Foobar[6] bar2.save bar3.save foo2.add_bar bar2 foo2.add_bar bar3 foo2.save # this work... ar = Array.new foo1.bars.each {|ii| ar.push(ii.foobars) } ar.flatten! ar.size foo_foobars = foo1.bars.foobars assert_equal 3, foo_foobars.size assert_equal Foobar, foo_foobars.first.class end end