DG MS; cannot friend request an existing friend.
This commit is contained in:
parent
b052ddeb84
commit
cf352b6f8d
3 changed files with 34 additions and 9 deletions
|
|
@ -27,10 +27,12 @@ class User < Person
|
|||
|
||||
######### Friend Requesting
|
||||
def send_friend_request_to(friend_url)
|
||||
p = Request.instantiate(:to => friend_url, :from => self)
|
||||
if p.save
|
||||
p.push_to_url friend_url
|
||||
p
|
||||
unless Person.where(:url => friend_url).first
|
||||
p = Request.instantiate(:to => friend_url, :from => self)
|
||||
if p.save
|
||||
p.push_to_url friend_url
|
||||
p
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -48,6 +50,14 @@ class User < Person
|
|||
request.destroy
|
||||
end
|
||||
|
||||
def ignore_friend_request(friend_request_id)
|
||||
request = Request.where(:id => friend_request_id).first
|
||||
person = request.person
|
||||
|
||||
person.destroy unless person.active
|
||||
request.destroy
|
||||
end
|
||||
|
||||
def receive_friend_request(friend_request)
|
||||
if Request.where(:callback_url => friend_request.callback_url).first
|
||||
friend_request.activate_friend
|
||||
|
|
@ -56,7 +66,6 @@ class User < Person
|
|||
friend_request.save
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def mine?(post)
|
||||
self == post.person
|
||||
|
|
|
|||
|
|
@ -117,11 +117,11 @@ describe "parser in application helper" do
|
|||
xml = Request.build_xml_for [request]
|
||||
|
||||
@person.destroy
|
||||
Person.friends.all.count.should be 0
|
||||
Person.all.count.should be 1
|
||||
store_objects_from_xml(xml)
|
||||
Person.friends.all.count.should be 1
|
||||
Person.all.count.should be 2
|
||||
|
||||
Person.friends.first.id.should == original_person_id
|
||||
Person.where(:url => request.callback_url).first.id.should == original_person_id
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -19,10 +19,26 @@ describe User do
|
|||
Person.where(:id => @friend.id).first.active.should == true
|
||||
end
|
||||
|
||||
it 'should be able to ignore a pending friend request' do
|
||||
@user = Factory.create(:user)
|
||||
@friend = Factory.create(:person)
|
||||
r = Request.instantiate(:to => @user.url, :from => @friend)
|
||||
r.save
|
||||
|
||||
|
||||
Person.count.should == 2
|
||||
@friend.active.should == false
|
||||
|
||||
@user.ignore_friend_request(r.id)
|
||||
|
||||
Person.count.should == 1
|
||||
Request.count.should == 0
|
||||
end
|
||||
|
||||
it 'should not be able to friend request an existing friend' do
|
||||
@user = Factory.create(:user)
|
||||
@friend = Factory.create(:person, :active => true)
|
||||
|
||||
@user.send_friend_request_to( @friend.url ).should be nil
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue