MS IZ request specs now PASS
This commit is contained in:
parent
b9718c079b
commit
a45d852f30
7 changed files with 30 additions and 23 deletions
|
|
@ -40,7 +40,7 @@ class User
|
||||||
######### Friend Requesting ###########
|
######### Friend Requesting ###########
|
||||||
def send_friend_request_to(friend_url)
|
def send_friend_request_to(friend_url)
|
||||||
|
|
||||||
unless self.friends.detect{ |x| x.url == friend_url}
|
unless self.friends.detect{ |x| x.receive_url == friend_url}
|
||||||
p = Request.instantiate(:to => friend_url, :from => self.person)
|
p = Request.instantiate(:to => friend_url, :from => self.person)
|
||||||
if p.save
|
if p.save
|
||||||
self.pending_requests << p
|
self.pending_requests << p
|
||||||
|
|
@ -76,8 +76,7 @@ class User
|
||||||
|
|
||||||
def receive_friend_request(friend_request)
|
def receive_friend_request(friend_request)
|
||||||
Rails.logger.debug("receiving friend request #{friend_request.to_json}")
|
Rails.logger.debug("receiving friend request #{friend_request.to_json}")
|
||||||
|
if pending_requests.detect{|req| (req.callback_url == person.receive_url) && (req.destination_url == person.receive_url)}
|
||||||
if Request.where(:callback_url => person.receive_url, :destination_url => person.receive_url).first
|
|
||||||
activate_friend friend_request.person
|
activate_friend friend_request.person
|
||||||
Rails.logger.debug("#{self.real_name}'s friend request has been accepted")
|
Rails.logger.debug("#{self.real_name}'s friend request has been accepted")
|
||||||
friend_request.destroy
|
friend_request.destroy
|
||||||
|
|
|
||||||
|
|
@ -60,17 +60,17 @@ module Diaspora
|
||||||
objects = parse_objects_from_xml(xml)
|
objects = parse_objects_from_xml(xml)
|
||||||
objects.each do |p|
|
objects.each do |p|
|
||||||
Rails.logger.debug("Receiving object:\n#{p.inspect}")
|
Rails.logger.debug("Receiving object:\n#{p.inspect}")
|
||||||
|
|
||||||
if p.is_a? Retraction
|
if p.is_a? Retraction
|
||||||
Rails.logger.debug "Got a retraction for #{p.post_id}"
|
Rails.logger.debug "Got a retraction for #{p.post_id}"
|
||||||
p.perform
|
p.perform
|
||||||
|
|
||||||
elsif p.is_a? Request
|
elsif p.is_a? Request
|
||||||
puts user.pending_requests.count
|
|
||||||
user.receive_friend_request(p)
|
user.receive_friend_request(p)
|
||||||
puts user.pending_requests.count
|
|
||||||
|
|
||||||
elsif p.is_a? Profile
|
elsif p.is_a? Profile
|
||||||
p.save
|
p.save
|
||||||
|
|
||||||
elsif p.respond_to?(:person) && !(p.person.nil?) && !(p.person.is_a? User)
|
elsif p.respond_to?(:person) && !(p.person.nil?) && !(p.person.is_a? User)
|
||||||
Rails.logger.debug("Saving object with success: #{p.save}")
|
Rails.logger.debug("Saving object with success: #{p.save}")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ describe RequestsHelper do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return the correct tag and url for a given address' do
|
it 'should return the correct tag and url for a given address' do
|
||||||
relationship_flow('tom@tom.joindiaspora.com')[:friend].should == 'http://tom.joindiaspora.com/'
|
relationship_flow('tom@tom.joindiaspora.com')[:friend].include?("receive/user").should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
include Diaspora::Parser
|
include Diaspora::Parser
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
describe Diaspora::Parser do
|
describe Diaspora::Parser do
|
||||||
before do
|
before do
|
||||||
@user = Factory.create(:user, :email => "bob@aol.com")
|
@user = Factory.create(:user, :email => "bob@aol.com")
|
||||||
|
|
@ -123,7 +125,8 @@ describe Diaspora::Parser do
|
||||||
Person.all.count.should be 2
|
Person.all.count.should be 2
|
||||||
|
|
||||||
Person.first(:_id => original_person_id).serialized_key.include?("PUBLIC").should be true
|
Person.first(:_id => original_person_id).serialized_key.include?("PUBLIC").should be true
|
||||||
Person.where(:url => request.callback_url).first.id.should == original_person_id
|
url = "http://" + request.callback_url.split("/")[2] + "/"
|
||||||
|
Person.where(:url => url).first.id.should == original_person_id
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not create a new person if the person is already here" do
|
it "should not create a new person if the person is already here" do
|
||||||
|
|
@ -140,19 +143,23 @@ describe Diaspora::Parser do
|
||||||
|
|
||||||
@user2.reload
|
@user2.reload
|
||||||
@user2.person.reload
|
@user2.person.reload
|
||||||
puts @user2.inspect
|
|
||||||
puts @user2.person.inspect
|
|
||||||
@user2.person.serialized_key.include?("PRIVATE").should be true
|
@user2.person.serialized_key.include?("PRIVATE").should be true
|
||||||
|
|
||||||
Person.where(:url => request.callback_url).first.id.should == original_person_id
|
url = "http://" + request.callback_url.split("/")[2] + "/"
|
||||||
|
Person.where(:url => url).first.id.should == original_person_id
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should activate the Person if I initiated a request to that url" do
|
it "should activate the Person if I initiated a request to that url" do
|
||||||
request = Request.instantiate(:to => @person.url, :from => @user).save
|
request = Request.instantiate(:to => @person.receive_url, :from => @user)
|
||||||
|
request.save
|
||||||
|
@user.pending_requests << request
|
||||||
|
@user.save
|
||||||
|
|
||||||
|
|
||||||
request_remote = Request.new
|
request_remote = Request.new
|
||||||
request_remote.destination_url = @user.url
|
request_remote.id = request.id
|
||||||
request_remote.callback_url = @user.url
|
request_remote.destination_url = @user.receive_url
|
||||||
|
request_remote.callback_url = @user.receive_url
|
||||||
request_remote.person = @person
|
request_remote.person = @person
|
||||||
request_remote.exported_key = @person.export_key
|
request_remote.exported_key = @person.export_key
|
||||||
|
|
||||||
|
|
@ -163,6 +170,7 @@ describe Diaspora::Parser do
|
||||||
store_objects_from_xml(xml, @user)
|
store_objects_from_xml(xml, @user)
|
||||||
new_person = Person.first(:url => @person.url)
|
new_person = Person.first(:url => @person.url)
|
||||||
new_person.nil?.should be false
|
new_person.nil?.should be false
|
||||||
|
|
||||||
@user.reload
|
@user.reload
|
||||||
@user.friends.include?(new_person).should be true
|
@user.friends.include?(new_person).should be true
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ describe Comment do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should send a user comment on his own post to lots of people' do
|
it 'should send a user comment on his own post to lots of people' do
|
||||||
allowed_urls = @user_status.people_with_permissions.map{|x| x = x.url + "receive/"}
|
allowed_urls = @user_status.people_with_permissions.map{|x| x = x.receive_url}
|
||||||
message_queue.should_receive(:add_post_request).with(allowed_urls, anything)
|
message_queue.should_receive(:add_post_request).with(allowed_urls, anything)
|
||||||
@user.comment "yo", :on => @user_status
|
@user.comment "yo", :on => @user_status
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,10 @@ describe Request do
|
||||||
user = Factory.create(:user)
|
user = Factory.create(:user)
|
||||||
remote_person = Factory.build(:person, :email => "robert@grimm.com", :url => "http://king.com/")
|
remote_person = Factory.build(:person, :email => "robert@grimm.com", :url => "http://king.com/")
|
||||||
|
|
||||||
Request.instantiate(:from => user.person, :to => remote_person.url).save
|
Request.instantiate(:from => user.person, :to => remote_person.receive_url).save
|
||||||
Request.instantiate(:from => user.person, :to => remote_person.url).save
|
Request.instantiate(:from => user.person, :to => remote_person.receive_url).save
|
||||||
Request.instantiate(:from => user.person, :to => remote_person.url).save
|
Request.instantiate(:from => user.person, :to => remote_person.receive_url).save
|
||||||
Request.instantiate(:from => remote_person, :to => user.url).save
|
Request.instantiate(:from => remote_person, :to => user.receive_url).save
|
||||||
|
|
||||||
Request.for_user(user).all.count.should == 1
|
Request.for_user(user).all.count.should == 1
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ describe User do
|
||||||
describe 'friend requesting' do
|
describe 'friend requesting' do
|
||||||
it "should be able to accept a pending friend request" do
|
it "should be able to accept a pending friend request" do
|
||||||
friend = Factory.create(:person)
|
friend = Factory.create(:person)
|
||||||
r = Request.instantiate(:to => @user.url, :from => friend)
|
r = Request.instantiate(:to => @user.receive_url, :from => friend)
|
||||||
r.save
|
r.save
|
||||||
Person.all.count.should == 2
|
Person.all.count.should == 2
|
||||||
Request.for_user(@user).all.count.should == 1
|
Request.for_user(@user).all.count.should == 1
|
||||||
|
|
@ -39,7 +39,7 @@ describe User do
|
||||||
|
|
||||||
it 'should be able to ignore a pending friend request' do
|
it 'should be able to ignore a pending friend request' do
|
||||||
friend = Factory.create(:person)
|
friend = Factory.create(:person)
|
||||||
r = Request.instantiate(:to => @user.url, :from => friend)
|
r = Request.instantiate(:to => @user.receive_url, :from => friend)
|
||||||
r.save
|
r.save
|
||||||
|
|
||||||
Person.count.should == 2
|
Person.count.should == 2
|
||||||
|
|
@ -58,7 +58,7 @@ describe User do
|
||||||
@user.save
|
@user.save
|
||||||
|
|
||||||
|
|
||||||
@user.send_friend_request_to( friend.url ).should be nil
|
@user.send_friend_request_to( friend.receive_url ).should be nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to give me the terse url for webfinger' do
|
it 'should be able to give me the terse url for webfinger' do
|
||||||
|
|
@ -73,13 +73,13 @@ describe User do
|
||||||
@user.pending_requests.empty?.should be true
|
@user.pending_requests.empty?.should be true
|
||||||
@user.friends.empty?.should be true
|
@user.friends.empty?.should be true
|
||||||
|
|
||||||
request = Request.instantiate(:to => @user.url, :from => person_one)
|
request = Request.instantiate(:to => @user.receive_url, :from => person_one)
|
||||||
person_one.destroy
|
person_one.destroy
|
||||||
@user.receive_friend_request request
|
@user.receive_friend_request request
|
||||||
@user.pending_requests.size.should be 1
|
@user.pending_requests.size.should be 1
|
||||||
@user.friends.size.should be 0
|
@user.friends.size.should be 0
|
||||||
|
|
||||||
request_two = Request.instantiate(:to => @user.url, :from => person_two)
|
request_two = Request.instantiate(:to => @user.receive_url, :from => person_two)
|
||||||
person_two.destroy
|
person_two.destroy
|
||||||
@user.receive_friend_request request_two
|
@user.receive_friend_request request_two
|
||||||
@user.pending_requests.size.should be 2
|
@user.pending_requests.size.should be 2
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue