diff --git a/app/models/request.rb b/app/models/request.rb index 6108868d8..ae5727576 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -10,7 +10,9 @@ class Request key :destination_url, String key :callback_url, String - key :person, Person + key :person_id, ObjectId + + belongs_to :person validates_presence_of :destination_url, :callback_url diff --git a/app/models/user.rb b/app/models/user.rb index 839ec65da..812d1f9e5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,7 +4,7 @@ class User < Person :recoverable, :rememberable, :trackable, :validatable - before_create :assign_key + #before_create :assign_key validates_presence_of :profile before_validation :do_bad_things @@ -43,7 +43,7 @@ class User < Person request = Request.where(:id => friend_request_id).first request.activate_friend request.person = self - request.push_to(self.callback_url) + request.push_to_url(request.callback_url) request.destroy end @@ -52,6 +52,7 @@ class User < Person friend_request.activate_friend friend_request.destroy else + #does this actually save as the same id? friend_request.save end end diff --git a/spec/lib/parser_spec.rb b/spec/lib/parser_spec.rb index eca3cb1b9..f3eafdb2a 100644 --- a/spec/lib/parser_spec.rb +++ b/spec/lib/parser_spec.rb @@ -127,7 +127,7 @@ describe "parser in application helper" do request_remote = Request.new(:_id => request.id)# request_remote.destination_url = @user.url request_remote.callback_url = @user.url - request_remote.person = @person.clone + request_remote.person = @person xml = Request.build_xml_for [request_remote] diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index 5bed0a59d..9669ff38c 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -11,10 +11,21 @@ describe Request do end it 'should generate xml for the User as a Person' do - user = Factory.create(:user) - request = Request.new(:url => "http://www.google.com/", :person => user) + user = User.create(:email => "rob@bob.com") + + user.profile = Factory.create(:profile) + + user.save(:validate => false) + user.profile.save + + request = Request.instantiate(:to => "http://www.google.com/", :from => user) xml = request.to_xml.to_s + + puts xml + puts user.profile.first_name + puts user.profile.last_name + xml.include?(user.email).should be true xml.include?(user.url).should be true xml.include?(user.profile.first_name).should be true diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index abdbdf22a..120b68c1e 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -6,4 +6,20 @@ describe User do Factory.create(:user) Person.count.should == n+1 end + + it "should be able to accept a pending friend request" do + @user = Factory.create(:user) + @friend = Factory.create(:person) + + r = Request.instantiate(:to => @user.url, :from => @friend) + r.save + + Person.all.count.should == 2 + Request.for_user(@user).all.count.should == 1 + + @user.accept_friend_request(r.id) + + Request.for_user(@user).all.count.should == 0 + Person.where(:id => @friend.id).first.active.should == true + end end