Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8764

Show
Ignore:
Timestamp:
02/01/08 01:43:47 (9 months ago)
Author:
bitsweat
Message:

Add a handful of cache store tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/lib/active_support/cache.rb

    r8763 r8764  
     1require 'benchmark' 
     2 
    13module ActiveSupport 
    24  module Cache 
  • trunk/activesupport/test/caching_test.rb

    r8563 r8764  
    2626  end 
    2727end 
     28 
     29uses_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 
     53end