Sha256: c158933bd7c5b5fa14c74b58e27923df60a74a4f00549959ce86808e91a431cd

Contents?: true

Size: 1.72 KB

Versions: 11

Compression:

Stored size: 1.72 KB

Contents

require 'spec_helper'

describe '#hdel(key, field)' do
  before do
    @key = 'mock-redis-test:hdel'
    @redises.hset(@key, 'k1', 'v1')
    @redises.hset(@key, 'k2', 'v2')
  end

  it 'returns 1 when it removes a field' do
    @redises.hdel(@key, 'k1').should == 1
  end

  it 'returns 0 when it does not remove a field' do
    @redises.hdel(@key, 'nonesuch').should == 0
  end

  it 'actually removes the field' do
    @redises.hdel(@key, 'k1')
    @redises.hget(@key, 'k1').should be_nil
  end

  it 'treats the field as a string' do
    field = 2
    @redises.hset(@key, field, 'two')
    @redises.hdel(@key, field)
    @redises.hget(@key, field).should be_nil
  end

  it 'removes only the field specified' do
    @redises.hdel(@key, 'k1')
    @redises.hget(@key, 'k2').should == 'v2'
  end

  it 'cleans up empty hashes' do
    @redises.hdel(@key, 'k1')
    @redises.hdel(@key, 'k2')
    @redises.get(@key).should be_nil
  end

  it 'supports a variable number of arguments' do
    @redises.hdel(@key, 'k1', 'k2')
    @redises.get(@key).should be_nil
  end

  it 'treats variable arguments as strings' do
    field = 2
    @redises.hset(@key, field, 'two')
    @redises.hdel(@key, field)
    @redises.hget(@key, field).should be_nil
  end

  it 'supports a variable number of fields as array' do
    @redises.hdel(@key, %w[k1 k2]).should == 2

    @redises.hget(@key, 'k1').should be_nil
    @redises.hget(@key, 'k2').should be_nil
    @redises.get(@key).should be_nil
  end

  it 'supports a list of fields in various way' do
    @redises.hdel(@key, ['k1'], 'k2').should == 2

    @redises.hget(@key, 'k1').should be_nil
    @redises.hget(@key, 'k2').should be_nil
    @redises.get(@key).should be_nil
  end

  it_should_behave_like 'a hash-only command'
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mock_redis-0.28.0 spec/commands/hdel_spec.rb
mock_redis-0.27.3 spec/commands/hdel_spec.rb
mock_redis-0.27.2 spec/commands/hdel_spec.rb
mock_redis-0.27.1 spec/commands/hdel_spec.rb
mock_redis-0.27.0 spec/commands/hdel_spec.rb
mock_redis-0.26.0 spec/commands/hdel_spec.rb
mock_redis-0.25.0 spec/commands/hdel_spec.rb
mock_redis-0.24.0 spec/commands/hdel_spec.rb
mock_redis-0.23.0 spec/commands/hdel_spec.rb
mock_redis-0.22.0 spec/commands/hdel_spec.rb
mock_redis-0.21.0 spec/commands/hdel_spec.rb