mock_redis 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.5.2
2
+ * Support `watch`
3
+ * `sadd` is now Redis 2.4-compliant
4
+
1
5
  ### 0.5.1
2
6
  * Support `MockRedis.connect`
3
7
 
@@ -6,8 +6,18 @@ class MockRedis
6
6
  include Assertions
7
7
  include UtilityMethods
8
8
 
9
- def sadd(key, member)
10
- with_set_at(key) {|s| !!s.add?(member.to_s)}
9
+ def sadd(key, members)
10
+ members = [members].flatten.map(&:to_s)
11
+
12
+ with_set_at(key) do |s|
13
+ if members.size > 1
14
+ size_before = s.size
15
+ members.reverse.each {|m| s << m}
16
+ s.size - size_before
17
+ else
18
+ !!s.add?(members.first)
19
+ end
20
+ end
11
21
  end
12
22
 
13
23
  def scard(key)
@@ -78,7 +78,7 @@ class MockRedis
78
78
  end
79
79
 
80
80
  def watch(_)
81
- nil
81
+ yield self if block_given?
82
82
  end
83
83
 
84
84
  end
@@ -1,3 +1,3 @@
1
1
  class MockRedis
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  end
@@ -18,5 +18,24 @@ describe '#sadd(key, member)' do
18
18
  @redises.smembers(@key).should == %w[2 1]
19
19
  end
20
20
 
21
+ describe 'adding multiple members at once' do
22
+
23
+ it "returns the amount of added members" do
24
+ @redises.sadd(@key, [1, 2, 3]).should == 3
25
+ @redises.sadd(@key, [1, 2, 3, 4]).should == 1
26
+ end
27
+
28
+ it "returns 0 if the set did already contain all members" do
29
+ @redises.sadd(@key, [1, 2, 3])
30
+ @redises.sadd(@key, [1, 2, 3]).should == 0
31
+ end
32
+
33
+ it "adds the members to the set" do
34
+ @redises.sadd(@key, [1, 2, 3])
35
+ @redises.smembers(@key).should == %w[1 2 3]
36
+ end
37
+
38
+ end
39
+
21
40
  it_should_behave_like "a set-only command"
22
41
  end
@@ -4,4 +4,13 @@ describe '#watch(key)' do
4
4
  it "responds with nil" do
5
5
  @redises.watch('mock-redis-test').should be_nil
6
6
  end
7
+
8
+ it 'EXECs its MULTI on successes' do
9
+ @redises.watch 'foo' do
10
+ @redises.multi do |multi|
11
+ multi.set 'bar', 'baz'
12
+ end
13
+ end
14
+ @redises.get('bar').should eq('baz')
15
+ end
7
16
  end
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.5.1
4
+ version: 0.5.2
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: 2012-09-06 00:00:00.000000000 Z
13
+ date: 2012-09-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake