Tests the base functionality that should be identical across all cache stores.

Methods
T
Instance Public methods
test_array_as_cache_key()
# File activesupport/test/caching_test.rb, line 282
def test_array_as_cache_key
  @cache.write([:fu, "foo"], "bar")
  assert_equal "bar", @cache.read("fu/foo")
end
test_cache_key()
# File activesupport/test/caching_test.rb, line 264
def test_cache_key
  obj = Object.new
  def obj.cache_key
    :foo
  end
  @cache.write(obj, "bar")
  assert_equal "bar", @cache.read("foo")
end
test_crazy_key_characters()
# File activesupport/test/caching_test.rb, line 381
def test_crazy_key_characters
  crazy_key = "#/:*(<+=> )&$%@?;'\"\'`~-"
  assert @cache.write(crazy_key, "1", :raw => true)
  assert_equal "1", @cache.read(crazy_key)
  assert_equal "1", @cache.fetch(crazy_key)
  assert @cache.delete(crazy_key)
  assert_equal "2", @cache.fetch(crazy_key, :raw => true) { "2" }
  assert_equal 3, @cache.increment(crazy_key)
  assert_equal 2, @cache.decrement(crazy_key)
end
test_delete()
# File activesupport/test/caching_test.rb, line 308
def test_delete
  @cache.write('foo', 'bar')
  assert @cache.exist?('foo')
  assert @cache.delete('foo')
  assert !@cache.exist?('foo')
end
test_exist()
# File activesupport/test/caching_test.rb, line 297
def test_exist
  @cache.write('foo', 'bar')
  assert @cache.exist?('foo')
  assert !@cache.exist?('bar')
end
test_expires_in()
# File activesupport/test/caching_test.rb, line 329
def test_expires_in
  time = Time.local(2008, 4, 24)
  Time.stubs(:now).returns(time)

  @cache.write('foo', 'bar')
  assert_equal 'bar', @cache.read('foo')

  Time.stubs(:now).returns(time + 30)
  assert_equal 'bar', @cache.read('foo')

  Time.stubs(:now).returns(time + 61)
  assert_nil @cache.read('foo')
end
test_fetch_with_cache_miss()
# File activesupport/test/caching_test.rb, line 177
def test_fetch_with_cache_miss
  @cache.expects(:write).with('foo', 'baz', @cache.options)
  assert_equal 'baz', @cache.fetch('foo') { 'baz' }
end
test_fetch_with_cached_nil()
# File activesupport/test/caching_test.rb, line 189
def test_fetch_with_cached_nil
  @cache.write('foo', nil)
  @cache.expects(:write).never
  assert_nil @cache.fetch('foo') { 'baz' }
end
test_fetch_with_forced_cache_miss()
# File activesupport/test/caching_test.rb, line 182
def test_fetch_with_forced_cache_miss
  @cache.write('foo', 'bar')
  @cache.expects(:read).never
  @cache.expects(:write).with('foo', 'bar', @cache.options.merge(:force => true))
  @cache.fetch('foo', :force => true) { 'bar' }
end
test_fetch_without_cache_miss()
# File activesupport/test/caching_test.rb, line 171
def test_fetch_without_cache_miss
  @cache.write('foo', 'bar')
  @cache.expects(:write).never
  assert_equal 'bar', @cache.fetch('foo') { 'baz' }
end
test_hash_as_cache_key()
# File activesupport/test/caching_test.rb, line 287
def test_hash_as_cache_key
  @cache.write({:foo => 1, :fu => 2}, "bar")
  assert_equal "bar", @cache.read("foo=1/fu=2")
end
test_keys_are_case_sensitive()
# File activesupport/test/caching_test.rb, line 292
def test_keys_are_case_sensitive
  @cache.write("foo", "bar")
  assert_nil @cache.read("FOO")
end
test_nil_exist()
# File activesupport/test/caching_test.rb, line 303
def test_nil_exist
  @cache.write('foo', nil)
  assert @cache.exist?('foo')
end
test_original_store_objects_should_not_be_immutable()
# File activesupport/test/caching_test.rb, line 323
def test_original_store_objects_should_not_be_immutable
  bar = 'bar'
  @cache.write('foo', bar)
  assert_nothing_raised { bar.gsub!(/.*/, 'baz') }
end
test_param_as_cache_key()
# File activesupport/test/caching_test.rb, line 273
def test_param_as_cache_key
  obj = Object.new
  def obj.to_param
    "foo"
  end
  @cache.write(obj, "bar")
  assert_equal "bar", @cache.read("foo")
end
test_race_condition_protection()
# File activesupport/test/caching_test.rb, line 343
def test_race_condition_protection
  time = Time.now
  @cache.write('foo', 'bar', :expires_in => 60)
  Time.stubs(:now).returns(time + 61)
  result = @cache.fetch('foo', :race_condition_ttl => 10) do
    assert_equal 'bar', @cache.read('foo')
    "baz"
  end
  assert_equal "baz", result
end
test_race_condition_protection_is_limited()
# File activesupport/test/caching_test.rb, line 354
def test_race_condition_protection_is_limited
  time = Time.now
  @cache.write('foo', 'bar', :expires_in => 60)
  Time.stubs(:now).returns(time + 71)
  result = @cache.fetch('foo', :race_condition_ttl => 10) do
    assert_equal nil, @cache.read('foo')
    "baz"
  end
  assert_equal "baz", result
end
test_race_condition_protection_is_safe()
# File activesupport/test/caching_test.rb, line 365
def test_race_condition_protection_is_safe
  time = Time.now
  @cache.write('foo', 'bar', :expires_in => 60)
  Time.stubs(:now).returns(time + 61)
  begin
    @cache.fetch('foo', :race_condition_ttl => 10) do
      assert_equal 'bar', @cache.read('foo')
      raise ArgumentError.new
    end
  rescue ArgumentError
  end
  assert_equal "bar", @cache.read('foo')
  Time.stubs(:now).returns(time + 71)
  assert_nil @cache.read('foo')
end
test_read_and_write_compressed_large_data()
# File activesupport/test/caching_test.rb, line 252
def test_read_and_write_compressed_large_data
  @cache.write('foo', 'bar', :compress => true, :compress_threshold => 2)
  raw_value = @cache.send(:read_entry, 'foo', {}).raw_value
  assert_equal 'bar', @cache.read('foo')
  assert_equal 'bar', Marshal.load(Zlib::Inflate.inflate(raw_value))
end
test_read_and_write_compressed_nil()
# File activesupport/test/caching_test.rb, line 259
def test_read_and_write_compressed_nil
  @cache.write('foo', nil, :compress => true)
  assert_nil @cache.read('foo')
end
test_read_and_write_compressed_small_data()
# File activesupport/test/caching_test.rb, line 245
def test_read_and_write_compressed_small_data
  @cache.write('foo', 'bar', :compress => true)
  raw_value = @cache.send(:read_entry, 'foo', {}).raw_value
  assert_equal 'bar', @cache.read('foo')
  assert_equal 'bar', Marshal.load(raw_value)
end
test_read_multi()
# File activesupport/test/caching_test.rb, line 230
def test_read_multi
  @cache.write('foo', 'bar')
  @cache.write('fu', 'baz')
  @cache.write('fud', 'biz')
  assert_equal({"foo" => "bar", "fu" => "baz"}, @cache.read_multi('foo', 'fu'))
end
test_read_multi_with_expires()
# File activesupport/test/caching_test.rb, line 237
def test_read_multi_with_expires
  @cache.write('foo', 'bar', :expires_in => 0.001)
  @cache.write('fu', 'baz')
  @cache.write('fud', 'biz')
  sleep(0.002)
  assert_equal({"fu" => "baz"}, @cache.read_multi('foo', 'fu'))
end
test_read_should_return_a_different_object_id_each_time_it_is_called()
# File activesupport/test/caching_test.rb, line 315
def test_read_should_return_a_different_object_id_each_time_it_is_called
  @cache.write('foo', 'bar')
  assert_not_equal @cache.read('foo').object_id, @cache.read('foo').object_id
  value = @cache.read('foo')
  value << 'bingo'
  assert_not_equal value, @cache.read('foo')
end
test_really_long_keys()
# File activesupport/test/caching_test.rb, line 392
def test_really_long_keys
  key = ""
  900.times{key << "x"}
  assert @cache.write(key, "bar")
  assert_equal "bar", @cache.read(key)
  assert_equal "bar", @cache.fetch(key)
  assert_nil @cache.read("#{key}x")
  assert_equal({key => "bar"}, @cache.read_multi(key))
  assert @cache.delete(key)
end
test_should_overwrite()
# File activesupport/test/caching_test.rb, line 165
def test_should_overwrite
  @cache.write('foo', 'bar')
  @cache.write('foo', 'baz')
  assert_equal 'baz', @cache.read('foo')
end
test_should_read_and_write_false()
# File activesupport/test/caching_test.rb, line 210
def test_should_read_and_write_false
  assert @cache.write('foo', false)
  assert_equal false, @cache.read('foo')
end
test_should_read_and_write_hash()
# File activesupport/test/caching_test.rb, line 195
def test_should_read_and_write_hash
  assert @cache.write('foo', {:a => "b"})
  assert_equal({:a => "b"}, @cache.read('foo'))
end
test_should_read_and_write_integer()
# File activesupport/test/caching_test.rb, line 200
def test_should_read_and_write_integer
  assert @cache.write('foo', 1)
  assert_equal 1, @cache.read('foo')
end
test_should_read_and_write_nil()
# File activesupport/test/caching_test.rb, line 205
def test_should_read_and_write_nil
  assert @cache.write('foo', nil)
  assert_equal nil, @cache.read('foo')
end
test_should_read_and_write_strings()
# File activesupport/test/caching_test.rb, line 160
def test_should_read_and_write_strings
  assert @cache.write('foo', 'bar')
  assert_equal 'bar', @cache.read('foo')
end
test_should_read_cached_hash_from_previous_rails_versions()
# File activesupport/test/caching_test.rb, line 220
def test_should_read_cached_hash_from_previous_rails_versions
  @old_cache = ActiveSupport::Cache::Entry.create( {}, Time.now )
  assert_equal( {}, @old_cache.value )
end
test_should_read_cached_numeric_from_previous_rails_versions()
# File activesupport/test/caching_test.rb, line 215
def test_should_read_cached_numeric_from_previous_rails_versions
  @old_cache = ActiveSupport::Cache::Entry.create( 1, Time.now )
  assert_equal( 1, @old_cache.value )
end
test_should_read_cached_string_from_previous_rails_versions()
# File activesupport/test/caching_test.rb, line 225
def test_should_read_cached_string_from_previous_rails_versions
  @old_cache = ActiveSupport::Cache::Entry.create( 'string', Time.now )
  assert_equal( 'string', @old_cache.value )
end