diff --git a/app/models/friend_request.rb b/app/models/friend_request.rb index a6da914b2..4554f5f47 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, :check_for_friend_requests + before_save :check_for_friend_requests def to_friend_xml friend = Friend.new @@ -19,8 +19,12 @@ class FriendRequest friend.to_xml end - def shoot_off - push_friend_request_to_url(self.url) + def self.for(url) + friend_request = FriendRequest.new(:url => url) + friend_request.sender = User.first + friend_request.save + + friend_request.push_friend_request_to_url(friend_request.url) end def check_for_friend_requests diff --git a/spec/models/friend_request_spec.rb b/spec/models/friend_request_spec.rb index 6b2ff20e3..0d2e3069a 100644 --- a/spec/models/friend_request_spec.rb +++ b/spec/models/friend_request_spec.rb @@ -20,12 +20,10 @@ describe FriendRequest do friend_xml.include?(user.profile.last_name).should be true end - it 'should be sent to the url upon save' do + it 'should be sent to the url upon for action' do FriendRequest.send(:class_variable_get, :@@queue).should_receive(:add_post_request) - - friend_request = FriendRequest.new(:url => "http://www.google.com") - friend_request.sender = Factory.create(:user) - friend_request.save + Factory.create(:user) + FriendRequest.for("http://www.google.com") end it "should activate a friend if it exists on creation of a request for that url" do