added mutual flag, removed pending from contact, specs are green. wip

This commit is contained in:
danielgrippi 2011-04-05 16:12:53 -07:00
parent 07f7eff782
commit 68375fdb02
34 changed files with 219 additions and 314 deletions

3
.rspec
View file

@ -1,3 +1,4 @@
--format Fuubar
--profile
--color
--color
--tag ~performance

View file

@ -64,7 +64,6 @@ class AspectMembershipsController < ApplicationController
end
end
def update
@person = Person.find(params[:person_id])
@from_aspect = current_user.aspects.where(:id => params[:aspect_id]).first

View file

@ -78,7 +78,7 @@ class PeopleController < ApplicationController
@contacts_of_contact = []
end
if (@person != current_user.person) && (!@contact || @contact.pending)
if (@person != current_user.person) && (!@contact || @contact.mutual)
@commenting_disabled = true
else
@commenting_disabled = false

View file

@ -5,7 +5,7 @@
class Aspect < ActiveRecord::Base
belongs_to :user
has_many :aspect_memberships
has_many :aspect_memberships, :dependent => :destroy
has_many :contacts, :through => :aspect_memberships
has_many :aspect_visibilities

View file

@ -9,14 +9,4 @@ class AspectMembership < ActiveRecord::Base
has_one :user, :through => :contact
has_one :person, :through => :contact
before_destroy :ensure_membership
def ensure_membership
if self.contact.aspect_memberships.count == 1
errors[:base] << I18n.t('shared.contact_list.cannot_remove')
false
else
true
end
end
end

View file

@ -3,8 +3,6 @@
# the COPYRIGHT file.
class Contact < ActiveRecord::Base
default_scope where(:pending => false)
belongs_to :user
validates_presence_of :user

View file

@ -19,7 +19,7 @@ class Invitation < ActiveRecord::Base
if opts[:from].contact_for(opts[:from].person)
raise "You are already connceted to this person"
elsif not existing_user.invited?
opts[:from].send_contact_request_to(existing_user.person, opts[:into])
opts[:from].share_with(existing_user.person, opts[:into])
return
elsif Invitation.where(:sender_id => opts[:from].id, :recipient_id => existing_user.id).first
raise "You already invited this person"

View file

@ -3,8 +3,6 @@
# the COPYRIGHT file.
class PostVisibility < ActiveRecord::Base
default_scope where(:hidden => false)
belongs_to :contact
belongs_to :post
end

View file

@ -66,10 +66,7 @@ class Request < ActiveRecord::Base
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, :pending => false)
#user.receive_contact_request(self)
user.contacts.create(:person_id => person.id)
self.save
self
end

View file

@ -328,15 +328,15 @@ class User < ActiveRecord::Base
end
def disconnect_everyone
Contact.unscoped.where(:user_id => self.id).each { |contact|
self.contacts.each do |contact|
unless contact.person.owner.nil?
contact.person.owner.disconnected_by self.person
remove_contact(contact)
contact.person.owner.disconnected_by(self.person)
remove_contact(contact, :force => true)
else
self.disconnect contact
self.disconnect(contact)
end
}
self.aspects.delete_all
end
self.aspects.destroy_all
end
def remove_mentions

View file

@ -10,4 +10,4 @@
%ul
- for aspect in aspects
= render 'aspects/aspect', :aspect => aspect, :contacts => aspect.contacts.reject{|x| x.pending == true}
= render 'aspects/aspect', :aspect => aspect, :contacts => aspect.contacts

View file

@ -5,11 +5,9 @@
- content_for :head do
=javascript_include_tag 'contact-list'
.aspects
- if !contact || !contact.persisted?
- elsif contact.pending
%h4
= t('people.person.pending_request')
- else
/ TODO(*) add following method in contact
- if contact && contact.persisted?
.badges{:class => ("hidden" if !contact.persisted?)}
= aspect_badges(aspects_with_person, :link => true)
%p

View file

@ -35,7 +35,7 @@
%br
%hr{:style=>"width:300px;"}
-if user_signed_in? && ((contact.persisted? && !contact.pending?) || person == current_user.person || @incoming_request)
-if user_signed_in? && ((contact.persisted? && contact.mutual?) || person == current_user.person || @incoming_request)
%ul#profile_information
- unless person.profile.bio.blank?
%li

View file

@ -36,7 +36,7 @@
= 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
- if user_signed_in? && @contact.mutual?
.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'

View file

@ -1,7 +1,8 @@
%li.remote_friend{:id => "uid_" + friend.uid, :uid => friend.uid}
.right
-if friend.contact && !friend.contact.pending
= t('people.person.already_connected')
-if friend.contact
/ TODO(*) add following method in Contact
sharing
- elsif friend.invitation_id
= t('invitations.new.already_invited')
%br

View file

@ -0,0 +1,42 @@
class ContactRemovePendingAddMutual < ActiveRecord::Migration
def self.up
add_column :contacts, :mutual, :boolean, :default => false, :null => false
execute( <<SQL
UPDATE contacts
SET contacts.mutual = true
WHERE contacts.pending = false
SQL
)
remove_foreign_key "contacts", "people"
remove_index :contacts, [:person_id, :pending]
remove_index :contacts, [:user_id, :pending]
add_index :contacts, :person_id
add_foreign_key "contacts", "people", :name => "contacts_person_id_fk", :dependent => :delete
remove_column :contacts, :pending
end
def self.down
remove_foreign_key "contacts", "people"
remove_index :contacts, :person_id
add_column :contacts, :pending, :default => true, :null => false
add_index :contacts, [:user_id, :pending]
add_index :contacts, [:person_id, :pending]
add_foreign_key "contacts", "people", :name => "contacts_person_id_fk", :dependent => :delete
execute( <<SQL
UPDATE contacts
SET contacts.pending = false
WHERE contacts.mutual = true
SQL
)
remove_column :contacts, :mutual
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110331222629) do
ActiveRecord::Schema.define(:version => 20110405171412) do
create_table "aspect_memberships", :force => true do |t|
t.integer "aspect_id", :null => false
@ -68,17 +68,16 @@ ActiveRecord::Schema.define(:version => 20110331222629) do
add_index "comments", ["post_id"], :name => "index_comments_on_post_id"
create_table "contacts", :force => true do |t|
t.integer "user_id", :null => false
t.integer "person_id", :null => false
t.boolean "pending", :default => true, :null => false
t.integer "user_id", :null => false
t.integer "person_id", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "mongo_id"
t.boolean "mutual", :default => false, :null => false
end
add_index "contacts", ["mongo_id"], :name => "index_contacts_on_mongo_id"
add_index "contacts", ["person_id", "pending"], :name => "index_contacts_on_person_id_and_pending"
add_index "contacts", ["user_id", "pending"], :name => "index_contacts_on_user_id_and_pending"
add_index "contacts", ["person_id"], :name => "index_contacts_on_person_id"
add_index "contacts", ["user_id", "person_id"], :name => "index_contacts_on_user_id_and_person_id", :unique => true
create_table "conversation_visibilities", :force => true do |t|
@ -250,6 +249,7 @@ ActiveRecord::Schema.define(:version => 20110331222629) do
add_index "posts", ["status_message_id", "pending"], :name => "index_posts_on_status_message_id_and_pending"
add_index "posts", ["status_message_id"], :name => "index_posts_on_status_message_id"
add_index "posts", ["type", "pending", "id"], :name => "index_posts_on_type_and_pending_and_id"
add_index "posts", ["type"], :name => "index_posts_on_type"
create_table "profiles", :force => true do |t|
t.string "diaspora_handle"

View file

@ -5,7 +5,6 @@
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?
@ -21,88 +20,33 @@ module Diaspora
contact
end
def receive_contact_request(request)
self.contacts.find_or_create_by_person_id(request.sender.id)
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
=begin
def send_contact_request_to(desired_contact, aspect)
self.contacts.new(:person => desired_contact,
:pending => true)
def remove_contact(contact, opts={:force => false})
posts = contact.posts.all
contact.aspects << aspect
if contact.save!
request = contact.dispatch_request
request
if !contact.mutual || opts[:force]
contact.destroy
else
nil
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)
if notification = Notification.where(:target_id=>request.id).first
notification.update_attributes(:unread=>false)
contact.update_attributes(:mutual => false)
contact.post_visibilities.destroy_all
contact.aspect_memberships.destroy_all
end
request.destroy
request.reverse_for(self)
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
reversed_request = accept_contact_request(request, aspects.where(:id => aspect_id).first )
dispatch_contact_acceptance reversed_request, requester
end
def ignore_contact_request(contact_request_id)
request = Request.where(:recipient_id => self.person.id, :id => contact_request_id).first
request.destroy
end
def receive_contact_request(contact_request)
#response from a contact request you sent
if original_contact = self.contact_for(contact_request.sender)
receive_request_acceptance(contact_request, original_contact)
#this is a new contact request
elsif contact_request.sender != self.person
if contact_request.save!
Rails.logger.info("event=contact_request status=received_new_request from=#{contact_request.sender.diaspora_handle} to=#{self.diaspora_handle}")
posts.each do |p|
if p.user_refs < 1
p.destroy
end
else
Rails.logger.info "event=contact_request status=abort from=#{contact_request.sender.diaspora_handle} to=#{self.diaspora_handle} reason=self-love"
return nil
end
contact_request
end
def receive_request_acceptance(received_request, contact)
contact.pending = false
contact.save
Rails.logger.info("event=contact_request status=received_acceptance from=#{received_request.sender.diaspora_handle} to=#{self.diaspora_handle}")
received_request.destroy
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}")
@ -112,24 +56,12 @@ module Diaspora
remove_contact(bad_contact)
end
def remove_contact(contact)
bad_person_id = contact.person_id
posts = contact.posts.all
contact.destroy
posts.each do |post|
if post.user_refs < 1
post.destroy
end
end
end
def disconnected_by(person)
Rails.logger.info("event=disconnected_by user=#{diaspora_handle} target=#{person.diaspora_handle}")
if contact = self.contact_for(person)
remove_contact(contact)
end
end
end
end
end

View file

@ -48,7 +48,7 @@ module Diaspora
end
def contact_for_person_id(person_id)
Contact.unscoped.where(:user_id => self.id, :person_id => person_id).includes(:person => :profile).first if person_id
Contact.where(:user_id => self.id, :person_id => person_id).includes(:person => :profile).first
end
def people_in_aspects(requested_aspects, opts={})

View file

@ -34,7 +34,6 @@ describe AspectMembershipsController do
end
end
describe "#destroy" do
it 'removes contacts from an aspect' do
@user.add_contact_to_aspect(@contact, @aspect1)
@ -47,17 +46,6 @@ describe AspectMembershipsController do
@aspect0.contacts.include?(@contact).should be false
end
describe "#update" do
it 'calls the move_contact method' do
@controller.stub!(:current_user).and_return(@user)
@user.should_receive(:move_contact)
put :update, :id => 123,
:person_id => @user.person.id,
:aspect_id => @aspect0.id,
:to => @aspect1.id
end
end
context 'aspect membership does not exist' do
it 'person does not exist' do
delete :destroy,
@ -77,14 +65,16 @@ describe AspectMembershipsController do
response.body.should include "Could not find the selected person in that aspect"
end
end
end
it 'has the error of cannot delete contact from last aspect if its the last aspect' do
delete :destroy,
:format => 'js', :id => 123,
:person_id => @user2.person.id,
:aspect_id => @aspect0.id
response.should_not be_success
response.body.should include "Cannot remove person from last aspect"
describe "#update" do
it 'calls the move_contact method' do
@controller.stub!(:current_user).and_return(@user)
@user.should_receive(:move_contact)
put :update, :id => 123,
:person_id => @user.person.id,
:aspect_id => @aspect0.id,
:to => @aspect1.id
end
end
end

View file

@ -9,13 +9,13 @@ describe AspectsController do
render_views
before do
@bob = bob
@bob = bob
@alice = alice
@alice.getting_started = false
@alice.save
sign_in :user, @alice
@alices_aspect_1 = @alice.aspects.first
@alices_aspect_2 = @alice.aspects.create(:name => "another aspect")
@alices_aspect_1 = @alice.aspects.first
@alices_aspect_2 = @alice.aspects.create(:name => "another aspect")
@controller.stub(:current_user).and_return(@alice)
request.env["HTTP_REFERER"] = 'http://' + request.host
@ -142,7 +142,7 @@ describe AspectsController do
get :index
assigns(:posts).should == @posts.reverse
get :index, :sort_order => "updated_at"
assigns(:posts).should == @posts
assigns(:posts).map(&:id).should == @posts.map(&:id)
end
it "doesn't allow SQL injection" do
@ -232,6 +232,7 @@ describe AspectsController do
get :manage
response.should be_success
end
it "performs reasonably", :performance => true do
require 'benchmark'
8.times do |n|
@ -245,32 +246,31 @@ describe AspectsController do
get :manage
}.should < 4.5
end
it "assigns aspect to manage" do
get :manage
assigns(:aspect).should == :manage
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
@alice.send_contact_request_to(Factory(:user).person, @alices_aspect_1)
Contact.unscoped.where(:user_id => @alice.id).count.should == 2
it "assigns contacts" do
get :manage
contacts = assigns(:contacts)
contacts.count.should == 1
contacts.first.should == contact
contacts.to_set.should == alice.contacts.to_set
end
end
describe "#update" do
before do
it "doesn't overwrite name" do
@alices_aspect_1 = @alice.aspects.create(:name => "Bruisers")
end
it "doesn't overwrite random attributes" do
new_user = Factory.create :user
params = {"name" => "Bruisers"}
new_user = Factory.create :user
params = {"name" => "Bruisers"}
params[:user_id] = new_user.id
put('update', :id => @alices_aspect_1.id, "aspect" => params)
put(:update, :id => @alices_aspect_1.id, :aspect => params)
Aspect.find(@alices_aspect_1.id).user_id.should == @alice.id
end
end

