Add some scopes for Request, take putses out of specs

This commit is contained in:
Raphael 2010-11-18 18:04:29 -08:00
parent bad76d8cef
commit 655e92ebdd
5 changed files with 47 additions and 5 deletions

View file

@ -23,6 +23,17 @@ class Request
validate :no_pending_request, :if => :sent
#before_validation :clean_link
scope :from, lambda { |person|
target = (person.is_a?(User) ? person.person : person)
where(:from_id => target.id)
}
scope :to, lambda { |person|
target = (person.is_a?(User) ? person.person : person)
where(:to_id => target.id)
}
def self.instantiate(opts = {})
self.new(:from => opts[:from],

View file

@ -85,7 +85,7 @@ module Diaspora
end
def request_for(to_person)
Request.first(:from_id => self.person.id, :to_id => to_person.id)
Request.from(self.person).to(to_person).first
end
end
end

View file

@ -14,10 +14,10 @@ module RakeHelpers
backer_name = backers[n+offset][0].to_s.strip
backer_email = backers[n+offset][1].to_s.gsub('.ksr', '').strip
unless User.find_by_email(backer_email)
puts "sending email to: #{backer_name} #{backer_email}"
puts "sending email to: #{backer_name} #{backer_email}" unless Rails.env == 'test'
Invitation.create_invitee(:email => backer_email, :name => backer_name, :invites => 5)
else
puts "user with the email exists: #{backer_email} , #{backer_name} "
puts "user with the email exists: #{backer_email} , #{backer_name} " unless Rails.env == 'test'
end
end
churn_through

View file

@ -43,6 +43,37 @@ describe Request do
end
end
describe 'scopes' do
before do
@request = Request.instantiate(: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 '#request_from_me' do
it 'recognizes requests from me' do
user.request_from_me?(request).should be_true

View file

@ -53,9 +53,9 @@ describe Diaspora::UserModules::Connecting do
before do
request_for_user.save
user.receive(request_for_user.to_diaspora_xml, person)
@received_request = Request.first(:from_id => request_for_user.from.id, :to_id => user.person.id, :sent => false)
@received_request = Request.from(person).to(user.person).first(:sent => false)
user.receive(request2_for_user.to_diaspora_xml, person_one)
@received_request2 = Request.first(:from_id => request2_for_user.from.id, :to_id => user.person.id, :sent => false)
@received_request2 = Request.from(person_one).to(user.person).first(:sent => false)
user.reload
end