mock_redis 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/lib/mock_redis/set_methods.rb +12 -2
- data/lib/mock_redis/transaction_wrapper.rb +1 -1
- data/lib/mock_redis/version.rb +1 -1
- data/spec/commands/sadd_spec.rb +19 -0
- data/spec/commands/watch_spec.rb +9 -0
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -6,8 +6,18 @@ class MockRedis
|
|
6
6
|
include Assertions
|
7
7
|
include UtilityMethods
|
8
8
|
|
9
|
-
def sadd(key,
|
10
|
-
|
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)
|
data/lib/mock_redis/version.rb
CHANGED
data/spec/commands/sadd_spec.rb
CHANGED
@@ -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
|
data/spec/commands/watch_spec.rb
CHANGED
@@ -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.
|
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-
|
13
|
+
date: 2012-09-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|