Sha256: d79cc08afbdbb0aeb66e85eb9df8705045ce9ce5dbf2d51a0d3fac7802a3bba8

Contents?: true

Size: 1.37 KB

Versions: 15

Compression:

Stored size: 1.37 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/helper')

describe 'Padrino::Cache - Moneta store' do
  def setup
    @test_key = "val_#{Time.now.to_i}"
  end

  def teardown
    Padrino.cache.clear
  end

  class Foo
    def bar; "bar"; end
  end

  it "return nil trying to get a value that doesn't exist" do
    Padrino.cache.clear
    assert_nil Padrino.cache[@test_key]
  end

  it 'set and get an object with marshal' do
    Padrino.cache[@test_key] = Foo.new
    assert_equal "bar", Padrino.cache[@test_key].bar
  end

  it 'set and get a nil value' do
    Padrino.cache[@test_key] = nil
    assert_equal '', Padrino.cache[@test_key].to_s
  end

  it 'set and get a raw value' do
    Padrino.cache[@test_key] = 'foo'
    assert_equal 'foo', Padrino.cache[@test_key]
  end

  it "set a value that expires" do
    init_time = ( Time.now - 20 )
    Time.stub(:now, init_time) { Padrino.cache.store(@test_key, 'test', :expires => 1) }
    Time.stub(:now, init_time + 20) { assert_nil Padrino.cache[@test_key] }
  end

  it "be able to cache forever" do
    Padrino.cache.store('forever', 'cached', :expires => false)
    2.times { |i| assert_equal 'cached', Padrino.cache['forever'] }
  end

  it 'delete a value' do
    Padrino.cache[@test_key] = 'test'
    assert_equal 'test', Padrino.cache[@test_key]
    Padrino.cache.delete(@test_key)
    assert_nil Padrino.cache[@test_key]
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
padrino-cache-0.16.0.pre3 test/test_moneta_store.rb
padrino-cache-0.16.0.pre2 test/test_moneta_store.rb
padrino-cache-0.15.3 test/test_moneta_store.rb
padrino-cache-0.15.2 test/test_moneta_store.rb
padrino-cache-0.15.1 test/test_moneta_store.rb
padrino-cache-0.15.0 test/test_moneta_store.rb
padrino-cache-0.14.4 test/test_moneta_store.rb
padrino-cache-0.14.3 test/test_moneta_store.rb
padrino-cache-0.14.2 test/test_moneta_store.rb
padrino-cache-0.14.1.1 test/test_moneta_store.rb
padrino-cache-0.14.1 test/test_moneta_store.rb
padrino-cache-0.14.0.2 test/test_moneta_store.rb
padrino-cache-0.14.0.1 test/test_moneta_store.rb
padrino-cache-0.14.0 test/test_moneta_store.rb
padrino-cache-0.14.0.rc2 test/test_moneta_store.rb