mock_redis 0.1.2 → 0.2.0

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,6 @@
1
+ ### 0.2.0
2
+ * Support passing a block to `#multi`.
3
+
1
4
  ### 0.1.2
2
5
  * Fixes for 1.9.2; no functionality changes.
3
6
 
data/lib/mock_redis.rb CHANGED
@@ -21,8 +21,8 @@ class MockRedis
21
21
  super || @db.respond_to?(method, include_private)
22
22
  end
23
23
 
24
- def method_missing(method, *args)
25
- @db.send(method, *args)
24
+ def method_missing(method, *args, &block)
25
+ @db.send(method, *args, &block)
26
26
  end
27
27
 
28
28
  def initialize_copy(source)
@@ -60,7 +60,12 @@ class MockRedis
60
60
  raise RuntimeError, "ERR MULTI calls can not be nested"
61
61
  end
62
62
  @in_multi = true
63
- 'OK'
63
+ if block_given?
64
+ yield(self)
65
+ self.exec
66
+ else
67
+ 'OK'
68
+ end
64
69
  end
65
70
 
66
71
  def unwatch
@@ -1,3 +1,3 @@
1
1
  class MockRedis
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -18,6 +18,29 @@ describe 'transactions (multi/exec/discard)' do
18
18
  end
19
19
  end
20
20
 
21
+ context "#blocks" do
22
+ it "implicitly runs exec when finished" do
23
+ @redises.set("counter", 5)
24
+ @redises.multi do |r|
25
+ r.set("test", 1)
26
+ r.incr("counter")
27
+ end
28
+ @redises.get("counter").should == "6"
29
+ @redises.get("test").should == "1"
30
+ end
31
+
32
+ it "forbids nesting via blocks" do
33
+ # Have to use only the mock here. redis-rb has a bug in it where
34
+ # nested #multi calls raise NoMethodError because it gets a nil
35
+ # where it's not expecting one.
36
+ @redises.mock.multi do |r|
37
+ lambda do
38
+ r.multi {}
39
+ end.should raise_error(RuntimeError)
40
+ end
41
+ end
42
+ end
43
+
21
44
  context "#discard" do
22
45
  it "responds with 'OK' after #multi" do
23
46
  @redises.multi
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mock_redis
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Samuel Merritt
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-24 00:00:00 -07:00
18
+ date: 2011-09-28 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency