Request spec passes, no more scope on requests
This commit is contained in:
parent
4c47d8334c
commit
dcf630fd9a
2 changed files with 5 additions and 46 deletions
|
|
@ -20,17 +20,6 @@ class Request < ActiveRecord::Base
|
||||||
validate :not_already_connected
|
validate :not_already_connected
|
||||||
validate :not_friending_yourself
|
validate :not_friending_yourself
|
||||||
|
|
||||||
scope :from, lambda { |person|
|
|
||||||
target = (person.is_a?(User) ? person.person : person)
|
|
||||||
where(:sender_id => target.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
scope :to, lambda { |person|
|
|
||||||
target = (person.is_a?(User) ? person.person : person)
|
|
||||||
where(:recipient_id => target.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def self.diaspora_initialize(opts = {})
|
def self.diaspora_initialize(opts = {})
|
||||||
self.new(:sender => opts[:from],
|
self.new(:sender => opts[:from],
|
||||||
:recipient => opts[:to],
|
:recipient => opts[:to],
|
||||||
|
|
@ -65,7 +54,7 @@ class Request < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.hashes_for_person person
|
def self.hashes_for_person person
|
||||||
requests = Request.to(person).all
|
requests = Request.where(:recipient_id => person.id)
|
||||||
senders = Person.where(:id => requests.map{|r| r.sender_id})
|
senders = Person.where(:id => requests.map{|r| r.sender_id})
|
||||||
senders_hash = {}
|
senders_hash = {}
|
||||||
senders.each{|sender| senders_hash[sender.id] = sender}
|
senders.each{|sender| senders_hash[sender.id] = sender}
|
||||||
|
|
|
||||||
|
|
@ -50,36 +50,6 @@ describe Request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'scopes' do
|
|
||||||
before do
|
|
||||||
@request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
|
|
||||||
@request.save
|
|
||||||
end
|
|
||||||
describe '.from' do
|
|
||||||
it 'returns requests from a person' do
|
|
||||||
query = Request.from(@user.person)
|
|
||||||
query.first.should == @request
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns requests from a user' do
|
|
||||||
query = Request.from(@user)
|
|
||||||
query.first.should == @request
|
|
||||||
end
|
|
||||||
end
|
|
||||||
describe '.to' do
|
|
||||||
it 'returns requests to a person' do
|
|
||||||
query = Request.to(@user2.person)
|
|
||||||
query.first.should == @request
|
|
||||||
end
|
|
||||||
it 'returns requests to a user' do
|
|
||||||
query = Request.to(@user2)
|
|
||||||
query.first.should == @request
|
|
||||||
end
|
|
||||||
end
|
|
||||||
it 'chains' do
|
|
||||||
Request.from(@user).to(@user2.person).first.should == @request
|
|
||||||
end
|
|
||||||
end
|
|
||||||
describe '#notification_type' do
|
describe '#notification_type' do
|
||||||
before do
|
before do
|
||||||
@request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
|
@request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
|
||||||
|
|
@ -105,7 +75,7 @@ describe Request do
|
||||||
@hash = @hashes.first
|
@hash = @hashes.first
|
||||||
end
|
end
|
||||||
it 'gives back requests' do
|
it 'gives back requests' do
|
||||||
@hash[:request].should == Request.from(@user2).to(@user).first
|
@hash[:request].should == Request.where(:sender_id => @user2.person.id, :recipient_id => @user.person.id).first
|
||||||
end
|
end
|
||||||
it 'gives back people' do
|
it 'gives back people' do
|
||||||
@hash[:sender].should == @user2.person
|
@hash[:sender].should == @user2.person
|
||||||
|
|
@ -121,11 +91,11 @@ describe Request do
|
||||||
@xml = @request.to_xml.to_s
|
@xml = @request.to_xml.to_s
|
||||||
end
|
end
|
||||||
describe 'serialization' do
|
describe 'serialization' do
|
||||||
it 'should not generate xml for the User as a Person' do
|
it 'does not generate xml for the User as a Person' do
|
||||||
@xml.should_not include @user.person.profile.first_name
|
@xml.should_not include @user.person.profile.first_name
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should serialize the handle and not the sender' do
|
it 'serializes the handle and not the sender' do
|
||||||
@xml.should include @user.person.diaspora_handle
|
@xml.should include @user.person.diaspora_handle
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -133,7 +103,7 @@ describe Request do
|
||||||
@xml.should include @user2.person.diaspora_handle
|
@xml.should include @user2.person.diaspora_handle
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not serialize the exported key' do
|
it 'does not serialize the exported key' do
|
||||||
@xml.should_not include @user.person.exported_key
|
@xml.should_not include @user.person.exported_key
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue