Sha256: 927f788b47f23770701f6a43da85e6dfa28cf7858e688c8054a8d2076cb24a3a

Contents?: true

Size: 1.13 KB

Versions: 33

Compression:

Stored size: 1.13 KB

Contents

require 'spec_helper'

describe '#hsetnx(key, field)' do
  before do
    @key = 'mock-redis-test:hsetnx'
  end

  it 'returns true if the field is absent' do
    @redises.hsetnx(@key, 'field', 'val').should == true
  end

  it 'returns 0 if the field is present' do
    @redises.hset(@key, 'field', 'val')
    @redises.hsetnx(@key, 'field', 'val').should == false
  end

  it 'leaves the field unchanged if the field is present' do
    @redises.hset(@key, 'field', 'old')
    @redises.hsetnx(@key, 'field', 'new')
    @redises.hget(@key, 'field').should == 'old'
  end

  it 'sets the field if the field is absent' do
    @redises.hsetnx(@key, 'field', 'new')
    @redises.hget(@key, 'field').should == 'new'
  end

  it 'creates a hash if there is no such field' do
    @redises.hsetnx(@key, 'field', 'val')
    @redises.hget(@key, 'field').should == 'val'
  end

  it 'stores values as strings' do
    @redises.hsetnx(@key, 'num', 1)
    @redises.hget(@key, 'num').should == '1'
  end

  it 'stores fields as strings' do
    @redises.hsetnx(@key, 1, 'one')
    @redises.hget(@key, '1').should == 'one'
  end

  it_should_behave_like 'a hash-only command'
end

Version data entries

33 entries across 33 versions & 1 rubygems

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