From dcf630fd9a947a6d60a1e1ba3243f23dd7a3681e Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 20 Dec 2010 13:59:46 -0800 Subject: [PATCH] Request spec passes, no more scope on requests --- app/models/request.rb | 13 +------------ spec/models/request_spec.rb | 38 ++++--------------------------------- 2 files changed, 5 insertions(+), 46 deletions(-) diff --git a/app/models/request.rb b/app/models/request.rb index f0663f413..e23a715c1 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -20,17 +20,6 @@ class Request < ActiveRecord::Base validate :not_already_connected 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 = {}) self.new(:sender => opts[:from], :recipient => opts[:to], @@ -65,7 +54,7 @@ class Request < ActiveRecord::Base end 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_hash = {} senders.each{|sender| senders_hash[sender.id] = sender} diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index 83ecc2f74..6de0401e9 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -50,36 +50,6 @@ describe Request do 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 before do @request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect) @@ -105,7 +75,7 @@ describe Request do @hash = @hashes.first end 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 it 'gives back people' do @hash[:sender].should == @user2.person @@ -121,11 +91,11 @@ describe Request do @xml = @request.to_xml.to_s end 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 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 end @@ -133,7 +103,7 @@ describe Request do @xml.should include @user2.person.diaspora_handle 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 end end