test/structure_test.rb in structure-0.14.1 vs test/structure_test.rb in structure-0.15.0
- old
+ new
@@ -1,28 +1,18 @@
-$:.push File.expand_path('../../lib', __FILE__)
+require File.expand_path('../helper.rb', __FILE__)
-require 'rubygems'
-require 'bundler/setup'
-
-begin
- require 'ruby-debug'
-rescue LoadError
-end
-
-require 'structure'
-require 'test/unit'
-
class Book < Structure
key :title
key :published, Boolean, :default => true
key :pages, Integer
end
class Person < Structure
key :name
one :partner
many :friends
+ many :parents, :default => 2.times.map { Person.new }
end
class TestStructure < Test::Unit::TestCase
def test_enumeration
assert_respond_to Book.new, :map
@@ -99,9 +89,14 @@
person = Person.new
friend = Person.new
person.friends << person
assert_equal 1, person.friends.count
assert_equal 0, friend.friends.count
+ end
+
+ def test_many
+ person = Person.new
+ assert_equal 2, person.parents.size
end
def test_json
book = Book.new(:title => 'Foo')
json = book.to_json