Sha256: 24db03d8bd09a2d28c74578c83213026d2e52722323ca33e473ac97fb0935248

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'
require 'vin_exploder/cache/em_synchrony_couchdb_cache_store'

module VinExploder
module Cache

describe EMSynchronyCouchDBCacheStore do
  let(:db_name) { 'vindecoder_test' }
  let(:options) { {:host => 'localhost', :port => 5984, :db_name => db_name} }
  let(:store) { EMSynchronyCouchDBCacheStore.new options }
  let(:vin) { '3D7LU38C83G854645' }
  let(:doc) { {:vin => vin, :make => 'Ford' } }

  def with_synchrony(&test)
    EM.synchrony do
      test.call
      EM.stop
    end
  end

  before do
    with_synchrony do
      EM::Synchrony::CouchDB.connect(options).delete_db(db_name)
    end
  end

  it "should read and write a hash" do
    with_synchrony do
      store.read(vin).should be_nil
      store.write(vin, doc)
      store.read(vin).should == doc
    end
  end

  it "should delete a vin from the cache" do
    with_synchrony do
      store.write(vin, doc)
      store.read(vin).should == doc
      store.delete(vin).should be_true
      store.read(vin).should be_nil
    end
  end

  it "should use the value provided by the block if the vin is not in the cache" do
    with_synchrony do
      store.read(vin).should be_nil
      store.fetch(vin) { doc }
      store.read(vin).should == doc
    end
  end

  it "should not yield to the block if the vin is already in the cache" do
    with_synchrony do
      store.write(vin, doc)
      expect{|b|
        store.fetch(vin, &b)
      }.not_to yield_control
    end
  end
end

end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vin_exploder-0.5.0 spec/cache/em_synchrony_couchdb_cache_store_spec.rb