DG IZ added the FriendRequest model.

This commit is contained in:
ilya 2010-07-05 23:28:14 -04:00
parent b1ca01edb4
commit 027d953cf4
3 changed files with 72 additions and 1 deletions

View file

@ -0,0 +1,25 @@
class FriendRequest
include MongoMapper::Document
include ROXML
xml_accessor :sender, :as => Person
xml_accessor :recipient, :as => Person
key :sender, Person
key :recipient, Person
validates_presence_of :sender, :recipient
def accept
f = Friend.new
f.email = self.sender.email
f.url = self.sender.url
f.save
self.destroy
end
def reject
self.destroy
end
end

View file

@ -0,0 +1,46 @@
require 'spec_helper'
describe FriendRequest do
before do
sender = Factory.build(:user, :email => "bob@aol.com", :url => "http://google.com/")
recipient = Factory.build(:person, :email => "robert@grimm.com", :url => "http://robert.com")
@r = FriendRequest.create(:sender => sender, :recipient => recipient)
end
it 'should have sender and recipient credentials after serialization' do
xml = @r.to_xml.to_s
xml.include?(@r.sender.url).should be true
xml.include?(@r.sender.email).should be true
xml.include?(@r.recipient.url).should be true
xml.include?(@r.recipient.email).should be true
end
describe "acceptance" do
it 'should create a friend' do
Friend.count.should be 0
@r.accept
Friend.count.should be 1
end
it 'should remove the request' do
FriendRequest.count.should be 1
@r.accept
FriendRequest.count.should be 0
end
end
describe "rejection" do
it 'should not create a friend' do
Friend.count.should be 0
@r.reject
Friend.count.should be 0
end
it 'should remove the request' do
FriendRequest.count.should be 1
@r.reject
FriendRequest.count.should be 0
end
end
end

View file

@ -11,8 +11,8 @@ describe Person do
user = Factory.create(:user)
friend = Factory.build(:friend, :url => user.url)
friend.valid?.should == false
end
it 'should serialize to xml' do
friend_one = Factory.create(:friend)
xml = friend_one.to_xml.to_s