aspect membership refactor complete
This commit is contained in:
parent
c6eb5d0340
commit
8c2e6dd8cb
8 changed files with 44 additions and 58 deletions
|
|
@ -55,7 +55,7 @@ class AspectMembershipsController < ApplicationController
|
|||
|
||||
def create
|
||||
@person = Person.find(params[:person_id])
|
||||
@aspect = current_user.aspects.where(params[:aspect_id]).first
|
||||
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first
|
||||
@contact = current_user.contact_for(@person)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,12 +6,13 @@ class ContactsController < ApplicationController
|
|||
before_filter :authenticate_user!
|
||||
|
||||
def new
|
||||
#should be share_with?
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def create
|
||||
@person = Person.find(params[:person_id])
|
||||
@aspect = current_user.aspects.find(params[:aspect_id])
|
||||
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first
|
||||
|
||||
request_to_aspect(@aspect, @person)
|
||||
|
||||
|
|
|
|||
|
|
@ -74,11 +74,13 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def move_contact(person, to_aspect, from_aspect)
|
||||
return true if to_aspect == from_aspect
|
||||
contact = contact_for(person)
|
||||
if to_aspect == from_aspect
|
||||
true
|
||||
elsif add_contact_to_aspect(contact, to_aspect)
|
||||
delete_person_from_aspect(person.id, from_aspect.id)
|
||||
if add_contact_to_aspect(contact, to_aspect)
|
||||
membership = contact ? contact.aspect_memberships.where(:aspect_id => from_aspect.id).first : nil
|
||||
return ( membership && membership.destroy )
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -92,20 +94,6 @@ class User < ActiveRecord::Base
|
|||
contact.aspect_memberships.create!(:aspect => aspect)
|
||||
end
|
||||
|
||||
|
||||
def delete_person_from_aspect(person_id, aspect_id, opts = {})
|
||||
aspect = Aspect.find(aspect_id)
|
||||
raise "Can not delete a person from an aspect you do not own" unless aspect.user == self
|
||||
contact = contact_for Person.find(person_id)
|
||||
|
||||
if opts[:force] || contact.aspect_ids.count > 1
|
||||
contact.aspects.delete(aspect)
|
||||
else
|
||||
raise "Can not delete a person from last aspect"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
######## Posting ########
|
||||
def build_post(class_name, opts = {})
|
||||
opts[:person] = self.person
|
||||
|
|
|
|||
|
|
@ -29,6 +29,27 @@ Feature: sending and receiving requests
|
|||
And I am on the aspects manage page
|
||||
Then I should see 1 contact in "Besties"
|
||||
|
||||
Scenario: accepting a contact request to multiple aspects
|
||||
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
|
||||
|
||||
When I go to the home page
|
||||
Then I go to the aspects manage page
|
||||
|
||||
Then I should see 1 contact in "Unicorns"
|
||||
Then I should see 1 contact in "Besties"
|
||||
Then I go to the destroy user session page
|
||||
|
||||
When I sign in as "bob@bob.bob"
|
||||
And I am on the aspects manage page
|
||||
Then I should see 1 contact in "Besties"
|
||||
|
||||
|
||||
|
||||
Scenario: accepting a contact request into a new aspect
|
||||
When I sign in as "alice@alice.alice"
|
||||
|
|
|
|||
|
|
@ -40,6 +40,12 @@ When /^I press the first "([^"]*)"(?: within "([^"]*)")?$/ do |link_selector, wi
|
|||
find(:css, link_selector).click
|
||||
end
|
||||
end
|
||||
|
||||
When /^I press the ([\d])(nd|rd|st|th) "([^"]*)"(?: within "([^"]*)")?$/ do |number,rd, link_selector, within_selector|
|
||||
with_scope(within_selector) do
|
||||
find(:css, link_selector+":nth-child(#{number})").click
|
||||
end
|
||||
end
|
||||
Then /^(?:|I )should see a "([^"]*)"(?: within "([^"]*)")?$/ do |selector, scope_selector|
|
||||
with_scope(scope_selector) do
|
||||
page.has_css?(selector).should be_true
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ Given /^a user with username "([^\"]*)" and password "([^\"]*)"$/ do |username,
|
|||
@me ||= Factory(:user, :username => username, :password => password,
|
||||
:password_confirmation => password, :getting_started => false)
|
||||
@me.aspects.create(:name => "Besties")
|
||||
@me.aspects.create(:name => "Unicorns")
|
||||
end
|
||||
|
||||
Given /^that I am a rock star$/ do
|
||||
|
|
@ -12,6 +13,7 @@ Given /^a user with email "([^\"]*)"$/ do |email|
|
|||
user = Factory(:user, :email => email, :password => 'password',
|
||||
:password_confirmation => 'password', :getting_started => false)
|
||||
user.aspects.create(:name => "Besties")
|
||||
user.aspects.create(:name => "Unicorns")
|
||||
end
|
||||
|
||||
Given /^I have been invited by an admin$/ do
|
||||
|
|
|
|||
|
|
@ -87,6 +87,9 @@ $(document).ready(function() {
|
|||
|
||||
$(".badges").prepend(json.badge_html);
|
||||
$(this).parent().html(json.button_html);
|
||||
|
||||
$('.aspect_list ul').find('.add').each(function(a,b){$(b).attr('href', $(b).attr('href').replace('contacts','aspect_memberships'));})
|
||||
|
||||
$(this).fadeTo(200,1);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -169,42 +169,6 @@ describe Aspect do
|
|||
user.add_contact_to_aspect(@contact, aspect).should == true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#delete_person_from_aspect' do
|
||||
it 'deletes a user from the aspect' do
|
||||
user.add_contact_to_aspect(@contact, aspect1)
|
||||
user.reload
|
||||
user.delete_person_from_aspect(user2.person.id, aspect1.id)
|
||||
user.reload
|
||||
aspect1.contacts(true).include?(@contact).should be_false
|
||||
end
|
||||
|
||||
it 'should check to make sure you have the aspect ' do
|
||||
proc{user.delete_person_from_aspect(user2.person.id, aspect2.id) }.should raise_error /Can not delete a person from an aspect you do not own/
|
||||
end
|
||||
|
||||
it 'deletes no posts' do
|
||||
user.add_contact_to_aspect(@contact, aspect1)
|
||||
user.reload
|
||||
user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id)
|
||||
lambda{
|
||||
user.delete_person_from_aspect(user2.person.id, aspect1.id)
|
||||
}.should_not change(Post, :count)
|
||||
end
|
||||
|
||||
it 'should not allow removing a contact from their last aspect' do
|
||||
proc{user.delete_person_from_aspect(user2.person.id, aspect.id) }.should raise_error /Can not delete a person from last aspect/
|
||||
end
|
||||
|
||||
it 'should allow a force removal of a contact from an aspect' do
|
||||
@contact.aspect_ids.should_receive(:count).exactly(0).times
|
||||
|
||||
user.add_contact_to_aspect(@contact, aspect1)
|
||||
user.delete_person_from_aspect(user2.person.id, aspect.id, :force => true)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'moving and removing posts' do
|
||||
before do
|
||||
@message = user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id)
|
||||
|
|
@ -214,7 +178,8 @@ describe Aspect do
|
|||
|
||||
it 'should keep the contact\'s posts in previous aspect' do
|
||||
aspect.post_ids.count.should == 1
|
||||
user.delete_person_from_aspect(user2.person.id, aspect.id, :force => true)
|
||||
user.move_contact(user2.person, user.aspects.create(:name => "Another aspect"), aspect)
|
||||
|
||||
|
||||
aspect.reload
|
||||
aspect.post_ids.count.should == 1
|
||||
|
|
@ -222,7 +187,7 @@ describe Aspect do
|
|||
|
||||
it 'should not delete other peoples posts' do
|
||||
connect_users(user, aspect, user3, aspect3)
|
||||
user.delete_person_from_aspect(user3.person.id, aspect.id, :force => true)
|
||||
user.move_contact(user3.person, user.aspects.create(:name => "Another aspect"), aspect)
|
||||
aspect.reload
|
||||
aspect.posts.should == [@message]
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue