From 847f4fd26081aadf855b0395f3dd5aa84a0af778 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 5 Apr 2011 18:53:10 -0700 Subject: [PATCH] edited subscribers to include all contacts on public posts. added the ability to drop an aspect regardless of contacts contained. wip. --- app/controllers/users_controller.rb | 2 +- app/models/aspect_membership.rb | 7 ++++++ app/models/post.rb | 6 +++++- app/views/people/_relationship_action.haml | 2 +- features/accepts_invitation.feature | 11 +--------- spec/models/aspect_membership_spec.rb | 25 ++++++++++++++++------ spec/models/post_spec.rb | 7 +++++- 7 files changed, 40 insertions(+), 20 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 431259e51..a76ccabbf 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -113,7 +113,7 @@ class UsersController < ApplicationController end - if @step == 3 && @requests.length == 0 && @friends.length == 0 + if @step == 3 && @friends.length == 0 @user.update_attributes(:getting_started => false) flash[:notice] = I18n.t('users.getting_started.could_not_find_anyone') redirect_to root_path diff --git a/app/models/aspect_membership.rb b/app/models/aspect_membership.rb index f79d31520..f02ce4a0f 100644 --- a/app/models/aspect_membership.rb +++ b/app/models/aspect_membership.rb @@ -9,4 +9,11 @@ class AspectMembership < ActiveRecord::Base has_one :user, :through => :contact has_one :person, :through => :contact + before_destroy do + unless self.contact.aspects.size > 1 + self.user.disconnect(self.contact) + end + true + end + end diff --git a/app/models/post.rb b/app/models/post.rb index 359e04aff..502acb1a5 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -65,7 +65,11 @@ class Post < ActiveRecord::Base end def subscribers(user) - user.people_in_aspects(user.aspects_with_post(self.id)) + if self.public? + user.contact_people + else + user.people_in_aspects(user.aspects_with_post(self.id)) + end end def receive(user, person) diff --git a/app/views/people/_relationship_action.haml b/app/views/people/_relationship_action.haml index 96f653f82..25d457343 100644 --- a/app/views/people/_relationship_action.haml +++ b/app/views/people/_relationship_action.haml @@ -1,6 +1,6 @@ - if person.owner_id == current_user.id = t('people.person.thats_you') -- elsif contact && !contact.pending +- elsif contact && contact.mutual = t('people.person.already_connected') - else = link_to t('people.show.start_sharing'), diff --git a/features/accepts_invitation.feature b/features/accepts_invitation.feature index 1fbe38431..a7ad79506 100644 --- a/features/accepts_invitation.feature +++ b/features/accepts_invitation.feature @@ -37,14 +37,5 @@ Feature: invitation acceptance And I should see "Would you like to find your Facebook friends on Diaspora?" When I follow "Skip" - Then I should see "People already on Diaspora" - - And I press the first ".share_with.button" - And I press the first ".add.button" within "#facebox #aspects_list ul > li:first-child" - And I wait for the ajax to finish - - When I go to the home page - Then I go to the manage aspects page - Then I should see 1 contact in "Family" - + Then I should be on the aspects page diff --git a/spec/models/aspect_membership_spec.rb b/spec/models/aspect_membership_spec.rb index 12f1c7fc4..fb09ccabc 100644 --- a/spec/models/aspect_membership_spec.rb +++ b/spec/models/aspect_membership_spec.rb @@ -6,13 +6,26 @@ require 'spec_helper' describe AspectMembership do - describe '#before_delete' do - it 'calls disconnect' do - pending - alice.should_receive(:disconnect).with(alice.contact_for(bob)) + describe '#before_destroy' do + before do + @aspect = alice.aspects.create(:name => "two") + @contact = alice.contact_for(bob.person) - alice.aspects.create(:name => "two") - alice.aspects.first.destroy + @am = alice.aspects.first.aspect_memberships.first + @am.stub!(:user).and_return(alice) + end + + it 'calls disconnect if its the last aspect for the contact' do + alice.should_receive(:disconnect).with(@contact) + + @am.destroy + end + + it 'does not call disconnect if its not the last aspect for the contact' do + alice.should_not_receive(:disconnect) + + alice.add_contact_to_aspect(@contact, @aspect) + @am.destroy end end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index b55558af4..d63a2641f 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -39,11 +39,16 @@ describe Post do describe '#subscribers' do it 'returns the people contained in the aspects the post appears in' do - post = @user.post :status_message, :text => "hello", :to => @aspect.id post.subscribers(@user).should == [] end + + it 'returns all a users contacts if the post is public' do + post = @user.post :status_message, :text => "hello", :to => @aspect.id, :public => true + + post.subscribers(@user).to_set.should == @user.contact_people.to_set + end end describe '#receive' do