Skip to content
Extraits de code Groupes Projets
Valider 8c2e6dd8 rédigé par maxwell's avatar maxwell Validation de zhitomirskiyi
Parcourir les fichiers

aspect membership refactor complete

parent c6eb5d03
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -55,7 +55,7 @@ class AspectMembershipsController < ApplicationController ...@@ -55,7 +55,7 @@ class AspectMembershipsController < ApplicationController
def create def create
@person = Person.find(params[:person_id]) @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) @contact = current_user.contact_for(@person)
......
...@@ -6,12 +6,13 @@ class ContactsController < ApplicationController ...@@ -6,12 +6,13 @@ class ContactsController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
def new def new
#should be share_with?
render :nothing => true render :nothing => true
end end
def create def create
@person = Person.find(params[:person_id]) @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) request_to_aspect(@aspect, @person)
......
...@@ -74,11 +74,13 @@ class User < ActiveRecord::Base ...@@ -74,11 +74,13 @@ class User < ActiveRecord::Base
end end
def move_contact(person, to_aspect, from_aspect) def move_contact(person, to_aspect, from_aspect)
return true if to_aspect == from_aspect
contact = contact_for(person) contact = contact_for(person)
if to_aspect == from_aspect if add_contact_to_aspect(contact, to_aspect)
true membership = contact ? contact.aspect_memberships.where(:aspect_id => from_aspect.id).first : nil
elsif add_contact_to_aspect(contact, to_aspect) return ( membership && membership.destroy )
delete_person_from_aspect(person.id, from_aspect.id) else
false
end end
end end
...@@ -92,20 +94,6 @@ class User < ActiveRecord::Base ...@@ -92,20 +94,6 @@ class User < ActiveRecord::Base
contact.aspect_memberships.create!(:aspect => aspect) contact.aspect_memberships.create!(:aspect => aspect)
end 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 ######## ######## Posting ########
def build_post(class_name, opts = {}) def build_post(class_name, opts = {})
opts[:person] = self.person opts[:person] = self.person
......
...@@ -29,6 +29,27 @@ Feature: sending and receiving requests ...@@ -29,6 +29,27 @@ Feature: sending and receiving requests
And I am on the aspects manage page And I am on the aspects manage page
Then I should see 1 contact in "Besties" 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 Scenario: accepting a contact request into a new aspect
When I sign in as "alice@alice.alice" When I sign in as "alice@alice.alice"
......
...@@ -40,6 +40,12 @@ When /^I press the first "([^"]*)"(?: within "([^"]*)")?$/ do |link_selector, wi ...@@ -40,6 +40,12 @@ When /^I press the first "([^"]*)"(?: within "([^"]*)")?$/ do |link_selector, wi
find(:css, link_selector).click find(:css, link_selector).click
end end
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| Then /^(?:|I )should see a "([^"]*)"(?: within "([^"]*)")?$/ do |selector, scope_selector|
with_scope(scope_selector) do with_scope(scope_selector) do
page.has_css?(selector).should be_true page.has_css?(selector).should be_true
......
...@@ -2,6 +2,7 @@ Given /^a user with username "([^\"]*)" and password "([^\"]*)"$/ do |username, ...@@ -2,6 +2,7 @@ Given /^a user with username "([^\"]*)" and password "([^\"]*)"$/ do |username,
@me ||= Factory(:user, :username => username, :password => password, @me ||= Factory(:user, :username => username, :password => password,
:password_confirmation => password, :getting_started => false) :password_confirmation => password, :getting_started => false)
@me.aspects.create(:name => "Besties") @me.aspects.create(:name => "Besties")
@me.aspects.create(:name => "Unicorns")
end end
Given /^that I am a rock star$/ do Given /^that I am a rock star$/ do
...@@ -12,6 +13,7 @@ Given /^a user with email "([^\"]*)"$/ do |email| ...@@ -12,6 +13,7 @@ Given /^a user with email "([^\"]*)"$/ do |email|
user = Factory(:user, :email => email, :password => 'password', user = Factory(:user, :email => email, :password => 'password',
:password_confirmation => 'password', :getting_started => false) :password_confirmation => 'password', :getting_started => false)
user.aspects.create(:name => "Besties") user.aspects.create(:name => "Besties")
user.aspects.create(:name => "Unicorns")
end end
Given /^I have been invited by an admin$/ do Given /^I have been invited by an admin$/ do
......
...@@ -87,6 +87,9 @@ $(document).ready(function() { ...@@ -87,6 +87,9 @@ $(document).ready(function() {
$(".badges").prepend(json.badge_html); $(".badges").prepend(json.badge_html);
$(this).parent().html(json.button_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); $(this).fadeTo(200,1);
}); });
......
...@@ -169,42 +169,6 @@ describe Aspect do ...@@ -169,42 +169,6 @@ describe Aspect do
user.add_contact_to_aspect(@contact, aspect).should == true user.add_contact_to_aspect(@contact, aspect).should == true
end end
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 context 'moving and removing posts' do
before do before do
@message = user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id) @message = user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id)
...@@ -214,7 +178,8 @@ describe Aspect do ...@@ -214,7 +178,8 @@ describe Aspect do
it 'should keep the contact\'s posts in previous aspect' do it 'should keep the contact\'s posts in previous aspect' do
aspect.post_ids.count.should == 1 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.reload
aspect.post_ids.count.should == 1 aspect.post_ids.count.should == 1
...@@ -222,7 +187,7 @@ describe Aspect do ...@@ -222,7 +187,7 @@ describe Aspect do
it 'should not delete other peoples posts' do it 'should not delete other peoples posts' do
connect_users(user, aspect, user3, aspect3) 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.reload
aspect.posts.should == [@message] aspect.posts.should == [@message]
end end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter