Created
June 6, 2011 19:30
-
-
Save Ragmaanir/1010908 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 "dm_spec" | |
require 'dm-core' | |
require 'dm-migrations' | |
require 'dm-types' | |
require 'dm-validations' | |
require 'dm-timestamps' | |
describe DmSpec do | |
before(:all) do | |
DataMapper.setup(:default, 'sqlite::memory:') | |
class User | |
include DataMapper::Resource | |
property :id, Serial | |
has n, :friendship_requests,'FriendshipRequest', :child_key => [ :sender_id ] | |
has n, :friendship_offers, 'FriendshipRequest', :child_key => [ :receiver_id ] | |
has n, :friendships_requested, 'Friendship', :child_key => [:user_id] | |
has n, :friendships_offered, 'Friendship', :child_key => [:friend_id] | |
end | |
class FriendshipRequest | |
include DataMapper::Resource | |
belongs_to :sender, 'User', :key => true | |
belongs_to :receiver, 'User', :key => true | |
has 1, :friendship, :child_key => [:user_id,:friend_id] | |
end | |
class Friendship | |
include DataMapper::Resource | |
belongs_to :user, 'User', :key => true | |
belongs_to :friend, 'User', :key => true | |
belongs_to :request, 'FriendshipRequest' #, :child_key => [:sender_id,:receiver_id] | |
end | |
DataMapper.auto_migrate! | |
end | |
describe 'Friendship' do | |
it do | |
user = User.create | |
friend = User.create | |
req = FriendshipRequest.create(:sender => user, :receiver => friend) | |
fs = Friendship.create(:user => user, :friend => friend, :request => req) | |
fs.request.should == req | |
fs.reload | |
# Since the request-property is not present in the DB, it is set to nil | |
fs.request.should_not be_nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment