crappycounter 0.0.1 → 0.0.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/lib/crappy_counter/version.rb +1 -1
- data/lib/crappy_counter.rb +1 -1
- data/spec/crappy_counter_spec.rb +23 -20
- metadata +1 -1
data/lib/crappy_counter.rb
CHANGED
@@ -18,7 +18,7 @@ module CrappyCounter
|
|
18
18
|
date_key << "#{combined_key}:"
|
19
19
|
[:year, :month, :day].each do |date_param|
|
20
20
|
next unless date.respond_to?(date_param)
|
21
|
-
date_key << date.send(date_param)
|
21
|
+
date_key << date.send(date_param).to_s
|
22
22
|
$redis.incr date_key
|
23
23
|
end
|
24
24
|
end
|
data/spec/crappy_counter_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
require 'redis'
|
2
3
|
|
3
4
|
describe CrappyCounter do
|
4
5
|
|
@@ -32,49 +33,51 @@ describe CrappyCounter do
|
|
32
33
|
context "with a date" do
|
33
34
|
|
34
35
|
let(:today) {
|
35
|
-
today
|
36
|
-
today
|
37
|
-
today.stub(:
|
38
|
-
today.stub(:
|
39
|
-
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
|
40
42
|
}
|
41
43
|
|
42
44
|
before(:each) do
|
43
|
-
|
45
|
+
#$redis = double "Redis"
|
46
|
+
$redis = Redis.new(:host => 'localhost', :port => 6379)
|
44
47
|
end
|
45
48
|
|
46
49
|
it "ignores an invalid date" do
|
47
50
|
today = "non-date"
|
48
51
|
|
49
|
-
|
52
|
+
#$redis.should_receive(:incr).with("first_key")
|
50
53
|
|
51
54
|
CrappyCounter.incr keys: ["first_key"], date: today
|
52
55
|
end
|
53
56
|
|
54
57
|
it "ignores a nil date" do
|
55
|
-
|
58
|
+
#$redis.should_receive(:incr).with("first_key")
|
56
59
|
|
57
60
|
CrappyCounter.incr keys: ["first_key"], date: nil
|
58
61
|
end
|
59
62
|
|
60
63
|
it "increments a single key" do
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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")
|
65
68
|
|
66
69
|
CrappyCounter.incr keys: ["first_key"], date: today
|
67
70
|
end
|
68
71
|
|
69
72
|
it "increments multiple keys" do
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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")
|
78
81
|
|
79
82
|
CrappyCounter.incr keys: ["first_key", "second_key"], date: today
|
80
83
|
end
|