Browse files

Merge pull request #1 from dawanda/master

Spec failing when run in a certain order.
  • Loading branch information...
2 parents b0b1402 + 6176cfb commit 11308a66b9625f340eeffe0f9821fc83c3312d35 @grosser committed Mar 29, 2012
Showing with 14 additions and 4 deletions.
  1. +3 −1 lib/cachy.rb
  2. +11 −3 spec/cachy_spec.rb
View
4 lib/cachy.rb
@@ -29,7 +29,7 @@ def self.cache(*args)
cache_store.write key, result, options
result
end
-
+
def self.cache_if(cond, *args, &block)
if cond
cache(*args, &block)
@@ -118,6 +118,8 @@ class << self
def self.cache_store=(cache)
@cache_store = wrap_cache(cache)
@cache_store.write HEALTH_CHECK_KEY, 'yes'
+ @key_versions_cache_store = nil
+ memory_store.clear
end
def self.cache_store
View
14 spec/cachy_spec.rb
@@ -49,22 +49,22 @@
Cachy.cache(:x){ true }.should == true
end
end
-
+
describe :cache_if do
it "should not call the cache command if condition is wrong" do
Cachy.should_not_receive(:cache)
Cachy.cache_if(false, :x) do
"asd"
end
end
-
+
it "should call cache command if condition is true" do
Cachy.should_receive(:cache)
Cachy.cache_if(true, :x) do
"asd"
end
end
-
+
it "should pass params correctly" do
Cachy.should_receive(:cache).with(:x, {:y => 1}, :expires_in => 3)
Cachy.cache_if(true, :x, {:y => 1}, :expires_in => 3) do
@@ -357,6 +357,14 @@ def @mock.[](x)
Cachy.increment_key :x
Cachy.key_versions.should == {:x => 2}
end
+
+ it "invalidates the cached key_versions_cache_store when a new cache store is used" do
+ key_cache.write(Cachy::KEY_VERSIONS_KEY, :x => 1)
+ Cachy.key_versions_cache_store = key_cache
+ Cachy.key_versions.should == {:x => 1}
+ Cachy.cache_store = @cache
+ Cachy.key_versions.should == {}
+ end
end
describe :delete_key do

0 comments on commit 11308a6

Please sign in to comment.