| 1 |
require 'abstract_unit' |
|---|
| 2 |
|
|---|
| 3 |
class CacheStoreSettingTest < Test::Unit::TestCase |
|---|
| 4 |
def test_file_fragment_cache_store |
|---|
| 5 |
store = ActiveSupport::Cache.lookup_store :file_store, "/path/to/cache/directory" |
|---|
| 6 |
assert_kind_of(ActiveSupport::Cache::FileStore, store) |
|---|
| 7 |
assert_equal "/path/to/cache/directory", store.cache_path |
|---|
| 8 |
end |
|---|
| 9 |
|
|---|
| 10 |
def test_drb_fragment_cache_store |
|---|
| 11 |
store = ActiveSupport::Cache.lookup_store :drb_store, "druby://localhost:9192" |
|---|
| 12 |
assert_kind_of(ActiveSupport::Cache::DRbStore, store) |
|---|
| 13 |
assert_equal "druby://localhost:9192", store.address |
|---|
| 14 |
end |
|---|
| 15 |
|
|---|
| 16 |
def test_mem_cache_fragment_cache_store |
|---|
| 17 |
store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost" |
|---|
| 18 |
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store) |
|---|
| 19 |
assert_equal %w(localhost), store.addresses |
|---|
| 20 |
end |
|---|
| 21 |
|
|---|
| 22 |
def test_object_assigned_fragment_cache_store |
|---|
| 23 |
store = ActiveSupport::Cache.lookup_store ActiveSupport::Cache::FileStore.new("/path/to/cache/directory") |
|---|
| 24 |
assert_kind_of(ActiveSupport::Cache::FileStore, store) |
|---|
| 25 |
assert_equal "/path/to/cache/directory", store.cache_path |
|---|
| 26 |
end |
|---|
| 27 |
end |
|---|
| 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 |
|---|