Sha256: 2bd596225e19d38402d282428fbd525638f23ec4b46f8a57171ed463abdf32eb

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

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

module VinExploder
module Cache

describe EMSynchronyCouchDBCacheStore, :couchdb => true  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.2 spec/cache/em_synchrony_couchdb_cache_store_spec.rb