diff --git a/lib/mock_redis/database.rb b/lib/mock_redis/database.rb index e9fb3746..e7d2a746 100644 --- a/lib/mock_redis/database.rb +++ b/lib/mock_redis/database.rb @@ -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 @@ -20,7 +21,7 @@ class Database def initialize(base, *args) @base = base - @data = {} + @data = MockRedis::IndifferentHash.new @expire_times = [] end diff --git a/lib/mock_redis/indifferent_hash.rb b/lib/mock_redis/indifferent_hash.rb new file mode 100644 index 00000000..38242616 --- /dev/null +++ b/lib/mock_redis/indifferent_hash.rb @@ -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 diff --git a/spec/commands/get_spec.rb b/spec/commands/get_spec.rb index ed59654c..a9e175be 100644 --- a/spec/commands/get_spec.rb +++ b/spec/commands/get_spec.rb @@ -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