mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add a handful of cache store tests
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8764 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
2f7ce08b56
commit
e59de6046c
2 changed files with 28 additions and 0 deletions
|
@ -1,3 +1,5 @@
|
|||
require 'benchmark'
|
||||
|
||||
module ActiveSupport
|
||||
module Cache
|
||||
def self.lookup_store(*store_option)
|
||||
|
|
|
@ -25,3 +25,29 @@ class CacheStoreSettingTest < Test::Unit::TestCase
|
|||
assert_equal "/path/to/cache/directory", store.cache_path
|
||||
end
|
||||
end
|
||||
|
||||
uses_mocha 'high-level cache store tests' do
|
||||
class CacheStoreTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@cache = ActiveSupport::Cache.lookup_store(:memory_store)
|
||||
end
|
||||
|
||||
def test_fetch_without_cache_miss
|
||||
@cache.stubs(:read).with('foo', {}).returns('bar')
|
||||
@cache.expects(:write).never
|
||||
assert_equal 'bar', @cache.fetch('foo') { 'baz' }
|
||||
end
|
||||
|
||||
def test_fetch_with_cache_miss
|
||||
@cache.stubs(:read).with('foo', {}).returns(nil)
|
||||
@cache.expects(:write).with('foo', 'baz', {})
|
||||
assert_equal 'baz', @cache.fetch('foo') { 'baz' }
|
||||
end
|
||||
|
||||
def test_fetch_with_forced_cache_miss
|
||||
@cache.expects(:read).never
|
||||
@cache.expects(:write).with('foo', 'bar', :force => true)
|
||||
@cache.fetch('foo', :force => true) { 'bar' }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue