All green except invite connecting +2 misc.
This commit is contained in:
parent
c800b0bfef
commit
590e1fd93f
27 changed files with 262 additions and 616 deletions
|
|
@ -123,7 +123,6 @@ class AspectsController < ApplicationController
|
|||
def manage
|
||||
@aspect = :manage
|
||||
@contacts = current_user.contacts.includes(:person => :profile)
|
||||
@remote_requests = Request.where(:recipient_id => current_user.person.id).includes(:sender => :profile)
|
||||
@aspects = @all_aspects.includes(:contacts => {:person => :profile})
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -17,9 +17,7 @@ class ContactsController < ApplicationController
|
|||
@person = Person.find(params[:person_id])
|
||||
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first
|
||||
|
||||
@contact = request_to_aspect(@aspect, @person)
|
||||
|
||||
if @contact && @contact.persisted?
|
||||
if @contact = share_in_aspect(@aspect, @person)
|
||||
flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success'
|
||||
|
||||
respond_to do |format|
|
||||
|
|
@ -40,15 +38,11 @@ class ContactsController < ApplicationController
|
|||
end
|
||||
|
||||
def edit
|
||||
@all_aspects ||= current_user.aspects
|
||||
@contact = Contact.unscoped.where(:id => params[:id], :user_id => current_user.id).first
|
||||
|
||||
@contact = current_user.contacts.unscoped.find(params[:id])
|
||||
@person = @contact.person
|
||||
@aspects_with_person = []
|
||||
|
||||
if @contact
|
||||
@aspects_with_person = @contact.aspects
|
||||
end
|
||||
@all_aspects ||= current_user.aspects
|
||||
@aspects_with_person = @contact.aspects || []
|
||||
|
||||
@aspects_without_person = @all_aspects - @aspects_with_person
|
||||
|
||||
|
|
@ -56,7 +50,8 @@ class ContactsController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
contact = Contact.unscoped.where(:id => params[:id], :user_id => current_user.id).first
|
||||
contact = current_user.contacts.unscoped.find(params[:id])
|
||||
|
||||
if current_user.disconnect(contact)
|
||||
flash[:notice] = I18n.t('contacts.destroy.success', :name => contact.person.name)
|
||||
else
|
||||
|
|
@ -67,13 +62,7 @@ class ContactsController < ApplicationController
|
|||
|
||||
private
|
||||
|
||||
def request_to_aspect(aspect, person)
|
||||
current_user.send_contact_request_to(person, aspect)
|
||||
contact = current_user.contact_for(person)
|
||||
if request = Request.where(:sender_id => person.id, :recipient_id => current_user.person.id).first
|
||||
request.destroy
|
||||
contact.update_attributes(:pending => false)
|
||||
end
|
||||
contact
|
||||
def share_in_aspect(aspect, person)
|
||||
current_user.share_with(person, aspect)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -39,10 +39,6 @@ class PeopleController < ApplicationController
|
|||
|
||||
def hashes_for_people people, aspects
|
||||
ids = people.map{|p| p.id}
|
||||
requests = {}
|
||||
Request.where(:sender_id => ids, :recipient_id => current_user.person.id).each do |r|
|
||||
requests[r.id] = r
|
||||
end
|
||||
contacts = {}
|
||||
Contact.unscoped.where(:user_id => current_user.id, :person_id => ids).each do |contact|
|
||||
contacts[contact.person_id] = contact
|
||||
|
|
@ -51,7 +47,6 @@ class PeopleController < ApplicationController
|
|||
people.map{|p|
|
||||
{:person => p,
|
||||
:contact => contacts[p.id],
|
||||
:request => requests[p.id],
|
||||
:aspects => aspects}
|
||||
}
|
||||
end
|
||||
|
|
@ -63,17 +58,14 @@ class PeopleController < ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
|
||||
@post_type = :all
|
||||
@aspect = :profile
|
||||
@share_with = (params[:share_with] == 'true')
|
||||
|
||||
if @person
|
||||
|
||||
@profile = @person.profile
|
||||
|
||||
if current_user
|
||||
@incoming_request = current_user.request_from(@person)
|
||||
@contact = current_user.contact_for(@person)
|
||||
@aspects_with_person = []
|
||||
if @contact
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require File.join(Rails.root, 'lib/webfinger')
|
||||
|
||||
class RequestsController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
include RequestsHelper
|
||||
|
||||
respond_to :html
|
||||
|
||||
def destroy
|
||||
if notification = Notification.where(:recipient_id => current_user.id, :target_id=> params[:id]).first
|
||||
notification.update_attributes(:unread=>false)
|
||||
end
|
||||
|
||||
if params[:accept]
|
||||
if params[:aspect_id]
|
||||
@contact = current_user.accept_and_respond( params[:id], params[:aspect_id])
|
||||
flash[:notice] = I18n.t 'requests.destroy.success'
|
||||
respond_with @contact, :location => requests_url
|
||||
else
|
||||
flash[:error] = I18n.t 'requests.destroy.error'
|
||||
respond_with @contact, :location => requests_url
|
||||
end
|
||||
else
|
||||
current_user.ignore_contact_request params[:id]
|
||||
flash[:notice] = I18n.t 'requests.destroy.ignore'
|
||||
head :ok
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
aspect = current_user.aspects.where(:id => params[:request][:into]).first
|
||||
account = params[:request][:to].strip
|
||||
person = Person.by_account_identifier(account)
|
||||
existing_request = Request.where(:sender_id => person.id, :recipient_id => current_user.person.id).first if person
|
||||
if existing_request
|
||||
current_user.accept_and_respond(existing_request.id, aspect.id)
|
||||
redirect_to :back
|
||||
else
|
||||
|
||||
@contact = Contact.new(:user => current_user,
|
||||
:person => person,
|
||||
:aspect_ids => [aspect.id],
|
||||
:pending => true)
|
||||
|
||||
if @contact.save
|
||||
@contact.dispatch_request
|
||||
flash.now[:notice] = I18n.t('requests.create.sent')
|
||||
redirect_to :back
|
||||
else
|
||||
flash.now[:error] = @contact.errors.full_messages.join(', ')
|
||||
redirect_to :back
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -85,9 +85,9 @@ class Invitation < ActiveRecord::Base
|
|||
recipient.invite!
|
||||
end
|
||||
|
||||
def to_request!
|
||||
request = sender.send_contact_request_to(recipient.person, aspect)
|
||||
destroy if request
|
||||
request
|
||||
def share_with!
|
||||
contact = sender.share_with(recipient.person, aspect)
|
||||
destroy if contact
|
||||
contact
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -66,7 +66,10 @@ class Request < ActiveRecord::Base
|
|||
|
||||
def receive(user, person)
|
||||
Rails.logger.info("event=receive payload_type=request sender=#{self.sender} to=#{self.recipient}")
|
||||
user.receive_contact_request(self)
|
||||
|
||||
user.contacts.create(:person_id => person.id, :pending => false)
|
||||
|
||||
#user.receive_contact_request(self)
|
||||
self.save
|
||||
self
|
||||
end
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ class User < ActiveRecord::Base
|
|||
self.password = opts[:password]
|
||||
self.password_confirmation = opts[:password_confirmation]
|
||||
self.save!
|
||||
invitations_to_me.each{|invitation| invitation.to_request!}
|
||||
invitations_to_me.each{|invitation| invitation.share_with!}
|
||||
log_string << "success"
|
||||
Rails.logger.info log_string
|
||||
|
||||
|
|
|
|||
|
|
@ -16,32 +16,7 @@
|
|||
=t('.manage_aspects')
|
||||
|
||||
#manage_aspect_zones
|
||||
.span-4.append-1.last
|
||||
.requests
|
||||
%h3=t('.requests')
|
||||
|
||||
%ul.dropzone
|
||||
- if @remote_requests.size < 1
|
||||
%li=t('.no_requests')
|
||||
- else
|
||||
- for req in @remote_requests
|
||||
%li.person.request{:data=>{:guid=> req.id, :person_id=> req.sender.id}}
|
||||
.delete
|
||||
.x
|
||||
X
|
||||
.circle
|
||||
= link_to person_image_tag(req.sender), req.sender
|
||||
|
||||
- if @remote_requests.size > 0
|
||||
%p
|
||||
%i= "#{t('.drag_to_add')} =>"
|
||||
|
||||
= render 'shared/invitations', :invites => @invites
|
||||
|
||||
%div{:style=>"color:rgb(252,252,252);"}
|
||||
\.
|
||||
|
||||
.span-19.last
|
||||
.span-24.last
|
||||
- for aspect in @aspects
|
||||
.aspect.span-9{:data=>{:guid => aspect.id}}
|
||||
.aspect_name
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@
|
|||
= t('.share_with', :name => person.name)
|
||||
|
||||
.description
|
||||
= t('.accepts', :name => person.first_name)
|
||||
|
||||
= t('.following', :name => person.first_name)
|
||||
|
||||
= render :partial => 'contacts/share_with_list',
|
||||
:locals => {:person => person, :contact => contact,
|
||||
:aspects_with_person => aspects_with_person,
|
||||
:aspects_without_person => aspects_without_person}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,15 +2,6 @@
|
|||
= t('people.person.thats_you')
|
||||
- elsif contact && !contact.pending
|
||||
= t('people.person.already_connected')
|
||||
- elsif (contact && contact.pending) || (request && request.recipient == person)
|
||||
= t('people.person.pending_request')
|
||||
- elsif request && request.sender == person
|
||||
= link_to t('people.show.incoming_request', :name => truncate(person.name, :length => 20, :separator => ' ', :omission => '')),
|
||||
{:controller => "contacts",
|
||||
:action => "new",
|
||||
:person_id => person.id},
|
||||
:class => 'share_with button',
|
||||
:rel => 'facebox'
|
||||
- else
|
||||
= link_to t('people.show.start_sharing'),
|
||||
{:controller => "contacts",
|
||||
|
|
|
|||
|
|
@ -26,14 +26,6 @@
|
|||
#author_info
|
||||
- if user_signed_in? && !(@contact.persisted? || current_user.person == @person)
|
||||
.right
|
||||
- if @incoming_request
|
||||
= link_to t('.incoming_request', :name => truncate(@person.name, :length => 20, :separator => ' ', :omission => '')),
|
||||
{:controller => "contacts",
|
||||
:action => "new",
|
||||
:person_id => @person.id},
|
||||
:class => 'share_with button',
|
||||
:rel => 'facebox'
|
||||
-else
|
||||
= link_to t('.start_sharing'),
|
||||
{:controller => "contacts",
|
||||
:action => "new",
|
||||
|
|
@ -43,7 +35,6 @@
|
|||
- if @share_with
|
||||
= javascript_tag "$(document).ready(function() {jQuery.facebox({ ajax: '#{new_contact_path(:person_id => @person.id)}' });});"
|
||||
|
||||
|
||||
- else
|
||||
- if user_signed_in? && @contact.person && @contact.pending? == false
|
||||
.right
|
||||
|
|
|
|||
|
|
@ -174,12 +174,11 @@ en:
|
|||
failure: "Failed to disconnect from %{name}"
|
||||
share_with_pane:
|
||||
share_with: "Start sharing with %{name}"
|
||||
accepts: "Once %{name} accepts, you'll start seeing each other's posts on Diaspora"
|
||||
following: "By placing %{name} in an aspect, you'll start following and sending posts to them."
|
||||
add_new_aspect: "add to new aspect"
|
||||
create:
|
||||
failure: "Failed to create contact"
|
||||
|
||||
|
||||
conversations:
|
||||
index:
|
||||
message_inbox: "Message Inbox"
|
||||
|
|
|
|||
|
|
@ -68,8 +68,6 @@ Diaspora::Application.routes.draw do
|
|||
get 'bookmarklet' => 'status_messages#bookmarklet'
|
||||
resource :profile
|
||||
|
||||
resources :requests, :only => [:destroy, :create]
|
||||
|
||||
resources :contacts, :except => [:index, :update]
|
||||
resources :aspect_memberships, :only => [:destroy, :create, :update]
|
||||
resources :post_visibilities, :only => [:update]
|
||||
|
|
|
|||
|
|
@ -8,26 +8,23 @@ Feature: sending and receiving requests
|
|||
And I am on "alice@alice.alice"'s page
|
||||
And I press the first ".share_with.button" within "#author_info"
|
||||
And I add the person to my first aspect
|
||||
|
||||
And I am on the home page
|
||||
Given I expand the publisher
|
||||
When I fill in "status_message_fake_text" with "I am following you"
|
||||
And I press "Share"
|
||||
|
||||
Then I go to the destroy user session page
|
||||
|
||||
Scenario: accepting a contact request
|
||||
Scenario: see follower's posts on their profile page and not on the home page
|
||||
When I sign in as "alice@alice.alice"
|
||||
And I am on the manage aspects page
|
||||
Then I should see 1 contact request
|
||||
When I drag the contact request to the "Besties" aspect
|
||||
And I wait for the ajax to finish
|
||||
Then I should see 1 contact in "Besties"
|
||||
And I am on "bob@bob.bob"'s page
|
||||
Then I should see "I am following you"
|
||||
|
||||
When I go to the home page
|
||||
Then I go to the manage aspects page
|
||||
Then I should see 1 contact in "Besties"
|
||||
Then I go to the destroy user session page
|
||||
And I am on the home page
|
||||
Then I should not see "I am following you"
|
||||
|
||||
When I sign in as "bob@bob.bob"
|
||||
And I am on the manage aspects page
|
||||
Then I should see 1 contact in "Besties"
|
||||
|
||||
Scenario: accepting a contact request to multiple aspects
|
||||
Scenario: mutual following the original follower should see private posts on their stream
|
||||
When I sign in as "alice@alice.alice"
|
||||
And I am on "bob@bob.bob"'s page
|
||||
And I press the 1st ".share_with.button" within "#author_info"
|
||||
|
|
@ -41,13 +38,19 @@ Feature: sending and receiving requests
|
|||
|
||||
Then I should see 1 contact in "Unicorns"
|
||||
Then I should see 1 contact in "Besties"
|
||||
|
||||
And I am on the home page
|
||||
Given I expand the publisher
|
||||
When I fill in "status_message_fake_text" with "I am following you back"
|
||||
And I press "Share"
|
||||
Then I go to the destroy user session page
|
||||
|
||||
When I sign in as "bob@bob.bob"
|
||||
And I am on the manage aspects page
|
||||
Then I should see 1 contact in "Besties"
|
||||
|
||||
|
||||
And I am on the home page
|
||||
Then I should see "I am following you back"
|
||||
|
||||
Scenario: accepting a contact request into a new aspect
|
||||
When I sign in as "alice@alice.alice"
|
||||
|
|
|
|||
|
|
@ -5,10 +5,22 @@
|
|||
module Diaspora
|
||||
module UserModules
|
||||
module Connecting
|
||||
|
||||
def share_with(person, aspect)
|
||||
contact = self.contacts.find_or_initialize_by_person_id(person.id)
|
||||
unless contact.persisted?
|
||||
contact.dispatch_request
|
||||
end
|
||||
contact.aspects << aspect
|
||||
contact.save
|
||||
contact
|
||||
end
|
||||
|
||||
#begin
|
||||
def send_contact_request_to(desired_contact, aspect)
|
||||
contact = Contact.new(:person => desired_contact,
|
||||
:user => self,
|
||||
self.contacts.new(:person => desired_contact,
|
||||
:pending => true)
|
||||
|
||||
contact.aspects << aspect
|
||||
|
||||
if contact.save!
|
||||
|
|
@ -19,6 +31,11 @@ module Diaspora
|
|||
end
|
||||
end
|
||||
|
||||
def dispatch_contact_acceptance(request, requester)
|
||||
Postzord::Dispatch.new(self, request).post
|
||||
request.destroy unless request.sender.owner
|
||||
end
|
||||
|
||||
def accept_contact_request(request, aspect)
|
||||
activate_contact(request.sender, aspect)
|
||||
|
||||
|
|
@ -30,12 +47,6 @@ module Diaspora
|
|||
request.reverse_for(self)
|
||||
end
|
||||
|
||||
def dispatch_contact_acceptance(request, requester)
|
||||
Postzord::Dispatch.new(self, request).post
|
||||
|
||||
request.destroy unless request.sender.owner
|
||||
end
|
||||
|
||||
def accept_and_respond(contact_request_id, aspect_id)
|
||||
request = Request.where(:recipient_id => self.person.id, :id => contact_request_id).first
|
||||
requester = request.sender
|
||||
|
|
@ -73,6 +84,14 @@ module Diaspora
|
|||
self.save
|
||||
end
|
||||
|
||||
def activate_contact(person, aspect)
|
||||
new_contact = Contact.create!(:user => self,
|
||||
:person => person,
|
||||
:aspects => [aspect],
|
||||
:pending => false)
|
||||
end
|
||||
#end
|
||||
|
||||
def disconnect(bad_contact)
|
||||
person = bad_contact.person
|
||||
Rails.logger.info("event=disconnect user=#{diaspora_handle} target=#{person.diaspora_handle}")
|
||||
|
|
@ -102,12 +121,6 @@ module Diaspora
|
|||
end
|
||||
end
|
||||
|
||||
def activate_contact(person, aspect)
|
||||
new_contact = Contact.create!(:user => self,
|
||||
:person => person,
|
||||
:aspects => [aspect],
|
||||
:pending => false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -78,11 +78,6 @@ module Diaspora
|
|||
self.aspects.all.collect{|x| x.id}
|
||||
end
|
||||
|
||||
def request_from(person)
|
||||
Request.where(:sender_id => person.id,
|
||||
:recipient_id => self.person.id).first
|
||||
end
|
||||
|
||||
def posts_from(person)
|
||||
return self.person.posts.where(:pending => false).order("created_at DESC") if person == self.person
|
||||
con = Contact.arel_table
|
||||
|
|
|
|||
|
|
@ -45,20 +45,6 @@ var AspectEdit = {
|
|||
var dropzone = $(this);
|
||||
var person = ui.draggable;
|
||||
|
||||
if (person.hasClass('request')) {
|
||||
$.ajax({
|
||||
type: "DELETE",
|
||||
url: "/requests/" + person.attr('data-guid'),
|
||||
data: {
|
||||
"accept": true,
|
||||
"aspect_id": dropzone.attr('data-aspect_id')
|
||||
},
|
||||
success: function() {
|
||||
AspectEdit.onDeleteRequestSuccess(person, dropzone);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (person.attr('data-aspect_id') != undefined && // a request doesn't have a data-aspect_id, but an existing contact does
|
||||
dropzone.attr('data-aspect_id') != person.attr('data-aspect_id')) {
|
||||
var aspect_id = person.attr('data-aspect_id')
|
||||
|
|
@ -95,16 +81,6 @@ var AspectEdit = {
|
|||
if( $(".person[data-guid='"+ person_id +"']").length == 1) {
|
||||
Diaspora.widgets.alert.alert("Error removing contact", "You cannot remove the person from the last aspect");
|
||||
} else {
|
||||
if (!person.hasClass('request')) {
|
||||
var aspect_id = person.attr('data-aspect_id')
|
||||
$.ajax({
|
||||
type: "DELETE",
|
||||
url: "/aspect_memberships/" + aspect_id,
|
||||
data: {
|
||||
'person_id': person_id
|
||||
}
|
||||
});
|
||||
}
|
||||
person.fadeOut(400, function() {
|
||||
person.remove();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -249,10 +249,6 @@ describe AspectsController do
|
|||
get :manage
|
||||
assigns(:aspect).should == :manage
|
||||
end
|
||||
it "assigns remote_requests" do
|
||||
get :manage
|
||||
assigns(:remote_requests).should be_empty
|
||||
end
|
||||
it "assigns contacts to only non-pending" do
|
||||
contact = @alice.contact_for(bob.person)
|
||||
Contact.unscoped.where(:user_id => @alice.id).count.should == 1
|
||||
|
|
@ -264,33 +260,6 @@ describe AspectsController do
|
|||
contacts.count.should == 1
|
||||
contacts.first.should == contact
|
||||
end
|
||||
context "when the user has pending requests" do
|
||||
before do
|
||||
requestor = Factory.create(:user)
|
||||
requestor_aspect = requestor.aspects.create(:name => "Meh")
|
||||
requestor.send_contact_request_to(@alice.person, requestor_aspect)
|
||||
|
||||
requestor.reload
|
||||
requestor_aspect.reload
|
||||
@alice.reload
|
||||
end
|
||||
it "succeeds" do
|
||||
get :manage
|
||||
response.should be_success
|
||||
end
|
||||
it "assigns aspect to manage" do
|
||||
get :manage
|
||||
assigns(:aspect).should == :manage
|
||||
end
|
||||
it "assigns remote_requests" do
|
||||
get :manage
|
||||
assigns(:remote_requests).count.should == 1
|
||||
end
|
||||
it "generates a jasmine fixture" do
|
||||
get :manage
|
||||
save_fixture(html_for("body"), "aspects_manage")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#update" do
|
||||
|
|
|
|||
|
|
@ -9,86 +9,47 @@ describe ContactsController do
|
|||
render_views
|
||||
|
||||
before do
|
||||
@user = alice
|
||||
@user2 = bob
|
||||
@aspect = alice.aspects.first
|
||||
@contact = alice.contact_for(bob.person)
|
||||
|
||||
@aspect0 = @user.aspects.first
|
||||
@aspect1 = @user.aspects.create(:name => "another aspect")
|
||||
@aspect2 = @user2.aspects.first
|
||||
|
||||
@contact = @user.contact_for(@user2.person)
|
||||
@user.getting_started = false
|
||||
@user.save
|
||||
sign_in :user, @user
|
||||
@controller.stub(:current_user).and_return(@user)
|
||||
request.env["HTTP_REFERER"] = 'http://' + request.host
|
||||
sign_in :user, alice
|
||||
@controller.stub(:current_user).and_return(alice)
|
||||
end
|
||||
|
||||
describe '#new' do
|
||||
it 'assigns a person' do
|
||||
get :new, :person_id => @user2.person.id
|
||||
assigns[:person].should == @user2.person
|
||||
get :new, :person_id => bob.person.id
|
||||
assigns[:person].should == bob.person
|
||||
end
|
||||
|
||||
it 'assigns aspects without person' do
|
||||
get :new, :person_id => @user2.person.id
|
||||
assigns[:aspects_without_person].should =~ @user.aspects
|
||||
get :new, :person_id => bob.person.id
|
||||
assigns[:aspects_without_person].should =~ alice.aspects
|
||||
end
|
||||
end
|
||||
|
||||
describe '#create' do
|
||||
|
||||
context 'with an incoming request' do
|
||||
before do
|
||||
@user3 = Factory.create(:user)
|
||||
@user3.send_contact_request_to(@user.person, @user3.aspects.create(:name => "Walruses"))
|
||||
end
|
||||
it 'deletes the request' do
|
||||
post :create,
|
||||
:format => 'js',
|
||||
:person_id => @user3.person.id,
|
||||
:aspect_id => @aspect1.id
|
||||
Request.where(:sender_id => @user3.person.id, :recipient_id => @user.person.id).first.should be_nil
|
||||
end
|
||||
it 'does not leave the contact pending' do
|
||||
post :create,
|
||||
:format => 'js',
|
||||
:person_id => @user3.person.id,
|
||||
:aspect_id => @aspect1.id
|
||||
@user.contact_for(@user3.person).should_not be_pending
|
||||
end
|
||||
end
|
||||
context 'with a non-contact' do
|
||||
before do
|
||||
@person = Factory(:person)
|
||||
@person = eve.person
|
||||
end
|
||||
|
||||
it 'calls send_contact_request_to' do
|
||||
@user.should_receive(:send_contact_request_to).with(@person, @aspect1)
|
||||
it 'calls share_in_aspect' do
|
||||
@controller.should_receive(:share_in_aspect).with(@aspect, @person)
|
||||
post :create,
|
||||
:format => 'js',
|
||||
:person_id => @person.id,
|
||||
:aspect_id => @aspect1.id
|
||||
end
|
||||
|
||||
it 'does not call add_contact_to_aspect' do
|
||||
@user.should_not_receive(:add_contact_to_aspect)
|
||||
post :create,
|
||||
:format => 'js',
|
||||
:person_id => @person.id,
|
||||
:aspect_id => @aspect1.id
|
||||
:aspect_id => @aspect.id
|
||||
end
|
||||
|
||||
it 'failure flashes error' do
|
||||
@controller.should_receive(:request_to_aspect).and_return(nil)
|
||||
@controller.should_receive(:share_in_aspect).and_return(nil)
|
||||
post :create,
|
||||
:format => 'js',
|
||||
:person_id => @person.id,
|
||||
:aspect_id => @aspect1.id
|
||||
:aspect_id => @aspect.id
|
||||
flash[:error].should_not be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#edit' do
|
||||
it 'assigns a contact' do
|
||||
|
|
@ -104,18 +65,18 @@ describe ContactsController do
|
|||
|
||||
describe '#destroy' do
|
||||
it 'disconnects from the person' do
|
||||
@user.should_receive(:disconnect).with(@contact)
|
||||
alice.should_receive(:disconnect).with(@contact)
|
||||
delete :destroy, :id => @contact.id
|
||||
end
|
||||
|
||||
it 'flases success if the contact is not destroyed' do
|
||||
@user.stub!(:disconnect).and_return(true)
|
||||
alice.stub!(:disconnect).and_return(true)
|
||||
delete :destroy, :id => @contact.id
|
||||
flash[:notice].should_not be_empty
|
||||
end
|
||||
|
||||
it 'flases failure if the contact is not destroyed' do
|
||||
@user.stub!(:disconnect).and_return(false)
|
||||
alice.stub!(:disconnect).and_return(false)
|
||||
delete :destroy, :id => @contact.id
|
||||
flash[:error].should_not be_empty
|
||||
end
|
||||
|
|
@ -125,4 +86,15 @@ describe ContactsController do
|
|||
response.should redirect_to(@contact.person)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#share_in_aspect' do
|
||||
it 'calls share_with' do
|
||||
aspect = alice.aspects.first
|
||||
person = eve.person
|
||||
|
||||
@controller.current_user.should_receive(:share_with).with(person, aspect)
|
||||
@controller.send(:share_in_aspect, aspect, person)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -89,21 +89,24 @@ describe InvitationsController do
|
|||
invited.aspects.count.should == 2
|
||||
end
|
||||
|
||||
it 'adds a pending request' do
|
||||
it 'adds a contact' do
|
||||
lambda {
|
||||
put :update, @accept_params
|
||||
Request.where(:recipient_id => invited.person.id).count.should == 1
|
||||
}.should change(@user.contacts, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
context 'failure' do
|
||||
before do
|
||||
@fail_params = @accept_params
|
||||
@fail_params[:user][:username] = @user.username
|
||||
end
|
||||
|
||||
it 'stays on the invitation accept form' do
|
||||
put :update, @fail_params
|
||||
response.location.include?(accept_user_invitation_path).should be_true
|
||||
end
|
||||
|
||||
it 'keeps the invitation token' do
|
||||
put :update, @fail_params
|
||||
response.location.include?("invitation_token=#{@invited_user.invitation_token}").should be_true
|
||||
|
|
|
|||
|
|
@ -1,141 +0,0 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe RequestsController do
|
||||
render_views
|
||||
before do
|
||||
@user = alice
|
||||
@other_user = eve
|
||||
|
||||
@controller.stub!(:current_user).and_return(@user)
|
||||
sign_in :user, @user
|
||||
request.env["HTTP_REFERER"] = "http://test.host"
|
||||
end
|
||||
|
||||
describe '#destroy' do
|
||||
before do
|
||||
@other_user.send_contact_request_to(@user.person, @other_user.aspects.first)
|
||||
@friend_request = Request.where(:recipient_id => @user.person.id).first
|
||||
end
|
||||
describe 'when accepting a contact request' do
|
||||
it "succeeds" do
|
||||
xhr :delete, :destroy,
|
||||
:accept => "true",
|
||||
:aspect_id => @user.aspects.first.id.to_s,
|
||||
:id => @friend_request.id.to_s
|
||||
response.should redirect_to(requests_path)
|
||||
end
|
||||
it "marks the notification as read" do
|
||||
notification = Notification.where(:recipient_id => @user.id, :target_id=> @friend_request.id).first
|
||||
notification.unread = true
|
||||
notification.save
|
||||
xhr :delete, :destroy,
|
||||
:accept => "true",
|
||||
:aspect_id => @user.aspects.first.id.to_s,
|
||||
:id => @friend_request.id.to_s
|
||||
notification.reload.unread.should == false
|
||||
end
|
||||
end
|
||||
describe 'when ignoring a contact request' do
|
||||
it "succeeds" do
|
||||
xhr :delete, :destroy,
|
||||
:id => @friend_request.id.to_s
|
||||
response.should be_success
|
||||
end
|
||||
it "removes the request object" do
|
||||
lambda {
|
||||
xhr :delete, :destroy,
|
||||
:id => @friend_request.id.to_s
|
||||
}.should change(Request, :count).by(-1)
|
||||
end
|
||||
|
||||
it "marks the notification as read" do
|
||||
notification = Notification.where(:recipient_id => @user.id, :target_id=> @friend_request.id).first
|
||||
notification.unread = true
|
||||
notification.save
|
||||
xhr :delete, :destroy,
|
||||
:id => @friend_request.id.to_s
|
||||
notification.reload.unread.should == false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#create' do
|
||||
context 'valid new request' do
|
||||
before do
|
||||
@params = {:request => {
|
||||
:to => @other_user.diaspora_handle,
|
||||
:into => @user.aspects[0].id
|
||||
}}
|
||||
end
|
||||
it 'creates a contact' do
|
||||
@user.contact_for(@other_user).should be_nil
|
||||
lambda {
|
||||
post :create, @params
|
||||
}.should change(Contact.unscoped,:count).by(1)
|
||||
new_contact = @user.reload.contact_for(@other_user.person)
|
||||
new_contact.should_not be_nil
|
||||
new_contact.should be_pending
|
||||
end
|
||||
it 'does not persist a Request' do
|
||||
lambda {
|
||||
post :create, @params
|
||||
}.should_not change(Request, :count)
|
||||
end
|
||||
end
|
||||
it 'autoaccepts and when sending a request to someone who sent me a request' do
|
||||
@other_user.send_contact_request_to(@user.person, @other_user.aspects[0])
|
||||
|
||||
post(:create, :request => {
|
||||
:to => @other_user.diaspora_handle,
|
||||
:into => @user.aspects[0].id}
|
||||
)
|
||||
Request.where(:recipient_id => @user.person.id).first.should be_nil
|
||||
@user.contact_for(@other_user.person).should be_true
|
||||
@user.aspects[0].contacts.where(:person_id => @other_user.person.id).first.should be_true
|
||||
end
|
||||
|
||||
it "redirects when requesting to be contacts with yourself" do
|
||||
post(:create, :request => {
|
||||
:to => @user.diaspora_handle,
|
||||
:into => @user.aspects[0].id
|
||||
}
|
||||
)
|
||||
flash[:error].should_not be_blank
|
||||
response.should redirect_to :back
|
||||
end
|
||||
|
||||
it "flashes and redirects when requesting an invalid identity" do
|
||||
post(:create, :request => {
|
||||
:to => "not_a_@valid_email",
|
||||
:into => @user.aspects[0].id
|
||||
}
|
||||
)
|
||||
flash[:error].should_not be_blank
|
||||
response.should redirect_to :back
|
||||
end
|
||||
|
||||
it "accepts no port numbers" do
|
||||
post(:create, :request => {
|
||||
:to => "johndoe@email.com:3000",
|
||||
:into => @user.aspects[0].id
|
||||
}
|
||||
)
|
||||
flash[:error].should_not be_blank
|
||||
response.should redirect_to :back
|
||||
end
|
||||
|
||||
it "redirects when requesting an identity from an invalid server" do
|
||||
post(:create, :request => {
|
||||
:to => "johndoe@notadiasporaserver.com",
|
||||
:into => @user.aspects[0].id
|
||||
}
|
||||
)
|
||||
flash[:error].should_not be_blank
|
||||
response.should redirect_to :back
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -3,13 +3,11 @@ module HelperMethods
|
|||
connect_users(u1, u1.aspects.first, u2, u2.aspects.first)
|
||||
end
|
||||
def connect_users(user1, aspect1, user2, aspect2)
|
||||
Contact.create!(:user => user1,
|
||||
:person => user2.person,
|
||||
user1.contacts.create!(:person => user2.person,
|
||||
:aspects => [aspect1],
|
||||
:pending => false)
|
||||
|
||||
Contact.create!(:user => user2,
|
||||
:person => user1.person,
|
||||
user2.contacts.create!(:person => user1.person,
|
||||
:aspects => [aspect2],
|
||||
:pending => false)
|
||||
user1.reload
|
||||
|
|
|
|||
|
|
@ -358,19 +358,6 @@ describe 'a user receives a post' do
|
|||
}.should change(StatusMessage, :count).by(-1)
|
||||
end
|
||||
|
||||
it "should activate the Person if I initiated a request to that url" do
|
||||
@user1.send_contact_request_to(@user3.person, @aspect)
|
||||
request = @user3.request_from(@user1.person)
|
||||
fantasy_resque do
|
||||
@user3.accept_and_respond(request.id, @aspect3.id)
|
||||
end
|
||||
@user1.reload
|
||||
@aspect.reload
|
||||
new_contact = @user1.contact_for(@user3.person)
|
||||
@aspect.contacts.include?(new_contact).should be true
|
||||
@user1.contacts.include?(new_contact).should be true
|
||||
end
|
||||
|
||||
it 'should process retraction for a person' do
|
||||
retraction = Retraction.for(@user2)
|
||||
retraction_xml = retraction.to_diaspora_xml
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ describe Invitation do
|
|||
let(:user) { alice }
|
||||
let(:aspect) { user.aspects.first }
|
||||
let(:user2) { eve }
|
||||
|
||||
before do
|
||||
user.invites = 20
|
||||
user.save
|
||||
|
|
@ -73,50 +74,47 @@ describe Invitation do
|
|||
|
||||
describe '.find_existing_user' do
|
||||
let(:inv) { Invitation.find_existing_user(@type, @identifier) }
|
||||
before do
|
||||
@users = []
|
||||
8.times do
|
||||
@users << Factory.create(:user)
|
||||
end
|
||||
@user_fb_id = 'abc123'
|
||||
@user_fb = Factory.create(:user, :invitation_service => "facebook", :invitation_identifier => @user_fb_id)
|
||||
end
|
||||
|
||||
context 'send a request to an existing' do
|
||||
context 'active user' do
|
||||
it 'by email' do
|
||||
@identifier = @users[3].email
|
||||
@identifier = alice.email
|
||||
@type = 'email'
|
||||
inv.should == @users[3]
|
||||
inv.should == alice
|
||||
end
|
||||
|
||||
it 'by service' do
|
||||
uid = '123324234'
|
||||
@users[0].services << Services::Facebook.new(:uid => uid)
|
||||
@users[0].save
|
||||
alice.services << Services::Facebook.new(:uid => uid)
|
||||
alice.save
|
||||
|
||||
@type = 'facebook'
|
||||
@identifier = uid
|
||||
|
||||
inv.should == @users[0]
|
||||
inv.should == alice
|
||||
end
|
||||
end
|
||||
|
||||
context 'invitated user' do
|
||||
it 'by email' do
|
||||
@identifier = @users[3].email
|
||||
@identifier = alice.email
|
||||
@type = 'email'
|
||||
|
||||
@users[3].invitation_identifier = @identifier
|
||||
@users[3].invitation_service = @type
|
||||
@users[3].save
|
||||
inv.should == @users[3]
|
||||
alice.invitation_identifier = @identifier
|
||||
alice.invitation_service = @type
|
||||
alice.save
|
||||
inv.should == alice
|
||||
end
|
||||
|
||||
it 'by service' do
|
||||
@identifier = @user_fb_id
|
||||
fb_id = 'abc123'
|
||||
alice.invitation_service = 'facebook'
|
||||
alice.invitation_identifier = fb_id
|
||||
alice.save
|
||||
|
||||
@identifier = fb_id
|
||||
@type = 'facebook'
|
||||
inv.should == @user_fb
|
||||
inv.should == alice
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -303,7 +301,7 @@ describe Invitation do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#to_request!' do
|
||||
describe '#share_with!' do
|
||||
before do
|
||||
@new_user = Invitation.invite(:from => user, :service => 'email', :identifier => @email, :into => aspect)
|
||||
acceptance_params = {:invitation_token => "abc",
|
||||
|
|
@ -317,38 +315,17 @@ describe Invitation do
|
|||
@new_user.save
|
||||
@invitation = @new_user.invitations_to_me.first
|
||||
end
|
||||
|
||||
it 'destroys the invitation' do
|
||||
lambda {
|
||||
@invitation.to_request!
|
||||
@invitation.share_with!
|
||||
}.should change(Invitation, :count).by(-1)
|
||||
end
|
||||
it 'creates a request, and sends it to the new user' do
|
||||
|
||||
it 'creates a contact for the inviter' do
|
||||
lambda {
|
||||
@invitation.to_request!
|
||||
}.should change(Request, :count).by(1)
|
||||
end
|
||||
it 'creates a pending contact for the inviter' do
|
||||
lambda {
|
||||
@invitation.to_request!
|
||||
@invitation.share_with!
|
||||
}.should change(Contact.unscoped, :count).by(1)
|
||||
@invitation.sender.contact_for(@new_user.person).should be_pending
|
||||
end
|
||||
describe 'return values' do
|
||||
before do
|
||||
@request = @invitation.to_request!
|
||||
end
|
||||
it 'returns the sent request' do
|
||||
@request.is_a?(Request).should be_true
|
||||
end
|
||||
it 'sets the receiving user' do
|
||||
@request.recipient.should == @new_user.person
|
||||
end
|
||||
it 'sets the sending user' do
|
||||
@request.sender.should == user.person
|
||||
end
|
||||
it 'sets the aspect' do
|
||||
@request.aspect.should == aspect
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -73,10 +73,9 @@ describe Request do
|
|||
end
|
||||
|
||||
describe '#receive' do
|
||||
it 'calls receive_contact_request on user' do
|
||||
it 'creates a contact' do
|
||||
request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
|
||||
|
||||
@user2.should_receive(:receive_contact_request).with(request)
|
||||
@user2.contacts.should_receive(:create).with(hash_including(:person_id => @user.person.id))
|
||||
request.receive(@user2, @user.person)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,98 +5,97 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Diaspora::UserModules::Connecting do
|
||||
let(:user) { alice }
|
||||
let(:aspect) { user.aspects.create(:name => 'heroes') }
|
||||
let(:aspect1) { user.aspects.create(:name => 'other') }
|
||||
|
||||
let(:aspect) { alice.aspects.first }
|
||||
let(:aspect1) { alice.aspects.create(:name => 'other') }
|
||||
let(:person) { Factory.create(:person) }
|
||||
|
||||
let(:aspect2) { eve.aspects.create(:name => "aspect two") }
|
||||
|
||||
let(:person_one) { Factory.create :person }
|
||||
let(:person_two) { Factory.create :person }
|
||||
let(:person_three) { Factory.create :person }
|
||||
|
||||
let(:user2) { eve }
|
||||
let(:aspect2) { user2.aspects.create(:name => "aspect two") }
|
||||
|
||||
describe '#send_contact_request_to' do
|
||||
it 'should not be able to contact request an existing contact' do
|
||||
user.activate_contact(user2.person, aspect1)
|
||||
alice.activate_contact(eve.person, aspect1)
|
||||
|
||||
proc {
|
||||
user.send_contact_request_to(user2.person, aspect1)
|
||||
alice.send_contact_request_to(eve.person, aspect1)
|
||||
}.should raise_error(ActiveRecord::RecordInvalid)
|
||||
end
|
||||
|
||||
it 'should not be able to contact request no-one' do
|
||||
proc {
|
||||
user.send_contact_request_to(nil, aspect)
|
||||
alice.send_contact_request_to(nil, aspect)
|
||||
}.should raise_error(ActiveRecord::RecordInvalid)
|
||||
end
|
||||
it 'creates a pending contact' do
|
||||
proc {
|
||||
user.send_contact_request_to(user2.person, aspect1)
|
||||
alice.send_contact_request_to(eve.person, aspect1)
|
||||
}.should change(Contact.unscoped, :count).by(1)
|
||||
user.contact_for(user2.person).pending.should == true
|
||||
user.contact_for(user2.person).should be_pending
|
||||
alice.contact_for(eve.person).pending.should == true
|
||||
alice.contact_for(eve.person).should be_pending
|
||||
end
|
||||
it 'persists no request for requester' do
|
||||
proc {
|
||||
user.send_contact_request_to(user2.person, aspect1)
|
||||
}.should_not change{Request.where(:recipient_id => user.person.id).count}
|
||||
alice.send_contact_request_to(eve.person, aspect1)
|
||||
}.should_not change{Request.where(:recipient_id => alice.person.id).count}
|
||||
end
|
||||
it 'persists a request for the recipient' do
|
||||
user.send_contact_request_to(user2.person, aspect1)
|
||||
user2.request_from(user.person).should_not be_nil
|
||||
alice.send_contact_request_to(eve.person, aspect1)
|
||||
eve.request_from(alice.person).should_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'contact requesting' do
|
||||
describe '#receive_contact_request' do
|
||||
before do
|
||||
@r = Request.diaspora_initialize(:to => user.person, :from => person)
|
||||
@r = Request.diaspora_initialize(:to => alice.person, :from => person)
|
||||
end
|
||||
|
||||
it 'adds a request to pending if it was not sent by user' do
|
||||
user.receive_contact_request(@r)
|
||||
Request.where(:recipient_id => user.person.id).all.should include @r
|
||||
alice.receive_contact_request(@r)
|
||||
Request.where(:recipient_id => alice.person.id).all.should include @r
|
||||
end
|
||||
|
||||
it 'creates no contact' do
|
||||
lambda {
|
||||
received_req = @r.receive(user, person_one)
|
||||
received_req = @r.receive(alice, person_one)
|
||||
}.should_not change(Contact, :count)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#receive_request_acceptance' do
|
||||
before do
|
||||
@original_request = user.send_contact_request_to(user2.person, aspect)
|
||||
@acceptance = @original_request.reverse_for(user2)
|
||||
@original_request = alice.send_contact_request_to(eve.person, aspect)
|
||||
@acceptance = @original_request.reverse_for(eve)
|
||||
end
|
||||
it 'connects to the acceptor' do
|
||||
user.receive_contact_request(@acceptance)
|
||||
user.contact_for(user2.person).should_not be_nil
|
||||
alice.receive_contact_request(@acceptance)
|
||||
alice.contact_for(eve.person).should_not be_nil
|
||||
end
|
||||
it 'deletes the acceptance' do
|
||||
user.receive_contact_request(@acceptance)
|
||||
Request.where(:sender_id => user2.person.id, :recipient_id => user.person.id).should be_empty
|
||||
alice.receive_contact_request(@acceptance)
|
||||
Request.where(:sender_id => eve.person.id, :recipient_id => alice.person.id).should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'received a contact request' do
|
||||
let(:request_for_user) {Request.diaspora_initialize(:to => user.person, :from => person)}
|
||||
let(:request2_for_user) {Request.diaspora_initialize(:to => user.person, :from => person_one)}
|
||||
let(:request_from_myself) {Request.diaspora_initialize(:to => user.person, :from => user.person)}
|
||||
let(:request_for_user) {Request.diaspora_initialize(:to => alice.person, :from => person)}
|
||||
let(:request2_for_user) {Request.diaspora_initialize(:to => alice.person, :from => person_one)}
|
||||
let(:request_from_myself) {Request.diaspora_initialize(:to => alice.person, :from => alice.person)}
|
||||
before do
|
||||
Request.diaspora_initialize(:from => person, :to => user.person).save
|
||||
Request.diaspora_initialize(:from => person_one, :to => user.person).save
|
||||
Request.diaspora_initialize(:from => person, :to => alice.person).save
|
||||
Request.diaspora_initialize(:from => person_one, :to => alice.person).save
|
||||
|
||||
@received_request = Request.where(:sender_id => person.id, :recipient_id => user.person.id).first
|
||||
@received_request2 = Request.where(:sender_id => person_one.id, :recipient_id => user.person.id).first
|
||||
@received_request = Request.where(:sender_id => person.id, :recipient_id => alice.person.id).first
|
||||
@received_request2 = Request.where(:sender_id => person_one.id, :recipient_id => alice.person.id).first
|
||||
end
|
||||
|
||||
it "should delete an accepted contact request" do
|
||||
proc {
|
||||
user.accept_contact_request(@received_request, aspect)
|
||||
alice.accept_contact_request(@received_request, aspect)
|
||||
}.should change(Request, :count ).by(-1)
|
||||
end
|
||||
|
||||
|
|
@ -104,19 +103,19 @@ describe Diaspora::UserModules::Connecting do
|
|||
notification = Factory.create(:notification, :target => @received_request)
|
||||
|
||||
Notification.where(:target_id=>@received_request.id).first.unread.should be_true
|
||||
user.accept_contact_request(@received_request, aspect)
|
||||
alice.accept_contact_request(@received_request, aspect)
|
||||
Notification.where(:target_id=>@received_request.id).first.unread.should be_false
|
||||
end
|
||||
|
||||
it 'should be able to ignore a pending contact request' do
|
||||
proc { user.ignore_contact_request(@received_request.id)
|
||||
proc { alice.ignore_contact_request(@received_request.id)
|
||||
}.should change(Request, :count ).by(-1)
|
||||
end
|
||||
|
||||
it 'should ignore a contact request from yourself' do
|
||||
reversed_request = request_from_myself.reverse_for(user)
|
||||
reversed_request = request_from_myself.reverse_for(alice)
|
||||
|
||||
user.receive_contact_request(reversed_request)
|
||||
alice.receive_contact_request(reversed_request)
|
||||
reversed_request.persisted?.should be false
|
||||
end
|
||||
end
|
||||
|
|
@ -124,9 +123,9 @@ describe Diaspora::UserModules::Connecting do
|
|||
describe 'multiple users accepting/rejecting the same person' do
|
||||
|
||||
before do
|
||||
@request1 = Request.diaspora_initialize(:to => user.person, :from => person_one)
|
||||
@request2 = Request.diaspora_initialize(:to => user2.person, :from => person_one)
|
||||
@request3 = Request.diaspora_initialize(:to => user2.person, :from => user.person)
|
||||
@request1 = Request.diaspora_initialize(:to => alice.person, :from => person_one)
|
||||
@request2 = Request.diaspora_initialize(:to => eve.person, :from => person_one)
|
||||
@request3 = Request.diaspora_initialize(:to => eve.person, :from => alice.person)
|
||||
|
||||
@req1_xml = @request1.to_diaspora_xml
|
||||
@req2_xml = @request2.to_diaspora_xml
|
||||
|
|
@ -139,94 +138,94 @@ describe Diaspora::UserModules::Connecting do
|
|||
|
||||
context 'request from one remote person to one local user' do
|
||||
before do
|
||||
zord = Postzord::Receiver.new(user, :person => user.person)
|
||||
zord = Postzord::Receiver.new(alice, :person => alice.person)
|
||||
@received_request = zord.parse_and_receive(@req3_xml)
|
||||
@received_request.reload
|
||||
end
|
||||
|
||||
it 'should connect the user other user on the same pod' do
|
||||
proc {
|
||||
user2.accept_contact_request(@received_request, aspect2)
|
||||
eve.accept_contact_request(@received_request, aspect2)
|
||||
}.should_not change(Person, :count)
|
||||
user2.contact_for(user.person).should_not be_nil
|
||||
eve.contact_for(alice.person).should_not be_nil
|
||||
end
|
||||
|
||||
it 'should not delete the ignored user on the same pod' do
|
||||
|
||||
proc {
|
||||
user2.ignore_contact_request(@received_request.id)
|
||||
eve.ignore_contact_request(@received_request.id)
|
||||
}.should_not change(Person, :count)
|
||||
user2.contact_for(user.person).should be_nil
|
||||
eve.contact_for(alice.person).should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'Two users receiving requests from one person' do
|
||||
before do
|
||||
zord1 = Postzord::Receiver.new(user, :person => person_one)
|
||||
zord2 = Postzord::Receiver.new(user, :person => person_one)
|
||||
zord1 = Postzord::Receiver.new(alice, :person => person_one)
|
||||
zord2 = Postzord::Receiver.new(alice, :person => person_one)
|
||||
|
||||
@req_to_user = zord1.parse_and_receive(@req1_xml)
|
||||
@req_to_user2 = zord2.parse_and_receive(@req2_xml)
|
||||
@req_to_eve = zord2.parse_and_receive(@req2_xml)
|
||||
end
|
||||
|
||||
describe '#accept_contact_request' do
|
||||
it 'should both users should connect the same person' do
|
||||
user.accept_contact_request @req_to_user, aspect
|
||||
user.contact_for(person_one).should_not be_nil
|
||||
alice.accept_contact_request @req_to_user, aspect
|
||||
alice.contact_for(person_one).should_not be_nil
|
||||
|
||||
user2.accept_contact_request @req_to_user2, aspect2
|
||||
user2.contact_for(person_one).should_not be_nil
|
||||
eve.accept_contact_request @req_to_eve, aspect2
|
||||
eve.contact_for(person_one).should_not be_nil
|
||||
end
|
||||
|
||||
it 'should keep the person around if one of the users rejects him' do
|
||||
user.accept_contact_request @req_to_user, aspect
|
||||
user.contact_for(person_one).should_not be_nil
|
||||
alice.accept_contact_request @req_to_user, aspect
|
||||
alice.contact_for(person_one).should_not be_nil
|
||||
|
||||
user2.ignore_contact_request @req_to_user2.id
|
||||
user2.contact_for(person_one).should be_nil
|
||||
eve.ignore_contact_request @req_to_eve.id
|
||||
eve.contact_for(person_one).should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
it 'should keep the person around if the users ignores them' do
|
||||
user.ignore_contact_request Request.where(:recipient_id => user.person.id).first.id
|
||||
user.contact_for(person_one).should be_nil
|
||||
alice.ignore_contact_request Request.where(:recipient_id => alice.person.id).first.id
|
||||
alice.contact_for(person_one).should be_nil
|
||||
|
||||
user2.ignore_contact_request Request.where(:recipient_id => user2.person.id).first.id
|
||||
user2.contact_for(person_one).should be_nil
|
||||
eve.ignore_contact_request Request.where(:recipient_id => eve.person.id).first.id
|
||||
eve.contact_for(person_one).should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
describe 'a user accepting rejecting multiple people' do
|
||||
describe 'a user accepting & rejecting multiple people' do
|
||||
before do
|
||||
request = Request.diaspora_initialize(:to => user.person, :from => person_one)
|
||||
@received_request = request.receive(user, person_one)
|
||||
request = Request.diaspora_initialize(:to => alice.person, :from => person_one)
|
||||
@received_request = request.receive(alice, person_one)
|
||||
end
|
||||
describe '#accept_contact_request' do
|
||||
it "deletes the received request" do
|
||||
lambda {
|
||||
user.accept_contact_request(@received_request, aspect)
|
||||
alice.accept_contact_request(@received_request, aspect)
|
||||
}.should change(Request, :count).by(-1)
|
||||
end
|
||||
it "creates a new contact" do
|
||||
lambda {
|
||||
user.accept_contact_request(@received_request, aspect)
|
||||
alice.accept_contact_request(@received_request, aspect)
|
||||
}.should change(Contact, :count).by(1)
|
||||
user.contact_for(person_one).should_not be_nil
|
||||
alice.contact_for(person_one).should_not be_nil
|
||||
end
|
||||
end
|
||||
describe '#ignore_contact_request' do
|
||||
it "removes the request" do
|
||||
lambda {
|
||||
user.ignore_contact_request(@received_request.id)
|
||||
alice.ignore_contact_request(@received_request.id)
|
||||
}.should change(Request, :count).by(-1)
|
||||
end
|
||||
it "creates no new contact" do
|
||||
lambda {
|
||||
user.ignore_contact_request(@received_request)
|
||||
alice.ignore_contact_request(@received_request)
|
||||
}.should_not change(Contact, :count)
|
||||
end
|
||||
end
|
||||
|
|
@ -283,4 +282,37 @@ describe Diaspora::UserModules::Connecting do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#share_with' do
|
||||
it 'finds or creates a contact' do
|
||||
lambda {
|
||||
alice.share_with(eve.person, alice.aspects.first)
|
||||
}.should change(alice.contacts, :count).by(1)
|
||||
end
|
||||
|
||||
it 'adds a contact to an aspect' do
|
||||
contact = alice.contacts.create(:person => eve.person)
|
||||
alice.contacts.stub!(:find_or_initialize_by_person_id).and_return(contact)
|
||||
|
||||
lambda {
|
||||
alice.share_with(eve.person, alice.aspects.first)
|
||||
}.should change(contact.aspects, :count).by(1)
|
||||
end
|
||||
|
||||
it 'dispatches a request' do
|
||||
contact = alice.contacts.new(:person => eve.person)
|
||||
alice.contacts.stub!(:find_or_initialize_by_person_id).and_return(contact)
|
||||
|
||||
contact.should_receive(:dispatch_request)
|
||||
alice.share_with(eve.person, alice.aspects.first)
|
||||
end
|
||||
|
||||
it 'does not dispatch a request' do
|
||||
contact = alice.contacts.create(:person => eve.person)
|
||||
alice.contacts.stub!(:find_or_initialize_by_person_id).and_return(contact)
|
||||
|
||||
contact.should_not_receive(:dispatch_request)
|
||||
alice.share_with(eve.person, alice.aspects.first)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -182,21 +182,6 @@ describe User do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#request_from" do
|
||||
let!(:user5) {Factory(:user)}
|
||||
|
||||
it 'should not have a pending request before connecting' do
|
||||
request = alice.request_from(user5.person)
|
||||
request.should be_nil
|
||||
end
|
||||
|
||||
it 'should have a pending request after sending a request' do
|
||||
alice.send_contact_request_to(user5.person, alice.aspects.first)
|
||||
request = user5.request_from(alice.person)
|
||||
request.should_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe '#posts_from' do
|
||||
before do
|
||||
@user3 = Factory(:user)
|
||||
|
|
|
|||
Loading…
Reference in a new issue