From a23a2691f30fe9e60e4b8f84e8dcdce3dbe0a18e Mon Sep 17 00:00:00 2001 From: ilya Date: Tue, 6 Jul 2010 20:09:20 -0400 Subject: [PATCH] DG IZ; starting fresh with requests --- app/models/friend_request.rb | 15 ------ app/views/friend_requests/_form.html.haml | 10 +--- .../friend_requests/_friend_request.html.haml | 5 +- .../friend_requests/_new_friend_request.haml | 8 ---- app/views/friend_requests/index.html.haml | 2 +- app/views/friend_requests/show.html.haml | 6 +-- lib/common.rb | 11 ----- spec/lib/parser_spec.rb | 10 ---- spec/models/friend_request_spec.rb | 48 ------------------- 9 files changed, 5 insertions(+), 110 deletions(-) diff --git a/app/models/friend_request.rb b/app/models/friend_request.rb index 7c18808b2..46fc65124 100644 --- a/app/models/friend_request.rb +++ b/app/models/friend_request.rb @@ -1,18 +1,3 @@ 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 diff --git a/app/views/friend_requests/_form.html.haml b/app/views/friend_requests/_form.html.haml index 1841efd8a..f9d962221 100644 --- a/app/views/friend_requests/_form.html.haml +++ b/app/views/friend_requests/_form.html.haml @@ -1,13 +1,5 @@ = form_for @friend_request do |f| = 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 - = f.submit + f.submit diff --git a/app/views/friend_requests/_friend_request.html.haml b/app/views/friend_requests/_friend_request.html.haml index 29e437cb6..f61edbeca 100644 --- a/app/views/friend_requests/_friend_request.html.haml +++ b/app/views/friend_requests/_friend_request.html.haml @@ -1,4 +1,3 @@ -%li.message{:id => post.id} +%li.message{:id => friend_request.id} - = post.inspect - %h2= post.sender.is_a? User + = friend_request.inspect diff --git a/app/views/friend_requests/_new_friend_request.haml b/app/views/friend_requests/_new_friend_request.haml index 598f718d2..f208c8ff4 100644 --- a/app/views/friend_requests/_new_friend_request.haml +++ b/app/views/friend_requests/_new_friend_request.haml @@ -1,12 +1,4 @@ = form_for @friend_request, :remote => true do |f| = 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 = f.submit diff --git a/app/views/friend_requests/index.html.haml b/app/views/friend_requests/index.html.haml index df91365ea..c7091fcbf 100644 --- a/app/views/friend_requests/index.html.haml +++ b/app/views/friend_requests/index.html.haml @@ -2,6 +2,6 @@ = render "friend_requests/new_friend_request", :friend_request => @friend_request %ul#stream - for friend_request in @friend_requests - = render "friend_request", :post => friend_request + = render "friend_request", :friend_request => friend_request #pagination = will_paginate @friend_requests diff --git a/app/views/friend_requests/show.html.haml b/app/views/friend_requests/show.html.haml index 5830e6c99..e4a482156 100644 --- a/app/views/friend_requests/show.html.haml +++ b/app/views/friend_requests/show.html.haml @@ -1,11 +1,7 @@ - title "Friend Request" %p - %strong Recipient: - = @friend_request.recipient -%p - %strong Sender: - = @friend_request.sender + = friend_request.inspect %p = link_to "Edit", edit_friend_request_path(@bookmark) diff --git a/lib/common.rb b/lib/common.rb index 5c66a6b2f..05f5243c3 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -34,8 +34,6 @@ module Diaspora 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 @@ -65,15 +63,6 @@ module Diaspora @@queue.process 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 "#{self.to_xml.to_s}" diff --git a/spec/lib/parser_spec.rb b/spec/lib/parser_spec.rb index 8da1fc0f4..bb71b6783 100644 --- a/spec/lib/parser_spec.rb +++ b/spec/lib/parser_spec.rb @@ -109,16 +109,6 @@ describe "parser in application helper" do 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 f72ed6320..72aede297 100644 --- a/spec/models/friend_request_spec.rb +++ b/spec/models/friend_request_spec.rb @@ -1,52 +1,4 @@ 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://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