Fix a failing spec under 1.9 in receive_spec

This commit is contained in:
Sarah Mei 2010-11-15 21:19:21 -08:00
parent 0b12c4e272
commit 9fa47c9bfa
3 changed files with 635 additions and 630 deletions

View file

@ -8,8 +8,8 @@ module Diaspora
def send_contact_request_to(desired_contact, aspect) def send_contact_request_to(desired_contact, aspect)
# should have different exception types for these? # should have different exception types for these?
raise "You cannot connect yourself" if desired_contact.nil? raise "You cannot connect yourself" if desired_contact.nil?
raise "You have already sent a contact request to that person!" if self.pending_requests.detect{ raise "You have already sent a contact request to that person!" if self.pending_requests.detect {
|x| x.to == desired_contact} |x| x.to == desired_contact }
raise "You are already connected to that person!" if contact_for desired_contact raise "You are already connected to that person!" if contact_for desired_contact
request = Request.instantiate( request = Request.instantiate(
:to => desired_contact, :to => desired_contact,
@ -94,19 +94,23 @@ module Diaspora
def remove_contact(bad_contact) def remove_contact(bad_contact)
contact = contact_for(bad_contact) contact = contact_for(bad_contact)
contact.aspects.each{|aspect| contact.aspects.each do |aspect|
contact.aspects.delete(aspect) contact.aspects.delete(aspect)
aspect.posts.each { |post| aspect.posts.each do |post|
aspect.post_ids.delete(post.id) if post.person == bad_contact aspect.post_ids.delete(post.id) if post.person == bad_contact
} end
aspect.save aspect.save
} end
self.raw_visible_posts.find_all_by_person_id( bad_contact.id ).each{|post| self.raw_visible_posts.find_all_by_person_id(bad_contact.id).each do |post|
self.visible_post_ids.delete( post.id ) self.visible_post_ids.delete(post.id)
post.user_refs -= 1 post.user_refs -= 1
(post.user_refs > 0 || post.person.owner.nil? == false) ? post.save : post.destroy if (post.user_refs > 0) || post.person.owner.nil? == false
} post.save
else
post.destroy
end
end
self.save self.save
raise "Contact not deleted" unless contact.destroy raise "Contact not deleted" unless contact.destroy
bad_contact.save bad_contact.save
@ -133,7 +137,7 @@ module Diaspora
end end
def requests_for_me def requests_for_me
pending_requests.select{|req| req.to == self.person} pending_requests.select { |req| req.to == self.person }
end end
end end
end end

1318
spec/fixtures/users.yaml vendored

File diff suppressed because it is too large Load diff

View file

@ -100,6 +100,7 @@ describe User do
it 'should be remove a post if the noone links to it' do it 'should be remove a post if the noone links to it' do
person = user2.person person = user2.person
user2.delete user2.delete
person.reload
lambda {user.disconnect(person)}.should change(Post, :count).by(-1) lambda {user.disconnect(person)}.should change(Post, :count).by(-1)
end end