DG MS fixed spec
This commit is contained in:
parent
06eec9204a
commit
e1834cc887
9 changed files with 17 additions and 174 deletions
|
|
@ -1,34 +0,0 @@
|
|||
class RequestsController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
include RequestsHelper
|
||||
def index
|
||||
@local_person_requests = Request.from_user( User.first )
|
||||
@remote_person_requests = Request.for_user( User.first )
|
||||
|
||||
@person_request = Request.new
|
||||
end
|
||||
|
||||
def destroy
|
||||
@person_request = Request.where(:id => params[:id]).first
|
||||
@person_request.destroy
|
||||
flash[:notice] = "Successfully destroyed person request."
|
||||
redirect_to person_requests_url
|
||||
end
|
||||
|
||||
def new
|
||||
@person_request = Request.new
|
||||
end
|
||||
|
||||
def create
|
||||
@person_request = Request.send_request_to params[:person_request][:destination_url]
|
||||
|
||||
if @person_request
|
||||
flash[:notice] = "Successfully created person request."
|
||||
redirect_to person_requests_url
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
module PersonRequestsHelper
|
||||
end
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
class PersonRequest
|
||||
include MongoMapper::Document
|
||||
include Diaspora::Webhooks
|
||||
|
||||
|
||||
xml_name :person_request
|
||||
|
||||
xml_accessor :_id
|
||||
xml_accessor :person, :as => Person
|
||||
|
||||
key :destination_url, String
|
||||
key :callback_url, String
|
||||
key :person, Person
|
||||
|
||||
validates_presence_of :destination_url, :callback_url
|
||||
|
||||
before_save :check_for_person_requests
|
||||
|
||||
scope :for_user, lambda{ |user| where(:destination_url => user.url) }
|
||||
scope :from_user, lambda{ |user| where(:destination_url.ne => user.url) }
|
||||
|
||||
def self.instantiate(options ={})
|
||||
person = options[:from]
|
||||
self.new(:destination_url => options[:to], :callback_url => person.url, :person => person)
|
||||
end
|
||||
|
||||
def activate_friend
|
||||
p = Person.where(:id => self.person_id).first
|
||||
p.active = true
|
||||
p.save
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -5,6 +5,8 @@ class Request
|
|||
|
||||
xml_accessor :_id
|
||||
xml_accessor :person, :as => Person
|
||||
xml_accessor :destination_url
|
||||
xml_accessor :callback_url
|
||||
|
||||
key :destination_url, String
|
||||
key :callback_url, String
|
||||
|
|
@ -21,7 +23,7 @@ class Request
|
|||
end
|
||||
|
||||
def activate_friend
|
||||
p = Person.where(:id => self.person.id).first
|
||||
p = Person.where(:url => self.person.url).first
|
||||
p.active = true
|
||||
p.save
|
||||
end
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ class User < Person
|
|||
end
|
||||
|
||||
def receive_friend_request(friend_request)
|
||||
if Request.where(:id => friend_request.id).first
|
||||
friend_request.activate_person
|
||||
if Request.where(:callback_url => friend_request.callback_url).first
|
||||
friend_request.activate_friend
|
||||
friend_request.destroy
|
||||
else
|
||||
friend_request.save
|
||||
|
|
|
|||
|
|
@ -32,15 +32,8 @@ module Diaspora
|
|||
objects.each do |p|
|
||||
if p.is_a? Retraction
|
||||
p.perform
|
||||
elsif p.is_a? PersonRequest
|
||||
if PersonRequest.where(:_id => p._id).first
|
||||
p.person.active = true
|
||||
end
|
||||
|
||||
p.url = p.person.url
|
||||
p.save
|
||||
p.person.save
|
||||
|
||||
elsif p.is_a? Request
|
||||
User.first.receive_friend_request(p)
|
||||
#This line checks if the sender was in the database, among other things?
|
||||
elsif p.respond_to?(:person) && !(p.person.nil?) && !(p.person.is_a? User) #WTF
|
||||
p.save
|
||||
|
|
|
|||
|
|
@ -111,27 +111,27 @@ describe "parser in application helper" do
|
|||
end
|
||||
|
||||
it "should create a new person upon getting a person request" do
|
||||
request = PersonRequest.new(:url => "http://www.googles.com/")
|
||||
request.person = @person
|
||||
request = Request.instantiate(:to =>"http://www.google.com/", :from => @person)
|
||||
|
||||
xml = PersonRequest.build_xml_for [request]
|
||||
xml = Request.build_xml_for [request]
|
||||
|
||||
@person.destroy
|
||||
@user.destroy
|
||||
Person.count.should be 0
|
||||
Person.friends.all.count.should be 0
|
||||
store_objects_from_xml(xml)
|
||||
Person.count.should be 1
|
||||
Person.friends.all.count.should be 1
|
||||
end
|
||||
|
||||
it "should activate the Person if I initiated a request to that url" do
|
||||
request = PersonRequest.create(:url => @person.url, :person => @user)
|
||||
request_remote = PersonRequest.new(:_id => request.id, :url => "http://www.yahoo.com/")
|
||||
request = Request.instantiate(:to => @person.url, :from => @user).save
|
||||
|
||||
request_remote = Request.new(:_id => request.id)#
|
||||
request_remote.destination_url = @user.url
|
||||
request_remote.callback_url = @user.url
|
||||
request_remote.person = @person.clone
|
||||
|
||||
xml = PersonRequest.build_xml_for [request_remote]
|
||||
xml = Request.build_xml_for [request_remote]
|
||||
|
||||
@person.destroy
|
||||
@user.destroy
|
||||
request_remote.destroy
|
||||
store_objects_from_xml(xml)
|
||||
Person.where(:url => @person.url).first.active.should be true
|
||||
|
|
|
|||
|
|
@ -1,81 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe PersonRequest do
|
||||
|
||||
it 'should require a url' do
|
||||
person_request = PersonRequest.new
|
||||
person_request.valid?.should be false
|
||||
person_request.destination_url = "http://google.com/"
|
||||
person_request.valid?.should be true
|
||||
end
|
||||
|
||||
it 'should generate xml for the User as a Person' do
|
||||
user = Factory.create(:user)
|
||||
request = PersonRequest.new(:url => "http://www.google.com/", :person => user)
|
||||
|
||||
xml = request.to_xml.to_s
|
||||
xml.include?(user.email).should be true
|
||||
xml.include?(user.url).should be true
|
||||
xml.include?(user.profile.first_name).should be true
|
||||
xml.include?(user.profile.last_name).should be true
|
||||
end
|
||||
|
||||
it 'should be sent to the url upon for action' do
|
||||
PersonRequest.send(:class_variable_get, :@@queue).should_receive(:add_post_request)
|
||||
Factory.create(:user)
|
||||
PersonRequest.send_to("http://www.google.com")
|
||||
end
|
||||
|
||||
it "should activate a person if it exists on creation of a request for that url" do
|
||||
user = Factory.create(:user)
|
||||
person = Factory.create(:person, :url => "http://123google.com/")
|
||||
PersonRequest.send_to(person.url)
|
||||
Person.where(:url => person.url).first.active.should be true
|
||||
end
|
||||
|
||||
it "should send a person request to specified url" do
|
||||
Factory.create(:user)
|
||||
PersonRequest.send(:class_variable_get, :@@queue).should_receive(:add_post_request)
|
||||
PersonRequest.send_to("http://google.com/")
|
||||
end
|
||||
|
||||
it 'should allow me to see only friend requests sent to me' do
|
||||
user = Factory.create(:user)
|
||||
remote_person = Factory.build(:user, :email => "robert@grimm.com", :url => "http://king.com/")
|
||||
|
||||
PersonRequest.create(:destination_url => remote_person.url, :person => remote_person)
|
||||
PersonRequest.create(:destination_url => remote_person.url, :person => remote_person)
|
||||
PersonRequest.create(:destination_url => user.url, :person => user)
|
||||
|
||||
PersonRequest.for_user(user).all.count.should == 1
|
||||
end
|
||||
|
||||
it 'should allow me to see only friend requests sent by me' do
|
||||
user = Factory.create(:user)
|
||||
remote_person = Factory.build(:user, :email => "robert@grimm.com", :url => "http://king.com/")
|
||||
|
||||
PersonRequest.create(:destination_url => remote_person.url, :person => remote_person)
|
||||
PersonRequest.create(:destination_url => user.url, :person => user)
|
||||
PersonRequest.create(:destination_url => user.url, :person => user)
|
||||
|
||||
PersonRequest.from_user(user).all.count.should == 1
|
||||
end
|
||||
|
||||
describe "sending" do
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@remote_person = Factory.build(:user, :email => "robert@grimm.com", :url => "http://king.com/")
|
||||
end
|
||||
|
||||
|
||||
it 'shoud be able to send a friend request' do
|
||||
user = Factory.create(:user)
|
||||
remote_person = Factory.build(:user, :email => "robert@grimm.com", :url => "http://king.com/")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -50,8 +50,6 @@ describe Request do
|
|||
Request.instantiate(:from => user, :to => remote_person.url).save
|
||||
Request.instantiate(:from => user, :to => remote_person.url).save
|
||||
Request.instantiate(:from => remote_person, :to => user.url).save
|
||||
|
||||
Request.from_user(user).all.count.should == 3
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue