Skip to content

Commit

Permalink
Ensure that commands respects symbols or strings for keys
Browse files Browse the repository at this point in the history
Change-Id: Ied52a1dbc2af72dbfe80e19cbf55ad02695fe211
Reviewed-on: https://gerrit.causes.com/17025
Tested-by: jenkins <[email protected]>
Reviewed-by: Alex Wallace <[email protected]>
  • Loading branch information
ecoffey authored and Aiden Scandella committed Jan 3, 2013
1 parent bdc98d0 commit 8a78a2d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/mock_redis/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'mock_redis/string_methods'
require 'mock_redis/zset_methods'
require 'mock_redis/sort_method'
require 'mock_redis/indifferent_hash'

class MockRedis
class Database
Expand All @@ -20,7 +21,7 @@ class Database

def initialize(base, *args)
@base = base
@data = {}
@data = MockRedis::IndifferentHash.new
@expire_times = []
end

Expand Down
11 changes: 11 additions & 0 deletions lib/mock_redis/indifferent_hash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class MockRedis
class IndifferentHash < Hash
def [](key)
super(key.to_s)
end

def []=(key, value)
super(key.to_s, value)
end
end
end
7 changes: 7 additions & 0 deletions spec/commands/get_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@
@redises.get(@key).should == "100"
end

it "stringifies key" do
key = :a_symbol

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

it_should_behave_like "a string-only command"
end

0 comments on commit 8a78a2d

Please sign in to comment.