Sha256: 9cf96cfa10d6f6beb3fe82a5a5e31fc9eba3f4a796854ef1f1ecbd8d7e0f0e99

Contents?: true

Size: 1.13 KB

Versions: 26

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 be_true
  end

  it "returns 0 if the field is present" do
    @redises.hset(@key, 'field', 'val')
    @redises.hsetnx(@key, 'field', 'val').should be_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

26 entries across 26 versions & 1 rubygems

Version Path
mock_redis-0.13.2 spec/commands/hsetnx_spec.rb
mock_redis-0.13.1 spec/commands/hsetnx_spec.rb
mock_redis-0.13.0 spec/commands/hsetnx_spec.rb
mock_redis-0.12.1 spec/commands/hsetnx_spec.rb
mock_redis-0.12.0 spec/commands/hsetnx_spec.rb
mock_redis-0.11.0 spec/commands/hsetnx_spec.rb
mock_redis-0.10.0 spec/commands/hsetnx_spec.rb
mock_redis-0.9.0 spec/commands/hsetnx_spec.rb
mock_redis-0.8.2 spec/commands/hsetnx_spec.rb
mock_redis-0.8.1 spec/commands/hsetnx_spec.rb
mock_redis-0.8.0 spec/commands/hsetnx_spec.rb
mock_redis-0.7.0 spec/commands/hsetnx_spec.rb
mock_redis-0.6.6 spec/commands/hsetnx_spec.rb
mock_redis-0.6.5 spec/commands/hsetnx_spec.rb
mock_redis-0.6.4 spec/commands/hsetnx_spec.rb
mock_redis-0.6.3 spec/commands/hsetnx_spec.rb
mock_redis-0.6.2 spec/commands/hsetnx_spec.rb
mock_redis-0.6.1 spec/commands/hsetnx_spec.rb
mock_redis-0.6.0 spec/commands/hsetnx_spec.rb
mock_redis-0.5.5 spec/commands/hsetnx_spec.rb