Skip to content

Instantly share code, notes, and snippets.

@revelation
Created October 14, 2008 03:15
Show Gist options
  • Save revelation/16660 to your computer and use it in GitHub Desktop.
Save revelation/16660 to your computer and use it in GitHub Desktop.
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
describe DataMapper::Associations do
describe "#has" do
before do
class Car
include DataMapper::Resource
property :id, Serial
has 1, :engine
end
class Engine
include DataMapper::Resource
property :id, Serial
belongs_to :car
end
end
it "should raise an error when has n..n is specified" do
lambda do
class BadCar
include DataMapper::Resource
has n..n, :pistons
end
end.should raise_error(ArgumentError)
end
describe "1" do
it "should create a new parent child relationship" do
c = Car.new
c.should respond_to(:engine)
c.should respond_to(:engine=)
end
end
describe "n" do
before(:each) do
class Car
include DataMapper::Resource
property :id, Serial
has 4, :doors
end
class Door
include DataMapper::Resource
property :id, Serial
belongs_to :car
end
end
it "should create a new one to many relationship" do
end
end
end
describe "#belongs_to" do
it "should create a new child parent relationship" do
e = Engine.new
e.should respond_to(:car)
e.should respond_to(:car=)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment