Sha256: 9469fd4a36cb2a49f579830073440d2b539cfdcbe9fcbf1125da0ff341e2612f

Contents?: true

Size: 1.28 KB

Versions: 33

Compression:

Stored size: 1.28 KB

Contents

require 'spec_helper'

describe '#select(db)' do
  before { @key = 'mock-redis-test:select' }

  it "returns 'OK'" do
    @redises.select(0).should == 'OK'
  end

  it "treats '0' and 0 the same" do
    @redises.select('0')
    @redises.set(@key, 'foo')
    @redises.select(0)
    @redises.get(@key).should == 'foo'
  end

  it 'switches databases' do
    @redises.select(0)
    @redises.set(@key, 'foo')

    @redises.select(1)
    @redises.get(@key).should be_nil

    @redises.select(0)
    @redises.get(@key).should == 'foo'
  end

  context '[mock only]' do
    # Time dependence introduces a bit of nondeterminism here
    before do
      @now = Time.now
      Time.stub(:now).and_return(@now)

      @mock = @redises.mock

      @mock.select(0)
      @mock.set(@key, 1)
      @mock.expire(@key, 100)

      @mock.select(1)
      @mock.set(@key, 2)
      @mock.expire(@key, 200)
    end

    it 'keeps expire times per-db' do
      @mock.select(0)
      @mock.ttl(@key).should == 100

      @mock.select(1)
      @mock.ttl(@key).should == 200
    end

    it 'keeps expire times in miliseconds per-db' do
      @mock.select(0)
      (100_000 - 1000..100_000 + 1000).should cover(@mock.pttl(@key))

      @mock.select(1)
      (200_000 - 1000..200_000 + 1000).should cover(@mock.pttl(@key))
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

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