require File.join(File.dirname(__FILE__), 'CONFIG.rb') $DBG = true require 'rubygems' require 'facets' require 'test/unit' require 'og' class TC_OgFinder < Test::Unit::TestCase # :nodoc: all class User property :name, String property :age, Fixnum property :father, String end def setup @og = Og.setup($og_config) end def test_all User.find_by_name('tml') User.find_by_name_and_age('tml', 3) User.find_all_by_name_and_age('tml', 3) User.find_all_by_name_and_age('tml', 3, :name_op => 'LIKE', :age_op => '>', :limit => 4) User.find_or_create_by_name_and_age('tml', 3) User.find_or_create_by_name_and_age('stella', 5) User.find_or_create_by_name_and_age('tml', 3) assert_equal 2, User.all.size # Basic check that tml is just right. u = User.find_by_name('tml') assert_equal('tml', u.name) assert_equal(3, u.age) assert_equal(nil, u.father) # Block form initialization works. u2 = User.find_or_create_by_name_and_age('tommy', 9) {|x| x.father = 'jack' } assert_equal('tommy', u2.name) assert_equal(9, u2.age) assert_equal('jack', u2.father) # Doesn't create another object same object. u3 = User.find_or_create_by_name_and_age('tommy', 9) {|x| x.father = 'jack' } assert_equal(1, User.find_all_by_name('tommy').size) end end