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

DG IZ; starting fresh with requests

parent f71b5b51
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
class FriendRequest class FriendRequest
include MongoMapper::Document
key :recipient_url
attr_accessor :sender
validates_presence_of :recipient_url
after_create :send_off
def send_off
sender = Friend.from_xml( self.sender.to_xml )
sender.push_to_url self.recipient_url
end
end end
= form_for @friend_request do |f| = form_for @friend_request do |f|
= f.error_messages = f.error_messages
= f.fields_for :recipient do |r|
%p
= r.label :email
= r.text_field :email
%p
= r.label :url
= r.text_field :url
%p %p
= f.submit f.submit
%li.message{:id => post.id} %li.message{:id => friend_request.id}
= post.inspect = friend_request.inspect
%h2= post.sender.is_a? User
= form_for @friend_request, :remote => true do |f| = form_for @friend_request, :remote => true do |f|
= f.error_messages = f.error_messages
= f.fields_for :recipient do |r|
%p
= r.label :email
= r.text_field :email
%p
= r.label :url
= r.text_field :url
%p %p
= f.submit = f.submit
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
= render "friend_requests/new_friend_request", :friend_request => @friend_request = render "friend_requests/new_friend_request", :friend_request => @friend_request
%ul#stream %ul#stream
- for friend_request in @friend_requests - for friend_request in @friend_requests
= render "friend_request", :post => friend_request = render "friend_request", :friend_request => friend_request
#pagination #pagination
= will_paginate @friend_requests = will_paginate @friend_requests
- title "Friend Request" - title "Friend Request"
%p %p
%strong Recipient: = friend_request.inspect
= @friend_request.recipient
%p
%strong Sender:
= @friend_request.sender
%p %p
= link_to "Edit", edit_friend_request_path(@bookmark) = link_to "Edit", edit_friend_request_path(@bookmark)
......
...@@ -34,8 +34,6 @@ module Diaspora ...@@ -34,8 +34,6 @@ module Diaspora
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
...@@ -65,15 +63,6 @@ module Diaspora ...@@ -65,15 +63,6 @@ module Diaspora
@@queue.process @@queue.process
end end
end end
def push_to_url(url)
if url
url = url + "receive/"
xml = self.class.build_xml_for([self])
@@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>"
......
...@@ -109,16 +109,6 @@ describe "parser in application helper" do ...@@ -109,16 +109,6 @@ describe "parser in application helper" do
StatusMessage.count.should == 0 StatusMessage.count.should == 0
end end
it 'should marshal friend requests' do
sender = Factory.build(:user, :email => "bob@aol.com", :url => "http://google.com/")
recipient = Factory.build(:person, :email => "robert@grimm.com", :url => "http://localhost:3000/")
friend_request = FriendRequest.new(:sender => sender, :recipient => recipient)
xml_request = Post.build_xml_for([friend_request])
FriendRequest.count.should be 0
store_objects_from_xml( xml_request )
FriendRequest.count.should be 1
end
end end
end end
require 'spec_helper' require 'spec_helper'
describe FriendRequest do 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://localhost:3000/")
@request = FriendRequest.create(:sender => sender, :recipient => recipient)
end
it 'should have sender and recipient credentials after serialization' do
xml = @request.to_xml.to_s
xml.include?(@request.sender.url).should be true
xml.include?(@request.sender.email).should be true
xml.include?(@request.recipient.url).should be true
xml.include?(@request.recipient.email).should be true
end
describe "acceptance" do
it 'should create a friend' do
Friend.count.should be 0
@request.accept
Friend.count.should be 1
end
it 'should remove the request' do
FriendRequest.count.should be 1
@request.accept
FriendRequest.count.should be 0
end
end
describe "rejection" do
it 'should not create a friend' do
Friend.count.should be 0
@request.reject
Friend.count.should be 0
end
it 'should remove the request' do
FriendRequest.count.should be 1
@request.reject
FriendRequest.count.should be 0
end
end
it 'should dispatch upon creation' do
FriendRequest.send(:class_variable_get, :@@queue).should_receive(:add_post_request)
sender = Factory.build(:user, :email => "bob@aol.com", :url => "http://google.com/")
recipient = Factory.build(:person, :email => "robert@grimm.com", :url => "http://localhost:3000/")
FriendRequest.create(:sender => sender, :recipient => recipient)
end
end end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter