Skip to content
Extraits de code Groupes Projets
Valider 027d953c rédigé par ilya's avatar ilya
Parcourir les fichiers

DG IZ added the FriendRequest model.

parent b1ca01ed
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
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
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
...@@ -11,8 +11,8 @@ describe Person do ...@@ -11,8 +11,8 @@ describe Person do
user = Factory.create(:user) user = Factory.create(:user)
friend = Factory.build(:friend, :url => user.url) friend = Factory.build(:friend, :url => user.url)
friend.valid?.should == false friend.valid?.should == false
end end
it 'should serialize to xml' do it 'should serialize to xml' do
friend_one = Factory.create(:friend) friend_one = Factory.create(:friend)
xml = friend_one.to_xml.to_s xml = friend_one.to_xml.to_s
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter