Created
October 15, 2008 17:48
-
-
Save revelation/16968 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 File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) | |
describe DataMapper::Associations 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 | |
@relationship = Car.relationships[:engine] | |
end | |
it "should respond to #has" do | |
Car.should respond_to(:has) | |
end | |
describe "#has" do | |
it "should return a DataMapper::Associations::Relationship" do | |
@relationship.should be_an_instance_of(DataMapper::Associations::Relationship) | |
end | |
it "should raise an ArgumentError if the cardinality is not understood" do | |
lambda do | |
class BadCar | |
include DataMapper::Resource | |
has n..n, :doors | |
end | |
end.should raise_error(ArgumentError) | |
end | |
describe "1" do | |
it "should create a relationship with Engine" do | |
@relationship.child_model.should == Engine | |
end | |
it "should return a OneToOne relationship" | |
end | |
describe "n" do | |
before(:each) do | |
class Car | |
include DataMapper::Resource | |
property :id, Serial | |
has n, :doors | |
end | |
class Door | |
include DataMapper::Resource | |
property :id, Serial | |
belongs_to :car | |
end | |
@car = Car.new | |
@relationship = Car.relationships[:doors] | |
end | |
it "should return a OneToMany relationship" | |
end | |
end | |
it "should respond to #belongs_to" do | |
Engine.should respond_to(:belongs_to) | |
end | |
describe "#belongs_to" do | |
it "should create a new relationship" do | |
Engine.relationships[:car].should be_a_kind_of(DataMapper::Associations::Relationship) | |
end | |
it "should create a relationship with Car" do | |
Engine.relationships[:car].parent_model.should == Car | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment