MS IZ got rid of the requests for me scope in the user
This commit is contained in:
parent
1075c4f96b
commit
8acdf21234
6 changed files with 48 additions and 40 deletions
|
|
@ -26,8 +26,6 @@ class Request
|
|||
validates_presence_of :destination_url, :callback_url
|
||||
before_validation :clean_link
|
||||
|
||||
scope :for_user, lambda{ |user| where(:destination_url => user.person.receive_url) }
|
||||
|
||||
def self.instantiate(options = {})
|
||||
person = options[:from]
|
||||
self.new(:destination_url => options[:to],
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ class User
|
|||
key :invites, Integer, :default => 5
|
||||
key :invitation_token, String
|
||||
key :invitation_sent_at, DateTime
|
||||
key :inviter_ids, Array
|
||||
key :friend_ids, Array
|
||||
key :pending_request_ids, Array
|
||||
key :visible_post_ids, Array
|
||||
key :visible_person_ids, Array
|
||||
key :inviter_ids, Array, :typecast => 'ObjectId'
|
||||
key :friend_ids, Array, :typecast => 'ObjectId'
|
||||
key :pending_request_ids, Array, :typecast => 'ObjectId'
|
||||
key :visible_post_ids, Array, :typecast => 'ObjectId'
|
||||
key :visible_person_ids, Array, :typecast => 'ObjectId'
|
||||
|
||||
key :invite_messages, Hash
|
||||
|
||||
|
|
|
|||
|
|
@ -29,9 +29,8 @@ module Diaspora
|
|||
end
|
||||
|
||||
def accept_friend_request(friend_request_id, aspect_id)
|
||||
request = Request.find_by_id(friend_request_id)
|
||||
pending_requests.delete(request)
|
||||
|
||||
request = pending_requests.find!(friend_request_id)
|
||||
pending_request_ids.delete(request.id.to_id)
|
||||
activate_friend(request.person, aspect_by_id(aspect_id))
|
||||
|
||||
request.reverse_for(self)
|
||||
|
|
@ -45,16 +44,16 @@ module Diaspora
|
|||
end
|
||||
|
||||
def accept_and_respond(friend_request_id, aspect_id)
|
||||
requester = Request.find_by_id(friend_request_id).person
|
||||
requester = pending_requests.find!(friend_request_id).person
|
||||
reversed_request = accept_friend_request(friend_request_id, aspect_id)
|
||||
dispatch_friend_acceptance reversed_request, requester
|
||||
end
|
||||
|
||||
def ignore_friend_request(friend_request_id)
|
||||
request = Request.find_by_id(friend_request_id)
|
||||
request = pending_requests.find!(friend_request_id)
|
||||
person = request.person
|
||||
|
||||
self.pending_requests.delete(request)
|
||||
self.pending_request_ids.delete(request.id)
|
||||
self.save
|
||||
|
||||
person.save
|
||||
|
|
|
|||
|
|
@ -31,17 +31,6 @@ describe Request do
|
|||
xml.should include user.exported_key
|
||||
end
|
||||
|
||||
it 'should allow me to see only friend requests sent to me' do
|
||||
remote_person = Factory.build(:person, :diaspora_handle => "robert@grimm.com", :url => "http://king.com/")
|
||||
|
||||
Request.instantiate(:into => aspect.id, :from => user.person, :to => remote_person.receive_url).save
|
||||
Request.instantiate(:into => aspect.id, :from => user.person, :to => remote_person.receive_url).save
|
||||
Request.instantiate(:into => aspect.id, :from => user.person, :to => remote_person.receive_url).save
|
||||
Request.instantiate(:into => aspect.id, :from => remote_person, :to => user.receive_url).save
|
||||
|
||||
Request.for_user(user).all.count.should == 1
|
||||
end
|
||||
|
||||
it 'should strip the destination url' do
|
||||
person_request = Request.new
|
||||
person_request.destination_url = " http://google.com/ "
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ describe Diaspora::UserModules::Friending do
|
|||
end
|
||||
|
||||
context 'friend requesting' do
|
||||
it "should assign a request to a aspect" do
|
||||
it "should assign a request to a aspect for the user that sent it out" do
|
||||
aspect.requests.size.should == 0
|
||||
|
||||
user.send_friend_request_to(friend, aspect)
|
||||
|
|
@ -34,21 +34,42 @@ describe Diaspora::UserModules::Friending do
|
|||
aspect.requests.size.should == 1
|
||||
end
|
||||
|
||||
it "should be able to accept a pending friend request" do
|
||||
r = Request.instantiate(:to => user.receive_url, :from => friend)
|
||||
r.save
|
||||
describe '#receive_friend_request' do
|
||||
it 'adds a request to pending if it was not sent by user' do
|
||||
r = Request.instantiate(:to => user.receive_url, :from => friend)
|
||||
r.save
|
||||
user.receive_friend_request(r)
|
||||
user.reload.pending_requests.should include r
|
||||
end
|
||||
|
||||
it 'should autoaccept a request the user sent' do
|
||||
request = user.send_friend_request_to(user2.person, aspect)
|
||||
request.reverse_for(user2)
|
||||
proc{user.receive_friend_request(request)}.should change(user.reload.friends, :count).by(1)
|
||||
end
|
||||
|
||||
proc { user.accept_friend_request(r.id, aspect.id) }.should change {
|
||||
Request.for_user(user).all.count }.by(-1)
|
||||
end
|
||||
|
||||
it 'should be able to ignore a pending friend request' do
|
||||
friend = Factory.create(:person)
|
||||
r = Request.instantiate(:to => user.receive_url, :from => friend)
|
||||
r.save
|
||||
context 'received a friend request' do
|
||||
|
||||
proc { user.ignore_friend_request(r.id) }.should change {
|
||||
Request.for_user(user).count }.by(-1)
|
||||
let(:request_for_user) {Request.instantiate(:to => user.receive_url, :from => friend)}
|
||||
let(:request2_for_user) {Request.instantiate(:to => user.receive_url, :from => person_one)}
|
||||
before do
|
||||
request_for_user.save
|
||||
user.receive_friend_request(request_for_user)
|
||||
user.receive_friend_request(request2_for_user)
|
||||
user.reload
|
||||
end
|
||||
|
||||
it "should delete an accepted friend request" do
|
||||
proc { user.accept_friend_request(request2_for_user.id, aspect.id) }.should change(
|
||||
user.reload.pending_requests, :count ).by(-1)
|
||||
end
|
||||
|
||||
it 'should be able to ignore a pending friend request' do
|
||||
proc { user.ignore_friend_request(request_for_user.id) }.should change (
|
||||
user.reload.pending_requests, :count ).by(-1)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should not be able to friend request an existing friend' do
|
||||
|
|
@ -168,20 +189,20 @@ describe Diaspora::UserModules::Friending do
|
|||
user.receive_friend_request @request
|
||||
|
||||
person_two.destroy
|
||||
user.pending_requests.size.should be 1
|
||||
user.reload.pending_requests.size.should be 1
|
||||
user.friends.size.should be 0
|
||||
|
||||
user.receive_friend_request @request_two
|
||||
user.pending_requests.size.should be 2
|
||||
user.reload.pending_requests.size.should be 2
|
||||
user.friends.size.should be 0
|
||||
|
||||
user.accept_friend_request @request.id, aspect.id
|
||||
user.pending_requests.size.should be 1
|
||||
user.reload.pending_requests.size.should be 1
|
||||
user.friends.size.should be 1
|
||||
user.friends.include?(person_one).should be true
|
||||
|
||||
user.ignore_friend_request @request_two.id
|
||||
user.pending_requests.size.should be 0
|
||||
user.reload.pending_requests.size.should be 0
|
||||
user.friends.size.should be 1
|
||||
user.friends.include?(person_two).should be false
|
||||
end
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ ImageUploader.enable_processing = false
|
|||
|
||||
def friend_users(user1, aspect1, user2, aspect2)
|
||||
request = user1.send_friend_request_to(user2.person, aspect1)
|
||||
user2.receive_friend_request(request)
|
||||
reversed_request = user2.accept_friend_request( request.id, aspect2.id)
|
||||
user1.reload
|
||||
user1.receive reversed_request.to_diaspora_xml, user2.person
|
||||
|
|
|
|||
Loading…
Reference in a new issue