Sha256: 6dd656e7f9e9140665f638b75871a23bb9f5c5030abd90fa2d4e508e80c61e2c

Contents?: true

Size: 1.17 KB

Versions: 32

Compression:

Stored size: 1.17 KB

Contents

require 'spec_helper'

describe "#expireat(key, timestamp)" do
  before do
    @key = 'mock-redis-test:expireat'
    @redises.set(@key, 'spork')
  end

  it "returns true for a key that exists" do
    @redises.expireat(@key, Time.now.to_i + 1).should be_true
  end

  it "returns false for a key that does not exist" do
    @redises.expireat('mock-redis-test:nonesuch', Time.now.to_i + 1).should be_false
  end

  it "removes a key immediately when timestamp is now" do
    @redises.expireat(@key, Time.now.to_i)
    @redises.get(@key).should be_nil
  end

  it "raises an error if you don't give it a Unix timestamp" do
    lambda do
      @redises.expireat(@key, Time.now)   # oops, forgot .to_i
    end.should raise_error(RuntimeError)
  end

  context "[mock only]" do
    # These are mock-only since we can't actually manipulate time in
    # the real Redis.

    before(:all) do
      @mock = @redises.mock
    end

    before do
      @now = Time.now
      Time.stub!(:now).and_return(@now)
    end

    it "removes keys after enough time has passed" do
      @mock.expireat(@key, @now.to_i + 5)
      Time.stub!(:now).and_return(@now + 5)
      @mock.get(@key).should be_nil
    end

  end
end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
mock_redis-0.11.0 spec/commands/expireat_spec.rb
mock_redis-0.10.0 spec/commands/expireat_spec.rb
mock_redis-0.9.0 spec/commands/expireat_spec.rb
mock_redis-0.8.2 spec/commands/expireat_spec.rb
mock_redis-0.8.1 spec/commands/expireat_spec.rb
mock_redis-0.8.0 spec/commands/expireat_spec.rb
mock_redis-0.7.0 spec/commands/expireat_spec.rb
mock_redis-0.6.6 spec/commands/expireat_spec.rb
mock_redis-0.6.5 spec/commands/expireat_spec.rb
mock_redis-0.6.4 spec/commands/expireat_spec.rb
mock_redis-0.6.3 spec/commands/expireat_spec.rb
mock_redis-0.6.2 spec/commands/expireat_spec.rb
mock_redis-0.6.1 spec/commands/expireat_spec.rb
mock_redis-0.6.0 spec/commands/expireat_spec.rb
mock_redis-0.5.5 spec/commands/expireat_spec.rb
mock_redis-0.5.4 spec/commands/expireat_spec.rb
mock_redis-0.5.3 spec/commands/expireat_spec.rb
mock_redis-0.5.2 spec/commands/expireat_spec.rb
mock_redis-0.5.1 spec/commands/expireat_spec.rb
mock_redis-0.5.0 spec/commands/expireat_spec.rb