Sha256: 431a12469dd5b0f345f6f5b6e58d5ad33d6aa1a6589ea90a1ba9adb8bd1d70ba

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

require File.expand_path('spec/spec_helper')

describe Ruco::FileStore do
  def mark_all_as_old
    store.send(:entries).each{|e| File.utime(1,1,e) }
  end

  before do
    @folder = 'spec/sessions'
    `rm -rf #{@folder}`
  end

  after do
    `rm -rf #{@folder}`
  end

  let(:store){ Ruco::FileStore.new(@folder, :keep => 3) }

  it "can get unstored stuff" do
    store.get('xxx').should == nil
  end

  it "can store stuff" do
    store.set('xxx', 1)
    store.get('xxx').should == 1
  end

  it "can store :keep keys" do
    store.set('xxx', 1)
    store.set('yyy', 1)
    store.set('zzz', 1)
    mark_all_as_old
    store.set('aaa', 2)
    store.get('aaa').should == 2
    ['xxx','yyy','zzz'].map{|f| store.get(f) }.should =~ [1,1,nil]
  end

  it "does not drop if used multiple times" do
    store.set('xxx', 1)
    store.set('yyy', 1)
    store.set('zzz', 1)
    store.set('zzz', 1)
    mark_all_as_old
    store.set('zzz', 1)
    store.set('zzz', 1)
    store.get('xxx').should == 1
  end

  it "can cache" do
    store.cache('x'){ 1 }.should == 1
    store.cache('x'){ 2 }.should == 1
  end

  it "can cache false" do
    store.cache('x'){ false }.should == false
    store.cache('x'){ 2 }.should == false
  end

  it "does not cache nil" do
    store.cache('x'){ nil }.should == nil
    store.cache('x'){ 2 }.should == 2
  end

  it "can delete" do
    store.set('x', 1)
    store.set('y', 2)
    store.delete('x')
    store.get('x').should == nil
    store.get('y').should == 2
  end

  it "can delete uncached" do
    store.set('x', 1)
    store.delete('z')
    store.get('x').should == 1
    store.get('z').should == nil
  end

  it "can clear" do
    store.set('x', 1)
    store.clear
    store.get('x').should == nil
  end

  it "can clear unstored" do
    store.clear
    store.get('x').should == nil
  end

  it "can store pure strings" do
    store = Ruco::FileStore.new(@folder, :keep => 3, :string => true)
    store.set('xxx','yyy')
    File.read(store.file('xxx')).should == 'yyy'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruco-0.2.0.beta7 spec/ruco/file_store_spec.rb
ruco-0.2.0.beta6 spec/ruco/file_store_spec.rb