diff --git a/app/models/friend.rb b/app/models/friend.rb index e98971890..33e06469b 100644 --- a/app/models/friend.rb +++ b/app/models/friend.rb @@ -1,4 +1,7 @@ class Friend < Person + + key :active, Boolean, :default => false + end diff --git a/app/models/friend_request.rb b/app/models/friend_request.rb index 1e95d9d09..a6da914b2 100644 --- a/app/models/friend_request.rb +++ b/app/models/friend_request.rb @@ -8,7 +8,7 @@ class FriendRequest validates_presence_of :url - before_save :shoot_off + before_save :shoot_off, :check_for_friend_requests def to_friend_xml friend = Friend.new @@ -23,4 +23,12 @@ class FriendRequest push_friend_request_to_url(self.url) end + def check_for_friend_requests + f = Friend.where(:url => self.url).first + if f + f.active = true + f.save + end + end + end diff --git a/lib/common.rb b/lib/common.rb index 71f88fe09..c6fc304c7 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -34,6 +34,9 @@ module Diaspora if p.is_a? Retraction p.perform elsif p.is_a? Friend + if FriendRequest.where(:url => p.url).first + p.active = true + end p.save #This line checks if the sender was in the database, among other things? elsif p.respond_to?(:person) && !(p.person.nil?) #WTF diff --git a/spec/lib/parser_spec.rb b/spec/lib/parser_spec.rb index 8ba09433c..8bff50717 100644 --- a/spec/lib/parser_spec.rb +++ b/spec/lib/parser_spec.rb @@ -123,6 +123,25 @@ describe "parser in application helper" do store_objects_from_xml(xml) Friend.count.should be 1 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 = " + + #{friend_request_remote.to_friend_xml.to_s} + + " + + @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 diff --git a/spec/models/friend_request_spec.rb b/spec/models/friend_request_spec.rb index 281911dfe..6b2ff20e3 100644 --- a/spec/models/friend_request_spec.rb +++ b/spec/models/friend_request_spec.rb @@ -26,7 +26,13 @@ describe FriendRequest do friend_request = FriendRequest.new(:url => "http://www.google.com") friend_request.sender = Factory.create(:user) 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