periodic_counter 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -2
- data/lib/periodic_counter.rb +38 -14
- data/require.rb +1 -1
- data/spec/db/migrate/001_counters.rb +2 -0
- data/spec/log/test.log +4125 -0
- data/spec/periodic_counter_spec.rb +29 -4
- metadata +2 -2
@@ -6,17 +6,21 @@ describe PeriodicCounter do
|
|
6
6
|
$db.migrate(1)
|
7
7
|
$db.migrate(0)
|
8
8
|
$db.migrate(1)
|
9
|
-
stub_time(PeriodicCounter.last_monday)
|
10
9
|
create_counter
|
11
10
|
end
|
12
11
|
|
13
12
|
it "should set up data and increment last_monday (today)" do
|
13
|
+
stub_time(PeriodicCounter.last_monday)
|
14
14
|
start
|
15
|
-
attributes = Counter.last.attributes
|
15
|
+
attributes = Counter.last.reload.attributes
|
16
16
|
data = attributes.delete('counter_data')
|
17
|
+
data.delete('counter_1_day_ago_at').to_s.should == PeriodicCounter.today.to_s
|
18
|
+
data.delete('counter_2_days_ago_at').to_s.should == PeriodicCounter.today.to_s
|
17
19
|
data.delete('counter_last_day_at').to_s.should == PeriodicCounter.today.to_s
|
18
20
|
data.delete('counter_last_2_days_at').to_s.should == PeriodicCounter.today.to_s
|
19
21
|
data.should == {
|
22
|
+
"counter_1_day_ago"=>1,
|
23
|
+
"counter_2_days_ago"=>1,
|
20
24
|
"counter_last_day"=>1,
|
21
25
|
"counter_last_2_days"=>1,
|
22
26
|
"counter_last_monday_before_today"=>0,
|
@@ -26,6 +30,8 @@ describe PeriodicCounter do
|
|
26
30
|
attributes.should == {
|
27
31
|
"id"=>1,
|
28
32
|
"counter"=>1,
|
33
|
+
"counter_1_day_ago"=>0,
|
34
|
+
"counter_2_days_ago"=>0,
|
29
35
|
"counter_last_day"=>0,
|
30
36
|
"counter_last_2_days"=>0,
|
31
37
|
"counter_last_monday"=>1,
|
@@ -35,13 +41,18 @@ describe PeriodicCounter do
|
|
35
41
|
end
|
36
42
|
|
37
43
|
it "should add to last_day, last_2_days, and last_monday counters on increment" do
|
44
|
+
stub_time(PeriodicCounter.last_monday)
|
38
45
|
Counter.last.update_attribute :counter, 2
|
39
46
|
start
|
40
47
|
attributes = Counter.last.attributes
|
41
48
|
data = attributes.delete('counter_data')
|
49
|
+
data.delete('counter_1_day_ago_at').to_s.should == PeriodicCounter.today.to_s
|
50
|
+
data.delete('counter_2_days_ago_at').to_s.should == PeriodicCounter.today.to_s
|
42
51
|
data.delete('counter_last_day_at').to_s.should == PeriodicCounter.today.to_s
|
43
52
|
data.delete('counter_last_2_days_at').to_s.should == PeriodicCounter.today.to_s
|
44
53
|
data.should == {
|
54
|
+
"counter_1_day_ago"=>2,
|
55
|
+
"counter_2_days_ago"=>2,
|
45
56
|
"counter_last_day"=>1,
|
46
57
|
"counter_last_2_days"=>1,
|
47
58
|
"counter_last_monday_before_today"=>0,
|
@@ -51,6 +62,8 @@ describe PeriodicCounter do
|
|
51
62
|
attributes.should == {
|
52
63
|
"id"=>1,
|
53
64
|
"counter"=>2,
|
65
|
+
"counter_1_day_ago"=>0,
|
66
|
+
"counter_2_days_ago"=>0,
|
54
67
|
"counter_last_day"=>1,
|
55
68
|
"counter_last_2_days"=>1,
|
56
69
|
"counter_last_monday"=>2,
|
@@ -61,13 +74,17 @@ describe PeriodicCounter do
|
|
61
74
|
|
62
75
|
it "should reset counter_last_day and increment last_tuesday" do
|
63
76
|
Counter.last.update_attribute :counter, 3
|
64
|
-
stub_time(
|
77
|
+
stub_time(PeriodicCounter.last_monday + 1.day) # Tuesday
|
65
78
|
start
|
66
79
|
attributes = Counter.last.attributes
|
67
80
|
data = attributes.delete('counter_data')
|
81
|
+
data.delete('counter_1_day_ago_at').to_s.should == PeriodicCounter.today.to_s
|
82
|
+
data.delete('counter_2_days_ago_at').to_s.should == (PeriodicCounter.today - 1.day).to_s
|
68
83
|
data.delete('counter_last_day_at').to_s.should == PeriodicCounter.today.to_s
|
69
84
|
data.delete('counter_last_2_days_at').to_s.should == (PeriodicCounter.today - 1.day).to_s
|
70
85
|
data.should == {
|
86
|
+
"counter_1_day_ago"=>3,
|
87
|
+
"counter_2_days_ago"=>2,
|
71
88
|
"counter_last_day"=>3,
|
72
89
|
"counter_last_2_days"=>1,
|
73
90
|
"counter_last_monday_before_today"=>3,
|
@@ -77,6 +94,8 @@ describe PeriodicCounter do
|
|
77
94
|
attributes.should == {
|
78
95
|
"id"=>1,
|
79
96
|
"counter"=>3,
|
97
|
+
"counter_1_day_ago"=>2,
|
98
|
+
"counter_2_days_ago"=>0,
|
80
99
|
"counter_last_day"=>0,
|
81
100
|
"counter_last_2_days"=>2,
|
82
101
|
"counter_last_monday"=>2,
|
@@ -87,13 +106,17 @@ describe PeriodicCounter do
|
|
87
106
|
|
88
107
|
it "should reset last_2_days and not touch last_wednesday" do
|
89
108
|
Counter.last.update_attribute :counter, 4
|
90
|
-
stub_time(
|
109
|
+
stub_time(PeriodicCounter.last_monday + 3.days) # Thursday
|
91
110
|
start
|
92
111
|
attributes = Counter.last.attributes
|
93
112
|
data = attributes.delete('counter_data')
|
113
|
+
data.delete('counter_1_day_ago_at').to_s.should == PeriodicCounter.today.to_s
|
114
|
+
data.delete('counter_2_days_ago_at').to_s.should == PeriodicCounter.today.to_s
|
94
115
|
data.delete('counter_last_day_at').to_s.should == PeriodicCounter.today.to_s
|
95
116
|
data.delete('counter_last_2_days_at').to_s.should == PeriodicCounter.today.to_s
|
96
117
|
data.should == {
|
118
|
+
"counter_1_day_ago"=>4,
|
119
|
+
"counter_2_days_ago"=>4,
|
97
120
|
"counter_last_day"=>4,
|
98
121
|
"counter_last_2_days"=>4,
|
99
122
|
"counter_last_monday_before_today"=>4,
|
@@ -103,6 +126,8 @@ describe PeriodicCounter do
|
|
103
126
|
attributes.should == {
|
104
127
|
"id"=>1,
|
105
128
|
"counter"=>4,
|
129
|
+
"counter_1_day_ago"=>3,
|
130
|
+
"counter_2_days_ago"=>2,
|
106
131
|
"counter_last_day"=>0,
|
107
132
|
"counter_last_2_days"=>0,
|
108
133
|
"counter_last_monday"=>2,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: periodic_counter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Winton Welsh
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-06-
|
12
|
+
date: 2010-06-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|