| | 28 | |
|---|
| | 29 | uses_mocha 'high-level cache store tests' do |
|---|
| | 30 | class CacheStoreTest < Test::Unit::TestCase |
|---|
| | 31 | def setup |
|---|
| | 32 | @cache = ActiveSupport::Cache.lookup_store(:memory_store) |
|---|
| | 33 | end |
|---|
| | 34 | |
|---|
| | 35 | def test_fetch_without_cache_miss |
|---|
| | 36 | @cache.stubs(:read).with('foo', {}).returns('bar') |
|---|
| | 37 | @cache.expects(:write).never |
|---|
| | 38 | assert_equal 'bar', @cache.fetch('foo') { 'baz' } |
|---|
| | 39 | end |
|---|
| | 40 | |
|---|
| | 41 | def test_fetch_with_cache_miss |
|---|
| | 42 | @cache.stubs(:read).with('foo', {}).returns(nil) |
|---|
| | 43 | @cache.expects(:write).with('foo', 'baz', {}) |
|---|
| | 44 | assert_equal 'baz', @cache.fetch('foo') { 'baz' } |
|---|
| | 45 | end |
|---|
| | 46 | |
|---|
| | 47 | def test_fetch_with_forced_cache_miss |
|---|
| | 48 | @cache.expects(:read).never |
|---|
| | 49 | @cache.expects(:write).with('foo', 'bar', :force => true) |
|---|
| | 50 | @cache.fetch('foo', :force => true) { 'bar' } |
|---|
| | 51 | end |
|---|
| | 52 | end |
|---|
| | 53 | end |
|---|