test/og/tc_finder.rb in og-0.25.0 vs test/og/tc_finder.rb in og-0.26.0
- old
+ new
@@ -9,10 +9,11 @@
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
@@ -26,8 +27,27 @@
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