Skip to content

Instantly share code, notes, and snippets.

@royw
Created September 22, 2009 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save royw/190973 to your computer and use it in GitHub Desktop.
Save royw/190973 to your computer and use it in GitHub Desktop.
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