Sha256: 029d7feeebf7f5492a5e625dafea21b6377574c00aaed90baea529e57f45d0ae

Contents?: true

Size: 1.27 KB

Versions: 31

Compression:

Stored size: 1.27 KB

Contents

require 'spec_helper'

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

  it 'returns true for a key that exists' do
    @redises.pexpireat(@key, (Time.now.to_f * 1000).to_i + 1).should == true
  end

  it 'returns false for a key that does not exist' do
    @redises.pexpireat('mock-redis-test:nonesuch',
                       (Time.now.to_f * 1000).to_i + 1).should == false
  end

  it 'removes a key immediately when timestamp is now' do
    @redises.pexpireat(@key, (Time.now.to_f * 1000).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.pexpireat(@key, Time.now) # oops, forgot .to_i
    end.should raise_error(Redis::CommandError)
  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.pexpireat(@key, (@now.to_f * 1000).to_i + 5)
      Time.stub(:now).and_return(@now + 0.006)
      @mock.get(@key).should be_nil
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
mock_redis-0.36.0 spec/commands/pexpireat_spec.rb
mock_redis-0.35.0 spec/commands/pexpireat_spec.rb
mock_redis-0.34.0 spec/commands/pexpireat_spec.rb
mock_redis-0.33.0 spec/commands/pexpireat_spec.rb
mock_redis-0.32.0 spec/commands/pexpireat_spec.rb
mock_redis-0.31.0 spec/commands/pexpireat_spec.rb
mock_redis-0.30.0 spec/commands/pexpireat_spec.rb
mock_redis-0.29.0 spec/commands/pexpireat_spec.rb
mock_redis-0.28.0 spec/commands/pexpireat_spec.rb
mock_redis-0.27.3 spec/commands/pexpireat_spec.rb
mock_redis-0.27.2 spec/commands/pexpireat_spec.rb
mock_redis-0.27.1 spec/commands/pexpireat_spec.rb
mock_redis-0.27.0 spec/commands/pexpireat_spec.rb
mock_redis-0.26.0 spec/commands/pexpireat_spec.rb
mock_redis-0.25.0 spec/commands/pexpireat_spec.rb
mock_redis-0.24.0 spec/commands/pexpireat_spec.rb
mock_redis-0.23.0 spec/commands/pexpireat_spec.rb
mock_redis-0.22.0 spec/commands/pexpireat_spec.rb
mock_redis-0.21.0 spec/commands/pexpireat_spec.rb
mock_redis-0.20.0 spec/commands/pexpireat_spec.rb