spec/bin/store_spec.rb in bin-0.6.2 vs spec/bin/store_spec.rb in bin-0.6.3

- old
+ new

@@ -4,28 +4,25 @@ before(:each) do DB.collections.each do |collection| collection.remove collection.drop_indexes end - - @collection = DB['bin_cache'] - @store = Bin::Store.new(@collection) end - let(:store) { @store } - let(:collection) { @collection } + let(:collection) { DB['bin_cache'] } + let(:store) { Bin::Store.new(collection) } it "has a collection" do store.collection.should == collection end it "defaults expires_in to 1.year" do store.expires_in.should == 1.year end it "can set default expires_in" do - Bin::Store.new(@collection, :expires_in => 5.minutes).expires_in.should == 5.minutes + Bin::Store.new(collection, :expires_in => 5.minutes).expires_in.should == 5.minutes end describe "#write" do before(:each) do store.write('foo', 'bar') @@ -57,10 +54,17 @@ it "sets expires_at if expires_in provided" do store.write('foo', 'bar', :expires_in => 5.seconds) document['expires_at'].to_i.should == (Time.now.utc + 5.seconds).to_i end + + it "always sets key as string" do + store.write(:baz, 'wick') + doc = collection.find_one(:_id => 'baz') + doc.should_not be_nil + doc['_id'].should be_instance_of(String) + end end describe "#read" do before(:each) do store.write('foo', 'bar') @@ -87,10 +91,14 @@ it "return value for existing and not expired key" do store.write('foo', 'bar', :expires_in => 20.seconds) store.read('foo').should == 'bar' end + + it "works with symbol" do + store.read(:foo).should == 'bar' + end end describe "#delete" do before(:each) do store.write('foo', 'bar') @@ -99,10 +107,16 @@ it "delete key from cache" do store.read('foo').should_not be_nil store.delete('foo') store.read('foo').should be_nil end + + it "works with symbol" do + store.read(:foo).should_not be_nil + store.delete(:foo) + store.read(:foo).should be_nil + end end describe "#delete_matched" do before(:each) do store.write('foo1', 'bar') @@ -134,10 +148,15 @@ end it "returns false if key not found" do store.exist?('not:found:key').should be_false end + + it "works with symbol" do + store.exist?(:foo).should be_true + store.exist?(:notfoundkey).should be_false + end end describe "#clear" do before(:each) do store.write('foo', 'bar') @@ -156,18 +175,29 @@ store.increment('views', 1) store.read('views').should == 1 store.increment('views', 2) store.read('views').should == 3 end + + it "works with symbol" do + store.increment(:views, 2) + store.read(:views).should == 2 + end end describe "#decrement" do it "decrement key by amount" do store.increment('views', 5) store.decrement('views', 2) store.read('views').should == 3 store.decrement('views', 2) store.read('views').should == 1 + end + + it "works with symbol" do + store.increment(:views, 2) + store.decrement(:views, 1) + store.read(:views).should == 1 end end describe "#stats" do it "returns stats" do \ No newline at end of file