View file

@ -39,7 +39,7 @@ describe ServicesController do
end
describe '#create' do
it 'creates a new OmniauthService' do
it 'creates a new OmniauthService' do
request.env['omniauth.auth'] = omniauth_auth
lambda{
post :create, :provider => 'twitter'

View file

@ -5,15 +5,11 @@ module HelperMethods
def connect_users(user1, aspect1, user2, aspect2)
user1.contacts.create!(:person => user2.person,
:aspects => [aspect1],
:pending => false)
:mutual => true)
user2.contacts.create!(:person => user1.person,
:aspects => [aspect2],
:pending => false)
user1.reload
user2.reload
aspect1.reload
aspect2.reload
:mutual => true)
end
def stub_success(address = 'abc@example.com', opts = {})

View file

@ -83,7 +83,7 @@ describe 'a user receives a post' do
it 'notifies users when receiving a mention in a post from a remote user' do
@remote_person = Factory.create(:person, :diaspora_handle => "foobar@foobar.com")
Contact.create!(:user => alice, :person => @remote_person, :aspects => [@aspect], :pending => false)
Contact.create!(:user => alice, :person => @remote_person, :aspects => [@aspect])
Notification.should_receive(:notify).with(alice, anything(), @remote_person)
@ -153,8 +153,8 @@ describe 'a user receives a post' do
end
it "adds a received post to the the contact" do
alice.raw_visible_posts.include?(@status_message).should be_true
@contact.posts.include?(@status_message).should be_true
alice.raw_visible_posts.should include(@status_message)
@contact.posts.should include(@status_message)
end
it 'removes posts upon disconnecting' do
@ -177,7 +177,7 @@ describe 'a user receives a post' do
@post.post_visibilities.reset
end
it 'deletes a post if the noone links to it' do
it 'deletes a post if the no one links to it' do
lambda {
alice.disconnected_by(@person)
}.should change(Post, :count).by(-1)

View file

@ -5,30 +5,15 @@
require 'spec_helper'
describe AspectMembership do
before do
@user = alice
@user2 = bob
@aspect = @user.aspects.create(:name => 'Boozers')
@contact = @user.contact_for(@user2.person)
end
it 'has an aspect' do
am = AspectMembership.new(:aspect => @aspect)
am.aspect.should == @aspect
end
describe '#before_delete' do
it 'calls disconnect' do
pending
alice.should_receive(:disconnect).with(alice.contact_for(bob))
it 'has a contact' do
am = AspectMembership.new(:contact => @contact)
am.contact.should == @contact
end
context 'validations' do
describe '#ensure_membership' do
it 'does not destroy from the final aspect' do
am = @contact.aspect_memberships.first
am.destroy
am.errors.should_not be_empty
end
alice.aspects.create(:name => "two")
alice.aspects.first.destroy
end
end
end

View file

@ -7,7 +7,6 @@ require 'spec_helper'
describe Invitation do
let(:user) { alice }
let(:aspect) { user.aspects.first }
let(:user2) { eve }
before do
user.invites = 20
@ -18,11 +17,11 @@ describe Invitation do
describe 'validations' do
before do
aspect
@invitation = Invitation.new(:sender => user, :recipient => user2, :aspect => aspect)
@invitation = Invitation.new(:sender => user, :recipient => eve, :aspect => aspect)
end
it 'is valid' do
@invitation.sender.should == user
@invitation.recipient.should == user2
@invitation.recipient.should == eve
@invitation.aspect.should == aspect
@invitation.should be_valid
end
@ -41,7 +40,7 @@ describe Invitation do
end
it 'has a message' do
@invitation = Invitation.new(:sender => user, :recipient => user2, :aspect => aspect)
@invitation = Invitation.new(:sender => user, :recipient => eve, :aspect => aspect)
@invitation.message = "!"
@invitation.message.should == "!"
end
@ -54,7 +53,7 @@ describe Invitation do
@identifier = "maggie@example.org"
inv.invitation_identifier.should == @identifier
inv.invitation_service.should == 'email'
inv.persisted?.should be_false
inv.should_not be_persisted
lambda {
inv.reload
}.should raise_error ActiveRecord::RecordNotFound
@ -162,12 +161,8 @@ describe Invitation do
end
it 'sends a contact request to a user with that email into the aspect' do
user2
user.should_receive(:send_contact_request_to) { |a, b|
a.should == user2.person
b.should == aspect
}
Invitation.invite(:from => user, :service => 'email', :identifier => user2.email, :into => aspect)
user.should_receive(:share_with).with(eve.person, aspect)
Invitation.invite(:from => user, :service => 'email', :identifier => eve.email, :into => aspect)
end
it 'decrements the invite count of the from user' do
@ -322,10 +317,10 @@ describe Invitation do
}.should change(Invitation, :count).by(-1)
end
it 'creates a contact for the inviter' do
it 'creates a contact for the inviter and invitee' do
lambda {
@invitation.share_with!
}.should change(Contact.unscoped, :count).by(1)
}.should change(Contact, :count).by(2)
end
end
end

View file

@ -301,7 +301,7 @@ describe Person do
@casey_grippi.profile.first_name = "AAA"
@casey_grippi.profile.save
requestor.send_contact_request_to(@user.person, requestor.aspects.first)
requestor.share_with(@user.person, requestor.aspects.first)
people = Person.search("AAA", @user)
people.map{|p| p.name}.should == [requestor.person, @yevgeniy_dodis, @robert_grimm, @casey_grippi, @eugene_weinstein].map{|p|p.name}
end

View file

@ -1,22 +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 PostVisibility do
before do
@alice = alice
@bob = bob
@status = @alice.post(:status_message, :text => "hello", :public => true, :to => @alice.aspects.first)
@vis = @status.post_visibilities.first
@vis.hidden = true
@vis.save
end
it 'is default scoped to not-hidden' do
PostVisibility.where(:id => @vis.id).should == []
PostVisibility.unscoped.where(:id => @vis.id).should == [@vis]
end
end

View file

@ -56,7 +56,8 @@ describe Request do
end
it 'returns request_accepted' do
@user.contacts.create(:person_id => @person.id, :pending => true)
pending 'TODO(*) take out request accepted'
@user.contacts.create(:person_id => @person.id)
@request.notification_type(@user, @person).should == Notifications::RequestAccepted
end

View file

@ -22,23 +22,33 @@ describe Diaspora::UserModules::Connecting do
@r = Request.diaspora_initialize(:to => alice.person, :from => person)
end
it 'creates no contact' do
it 'creates a contact' do
lambda {
received_req = @r.receive(alice, person_one)
}.should change(Contact, :count).by(1)
end
end
describe '#receive_request_acceptance' do
describe '#receive_contact_request' do
before do
@original_request = alice.send_contact_request_to(eve.person, aspect)
@acceptance = @original_request.reverse_for(eve)
@request = Request.new(:sender => eve.person, :recipient => alice.person)
end
it 'connects to the acceptor' do
alice.receive_contact_request(@acceptance)
alice.contact_for(eve.person).should_not be_nil
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 'deletes the acceptance' do
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
end
@ -64,46 +74,65 @@ describe Diaspora::UserModules::Connecting do
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)
alice.add_contact_to_aspect(contact, new_aspect)
lambda { alice.remove_contact(contact) }.should change(
contact.aspects, :count).from(2).to(0)
end
context 'with a post' do
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.include?(message).should be_true
bob.disconnect bob.contact_for(alice.person)
bob.reload.raw_visible_posts.include?(message).should be_false
end
lambda {
alice.remove_contact(contact)
}.should change(contact.aspects(true), :count).from(2).to(0)
end
end
describe '#disconnected_by' do
it 'removes a contacts mutual flag' do
pending 'needs migration'
alice.share_with(eve.person, alice.aspects.first)
alice.contacts.where(:person_id => eve.person.id).mutual.should be_true
eve.disconnected_by(alice.person)
alice.contacts.where(:person_id => eve.person.id).mutual.should be_false
it 'calls remove contact' do
bob.should_receive(:remove_contact).with(bob.contact_for(alice.person))
bob.disconnected_by(alice.person)
end
end
describe '#disconnect' do
it 'disconnects a contact on the same seed' do
bob.aspects.first.contacts.count.should == 2
lambda {
bob.disconnect bob.contact_for(alice.person) }.should change {
bob.contacts(true).count }.by(-1)
bob.aspects.first.contacts(true).count.should == 1
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
end
end

View file

@ -48,13 +48,11 @@ describe User do
inviter.invite_user(aspect.id, 'email', @email).email.should == @email
end
it 'throws if you try to add someone you"re connected to' do
it "throws if you try to add someone you're connected to" do
connect_users(inviter, aspect, another_user, wrong_aspect)
inviter.reload
proc{
inviter.invite_user(aspect.id, 'email', another_user.email)
}.should raise_error ActiveRecord::RecordInvalid
}.should raise_error ActiveRecord::RecordNotUnique
end
end

View file

@ -13,11 +13,10 @@ describe User do
describe "#raw_visible_posts" do
it "returns all the posts the user can see" do
connect_users(eve, @eves_aspect, alice, @alices_aspect)
self_post = alice.post(:status_message, :text => "hi", :to => @alices_aspect.id)
visible_post = eve.post(:status_message, :text => "hello", :to => @eves_aspect.id)
dogs = eve.aspects.create(:name => "dogs")
invisible_post = eve.post(:status_message, :text => "foobar", :to => dogs.id)
visible_post = bob.post(:status_message, :text => "hello", :to => bob.aspects.first.id)
dogs = bob.aspects.create(:name => "dogs")
invisible_post = bob.post(:status_message, :text => "foobar", :to => dogs.id)
stream = alice.raw_visible_posts
stream.should include(self_post)
@ -119,10 +118,6 @@ describe User do
end
it "only returns non-pending contacts" do
alice.send_contact_request_to(Factory(:user).person, @alices_aspect)
@alices_aspect.reload
alice.reload
alice.people_in_aspects([@alices_aspect]).should == [bob.person]
end

View file

@ -228,7 +228,7 @@ describe User do
end
it "returns false if the user has already sent a request to that person" do
alice.send_contact_request_to(eve.person, alice.aspects.first)
alice.share_with(eve.person, alice.aspects.first)
alice.reload
eve.reload
alice.can_add?(eve.person).should be_false
@ -332,22 +332,6 @@ describe User do
end
end
describe 'foreign key between aspects and contacts' do
it 'should delete an empty aspect' do
empty_aspect = alice.aspects.create(:name => 'decoy')
alice.aspects(true).include?(empty_aspect).should == true
empty_aspect.destroy
alice.aspects(true).include?(empty_aspect).should == false
end
it 'should not delete an aspect with contacts' do
aspect = alice.aspects.first
aspect.contacts.count.should > 0
proc { aspect.destroy }.should raise_error ActiveRecord::StatementInvalid
alice.aspects.include?(aspect).should == true
end
end
describe '#update_post' do
it 'sends a notification to aspects' do
m = mock()
@ -425,14 +409,18 @@ describe User do
it 'removes all contacts' do
lambda {
alice.destroy
}.should change { alice.contacts(true).count }.by(-1)
}.should change {
alice.contacts.count
}.by(-1)
end
it 'removes all service connections' do
Services::Facebook.create(:access_token => 'what', :user_id => alice.id)
lambda {
alice.destroy
}.should change { alice.services(true).count }.by(-1)
}.should change {
alice.services.count
}.by(-1)
end
describe '#remove_person' do
@ -471,7 +459,7 @@ describe User do
end
it 'has no error when the user has sent local requests' do
alice.send_contact_request_to(eve.person, alice.aspects.first)
alice.share_with(eve.person, alice.aspects.first)
lambda {
alice.destroy
}.should_not raise_error

View file

@ -1,16 +1,10 @@
class User
def send_contact_request_to(desired_contact, aspect)
fantasy_resque do
contact = Contact.new(:person => desired_contact,
:user => self,
:pending => true)
contact.aspects << aspect
if contact.save!
contact.dispatch_request
else
nil
end
alias_method :share_with_original, :share_with
def share_with(*args)
fantasy_resque do
share_with_original(*args)
end
end