diff --git a/app/controllers/friend_requests_controller.rb b/app/controllers/friend_requests_controller.rb new file mode 100644 index 000000000..3cb6a1b2b --- /dev/null +++ b/app/controllers/friend_requests_controller.rb @@ -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 diff --git a/app/models/friend_request.rb b/app/models/friend_request.rb index 33de9013f..a977144a0 100644 --- a/app/models/friend_request.rb +++ b/app/models/friend_request.rb @@ -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 diff --git a/app/views/friend_requests/_form.html.haml b/app/views/friend_requests/_form.html.haml new file mode 100644 index 000000000..e62bd4531 --- /dev/null +++ b/app/views/friend_requests/_form.html.haml @@ -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 diff --git a/app/views/friend_requests/_friend_request.html.haml b/app/views/friend_requests/_friend_request.html.haml new file mode 100644 index 000000000..9e58d056f --- /dev/null +++ b/app/views/friend_requests/_friend_request.html.haml @@ -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 diff --git a/app/views/friend_requests/_new_friend_request.haml b/app/views/friend_requests/_new_friend_request.haml new file mode 100644 index 000000000..0195ccbed --- /dev/null +++ b/app/views/friend_requests/_new_friend_request.haml @@ -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 diff --git a/app/views/friend_requests/edit.html.haml b/app/views/friend_requests/edit.html.haml new file mode 100644 index 000000000..11421d0ba --- /dev/null +++ b/app/views/friend_requests/edit.html.haml @@ -0,0 +1,8 @@ +- title "Edit Bookmark" + += render 'form' + +%p + = link_to "Show", bookmark_path(@bookmark) + | + = link_to "View All", bookmarks_path diff --git a/app/views/friend_requests/index.html.haml b/app/views/friend_requests/index.html.haml new file mode 100644 index 000000000..df91365ea --- /dev/null +++ b/app/views/friend_requests/index.html.haml @@ -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 diff --git a/app/views/friend_requests/new.html.haml b/app/views/friend_requests/new.html.haml new file mode 100644 index 000000000..c799efe57 --- /dev/null +++ b/app/views/friend_requests/new.html.haml @@ -0,0 +1,5 @@ +- title "New Friend Request" + += render 'form' + +%p= link_to "Back to List", friend_requests_path diff --git a/app/views/friend_requests/show.html.haml b/app/views/friend_requests/show.html.haml new file mode 100644 index 000000000..4b22ba43a --- /dev/null +++ b/app/views/friend_requests/show.html.haml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 09c43db14..08947f594 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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, diff --git a/lib/common.rb b/lib/common.rb index 6fc51ff2c..786a711c5 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -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 diff --git a/lib/message_handler.rb b/lib/message_handler.rb index 10268e1bc..ccd1456bc 100644 --- a/lib/message_handler.rb +++ b/lib/message_handler.rb @@ -37,8 +37,7 @@ class MessageHandler } } unless @queue.size == 0 end - - + def send_to_seed(message, http_response) #DO SOMETHING! end diff --git a/spec/lib/parser_spec.rb b/spec/lib/parser_spec.rb index 0205049f4..8da1fc0f4 100644 --- a/spec/lib/parser_spec.rb +++ b/spec/lib/parser_spec.rb @@ -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 diff --git a/spec/models/friend_request_spec.rb b/spec/models/friend_request_spec.rb index ed256fd3c..f72ed6320 100644 --- a/spec/models/friend_request_spec.rb +++ b/spec/models/friend_request_spec.rb @@ -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