mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:34:31 +08:00
BUGFIX: cache did not support non strings
also reduced mocking in tests
This commit is contained in:
@ -7,6 +7,17 @@ describe Cache do
|
||||
Cache.new
|
||||
end
|
||||
|
||||
it "supports fixnum" do
|
||||
cache.write("num", 1)
|
||||
cache.read("num").should == 1
|
||||
end
|
||||
|
||||
it "supports hash" do
|
||||
hash = {a: 1, b: [1,2,3]}
|
||||
cache.write("hash", hash)
|
||||
cache.read("hash").should == hash
|
||||
end
|
||||
|
||||
it "can be cleared" do
|
||||
cache.write("hello0", "world")
|
||||
cache.write("hello1", "world")
|
||||
@ -35,21 +46,20 @@ describe Cache do
|
||||
cache.fetch("key").should be_nil
|
||||
end
|
||||
|
||||
it "can store with expiry correctly" do
|
||||
key = cache.namespaced_key("key")
|
||||
$redis.expects(:get).with(key).returns nil
|
||||
$redis.expects(:setex).with(key, 60 , "bob")
|
||||
#TODO yuck on this mock
|
||||
it "calls setex in redis" do
|
||||
cache.delete("key")
|
||||
|
||||
r = cache.fetch("key", expires_in: 1.minute) do
|
||||
key = cache.namespaced_key("key")
|
||||
$redis.expects(:setex).with(key, 60 , Marshal.dump("bob"))
|
||||
|
||||
cache.fetch("key", expires_in: 1.minute) do
|
||||
"bob"
|
||||
end
|
||||
r.should == "bob"
|
||||
end
|
||||
|
||||
it "can store and fetch correctly" do
|
||||
key = cache.namespaced_key("key")
|
||||
$redis.expects(:get).with(key).returns nil
|
||||
$redis.expects(:set).with(key, "bob")
|
||||
cache.delete "key"
|
||||
|
||||
r = cache.fetch "key" do
|
||||
"bob"
|
||||
@ -58,9 +68,7 @@ describe Cache do
|
||||
end
|
||||
|
||||
it "can fetch existing correctly" do
|
||||
key = cache.namespaced_key("key")
|
||||
|
||||
$redis.expects(:get).with(key).returns "bill"
|
||||
cache.write "key", "bill"
|
||||
|
||||
r = cache.fetch "key" do
|
||||
"bob"
|
||||
|
Reference in New Issue
Block a user