Permalink
Browse files

Merge pull request #23 from Viximo/fix/mock

Fix Cash::Mock#get with multiple keys / #set without a ttl
  • Loading branch information...
2 parents 8c36cc0 + 7431386 commit 6f92c3afd425e8c1114a644cf99fd3af29f35fa3 @ashleym1972 ashleym1972 committed Aug 18, 2011
Showing with 22 additions and 13 deletions.
  1. +16 −12 lib/cash/mock.rb
  2. +6 −1 spec/spec_helper.rb
View
@@ -20,7 +20,7 @@ def initialize(value, raw, ttl)
@value = Marshal.dump(value)
end
- if ttl.zero?
+ if ttl.nil? || ttl.zero?
@ttl = self.class.default_ttl
else
@ttl = ttl
@@ -68,18 +68,22 @@ def set(key, value, ttl = CacheEntry.default_ttl, raw = false)
end
def get(key, raw = false)
- log "< get #{key}"
- unless self.has_unexpired_key?(key)
- log('> END')
- return nil
- end
-
- log("> sending key #{key}")
- log('> END')
- if raw
- self[key].value
+ if key.is_a?(Array)
+ get_multi(*key)
else
- self[key].unmarshal
+ log "< get #{key}"
+ unless self.has_unexpired_key?(key)
+ log('> END')
+ return nil
+ end
+
+ log("> sending key #{key}")
+ log('> END')
+ if raw
+ self[key].value
+ else
+ self[key].unmarshal
+ end
end
end
View
@@ -29,7 +29,12 @@
require 'fakeredis'
$memcache = Cash::Adapter::Redis.new(FakeRedis::Redis.new(),
:default_ttl => 1.minute.to_i)
-
+ when 'mock'
+ # Test with Mock client
+ require 'cash/adapter/memcache_client'
+ require 'cash/mock'
+ $memcache = Cash::Adapter::MemcacheClient.new(Cash::Mock.new(),
+ :default_ttl => 1.minute.to_i)
else
require 'cash/adapter/memcached'
# Test with memcached client

2 comments on commit 6f92c3a

Mind cutting an 0.3.0 release at this point?

I can but I'll have to comment out some tests because this thing is broken.

Please sign in to comment.