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
|
######### Friend Requesting
|
||||||
def send_friend_request_to(friend_url)
|
def send_friend_request_to(friend_url)
|
||||||
p = Request.instantiate(:to => friend_url, :from => self)
|
unless Person.where(:url => friend_url).first
|
||||||
if p.save
|
p = Request.instantiate(:to => friend_url, :from => self)
|
||||||
p.push_to_url friend_url
|
if p.save
|
||||||
p
|
p.push_to_url friend_url
|
||||||
|
p
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -48,6 +50,14 @@ class User < Person
|
||||||
request.destroy
|
request.destroy
|
||||||
end
|
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)
|
def receive_friend_request(friend_request)
|
||||||
if Request.where(:callback_url => friend_request.callback_url).first
|
if Request.where(:callback_url => friend_request.callback_url).first
|
||||||
friend_request.activate_friend
|
friend_request.activate_friend
|
||||||
|
|
@ -56,7 +66,6 @@ class User < Person
|
||||||
friend_request.save
|
friend_request.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def mine?(post)
|
def mine?(post)
|
||||||
self == post.person
|
self == post.person
|
||||||
|
|
|
||||||
|
|
@ -117,11 +117,11 @@ describe "parser in application helper" do
|
||||||
xml = Request.build_xml_for [request]
|
xml = Request.build_xml_for [request]
|
||||||
|
|
||||||
@person.destroy
|
@person.destroy
|
||||||
Person.friends.all.count.should be 0
|
Person.all.count.should be 1
|
||||||
store_objects_from_xml(xml)
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,26 @@ describe User do
|
||||||
Person.where(:id => @friend.id).first.active.should == true
|
Person.where(:id => @friend.id).first.active.should == true
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue