Skip to content
Extraits de code Groupes Projets
Valider ddf3a07f rédigé par root's avatar root
Parcourir les fichiers

Merge branch 'master' of github.com:diaspora/diaspora_rails

parents 9cbc9635 d5d4d4ae
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
class FriendRequest class FriendRequest
include MongoMapper::Document
include Diaspora::Webhooks
key :url, String
attr_accessor :sender
validates_presence_of :url
before_save :shoot_off
def to_friend_xml
friend = Friend.new
friend.email = sender.email
friend.url = sender.url
friend.profile = sender.profile.clone
friend.to_xml
end
def shoot_off
push_friend_request_to_url(self.url)
end
end end
...@@ -32,8 +32,9 @@ module Diaspora ...@@ -32,8 +32,9 @@ module Diaspora
objects.each do |p| objects.each do |p|
if p.is_a? Retraction if p.is_a? Retraction
p.perform p.perform
elsif p.is_a? Friend
p.save
#This line checks if the sender was in the database, among other things? #This line checks if the sender was in the database, among other things?
elsif p.respond_to?(:person) && !(p.person.nil?) #WTF elsif p.respond_to?(:person) && !(p.person.nil?) #WTF
p.save p.save
...@@ -64,6 +65,19 @@ module Diaspora ...@@ -64,6 +65,19 @@ module Diaspora
end end
end end
def push_friend_request_to_url(url)
if url
url = url + "receive/"
xml = "<XML>
<posts><post>
#{self.to_friend_xml.to_s}
</post></posts>
</XML>"
@@queue.add_post_request( [url], xml )
@@queue.process
end
end
def prep_webhook def prep_webhook
"<post>#{self.to_xml.to_s}</post>" "<post>#{self.to_xml.to_s}</post>"
end end
......
...@@ -108,7 +108,21 @@ describe "parser in application helper" do ...@@ -108,7 +108,21 @@ describe "parser in application helper" do
store_objects_from_xml( request ) store_objects_from_xml( request )
StatusMessage.count.should == 0 StatusMessage.count.should == 0
end end
it "should create a new friend upon getting a friend request" do
friend_request = FriendRequest.new(:url => "http://www.googles.com/")
friend_request.sender = @friend
xml = "<XML>
<posts><post>
#{friend_request.to_friend_xml.to_s}
</post></posts>
</XML>"
@friend.destroy
Friend.count.should be 0
store_objects_from_xml(xml)
Friend.count.should be 1
end
end end
end end
require 'spec_helper' require 'spec_helper'
describe FriendRequest do describe FriendRequest do
it 'should require a url' do
friend_request = FriendRequest.new
friend_request.valid?.should be false
friend_request.url = "http://google.com/"
friend_request.valid?.should be true
end
it 'should generate xml for the User as a Friend' do
friend_request = FriendRequest.new(:url => "http://www.google.com")
user = Factory.create(:user)
friend_request.sender = user
friend_xml = friend_request.to_friend_xml.to_s
friend_xml.include?(user.email).should be true
friend_xml.include?(user.url).should be true
friend_xml.include?(user.profile.first_name).should be true
friend_xml.include?(user.profile.last_name).should be true
end
it 'should be sent to the url upon save' do
FriendRequest.send(:class_variable_get, :@@queue).should_receive(:add_post_request)
friend_request = FriendRequest.new(:url => "http://www.google.com")
friend_request.sender = Factory.create(:user)
friend_request.save
end
end end
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