Created
September 22, 2009 10:32
-
-
Save royw/190973 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'dm-core' | |
require 'spec' | |
# run: spec -cfs 1-n.rb | |
DataMapper::Logger.new(STDOUT, :debug) | |
DataMapper.setup(:default, 'sqlite3::memory:') | |
class Team | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
belongs_to :school, :nullable => true | |
end | |
class School | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
has n, :teams | |
end | |
describe "1:n relationships" do | |
before :all do | |
DataMapper.auto_migrate! | |
end | |
before :each do | |
School.all.each {|o| o.teams.destroy; o.destroy} | |
Team.all.each {|o| o.destroy} | |
@school = School.create(:name => 'Lewisville High School') | |
@team = Team.create(:name => 'Fighting Farmers') | |
end | |
it "should not be associated" do | |
@school.teams.size.should == 0 | |
@team.school.should be_nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment