Fix expectation on redis cache spec

This commit is contained in:
Sarah Mei 2011-10-16 16:11:17 -07:00
parent c2c152ee4b
commit a3dce03f76

View file

@ -7,9 +7,6 @@ require 'spec_helper'
describe RedisCache do describe RedisCache do
before do before do
@redis = MockRedis.new @redis = MockRedis.new
#@redis = Redis.new
#@redis.keys.each{|p| @redis.del(p)}
@cache = RedisCache.new(bob, :created_at) @cache = RedisCache.new(bob, :created_at)
@cache.stub(:redis).and_return(@redis) @cache.stub(:redis).and_return(@redis)
end end
@ -46,15 +43,15 @@ describe RedisCache do
end end
it 'returns the most recent post ids (default created at, limit 15)' do it 'returns the most recent post ids (default created at, limit 15)' do
@cache.post_ids.should =~ 15.times.map {|n| n.to_s} @cache.post_ids.should =~ 15.times.map { |n| n.to_s }
end end
it 'returns posts ids after the specified time' do it 'returns posts ids after the specified time' do
@cache.post_ids(@timestamps[15]).should =~ (15...30).map {|n| n.to_s} @cache.post_ids(@timestamps[15]).should =~ (15...30).map { |n| n.to_s }
end end
it 'returns post ids with a non-default limit' do it 'returns post ids with a non-default limit' do
@cache.post_ids(@timestamp, 20).should =~ 20.times.map {|n| n.to_s} @cache.post_ids(@timestamp, 20).should =~ 20.times.map { |n| n.to_s }
end end
end end
@ -95,12 +92,13 @@ describe RedisCache do
sql = "long_sql" sql = "long_sql"
order = "created_at DESC" order = "created_at DESC"
@cache.should_receive(:order).and_return(order) @cache.should_receive(:order).and_return(order)
bob.should_receive(:visible_shareables_sql).with(Post, bob.should_receive(:visible_shareable_sql).with(
hash_including( Post,
:type => RedisCache.acceptable_types, hash_including(
:limit => RedisCache::CACHE_LIMIT, :type => RedisCache.acceptable_types,
:order => order)). :limit => RedisCache::CACHE_LIMIT,
and_return(sql) :order => order)).
and_return(sql)
Post.connection.should_receive(:select_all).with(sql).and_return([]) Post.connection.should_receive(:select_all).with(sql).and_return([])
@ -134,7 +132,7 @@ describe RedisCache do
@timestamps << created_time @timestamps << created_time
end end
post_ids = 100.times.map{|n| n.to_s} post_ids = 100.times.map { |n| n.to_s }
@cache.trim! @cache.trim!
@cache.post_ids(Time.now.to_i, @cache.size).should == post_ids[0...100] @cache.post_ids(Time.now.to_i, @cache.size).should == post_ids[0...100]
end end