Sha256: af1543a6520f4f704056e4f041387b69f6686e31f0e99fd1fe034ff2e4ad9396

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

$:.unshift File.join(File.dirname(__FILE__), 'lib')

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(
			:destroy => true,
			:store => :sqlite,
			:name => 'test'
		)		
	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

2 entries across 2 versions & 1 rubygems

Version Path
og-0.19.0 test/og/tc_polymorphic.rb
og-0.20.0 test/og/tc_polymorphic.rb