Sha256: f3f17ba118b02223943c873f02b0d7f74ee42aa4f61d261dcb0179874f32fa12

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

require File.join(File.dirname(__FILE__), 'CONFIG.rb')

require 'test/unit'
require 'og'

class TC_OgPolymorphic < Test::Unit::TestCase # :nodoc: all
  include Og

  # This class is a polymorphic parent. Ie' it acts as template
  # to generate customized versions of this class.
  
  class Comment
    property :body, String
    belongs_to :parent, Object # polymorphic marker !
    
    def initialize(body)
      @body = body
    end
  end

  class Article
    property :title, String
    has_many Comment

    def initialize(title)
      @title = title
    end    
  end
  
  class User
    property :name, String
    has_many Comment

    def initialize(name)
      @name = name
    end    
  end

  def setup
    @og = Og.setup($og_config)
  end

  def test_all
    u = User.create('gmosx')
    
    u.comments << User::Comment.create('Hello')
    u.comments << User::Comment.create('World')

    assert_equal 2, u.comments.size
    
    a = Article.create('test')
    
    a.comments << Article::Comment.create('Hello2')
    a.comments << Article::Comment.create('World2')    
    
    assert_equal 2, a.comments.size
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
og-0.24.0 test/og/tc_polymorphic.rb
og-0.25.0 test/og/tc_polymorphic.rb
og-0.26.0 test/og/tc_polymorphic.rb