Skip to content

Commit

Permalink
Fix get set reversibility (#158)
Browse files Browse the repository at this point in the history
* prefix keys with mock-redis-test to ensure cleared between runs

* test for string conversion in get method
  • Loading branch information
okhwaja authored and sds committed Jan 30, 2019
1 parent 9e9c907 commit 96492cf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/mock_redis/string_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def decrby(key, n)
end

def get(key)
key = key.to_s
assert_stringy(key)
data[key]
end
Expand Down
1 change: 1 addition & 0 deletions spec/commands/get_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

@redises.set(key, 'hello')
@redises.get(key.to_s).should == 'hello'
@redises.get(key).should == 'hello'
end

it_should_behave_like 'a string-only command'
Expand Down
4 changes: 2 additions & 2 deletions spec/commands/xadd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
end

it 'raises exception if id of 0 is added to an empty stream' do
expect { @redises.xadd('unknown-stream', { key: 'value' }, id: '0') }
expect { @redises.xadd('mock-redis-test:unknown-stream', { key: 'value' }, id: '0') }
.to raise_error(
Redis::CommandError,
'ERR The ID specified in XADD is equal or smaller than the target ' \
Expand All @@ -58,7 +58,7 @@
end

it 'does not raise exception on empty stream with id of 0 and positive sequence number' do
expect { @redises.xadd('unknown-stream', { key: 'value' }, id: '0-1') }
expect { @redises.xadd('mock-redis-test:unknown-stream', { key: 'value' }, id: '0-1') }
.to_not raise_error
end

Expand Down

0 comments on commit 96492cf

Please sign in to comment.