Skip to content

Commit

Permalink
make sure to populate cache on finds by non-primary-key attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyAghion authored and ngmoco:) committed Apr 23, 2010
1 parent 76468b5 commit 0e9c165
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/cash/query/abstract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def deserialize_objects(objects)

def find_from_keys(*missing_keys)
missing_ids = Array(missing_keys).flatten.collect { |key| key.split('/')[2].to_i }
find_from_ids_without_cache(missing_ids, @options1)
find_from_ids_without_cache(missing_ids, {})
end
end
end
Expand Down
12 changes: 11 additions & 1 deletion spec/cash/finders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,20 @@ module Cash
end

describe '#find_by_attr' do
before(:each) do
Story.find_by_title(@story.title) # populates cache for title with [@story.id]
end

it 'populates the cache' do
Story.find_by_title(@story.title)
Story.fetch("title/#{@story.title}").should == [@story.id]
end

it 'populates the cache when finding by non-primary-key attribute' do
Story.find_by_title(@story.title) # populates cache for id with record

mock(Story.connection).execute.never
Story.find_by_title(@story.title).id.should == @story.id # should hit cache only
end
end

describe '#find(:all, :conditions => ...)' do
Expand Down

0 comments on commit 0e9c165

Please sign in to comment.