Sha256: bb143af9621347949094d3c814dc4224cc9e04a2e90eec771dcd7bc104117c11

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

require 'helper'
require 'flipper/adapters/mongo_with_ttl'
require 'flipper/spec/shared_adapter_specs'

describe Flipper::Adapters::MongoWithTTL do
  let(:collection) { Mongo::Connection.new.db('testing')['testing'] }
  let(:criteria)   { {:_id => id} }
  let(:id)         { described_class::DefaultId }

  subject { Flipper::Adapters::MongoWithTTL.new(collection) }

  before do
    collection.remove(criteria)
  end

  it_should_behave_like 'a flipper adapter'

  it "can cache document in process for a number of seconds" do
    options = {:ttl => 10}
    adapter = Flipper::Adapters::MongoWithTTL.new(collection, options)
    adapter.write('foo', 'bar')
    now = Time.now
    Timecop.freeze(now)

    collection.should_receive(:find_one).with(:_id => id)
    adapter.read('foo')

    adapter.read('foo')
    adapter.read('bar')

    Timecop.travel(3)
    adapter.read('foo')

    Timecop.travel(6)
    adapter.read('foo')

    collection.should_receive(:find_one).with(:_id => id)
    Timecop.travel(1)
    adapter.read('foo')

    Timecop.travel(4)
    adapter.read('foo')
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flipper-mongo-0.1.1 spec/flipper/adapters/mongo_with_ttl_spec.rb
flipper-mongo-0.1.0 spec/flipper/adapters/mongo_with_ttl_spec.rb