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

DG MS friends now are delete

parent ed412e12
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -2,21 +2,32 @@ class Retraction
include ROXML
include Diaspora::Webhooks
def self.for(post)
result = self.new
result.post_id = post.id
result.person_id = post.person.id
result
def self.for(object)
retraction = self.new
retraction.post_id= object.id
retraction.person_id = person_id_from(object)
retraction.type = object.class
retraction
end
xml_accessor :post_id
xml_accessor :person_id
xml_accessor :type
attr_accessor :post_id
attr_accessor :person_id
attr_accessor :type
def perform
Post.delete(self.post_id)
self.type.constantize.delete(self.post_id)
end
def self.person_id_from(object)
if object.is_a? Person
object.id
else
object.person.id
end
end
end
......@@ -46,7 +46,7 @@ class User < Person
end
def ignore_friend_request(friend_request_id)
request = Request.where(:id => friend_request_id).first
request = Request.first(:id => friend_request_id)
person = request.person
person.destroy unless person.active
request.destroy
......@@ -61,6 +61,14 @@ class User < Person
end
end
def unfriend(friend_id)
bad_friend = Person.first(:id => friend_id, :active => true)
if bad_friend
Retraction.for(self).push_to_url(bad_friend.url)
bad_friend.destroy
end
end
###Helpers############
def mine?(post)
......
......@@ -76,7 +76,7 @@ module Diaspora
end
def people_with_permissions
Person.where( :_type => "Person" ).all
Person.friends.all
end
def self.build_xml_for(posts)
......
......@@ -11,6 +11,7 @@ end
Factory.define :person do |p|
p.email "bob@aol.com"
p.active true
p.sequence(:url) {|n|"http://google-#{n}.com/"}
p.profile Profile.new( :first_name => "Robert", :last_name => "Grimm" )
end
......
......@@ -26,9 +26,9 @@ describe Person do
end
it 'should only return active friends' do
Factory.create(:person, :active => true)
Factory.create(:person)
Factory.create(:person)
Factory.create(:person, :active => false)
Factory.create(:person, :active => false)
Person.friends.all.count.should == 1
end
......@@ -57,5 +57,16 @@ describe Person do
s.comments.count.should == 1
end
it 'should let a user unfriend another user' do
u = Factory.create(:user)
f = Factory.create(:person, :active => true)
Person.friends.all.count.should == 1
u.unfriend(f.id)
Person.friends.all.count.should == 0
end
end
......@@ -9,7 +9,7 @@ describe User do
it "should be able to accept a pending friend request" do
@user = Factory.create(:user)
@friend = Factory.create(:person)
@friend = Factory.create(:person, :active => false)
r = Request.instantiate(:to => @user.url, :from => @friend)
r.save
Person.all.count.should == 2
......@@ -21,7 +21,7 @@ describe User do
it 'should be able to ignore a pending friend request' do
@user = Factory.create(:user)
@friend = Factory.create(:person)
@friend = Factory.create(:person, :active => false)
r = Request.instantiate(:to => @user.url, :from => @friend)
r.save
......@@ -36,7 +36,7 @@ describe User do
it 'should not be able to friend request an existing friend' do
@user = Factory.create(:user)
@friend = Factory.create(:person, :active => true)
@friend = Factory.create(:person)
@user.send_friend_request_to( @friend.url ).should be nil
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