periodic_counter 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,10 +6,11 @@ describe PeriodicCounter do
6
6
  $db.migrate(1)
7
7
  $db.migrate(0)
8
8
  $db.migrate(1)
9
+ stub_time(PeriodicCounter.last_monday)
9
10
  create_counter
10
11
  end
11
12
 
12
- it "should not do anything but set up data" do
13
+ it "should set up data and increment last_monday (today)" do
13
14
  start
14
15
  attributes = Counter.last.attributes
15
16
  data = attributes.delete('counter_data')
@@ -17,17 +18,23 @@ describe PeriodicCounter do
17
18
  data.delete('counter_last_2_days_at').to_s.should == PeriodicCounter.today.to_s
18
19
  data.should == {
19
20
  "counter_last_day"=>1,
20
- "counter_last_2_days"=>1
21
+ "counter_last_2_days"=>1,
22
+ "counter_last_monday_before_today"=>0,
23
+ "counter_last_tuesday_before_today"=>1,
24
+ "counter_last_wednesday_before_today"=>1
21
25
  }
22
26
  attributes.should == {
23
27
  "id"=>1,
24
28
  "counter"=>1,
25
29
  "counter_last_day"=>0,
26
- "counter_last_2_days"=>0
30
+ "counter_last_2_days"=>0,
31
+ "counter_last_monday"=>1,
32
+ "counter_last_tuesday"=>0,
33
+ "counter_last_wednesday"=>0
27
34
  }
28
35
  end
29
36
 
30
- it "should add to both counters on increment" do
37
+ it "should add to last_day, last_2_days, and last_monday counters on increment" do
31
38
  Counter.last.update_attribute :counter, 2
32
39
  start
33
40
  attributes = Counter.last.attributes
@@ -36,19 +43,25 @@ describe PeriodicCounter do
36
43
  data.delete('counter_last_2_days_at').to_s.should == PeriodicCounter.today.to_s
37
44
  data.should == {
38
45
  "counter_last_day"=>1,
39
- "counter_last_2_days"=>1
46
+ "counter_last_2_days"=>1,
47
+ "counter_last_monday_before_today"=>0,
48
+ "counter_last_tuesday_before_today"=>2,
49
+ "counter_last_wednesday_before_today"=>2
40
50
  }
41
51
  attributes.should == {
42
52
  "id"=>1,
43
53
  "counter"=>2,
44
54
  "counter_last_day"=>1,
45
- "counter_last_2_days"=>1
55
+ "counter_last_2_days"=>1,
56
+ "counter_last_monday"=>2,
57
+ "counter_last_tuesday"=>0,
58
+ "counter_last_wednesday"=>0
46
59
  }
47
60
  end
48
61
 
49
- it "should reset counter_last_day" do
62
+ it "should reset counter_last_day and increment last_tuesday" do
50
63
  Counter.last.update_attribute :counter, 3
51
- stub_time(Time.now + 1.day)
64
+ stub_time(Time.now + 1.day) # Tuesday
52
65
  start
53
66
  attributes = Counter.last.attributes
54
67
  data = attributes.delete('counter_data')
@@ -56,19 +69,25 @@ describe PeriodicCounter do
56
69
  data.delete('counter_last_2_days_at').to_s.should == (PeriodicCounter.today - 1.day).to_s
57
70
  data.should == {
58
71
  "counter_last_day"=>3,
59
- "counter_last_2_days"=>1
72
+ "counter_last_2_days"=>1,
73
+ "counter_last_monday_before_today"=>3,
74
+ "counter_last_tuesday_before_today"=>2,
75
+ "counter_last_wednesday_before_today"=>3
60
76
  }
61
77
  attributes.should == {
62
78
  "id"=>1,
63
79
  "counter"=>3,
64
80
  "counter_last_day"=>0,
65
- "counter_last_2_days"=>2
81
+ "counter_last_2_days"=>2,
82
+ "counter_last_monday"=>2,
83
+ "counter_last_tuesday"=>1,
84
+ "counter_last_wednesday"=>0
66
85
  }
67
86
  end
68
87
 
69
- it "should reset counter_last_2_days" do
88
+ it "should reset last_2_days and not touch last_wednesday" do
70
89
  Counter.last.update_attribute :counter, 4
71
- stub_time(Time.now + 2.days)
90
+ stub_time(Time.now + 2.days) # Thursday
72
91
  start
73
92
  attributes = Counter.last.attributes
74
93
  data = attributes.delete('counter_data')
@@ -76,13 +95,19 @@ describe PeriodicCounter do
76
95
  data.delete('counter_last_2_days_at').to_s.should == PeriodicCounter.today.to_s
77
96
  data.should == {
78
97
  "counter_last_day"=>4,
79
- "counter_last_2_days"=>4
98
+ "counter_last_2_days"=>4,
99
+ "counter_last_monday_before_today"=>4,
100
+ "counter_last_tuesday_before_today"=>4,
101
+ "counter_last_wednesday_before_today"=>4
80
102
  }
81
103
  attributes.should == {
82
104
  "id"=>1,
83
105
  "counter"=>4,
84
106
  "counter_last_day"=>0,
85
- "counter_last_2_days"=>0
107
+ "counter_last_2_days"=>0,
108
+ "counter_last_monday"=>2,
109
+ "counter_last_tuesday"=>1,
110
+ "counter_last_wednesday"=>0
86
111
  }
87
112
  end
88
113
  end
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.2
4
+ version: 0.1.3
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-14 00:00:00 -07:00
12
+ date: 2010-06-17 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency