$:.unshift File.join(File.dirname(__FILE__), 'lib') $DBG = true require 'test/unit' require 'og' class TC_OgInheritance < Test::Unit::TestCase # :nodoc: all include Og class Document property :title, String schema_inheritance def initialize(title) @title = title end end class Article < Document property :body, String def initialize(title, body) @title, @body = title, body end end class Photo < Document property :url, String def initialize(title, url) @title, @url = title, url end end def test_all =begin @og = Og.setup( :store => :memory, :name => :test ) =end =begin @og = Og.setup( :destroy => true, :store => :sqlite, :name => 'test' ) =end #=begin @og = Og.setup( :destroy => true, :store => :psql, :name => 'test', :user => 'postgres', :password => 'navelrulez' ) #=end =begin @og = Og.setup( :destroy => true, :store => :mysql, :name => 'test', :user => 'root', :password => 'navelrulez' ) =end assert_equal [Document], Photo.metadata.superclass assert_equal [Photo, Article], Document.metadata.subclasses assert Document.metadata.schema_inheritance # propagate schema_inheritance flag. assert Photo.metadata.schema_inheritance # subclasses reuse the same table. assert_equal Document.table, Photo.table doc = Document.create('doc1') Photo.create('photo1', 'http:/www.gmosx.com/photo/1') Photo.create('photo2', 'http:/www.gmosx.com/photo/2') Article.create('art1', 'here comes the body') Article.create('art2', 'this is cool') Article.create('art3', 'this is cooler') docs = Document.all assert_equal 6, docs.size assert_equal 'art2', docs[4].title assert_equal Document, docs[0].class assert_equal Photo, docs[1].class assert_equal Article, docs[4].class photos = Photo.all assert_equal 2, photos.size assert_equal 'photo2', photos[1].title assert_equal 'http:/www.gmosx.com/photo/1', photos[0].url articles = Article.all assert_equal 3, articles.size assert_equal 'art3', articles[2].title articles = Article.all(:limit => 2) assert_equal 2, articles.size end end