aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/caching_test.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-02-01 01:43:47 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-02-01 01:43:47 +0000
commite59de6046cf01852e1b16e7a6a39de94aefa7e72 (patch)
tree0bb6ac26daea368aa14e9a67dcb3dcdff1f539be /activesupport/test/caching_test.rb
parent2f7ce08b569813a2898b19f025b364d180769058 (diff)
downloadrails-e59de6046cf01852e1b16e7a6a39de94aefa7e72.tar.gz
rails-e59de6046cf01852e1b16e7a6a39de94aefa7e72.tar.bz2
rails-e59de6046cf01852e1b16e7a6a39de94aefa7e72.zip
Add a handful of cache store tests
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8764 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test/caching_test.rb')
-rw-r--r--activesupport/test/caching_test.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index 4694cb11d1..a038f29f53 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -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