crappycounter 0.0.2 → 0.0.3

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.
@@ -25,4 +25,15 @@ module CrappyCounter
25
25
  end
26
26
  end
27
27
 
28
+ def self.lpush(opts)
29
+ raise NoRedisFound unless $redis
30
+
31
+ combined_key = ""
32
+ opts[:keys].each do |key|
33
+ combined_key << (combined_key.empty? ? key : ":#{key}")
34
+ $redis.lpush combined_key, opts[:values]
35
+ end
36
+
37
+ end
38
+
28
39
  end
@@ -1,3 +1,3 @@
1
1
  module CrappyCounter
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,85 +1,110 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
- require 'redis'
3
2
 
4
3
  describe CrappyCounter do
5
4
 
6
- it "raises an error if $redis is not defined" do
7
- expect {
8
- CrappyCounter.incr "key"
9
- }.to raise_error(CrappyCounter::NoRedisFound)
5
+ before(:each) do
6
+ $redis = double "Redis"
10
7
  end
11
8
 
12
- context "no date" do
9
+ context ".incr" do
13
10
 
14
- before(:each) do
15
- $redis = double "Redis"
11
+ it "raises an error if $redis is not defined" do
12
+ $redis = nil
13
+
14
+ expect {
15
+ CrappyCounter.incr "key"
16
+ }.to raise_error(CrappyCounter::NoRedisFound)
16
17
  end
17
18
 
18
- it "increments a single key" do
19
- $redis.should_receive(:incr).with("first_key")
19
+ context "no date" do
20
20
 
21
- CrappyCounter.incr keys: ["first_key"]
22
- end
21
+ it "increments a single key" do
22
+ $redis.should_receive(:incr).with("first_key")
23
23
 
24
- it "increments multiple keys" do
25
- $redis.should_receive(:incr).with("first_key")
26
- $redis.should_receive(:incr).with("first_key:second_key")
24
+ CrappyCounter.incr keys: ["first_key"]
25
+ end
26
+
27
+ it "increments multiple keys" do
28
+ $redis.should_receive(:incr).with("first_key")
29
+ $redis.should_receive(:incr).with("first_key:second_key")
30
+
31
+ CrappyCounter.incr keys: ["first_key", "second_key"]
32
+ end
27
33
 
28
- CrappyCounter.incr keys: ["first_key", "second_key"]
29
34
  end
30
35
 
31
- end
36
+ context "with a date" do
32
37
 
33
- context "with a date" do
38
+ let(:today) {
39
+ today = double "Date"
40
+ today.stub(:year => "2000")
41
+ today.stub(:month => "12")
42
+ today.stub(:day => "31")
43
+ today
44
+ }
34
45
 
35
- let(:today) {
36
- Date.today
37
- #today = double "Date"
38
- #today.stub(:year => "2000")
39
- #today.stub(:month => "12")
40
- #today.stub(:day => "31")
41
- #today
42
- }
46
+ it "ignores an invalid date" do
47
+ today = "non-date"
43
48
 
44
- before(:each) do
45
- #$redis = double "Redis"
46
- $redis = Redis.new(:host => 'localhost', :port => 6379)
47
- end
49
+ $redis.should_receive(:incr).with("first_key")
50
+
51
+ CrappyCounter.incr keys: ["first_key"], date: today
52
+ end
48
53
 
49
- it "ignores an invalid date" do
50
- today = "non-date"
54
+ it "ignores a nil date" do
55
+ $redis.should_receive(:incr).with("first_key")
51
56
 
52
- #$redis.should_receive(:incr).with("first_key")
57
+ CrappyCounter.incr keys: ["first_key"], date: nil
58
+ end
59
+
60
+ it "increments a single key" do
61
+ $redis.should_receive(:incr).with("first_key")
62
+ $redis.should_receive(:incr).with("first_key:2000")
63
+ $redis.should_receive(:incr).with("first_key:200012")
64
+ $redis.should_receive(:incr).with("first_key:20001231")
65
+
66
+ CrappyCounter.incr keys: ["first_key"], date: today
67
+ end
68
+
69
+ it "increments multiple keys" do
70
+ $redis.should_receive(:incr).with("first_key")
71
+ $redis.should_receive(:incr).with("first_key:2000")
72
+ $redis.should_receive(:incr).with("first_key:200012")
73
+ $redis.should_receive(:incr).with("first_key:20001231")
74
+ $redis.should_receive(:incr).with("first_key:second_key")
75
+ $redis.should_receive(:incr).with("first_key:second_key:2000")
76
+ $redis.should_receive(:incr).with("first_key:second_key:200012")
77
+ $redis.should_receive(:incr).with("first_key:second_key:20001231")
78
+
79
+ CrappyCounter.incr keys: ["first_key", "second_key"], date: today
80
+ end
53
81
 
54
- CrappyCounter.incr keys: ["first_key"], date: today
55
82
  end
56
83
 
57
- it "ignores a nil date" do
58
- #$redis.should_receive(:incr).with("first_key")
84
+ end
59
85
 
60
- CrappyCounter.incr keys: ["first_key"], date: nil
86
+
87
+ context ".lpush" do
88
+
89
+ it "raises an error if $redis is not defined" do
90
+ $redis = nil
91
+
92
+ expect {
93
+ CrappyCounter.lpush "key"
94
+ }.to raise_error(CrappyCounter::NoRedisFound)
61
95
  end
62
96
 
63
97
  it "increments a single key" do
64
- #$redis.should_receive(:incr).with("first_key")
65
- #$redis.should_receive(:incr).with("first_key:2000")
66
- #$redis.should_receive(:incr).with("first_key:200012")
67
- #$redis.should_receive(:incr).with("first_key:20001231")
98
+ $redis.should_receive(:lpush).with("first_key", ["value"])
68
99
 
69
- CrappyCounter.incr keys: ["first_key"], date: today
100
+ CrappyCounter.lpush keys: ["first_key"], values: ["value"]
70
101
  end
71
102
 
72
103
  it "increments multiple keys" do
73
- #$redis.should_receive(:incr).with("first_key")
74
- #$redis.should_receive(:incr).with("first_key:2000")
75
- #$redis.should_receive(:incr).with("first_key:200012")
76
- #$redis.should_receive(:incr).with("first_key:20001231")
77
- #$redis.should_receive(:incr).with("first_key:second_key")
78
- #$redis.should_receive(:incr).with("first_key:second_key:2000")
79
- #$redis.should_receive(:incr).with("first_key:second_key:200012")
80
- #$redis.should_receive(:incr).with("first_key:second_key:20001231")
81
-
82
- CrappyCounter.incr keys: ["first_key", "second_key"], date: today
104
+ $redis.should_receive(:lpush).with("first_key", ["value"])
105
+ $redis.should_receive(:lpush).with("first_key:second_key", ["value"])
106
+
107
+ CrappyCounter.lpush keys: ["first_key", "second_key"], values: ["value"]
83
108
  end
84
109
 
85
110
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crappycounter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-07 00:00:00.000000000 Z
12
+ date: 2012-12-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec