Sha256: f01446f5a30db42b41ff98a42b731d351b702908845d1bf5df2f88d76d278e52

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

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

require 'test/unit'
require 'ostruct'

require 'og'
require 'og/adapters/sqlite'

if defined?(SQLite3)

class TC_OgSqlite3 < Test::Unit::TestCase # :nodoc: all

	# Forward declaration.

	class Comment; end
	
	class Article
		prop_accessor :name, String
		prop_accessor :age, Fixnum
		has_many :comments, Comment

		def initialize (name = nil, age = nil)
			@name, @age = name, age
		end
	end

	class Comment
		prop_accessor :text, String
		belongs_to :article, Article

		def initialize(text = nil)
			@text = text
		end
	end

	def setup
		config = {
			:adapter => 'sqlite',
			:database => 'test',
			:connection_count => 2 
		}
		
		$DBG = true

		Og::Database.drop_db!(config)
		@og = Og::Database.new(config)
	end

	def teardown
		@og.shutdown
	end

	def test_all
		a = Article.new('gmosx', 30)
		a.save!

		a1 = Article[1]

		assert_equal 'gmosx', a1.name
		assert_equal 30, a1.age
		assert_equal 1, a1.oid

		Article.create('drak', 12)
		Article.create('ekarak', 34)
		Article.create('mario', 53)
		Article.create('elathan', 34)

		articles = Article.all

		assert_equal 5, articles.size

		a3 = Article[3]

		assert_equal 'ekarak', a3.name

		c1 = Comment.new('a comment')
		c1.save!
		a3.add_comment(c1)
		
		a5 = Article[3]
		assert_equal 1, a5.comments.size
	end

end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
og-0.16.0 test/og/adapters/tc_sqlite.rb