Revert FakeServiceUser work, needs more testing to make sure extra models aren't instantiated.

This reverts commit 0a8ce3b9f2.
This reverts commit f9ef9a4b47.
This reverts commit 164226a3d7.
This commit is contained in:
Raphael Sofaer 2011-05-17 10:29:07 -07:00
parent 1746f610b6
commit 5218bd89c6
4 changed files with 7 additions and 82 deletions

View file

@ -12,7 +12,7 @@ class ServiceUser < ActiveRecord::Base
def attach_local_models
service_for_uid = Services::Facebook.where(:type => service.type.to_s, :uid => self.uid).first
if !service_for_uid.blank? && (service_for_uid.user.person.profile.searchable)
self.person = service_for_uid.user.person
self.person = service_for_uid.user.person
else
self.person = nil
end
@ -28,28 +28,3 @@ class ServiceUser < ActiveRecord::Base
:invitation_identifier => self.uid}).first
end
end
class FakeServiceUser < HashWithIndifferentAccess
def initialize(row)
columns = ServiceUser.column_names
self.replace Hash[columns.zip(row)]
end
ServiceUser.column_names.each do |column|
symbol = column.to_sym
define_method symbol do
self[symbol]
end
end
ServiceUser.reflect_on_all_associations.each do |assoc|
define_method assoc.name do
if associated_id = self[assoc.primary_key_name]
assoc.klass.unscoped.find(associated_id)
else
nil
end
end
end
end

View file

@ -27,16 +27,14 @@ class Services::Facebook < Service
Resque.enqueue(Job::UpdateServiceUsers, self.id)
end
person = Person.arel_table
query = self.service_users.scoped
service_user = ServiceUser.arel_table
if opts[:local]
query = query.joins(:person).where(person[:owner_id].not_eq(nil))
ServiceUser.joins(:person).where(:service_id => self.id).where(person[:owner_id].not_eq(nil)).all
elsif opts[:remote]
query = query.joins(:person).where(person[:owner_id].eq(nil))
ServiceUser.joins(:person).where(:service_id => self.id).where(person[:owner_id].eq(nil)).all
else
self.service_users
end
result = ServiceUser.connection.execute(query.to_sql).to_a
fakes = result.map{|r| FakeServiceUser.new(r) }
end
def save_friends

View file

@ -106,42 +106,3 @@ JSON
end
end
end
describe FakeServiceUser do
describe '.initialize' do
before do
@data = [182, "820651", "Maxwell Salzberg", "http://cdn.fn.com/pic1.jpg", 299, 1610, nil, nil, nil, DateTime.parse("Tue May 17 00:31:44 UTC 2011"), DateTime.parse("Tue May 17 00:31:44 UTC 2011")]
@fake = FakeServiceUser.new(@data)
end
it 'takes a mysql row and sets the attr names to their values' do
@fake[:id].should == @data[0]
@fake[:uid].should == @data[1]
@fake[:name].should == @data[2]
@fake[:photo_url].should == @data[3]
@fake[:service_id].should == @data[4]
@fake[:person_id].should == @data[5]
@fake[:contact_id].should == @data[6]
@fake[:request_id].should == @data[7]
@fake[:invitation_id].should == @data[8]
@fake[:created_at].should == @data[9]
@fake[:updated_at].should == @data[10]
end
it 'has reader methods' do
@fake.photo_url.should == @data[3]
@fake.person_id.should == @data[5]
end
it 'has association methods' do
person = mock
Person.stub!(:unscoped).and_return(Person)
Person.should_receive(:find).with(@data[5]).and_return person
@fake.person.should == person
end
it 'does not error on an association with no id' do
@fake[:person_id] = nil
lambda{ @fake.person }.should_not raise_error
end
end
end

View file

@ -28,7 +28,7 @@ describe Services::Facebook do
end
context 'finder' do
before do
before do
@user2 = Factory.create(:user_with_aspect)
@user2_fb_id = '820651'
@user2_fb_name = 'Maxwell Salzberg'
@ -70,25 +70,16 @@ JSON
end
describe '#finder' do
it 'returns an array of non-activerecord objects' do
@service.save_friends
result = @service.finder
result.should be_an(Array)
result.first.should_not be_an ActiveRecord::Base
end
it 'does a syncronous call if it has not been called before' do
@service.should_receive(:save_friends)
@service.finder
end
it 'dispatches a resque job' do
Resque.should_receive(:enqueue).with(Job::UpdateServiceUsers, @service.id)
su2 = ServiceUser.create(:service => @user2_service, :uid => @user2_fb_id, :name => @user2_fb_name, :photo_url => @user2_fb_photo_url)
@service.service_users = [su2]
@service.finder
end
context 'opts' do
it 'only local does not return people who are remote' do
@service.save_friends