DG IZ; friend now has an active flag
This commit is contained in:
parent
d5d4d4ae84
commit
79c0e960ad
5 changed files with 41 additions and 2 deletions
|
|
@ -1,4 +1,7 @@
|
||||||
class Friend < Person
|
class Friend < Person
|
||||||
|
|
||||||
|
key :active, Boolean, :default => false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ class FriendRequest
|
||||||
|
|
||||||
validates_presence_of :url
|
validates_presence_of :url
|
||||||
|
|
||||||
before_save :shoot_off
|
before_save :shoot_off, :check_for_friend_requests
|
||||||
|
|
||||||
def to_friend_xml
|
def to_friend_xml
|
||||||
friend = Friend.new
|
friend = Friend.new
|
||||||
|
|
@ -23,4 +23,12 @@ class FriendRequest
|
||||||
push_friend_request_to_url(self.url)
|
push_friend_request_to_url(self.url)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_for_friend_requests
|
||||||
|
f = Friend.where(:url => self.url).first
|
||||||
|
if f
|
||||||
|
f.active = true
|
||||||
|
f.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,9 @@ module Diaspora
|
||||||
if p.is_a? Retraction
|
if p.is_a? Retraction
|
||||||
p.perform
|
p.perform
|
||||||
elsif p.is_a? Friend
|
elsif p.is_a? Friend
|
||||||
|
if FriendRequest.where(:url => p.url).first
|
||||||
|
p.active = true
|
||||||
|
end
|
||||||
p.save
|
p.save
|
||||||
#This line checks if the sender was in the database, among other things?
|
#This line checks if the sender was in the database, among other things?
|
||||||
elsif p.respond_to?(:person) && !(p.person.nil?) #WTF
|
elsif p.respond_to?(:person) && !(p.person.nil?) #WTF
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,25 @@ describe "parser in application helper" do
|
||||||
store_objects_from_xml(xml)
|
store_objects_from_xml(xml)
|
||||||
Friend.count.should be 1
|
Friend.count.should be 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should activate the Friend if I initiated a request to that url" do
|
||||||
|
friend_request = FriendRequest.create(:url => @friend.url, :sender => @user)
|
||||||
|
|
||||||
|
friend_request_remote = FriendRequest.new(:url => "http://www.yahoo.com/")
|
||||||
|
friend_request_remote.sender = @friend.clone
|
||||||
|
xml = "<XML>
|
||||||
|
<posts><post>
|
||||||
|
#{friend_request_remote.to_friend_xml.to_s}
|
||||||
|
</post></posts>
|
||||||
|
</XML>"
|
||||||
|
|
||||||
|
@friend.destroy
|
||||||
|
Friend.count.should be 0
|
||||||
|
store_objects_from_xml(xml)
|
||||||
|
Friend.count.should be 1
|
||||||
|
Friend.first.active.should be true
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,13 @@ describe FriendRequest do
|
||||||
friend_request = FriendRequest.new(:url => "http://www.google.com")
|
friend_request = FriendRequest.new(:url => "http://www.google.com")
|
||||||
friend_request.sender = Factory.create(:user)
|
friend_request.sender = Factory.create(:user)
|
||||||
friend_request.save
|
friend_request.save
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should activate a friend if it exists on creation of a request for that url" do
|
||||||
|
user = Factory.create(:user)
|
||||||
|
friend = Factory.create(:friend, :url => "http://google.com/")
|
||||||
|
FriendRequest.create(:url => friend.url, :sender => user)
|
||||||
|
Friend.first.active.should be true
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue