dispatching / receiving logic complete. following wip.
This commit is contained in:
parent
4f972a23f6
commit
aeda5a4e39
25 changed files with 293 additions and 238 deletions
|
|
@ -46,9 +46,8 @@ class AspectMembershipsController < ApplicationController
|
|||
def create
|
||||
@person = Person.find(params[:person_id])
|
||||
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first
|
||||
@contact = current_user.contact_for(@person)
|
||||
|
||||
current_user.add_contact_to_aspect(@contact, @aspect)
|
||||
current_user.share_with(@person, @aspect)
|
||||
|
||||
flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success'
|
||||
|
||||
|
|
|
|||
|
|
@ -13,30 +13,6 @@ class ContactsController < ApplicationController
|
|||
render :layout => false
|
||||
end
|
||||
|
||||
def create
|
||||
@person = Person.find(params[:person_id])
|
||||
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first
|
||||
|
||||
if @contact = share_in_aspect(@aspect, @person)
|
||||
flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success'
|
||||
|
||||
respond_to do |format|
|
||||
format.js { render :json => {
|
||||
:button_html => render_to_string(:partial => 'aspect_memberships/add_to_aspect',
|
||||
:locals => {:aspect_id => @aspect.id,
|
||||
:person_id => @person.id}),
|
||||
:badge_html => render_to_string(:partial => 'aspects/aspect_badge',
|
||||
:locals => {:aspect => @aspect}),
|
||||
:contact_id => @contact.id
|
||||
}}
|
||||
format.html{ redirect_to aspect_path(@aspect.id)}
|
||||
end
|
||||
else
|
||||
flash[:error] = I18n.t 'contacts.create.failure'
|
||||
redirect_to :back
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@contact = current_user.contacts.unscoped.find(params[:id])
|
||||
@person = @contact.person
|
||||
|
|
@ -50,7 +26,7 @@ class ContactsController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
contact = current_user.contacts.unscoped.find(params[:id])
|
||||
contact = current_user.contacts.find(params[:id])
|
||||
|
||||
if current_user.disconnect(contact)
|
||||
flash[:notice] = I18n.t('contacts.destroy.success', :name => contact.person.name)
|
||||
|
|
@ -60,9 +36,4 @@ class ContactsController < ApplicationController
|
|||
redirect_to contact.person
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def share_in_aspect(aspect, person)
|
||||
current_user.share_with(person, aspect)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ class PostVisibilitiesController < ApplicationController
|
|||
@post = Post.where(:id => params[:post_id]).select("id, author_id").first
|
||||
@contact = current_user.contact_for(@post.author)
|
||||
|
||||
if @vis = PostVisibility.where(:contact_id => @contact.id,
|
||||
:post_id => params[:post_id]).first
|
||||
if @contact && @vis = PostVisibility.where(:contact_id => @contact.id,
|
||||
:post_id => params[:post_id]).first
|
||||
@vis.hidden = !@vis.hidden
|
||||
if @vis.save
|
||||
render 'update'
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ module AspectsHelper
|
|||
end
|
||||
end
|
||||
|
||||
def add_to_aspect_button(aspect_id, person_id, kontroller)
|
||||
def add_to_aspect_button(aspect_id, person_id)
|
||||
link_to image_tag('icons/monotone_plus_add_round.png'),
|
||||
{:controller => kontroller,
|
||||
{:controller => 'aspect_memberships',
|
||||
:action => 'create',
|
||||
:aspect_id => aspect_id,
|
||||
:person_id => person_id},
|
||||
|
|
@ -45,13 +45,9 @@ module AspectsHelper
|
|||
:class => 'added button'
|
||||
end
|
||||
|
||||
def contact_or_membership(contact)
|
||||
(contact.persisted?) ? 'aspect_memberships' : 'contacts'
|
||||
end
|
||||
|
||||
def aspect_membership_button(aspect, contact, person)
|
||||
if contact.nil? || !aspect.contacts.include?(contact)
|
||||
add_to_aspect_button(aspect.id, person.id, contact_or_membership(contact))
|
||||
add_to_aspect_button(aspect.id, person.id)
|
||||
else
|
||||
remove_from_aspect_button(aspect.id, person.id)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -45,6 +45,15 @@ class Contact < ActiveRecord::Base
|
|||
similar_contacts = Person.joins(:contacts => :aspect_memberships).where(
|
||||
:aspect_memberships => {:aspect_id => incoming_aspect_ids}).where(people[:id].not_eq(self.user.person.id)).select('DISTINCT `people`.*')
|
||||
end
|
||||
|
||||
def sharing?
|
||||
self.persisted? && (self.mutual? || self.aspect_memberships.size == 0)
|
||||
end
|
||||
|
||||
def receiving?
|
||||
self.aspect_memberships.size > 0
|
||||
end
|
||||
|
||||
private
|
||||
def not_contact_for_self
|
||||
if person_id && person.owner == user
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ class Request
|
|||
end
|
||||
|
||||
def reverse_for accepting_user
|
||||
Request.new(
|
||||
:sender => accepting_user.person,
|
||||
:recipient => self.sender
|
||||
Request.diaspora_initialize(
|
||||
:from => accepting_user.person,
|
||||
:to => self.sender
|
||||
)
|
||||
end
|
||||
|
||||
|
|
@ -59,7 +59,15 @@ class Request
|
|||
|
||||
def receive(user, person)
|
||||
Rails.logger.info("event=receive payload_type=request sender=#{self.sender} to=#{self.recipient}")
|
||||
user.contacts.create(:person_id => person.id)
|
||||
|
||||
contact = user.contacts.find_or_initialize_by_person_id(self.sender.id)
|
||||
|
||||
if contact.receiving?
|
||||
contact.update_attributes(:mutual => true)
|
||||
else
|
||||
contact.save
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ class Retraction
|
|||
Rails.logger.debug "Performing retraction for #{post_guid}"
|
||||
self.target.unsocket_from_user receiving_user if target.respond_to? :unsocket_from_user
|
||||
self.target.destroy
|
||||
target.post_visibilities.delete_all
|
||||
Rails.logger.info("event=retraction status=complete type=#{self.type} guid=#{self.post_guid}")
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
-# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
-# licensed under the Affero General Public License version 3 or later. See
|
||||
-# the COPYRIGHT file.
|
||||
|
||||
.aspect_list#aspects_list{:data=> {:contact_id=> (contact ? contact.id : nil)}}
|
||||
%ul
|
||||
- for aspect in aspects_with_person
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
%hr{:style=>"width:300px;"}
|
||||
|
||||
%ul
|
||||
- if user_signed_in? && person != current_user.person
|
||||
- if user_signed_in? && contact.receiving?
|
||||
%li
|
||||
= render :partial => 'people/aspect_list',
|
||||
:locals => {:person => person,
|
||||
|
|
|
|||
|
|
@ -24,22 +24,23 @@
|
|||
|
||||
.span-15.last
|
||||
#author_info
|
||||
- if user_signed_in? && !((@contact.persisted? && @contact.mutual) || current_user.person == @person)
|
||||
.right
|
||||
= link_to t('.start_sharing'),
|
||||
{:controller => "contacts",
|
||||
:action => "new",
|
||||
:person_id => @person.id},
|
||||
:class => 'share_with button',
|
||||
:rel => 'facebox'
|
||||
- if @share_with
|
||||
= javascript_tag "$(document).ready(function() {jQuery.facebox({ ajax: '#{new_contact_path(:person_id => @person.id)}' });});"
|
||||
- if user_signed_in?
|
||||
- if !@contact.receiving? #!(current_user.person == @person) && !(@contact.persisted? && !@contact.sharing?)
|
||||
.right
|
||||
= link_to t('.start_sharing'),
|
||||
{:controller => "contacts",
|
||||
:action => "new",
|
||||
:person_id => @person.id},
|
||||
:class => 'share_with button',
|
||||
:rel => 'facebox'
|
||||
- if @share_with
|
||||
= javascript_tag "$(document).ready(function() {jQuery.facebox({ ajax: '#{new_contact_path(:person_id => @person.id)}' });});"
|
||||
|
||||
- else
|
||||
- if user_signed_in? && @contact.mutual?
|
||||
- elsif @contact
|
||||
.right
|
||||
= link_to t('.mention'), new_status_message_path(:person_id => @person.id), :class => 'button', :rel => 'facebox'
|
||||
= link_to t('.message'), new_conversation_path(:contact_id => @contact.id, :name => @contact.person.name, :contact_id => @contact.id), :class => 'button', :rel => 'facebox'
|
||||
- if @contact.mutual?
|
||||
= link_to t('.message'), new_conversation_path(:contact_id => @contact.id, :name => @contact.person.name, :contact_id => @contact.id), :class => 'button', :rel => 'facebox'
|
||||
|
||||
/- if @post_type == :photos
|
||||
/ = link_to t('layouts.header.view_profile'), person_path(@person)
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ Diaspora::Application.routes.draw do
|
|||
get 'bookmarklet' => 'status_messages#bookmarklet'
|
||||
resource :profile
|
||||
|
||||
resources :contacts, :except => [:index, :update]
|
||||
resources :contacts, :except => [:index, :update, :create]
|
||||
resources :aspect_memberships, :only => [:destroy, :create, :update]
|
||||
resources :post_visibilities, :only => [:update]
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@ SQL
|
|||
add_foreign_key "contacts", "people", :name => "contacts_person_id_fk", :dependent => :delete
|
||||
|
||||
remove_column :contacts, :pending
|
||||
|
||||
remove_foreign_key :aspect_memberships, :aspects
|
||||
add_foreign_key :aspect_memberships, :aspects, :dependent => :delete
|
||||
end
|
||||
|
||||
def self.down
|
||||
|
|
@ -45,5 +48,8 @@ SQL
|
|||
)
|
||||
|
||||
remove_column :contacts, :mutual
|
||||
|
||||
remove_foreign_key :aspect_memberships, :aspects
|
||||
add_foreign_key :aspect_memberships, :aspects
|
||||
end
|
||||
end
|
||||
|
|
|
|||
32
db/migrate/20110406202932_drop_requests_table.rb
Normal file
32
db/migrate/20110406202932_drop_requests_table.rb
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
class DropRequestsTable < ActiveRecord::Migration
|
||||
def self.up
|
||||
remove_foreign_key :requests, :column => :recipient_id
|
||||
remove_foreign_key :requests, :column => :sender_id
|
||||
|
||||
remove_index :requests, :mongo_id
|
||||
remove_index :requests, :recipient_id
|
||||
remove_index :requests, [:sender_id, :recipient_id]
|
||||
remove_index :requests, :sender_id
|
||||
|
||||
drop_table :requests
|
||||
end
|
||||
|
||||
def self.down
|
||||
create_table :requests, :force => true do |t|
|
||||
t.integer :sender_id, :null => false
|
||||
t.integer :recipient_id, :null => false
|
||||
t.integer :aspect_id
|
||||
t.datetime :created_at
|
||||
t.datetime :updated_at
|
||||
t.string :mongo_id
|
||||
end
|
||||
|
||||
add_index :requests, ["mongo_id"], :name => "index_requests_on_mongo_id"
|
||||
add_index :requests, ["recipient_id"], :name => "index_requests_on_recipient_id"
|
||||
add_index :requests, ["sender_id", "recipient_id"], :name => "index_requests_on_sender_id_and_recipient_id", :unique => true
|
||||
add_index :requests, ["sender_id"], :name => "index_requests_on_sender_id"
|
||||
|
||||
add_foreign_key :requests, :people, :column => "recipient_id", :dependent => :delete
|
||||
add_foreign_key :requests, :people, :column => "sender_id", :dependent => :delete
|
||||
end
|
||||
end
|
||||
|
|
@ -365,7 +365,7 @@ ActiveRecord::Schema.define(:version => 20110406202932) do
|
|||
add_index "users", ["mongo_id"], :name => "index_users_on_mongo_id"
|
||||
add_index "users", ["username"], :name => "index_users_on_username", :unique => true
|
||||
|
||||
add_foreign_key "aspect_memberships", "aspects", :name => "aspect_memberships_aspect_id_fk"
|
||||
add_foreign_key "aspect_memberships", "aspects", :name => "aspect_memberships_aspect_id_fk", :dependent => :delete
|
||||
add_foreign_key "aspect_memberships", "contacts", :name => "aspect_memberships_contact_id_fk", :dependent => :delete
|
||||
|
||||
add_foreign_key "aspect_visibilities", "aspects", :name => "aspect_visibilities_aspect_id_fk", :dependent => :delete
|
||||
|
|
|
|||
|
|
@ -6,7 +6,10 @@ Feature: sending and receiving requests
|
|||
And a user with email "alice@alice.alice"
|
||||
When I sign in as "bob@bob.bob"
|
||||
And I am on "alice@alice.alice"'s page
|
||||
And I press the first ".share_with.button" within "#author_info"
|
||||
|
||||
|
||||
And I press the first ".share_with.button"
|
||||
And I wait for the ajax to finish
|
||||
And I add the person to my first aspect
|
||||
|
||||
And I am on the home page
|
||||
|
|
@ -24,6 +27,22 @@ Feature: sending and receiving requests
|
|||
And I am on the home page
|
||||
Then I should not see "I am following you"
|
||||
|
||||
Scenario: see following's public posts on their profile page and on the home page
|
||||
Given I sign in as "alice@alice.alice"
|
||||
And I am on the home page
|
||||
And I expand the publisher
|
||||
And I fill in "status_message_fake_text" with "I am ALICE"
|
||||
And I press the first ".public_icon" within "#publisher"
|
||||
And I press "Share"
|
||||
And I go to the destroy user session page
|
||||
|
||||
When I sign in as "bob@bob.bob"
|
||||
And I am on "alice@alice.alice"'s page
|
||||
|
||||
Then I should see "I am ALICE"
|
||||
And I am on the home page
|
||||
Then I should see "I am ALICE"
|
||||
|
||||
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
|
||||
|
|
@ -52,7 +71,7 @@ Feature: sending and receiving requests
|
|||
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
|
||||
Scenario: following a contact request into a new aspect
|
||||
When I sign in as "alice@alice.alice"
|
||||
And I am on "bob@bob.bob"'s page
|
||||
And I press the first ".share_with.button" within "#author_info"
|
||||
|
|
@ -69,3 +88,36 @@ Feature: sending and receiving requests
|
|||
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: should not see start sharing and see mention if already a follower
|
||||
When I sign in as "bob@bob.bob"
|
||||
And I am on "alice@alice.alice"'s page
|
||||
|
||||
Then I should not see "start sharing"
|
||||
Then I should see "edit aspect membership"
|
||||
Then I should see "Mention"
|
||||
Then I should not see "Message"
|
||||
|
||||
Scenario: should see start sharing and not see mention if on a follower's page
|
||||
When I sign in as "alice@alice.alice"
|
||||
And I am on "bob@bob.bob"'s page
|
||||
|
||||
Then I should see "start sharing"
|
||||
Then I should not see "edit aspect membership"
|
||||
Then I should not see "Mention"
|
||||
Then I should not see "Message"
|
||||
|
||||
Scenario: should see start sharing & mention & message on mutual contacts
|
||||
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"
|
||||
And I press the 1st ".add.button" within "#facebox #aspects_list ul > li:first-child"
|
||||
And I wait for the ajax to finish
|
||||
And I press the 1st ".add.button" within "#facebox #aspects_list ul > li:nth-child(2)"
|
||||
And I wait for the ajax to finish
|
||||
And I am on "bob@bob.bob"'s page
|
||||
|
||||
Then I should not see "start sharing"
|
||||
Then I should see "edit aspect membership"
|
||||
Then I should see "Mention"
|
||||
Then I should see "Message"
|
||||
|
|
|
|||
|
|
@ -7,8 +7,12 @@ module Diaspora
|
|||
module Connecting
|
||||
def share_with(person, aspect)
|
||||
contact = self.contacts.find_or_initialize_by_person_id(person.id)
|
||||
unless contact.persisted?
|
||||
unless contact.receiving?
|
||||
contact.dispatch_request
|
||||
|
||||
if contact.sharing?
|
||||
contact.mutual = true
|
||||
end
|
||||
end
|
||||
contact.aspects << aspect
|
||||
contact.save
|
||||
|
|
@ -20,15 +24,6 @@ module Diaspora
|
|||
contact
|
||||
end
|
||||
|
||||
def receive_contact_request(request)
|
||||
contact = self.contacts.find_or_initialize_by_person_id(request.sender.id)
|
||||
if contact.persisted? && !contact.mutual?
|
||||
contact.mutual = true
|
||||
end
|
||||
contact.save
|
||||
request
|
||||
end
|
||||
|
||||
def remove_contact(contact, opts={:force => false})
|
||||
posts = contact.posts.all
|
||||
|
||||
|
|
@ -36,8 +31,7 @@ module Diaspora
|
|||
contact.destroy
|
||||
else
|
||||
contact.update_attributes(:mutual => false)
|
||||
contact.post_visibilities.destroy_all
|
||||
contact.aspect_memberships.destroy_all
|
||||
AspectMembership.where(:contact_id => contact.id).delete_all
|
||||
end
|
||||
|
||||
posts.each do |p|
|
||||
|
|
|
|||
|
|
@ -60,12 +60,7 @@ module Postzord
|
|||
end
|
||||
|
||||
def validate_object
|
||||
#begin similar
|
||||
unless @object.is_a?(Request) || @user.contact_for(@sender)
|
||||
Rails.logger.info("event=receive status=abort reason='sender not connected to recipient' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle} payload_type=#{@object.class}")
|
||||
return false
|
||||
end
|
||||
#special casey
|
||||
#special casey
|
||||
if @object.is_a?(Request)
|
||||
@object.sender_handle = @sender.diaspora_handle
|
||||
end
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ describe ContactsController do
|
|||
end
|
||||
|
||||
it 'calls share_in_aspect' do
|
||||
@controller.should_receive(:share_in_aspect).with(@aspect, @person)
|
||||
@controller.should_receive(:share_with).with(@aspect, @person)
|
||||
post :create,
|
||||
:format => 'js',
|
||||
:person_id => @person.id,
|
||||
|
|
@ -42,7 +42,7 @@ describe ContactsController do
|
|||
end
|
||||
|
||||
it 'failure flashes error' do
|
||||
@controller.should_receive(:share_in_aspect).and_return(nil)
|
||||
@controller.should_receive(:share_with).and_return(nil)
|
||||
post :create,
|
||||
:format => 'js',
|
||||
:person_id => @person.id,
|
||||
|
|
@ -86,15 +86,4 @@ 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
|
||||
|
|
|
|||
|
|
@ -8,31 +8,25 @@ require File.join(Rails.root, "spec", "shared_behaviors", "log_override")
|
|||
describe HomeController do
|
||||
render_views
|
||||
|
||||
before do
|
||||
@user = alice
|
||||
sign_in @user
|
||||
sign_out @user
|
||||
end
|
||||
|
||||
describe '#show' do
|
||||
it 'shows a login link if no user is not logged in' do
|
||||
it 'does not redirect' do
|
||||
get :show
|
||||
response.body.should include("login")
|
||||
response.should_not be_redirect
|
||||
end
|
||||
|
||||
it 'redirects to aspects index if user is logged in' do
|
||||
sign_in @user
|
||||
sign_in alice
|
||||
get :show, :home => true
|
||||
response.should redirect_to( :controller => 'aspects', :action => 'index')
|
||||
end
|
||||
|
||||
it 'redirects to aspects index with stored aspects' do
|
||||
sign_in @user
|
||||
@aspect0 = @user.aspects.all[0]
|
||||
@aspect1 = @user.aspects.create(:name => "Yeaaaah!")
|
||||
sign_in alice
|
||||
@aspect0 = alice.aspects.all[0]
|
||||
@aspect1 = alice.aspects.create(:name => "Yeaaaah!")
|
||||
@index_params = {:a_ids => [@aspect0.id.to_s, @aspect1.id.to_s]}
|
||||
@user.aspects.where(:id => @index_params[:a_ids]).update_all(:open => true)
|
||||
@user.save
|
||||
alice.aspects.where(:id => @index_params[:a_ids]).update_all(:open => true)
|
||||
alice.save
|
||||
get :show
|
||||
response.should redirect_to( :controller => 'aspects', :action => 'index', :a_ids => @index_params[:a_ids] )
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,16 +8,13 @@ describe PostVisibilitiesController do
|
|||
render_views
|
||||
|
||||
before do
|
||||
a2 = bob.aspects.create(:name => "two")
|
||||
bob.contacts.create(:person => alice.person, :aspects => [a2])
|
||||
|
||||
@status = bob.post(:status_message, :text => "hello", :to => a2)
|
||||
@status = alice.post(:status_message, :text => "hello", :to => alice.aspects.first)
|
||||
@vis = @status.post_visibilities.first
|
||||
end
|
||||
|
||||
describe '#update' do
|
||||
before do
|
||||
sign_in :user, alice
|
||||
sign_in :user, bob
|
||||
end
|
||||
|
||||
context "on a post you can see" do
|
||||
|
|
|
|||
|
|
@ -157,8 +157,8 @@ describe 'a user receives a post' do
|
|||
@contact.posts.should include(@status_message)
|
||||
end
|
||||
|
||||
it 'removes posts upon disconnecting' do
|
||||
alice.disconnect(@contact)
|
||||
it 'removes posts upon forceful removal' do
|
||||
alice.remove_contact(@contact, :force => true)
|
||||
alice.reload
|
||||
alice.raw_visible_posts.should_not include @status_message
|
||||
end
|
||||
|
|
@ -189,12 +189,13 @@ describe 'a user receives a post' do
|
|||
}.should change{@post.post_visibilities(true).count}.by(-1)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should keep track of user references for one person ' do
|
||||
@status_message.reload
|
||||
@status_message.user_refs.should == 3
|
||||
@status_message.contacts(true).should include(@contact)
|
||||
|
||||
alice.disconnect(@contact)
|
||||
alice.remove_contact(@contact, :force => true)
|
||||
@status_message.reload
|
||||
@status_message.contacts(true).should_not include(@contact)
|
||||
@status_message.post_visibilities.reset
|
||||
|
|
@ -214,7 +215,7 @@ describe 'a user receives a post' do
|
|||
@status_message.post_visibilities.reset
|
||||
@status_message.user_refs.should == 4
|
||||
|
||||
alice.disconnect(@contact)
|
||||
alice.remove_contact(@contact, :force => true)
|
||||
@status_message.post_visibilities.reset
|
||||
@status_message.user_refs.should == 3
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,13 +6,9 @@ require 'spec_helper'
|
|||
|
||||
describe Contact do
|
||||
describe 'aspect_memberships' do
|
||||
before do
|
||||
@user = alice
|
||||
@user2 = bob
|
||||
end
|
||||
it 'deletes dependent aspect memberships' do
|
||||
lambda{
|
||||
@user.contact_for(@user2.person).destroy
|
||||
alice.contact_for(bob.person).destroy
|
||||
}.should change(AspectMembership, :count).by(-1)
|
||||
end
|
||||
end
|
||||
|
|
@ -71,19 +67,23 @@ describe Contact do
|
|||
end
|
||||
#eve <-> bob <-> alice
|
||||
end
|
||||
|
||||
context 'on a contact for a local user' do
|
||||
before do
|
||||
@contact = @alice.contact_for(@bob.person)
|
||||
end
|
||||
|
||||
it "returns the target local user's contacts that are in the same aspect" do
|
||||
@contact.contacts.map{|p| p.id}.should == [@eve.person].concat(@people1).map{|p| p.id}
|
||||
end
|
||||
|
||||
it 'returns nothing if contacts_visible is false in that aspect' do
|
||||
asp = @bob.aspects.first
|
||||
asp.contacts_visible = false
|
||||
asp.save
|
||||
@contact.contacts.should == []
|
||||
end
|
||||
|
||||
it 'returns no duplicate contacts' do
|
||||
[@alice, @eve].each {|c| @bob.add_contact_to_aspect(@bob.contact_for(c.person), @bob.aspects.last)}
|
||||
contact_ids = @contact.contacts.map{|p| p.id}
|
||||
|
|
@ -102,7 +102,6 @@ describe Contact do
|
|||
|
||||
end
|
||||
|
||||
|
||||
context 'requesting' do
|
||||
before do
|
||||
@contact = Contact.new
|
||||
|
|
@ -133,4 +132,38 @@ describe Contact do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'sharing/receiving status' do
|
||||
before do
|
||||
alice.share_with(eve.person, alice.aspects.first)
|
||||
|
||||
@follower = eve.contact_for(alice.person)
|
||||
@following = alice.contact_for(eve.person)
|
||||
end
|
||||
|
||||
describe '#sharing?' do
|
||||
it 'returns true if contact has no aspect visibilities' do
|
||||
@follower.should be_sharing
|
||||
end
|
||||
|
||||
it 'returns false if contact has aspect visibilities' do
|
||||
@following.should_not be_sharing
|
||||
end
|
||||
|
||||
it 'returns false if contact is not persisted' do
|
||||
Contact.new.should_not be_sharing
|
||||
end
|
||||
end
|
||||
|
||||
describe '#receiving?' do
|
||||
it 'returns false if contact has no aspect visibilities' do
|
||||
@follower.should_not be_receiving
|
||||
end
|
||||
|
||||
it 'returns true if contact has aspect visibilities' do
|
||||
@following.should be_receiving
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -55,13 +55,8 @@ describe Notification do
|
|||
Notification.notify(@user, @request, @person)
|
||||
end
|
||||
|
||||
it 'creates the notification already read' do
|
||||
n = Notification.notify(@user, @request, @person)
|
||||
n.should_not be_unread
|
||||
end
|
||||
|
||||
it 'sockets to the recipient' do
|
||||
opts = {:target_id => @request.id,
|
||||
opts = {:target_id => @request.sender.id,
|
||||
:target_type => "Request",
|
||||
:actors => [@person],
|
||||
:recipient_id => @user.id}
|
||||
|
|
|
|||
|
|
@ -68,8 +68,23 @@ describe Request do
|
|||
describe '#receive' do
|
||||
it 'creates a contact' do
|
||||
request = Request.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect)
|
||||
eve.contacts.should_receive(:create).with(hash_including(:person_id => alice.person.id))
|
||||
request.receive(eve, alice.person)
|
||||
lambda{
|
||||
request.receive(eve, alice.person)
|
||||
}.should change{
|
||||
eve.contacts(true).size
|
||||
}.by(1)
|
||||
end
|
||||
|
||||
it 'sets mutual if a contact already exists' do
|
||||
alice.share_with(eve.person, alice.aspects.first)
|
||||
|
||||
lambda {
|
||||
Request.diaspora_initialize(:from => eve.person, :to => alice.person,
|
||||
:into => eve.aspects.first).receive(alice, eve.person)
|
||||
}.should change {
|
||||
alice.contacts.find_by_person_id(eve.person.id).mutual?
|
||||
}.from(false).to(true)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -16,113 +16,55 @@ describe Diaspora::UserModules::Connecting do
|
|||
let(:person_two) { Factory.create :person }
|
||||
let(:person_three) { Factory.create :person }
|
||||
|
||||
context 'contact requesting' do
|
||||
describe '#receive_contact_request' do
|
||||
it 'creates a contact' do
|
||||
r = Request.diaspora_initialize(:to => alice.person, :from => person)
|
||||
describe 'disconnecting' do
|
||||
describe '#remove_contact' do
|
||||
it 'removed non mutual contacts' do
|
||||
alice.share_with(eve.person, alice.aspects.first)
|
||||
lambda {
|
||||
alice.remove_contact alice.contact_for(eve.person)
|
||||
}.should change {
|
||||
alice.contacts(true).count
|
||||
}.by(-1)
|
||||
end
|
||||
|
||||
it 'removes a contacts mutual flag' do
|
||||
bob.contacts.find_by_person_id(alice.person.id).mutual.should be_true
|
||||
bob.remove_contact(bob.contact_for(alice.person))
|
||||
bob.contacts(true).find_by_person_id(alice.person.id).mutual.should be_false
|
||||
end
|
||||
|
||||
it 'should remove the contact from all aspects they are in' do
|
||||
contact = alice.contact_for(bob.person)
|
||||
new_aspect = alice.aspects.create(:name => 'new')
|
||||
alice.add_contact_to_aspect(contact, new_aspect)
|
||||
|
||||
lambda {
|
||||
received_req = r.receive(alice, person_one)
|
||||
}.should change(Contact, :count).by(1)
|
||||
alice.remove_contact(contact)
|
||||
}.should change(contact.aspects(true), :count).from(2).to(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#receive_contact_request' do
|
||||
before do
|
||||
@request = Request.new(:sender => eve.person, :recipient => alice.person)
|
||||
end
|
||||
it 'sets mutual on an existing contact' do
|
||||
alice.share_with(eve.person, aspect)
|
||||
lambda{
|
||||
alice.receive_contact_request(@request)
|
||||
}.should change{
|
||||
alice.contacts.find_by_person_id(eve.person.id).mutual
|
||||
}.from(false).to(true)
|
||||
end
|
||||
|
||||
it 'does not set mutual' do
|
||||
alice.receive_contact_request(@request)
|
||||
alice.contacts.find_by_person_id(eve.person.id).should_not be_mutual
|
||||
end
|
||||
|
||||
it 'doesnt set mutual on a contact' do
|
||||
pending
|
||||
alice.receive_contact_request(@acceptance)
|
||||
Request.where(:sender_id => eve.person.id, :recipient_id => alice.person.id).should be_empty
|
||||
describe '#disconnected_by' do
|
||||
it 'calls remove contact' do
|
||||
bob.should_receive(:remove_contact).with(bob.contact_for(alice.person))
|
||||
bob.disconnected_by(alice.person)
|
||||
end
|
||||
end
|
||||
|
||||
context 'received a contact request' do
|
||||
it 'should ignore a contact request from yourself' do
|
||||
request_from_myself = Request.diaspora_initialize(:to => alice.person, :from => alice.person)
|
||||
reversed_request = request_from_myself.reverse_for(alice)
|
||||
describe '#disconnect' do
|
||||
it 'calls remove contact' do
|
||||
contact = bob.contact_for(alice.person)
|
||||
|
||||
alice.receive_contact_request(reversed_request)
|
||||
reversed_request.persisted?.should be false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'disconnecting' do
|
||||
describe '#remove_contact' do
|
||||
it 'removed non mutual contacts' do
|
||||
alice.share_with(eve.person, alice.aspects.first)
|
||||
lambda {
|
||||
alice.remove_contact alice.contact_for(eve.person)
|
||||
}.should change {
|
||||
alice.contacts(true).count
|
||||
}.by(-1)
|
||||
end
|
||||
|
||||
it 'removes a contacts mutual flag' do
|
||||
lambda{
|
||||
bob.remove_contact(bob.contact_for(alice.person))
|
||||
}.should change {
|
||||
bob.contacts.find_by_person_id(alice.person.id).mutual
|
||||
}.from(true).to(false)
|
||||
end
|
||||
|
||||
it "deletes the disconnected user's posts from visible_posts" do
|
||||
StatusMessage.delete_all
|
||||
message = alice.post(:status_message, :text => "hi", :to => alice.aspects.first.id)
|
||||
|
||||
bob.reload.raw_visible_posts.should include(message)
|
||||
bob.disconnect bob.contact_for(alice.person)
|
||||
bob.reload.raw_visible_posts.should_not include(message)
|
||||
end
|
||||
|
||||
it 'should remove the contact from all aspects they are in' do
|
||||
contact = alice.contact_for(bob.person)
|
||||
new_aspect = alice.aspects.create(:name => 'new')
|
||||
alice.add_contact_to_aspect(contact, new_aspect)
|
||||
|
||||
lambda {
|
||||
alice.remove_contact(contact)
|
||||
}.should change(contact.aspects(true), :count).from(2).to(0)
|
||||
end
|
||||
bob.should_receive(:remove_contact).with(contact)
|
||||
bob.disconnect contact
|
||||
end
|
||||
|
||||
describe '#disconnected_by' do
|
||||
it 'calls remove contact' do
|
||||
bob.should_receive(:remove_contact).with(bob.contact_for(alice.person))
|
||||
bob.disconnected_by(alice.person)
|
||||
end
|
||||
end
|
||||
it 'dispatches a retraction' do
|
||||
p = mock()
|
||||
Postzord::Dispatch.should_receive(:new).and_return(p)
|
||||
p.should_receive(:post)
|
||||
|
||||
describe '#disconnect' do
|
||||
it 'calls remove contact' do
|
||||
contact = bob.contact_for(alice.person)
|
||||
|
||||
bob.should_receive(:remove_contact).with(contact)
|
||||
bob.disconnect contact
|
||||
end
|
||||
|
||||
it 'dispatches a retraction' do
|
||||
p = mock()
|
||||
Postzord::Dispatch.should_receive(:new).and_return(p)
|
||||
p.should_receive(:post)
|
||||
|
||||
bob.disconnect bob.contact_for(eve.person)
|
||||
end
|
||||
bob.disconnect bob.contact_for(eve.person)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -133,7 +75,19 @@ describe Diaspora::UserModules::Connecting do
|
|||
alice.share_with(eve.person, alice.aspects.first)
|
||||
}.should change(alice.contacts, :count).by(1)
|
||||
end
|
||||
|
||||
it 'does not set mutual on intial share request' do
|
||||
alice.share_with(eve.person, alice.aspects.first)
|
||||
alice.contacts.find_by_person_id(eve.person.id).should_not be_mutual
|
||||
end
|
||||
|
||||
it 'does set mutual on share-back request' do
|
||||
eve.share_with(alice.person, eve.aspects.first)
|
||||
|
||||
alice.share_with(eve.person, alice.aspects.first)
|
||||
alice.contacts.find_by_person_id(eve.person.id).should be_mutual
|
||||
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)
|
||||
|
|
@ -143,20 +97,34 @@ describe Diaspora::UserModules::Connecting do
|
|||
}.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)
|
||||
context 'dispatching' do
|
||||
it 'dispatches a request on initial 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
|
||||
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)
|
||||
it 'dispatches a request on a share-back' do
|
||||
eve.share_with(alice.person, eve.aspects.first)
|
||||
|
||||
contact.should_not_receive(:dispatch_request)
|
||||
alice.share_with(eve.person, alice.aspects.first)
|
||||
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 on adding to aspect aspect' do
|
||||
a2 = alice.aspects.create(:name => "two")
|
||||
|
||||
contact = alice.contacts.create(:person => eve.person, :aspects => [eve.aspects.first])
|
||||
alice.contacts.stub!(:find_or_initialize_by_person_id).and_return(contact)
|
||||
|
||||
contact.should_not_receive(:dispatch_request)
|
||||
alice.share_with(eve.person, a2)
|
||||
end
|
||||
end
|
||||
|
||||
it "should mark the corresponding notification as 'read'" do
|
||||
|
|
|
|||
Loading…
Reference in a new issue