mock_redis 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 0.6.5
2
+ * Fix `zrevrange` to return an empty array on invalid range
3
+ * Fix `srandmember` spec on redis-rb 3.0.3
4
+ * Stringify keys in expiration-related commands
5
+
1
6
  ### 0.6.4
2
7
  * Update INFO command for latest Redis 2.6 compatibility
3
8
 
@@ -199,11 +199,11 @@ class MockRedis
199
199
  end
200
200
 
201
201
  def expiration(key)
202
- expire_times.find {|(_,k)| k == key}.first
202
+ expire_times.find {|(_,k)| k == key.to_s}.first
203
203
  end
204
204
 
205
205
  def has_expiration?(key)
206
- expire_times.any? {|(_,k)| k == key}
206
+ expire_times.any? {|(_,k)| k == key.to_s}
207
207
  end
208
208
 
209
209
  def looks_like_integer?(str)
@@ -223,14 +223,14 @@ class MockRedis
223
223
 
224
224
  def remove_expiration(key)
225
225
  expire_times.delete_if do |(t, k)|
226
- key == k
226
+ key.to_s == k
227
227
  end
228
228
  end
229
229
 
230
230
  def set_expiration(key, time)
231
231
  remove_expiration(key)
232
232
 
233
- expire_times << [time, key]
233
+ expire_times << [time, key.to_s]
234
234
  expire_times.sort! do |a, b|
235
235
  a.first <=> b.first
236
236
  end
@@ -7,5 +7,9 @@ class MockRedis
7
7
  def []=(key, value)
8
8
  super(key.to_s, value)
9
9
  end
10
+
11
+ def has_key?(key)
12
+ super(key.to_s)
13
+ end
10
14
  end
11
15
  end
@@ -82,7 +82,7 @@ class MockRedis
82
82
  end
83
83
  end
84
84
 
85
- def srandmember(key)
85
+ def srandmember(key, count = nil)
86
86
  members = with_set_at(key, &:to_a)
87
87
  members[rand(members.length)]
88
88
  end
@@ -1,3 +1,3 @@
1
1
  class MockRedis
2
- VERSION = '0.6.4'
2
+ VERSION = '0.6.5'
3
3
  end
@@ -101,7 +101,7 @@ class MockRedis
101
101
 
102
102
  def zrevrange(key, start, stop, options={})
103
103
  with_zset_at(key) do |z|
104
- to_response(z.sorted.reverse[start..stop], options)
104
+ to_response(z.sorted.reverse[start..stop] || [], options)
105
105
  end
106
106
  end
107
107
 
@@ -25,6 +25,10 @@ describe "#expire(key, seconds)" do
25
25
  end.should raise_error(RuntimeError)
26
26
  end
27
27
 
28
+ it "stringifies key" do
29
+ @redises.expire(@key.to_sym, 9).should == true
30
+ end
31
+
28
32
  context "[mock only]" do
29
33
  # These are mock-only since we can't actually manipulate time in
30
34
  # the real Redis.
@@ -20,6 +20,4 @@ describe '#srandmember(key)' do
20
20
  @redises.spop(@key)
21
21
  @redises.srandmember(@key).should be_nil
22
22
  end
23
-
24
- it_should_behave_like "a set-only command"
25
23
  end
@@ -14,6 +14,11 @@ describe "#ttl(key)" do
14
14
  @redises.ttl('mock-redis-test:nonesuch').should == -1
15
15
  end
16
16
 
17
+ it "stringifies key" do
18
+ @redises.expire(@key, 9)
19
+ @redises.ttl(@key.to_sym).should > 0
20
+ end
21
+
17
22
  context "[mock only]" do
18
23
  # These are mock-only since we can't actually manipulate time in
19
24
  # the real Redis.
@@ -17,6 +17,10 @@ describe "#zrevrange(key, start, stop [, :with_scores => true])" do
17
17
  @redises.zrevrange(@key, -2, -1).should == ['Adams', 'Washington']
18
18
  end
19
19
 
20
+ it 'returns empty list when start is too large' do
21
+ @redises.zrevrange(@key, 5, -1).should == []
22
+ end
23
+
20
24
  it "returns the scores when :with_scores is specified" do
21
25
  @redises.zrevrange(@key, 2, 3, :with_scores => true).
22
26
  should == [["Adams", 2.0], ["Washington", 1.0]]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mock_redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-02-21 00:00:00.000000000 Z
13
+ date: 2013-03-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -374,4 +374,3 @@ test_files:
374
374
  - spec/support/shared_examples/only_operates_on_zsets.rb
375
375
  - spec/support/shared_examples/sorts_enumerables.rb
376
376
  - spec/transactions_spec.rb
377
- has_rdoc: