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