Skip to content

Commit

Permalink
cache the location when running class level finders
Browse files Browse the repository at this point in the history
  • Loading branch information
jnewland committed Mar 24, 2008
1 parent 6e447af commit f6f6148
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
13 changes: 10 additions & 3 deletions lib/ride_the_fireeagle.rb
Expand Up @@ -44,7 +44,10 @@ def convert_fe_users_to_ar_objects(fe_users)
users = []
fe_users.each do |fe_user|
user = find_by_fireeagle_access_token(fe_user.token)
users << user unless user.nil?
unless user.nil?
user.stash_location(fe_user.best_guess)
users << user
end
end
users
end
Expand Down Expand Up @@ -99,9 +102,13 @@ def location
return nil
end
end


def stash_location(location)
@location = location
end

private

def fireeagle
if self.authorized_with_fireeagle?
FireEagle::Client.new(
Expand Down
17 changes: 8 additions & 9 deletions spec/ride_the_fireeagle_spec.rb
Expand Up @@ -29,9 +29,8 @@
@user2 = User.create(:fireeagle_access_token => 'user2')
@location_1 = stub(FireEagle::Location, :name => 'location1')
@location_2 = stub(FireEagle::Location, :name => 'location2')
@fe_user_1 = stub(FireEagle::User, :token => 'user1', :location => @location_1)
@fe_user_2 = stub(FireEagle::User, :token => 'user2', :location => @location_2)

@fe_user_1 = stub(FireEagle::User, :token => 'user1', :best_guess => @location_1)
@fe_user_2 = stub(FireEagle::User, :token => 'user2', :best_guess => @location_2)
end

it "should load recently updated users" do
Expand All @@ -46,12 +45,12 @@
end

it "should cache users' locations when calling class level finders" do
pending("for obvious reasons") do
@client.should_receive(:within).with({:foo => :bar}, 10, 0).and_return([@fe_user_1, @fe_user_2])
@client.should_not_receive(:user)
users = User.find_fireeagle_within({:foo => :bar}, :limit => 10, :offset => 0)
users.first.location.should == @location_1
end
@client.should_receive(:within).with({:foo => :bar}, 10, 0).and_return([@fe_user_1, @fe_user_2])
users = User.find_fireeagle_within({:foo => :bar}, :limit => 10, :offset => 0)
user = users.first
user.stub!(:authorized_with_fireeagle?).and_return(true)
@client.should_not_receive(:user)
user.location.name.should == 'location1'
end

end
Expand Down

0 comments on commit f6f6148

Please sign in to comment.