Merge branch 'master' of github.com:diaspora/diaspora_rails
This commit is contained in:
commit
ddf3a07f76
4 changed files with 80 additions and 1 deletions
|
|
@ -1,3 +1,26 @@
|
|||
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
|
||||
|
|
|
|||
|
|
@ -32,8 +32,9 @@ module Diaspora
|
|||
|
||||
objects.each do |p|
|
||||
if p.is_a? Retraction
|
||||
|
||||
p.perform
|
||||
elsif p.is_a? Friend
|
||||
p.save
|
||||
#This line checks if the sender was in the database, among other things?
|
||||
elsif p.respond_to?(:person) && !(p.person.nil?) #WTF
|
||||
p.save
|
||||
|
|
@ -64,6 +65,19 @@ module Diaspora
|
|||
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
|
||||
"<post>#{self.to_xml.to_s}</post>"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -108,7 +108,21 @@ describe "parser in application helper" do
|
|||
store_objects_from_xml( request )
|
||||
StatusMessage.count.should == 0
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,32 @@
|
|||
require 'spec_helper'
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue