DG IZ; friend requests pass through the webhook, need to refactor the parser because now the XML does not make sense, no big deal. P.S. WTF is send_to_seed in message_handler

This commit is contained in:
ilya 2010-07-06 02:15:49 -04:00
parent 027d953cf4
commit 0587688d18
14 changed files with 161 additions and 15 deletions

View file

@ -0,0 +1,39 @@
class FriendRequestsController < ApplicationController
before_filter :authenticate_user!
def index
@friend_requests = FriendRequest.paginate :page => params[:page], :order => 'created_at DESC'
@friend_request = FriendRequest.new
@person = Person.new
end
def show
@friend_request = FriendRequest.where(:id => params[:id]).first
end
def destroy
@friend_request = FriendRequest.where(:id => params[:id]).first
@friend_request.destroy
flash[:notice] = "Successfully destroyed friend request."
redirect_to friend_requests_url
end
def new
@friend_request = FriendRequest.new
@receiver = Person.new
end
def create
puts params.inspect
@friend_request = FriendRequest.new(params[:friend_request])
if @friend_request.save
flash[:notice] = "Successfully created friend request."
redirect_to @friend_request
else
render :action => 'new'
end
end
end

View file

@ -1,7 +1,9 @@
class FriendRequest
include MongoMapper::Document
include ROXML
include Diaspora::Webhooks
xml_name :friend_request
xml_accessor :sender, :as => Person
xml_accessor :recipient, :as => Person
@ -9,6 +11,7 @@ class FriendRequest
key :recipient, Person
validates_presence_of :sender, :recipient
after_create :send_off
def accept
f = Friend.new
@ -21,5 +24,9 @@ class FriendRequest
def reject
self.destroy
end
def send_off
push_to [self.recipient]
end
end

View file

@ -0,0 +1,13 @@
= form_for @friend_request do |f|
= f.error_messages
= f.fields_for :receiver do |r|
%p
= r.label :email
= r.text_field :email
%p
= r.label :url
= r.text_field :url
%p
= f.submit

View file

@ -0,0 +1,18 @@
%li.message{:id => post.id, :class => ("mine" if mine?(post))}
%span.from
= link_to_person post.person
%b shared a link
%br
= post.title
%a{:href => "#{post.link}"}
= post.link
%div.time
= link_to(how_long_ago(post), bookmark_path(post))
\--
= link_to "show comments (#{post.comments.count})", '#', :class => "show_post_comments"
= render "comments/comments", :post => post
- if mine?(post)
.destroy_link
= link_to 'Delete', bookmark_path(post), :confirm => 'Are you sure?', :method => :delete, :remote => true

View file

@ -0,0 +1,12 @@
= form_for @friend_request, :remote => true do |f|
= f.error_messages
= f.fields_for :receiver do |r|
%p
= r.label :email
= r.text_field :email
%p
= r.label :url
= r.text_field :url
%p
= f.submit

View file

@ -0,0 +1,8 @@
- title "Edit Bookmark"
= render 'form'
%p
= link_to "Show", bookmark_path(@bookmark)
|
= link_to "View All", bookmarks_path

View file

@ -0,0 +1,7 @@
%h1 friend requests
= render "friend_requests/new_friend_request", :friend_request => @friend_request
%ul#stream
- for friend_request in @friend_requests
= render "friend_request", :post => friend_request
#pagination
= will_paginate @friend_requests

View file

@ -0,0 +1,5 @@
- title "New Friend Request"
= render 'form'
%p= link_to "Back to List", friend_requests_path

View file

@ -0,0 +1,18 @@
- title "Bookmark"
%p
%strong Title:
= @bookmark.title
%p
%strong Link:
= link_to @bookmark.link
%p
%strong Owner:
= @bookmark.person.real_name
%p
= link_to "Edit", edit_bookmark_path(@bookmark)
|
= link_to "Destroy", @bookmark, :confirm => 'Are you sure?', :method => :delete
|
= link_to "View All", bookmarks_path

View file

@ -4,6 +4,8 @@ Diaspora::Application.routes.draw do |map|
resources :friends
resources :status_messages
resources :comments
resources :friend_requests
match 'warzombie', :to => "dashboard#warzombie"
#routes for devise, not really sure you will need to mess with this in the future, lets put default,

View file

@ -34,7 +34,8 @@ module Diaspora
if p.is_a? Retraction
p.perform
elsif p.is_a? FriendRequest
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

View file

@ -37,8 +37,7 @@ class MessageHandler
}
} unless @queue.size == 0
end
def send_to_seed(message, http_response)
#DO SOMETHING!
end

View file

@ -108,6 +108,17 @@ describe "parser in application helper" do
store_objects_from_xml( request )
StatusMessage.count.should == 0
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

View file

@ -3,28 +3,28 @@ 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)
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 = @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
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
@r.accept
@request.accept
Friend.count.should be 1
end
it 'should remove the request' do
FriendRequest.count.should be 1
@r.accept
@request.accept
FriendRequest.count.should be 0
end
end
@ -32,15 +32,21 @@ describe FriendRequest do
describe "rejection" do
it 'should not create a friend' do
Friend.count.should be 0
@r.reject
@request.reject
Friend.count.should be 0
end
it 'should remove the request' do
FriendRequest.count.should be 1
@r.reject
@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