by_star 2.2.0.rc1 → 2.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.
- checksums.yaml +15 -0
- data/CHANGELOG.md +9 -1
- data/README.md +317 -208
- data/UPGRADING +5 -3
- data/lib/by_star/base.rb +18 -3
- data/lib/by_star/between.rb +52 -12
- data/lib/by_star/kernel.rb +3 -3
- data/lib/by_star/orm/active_record/by_star.rb +17 -10
- data/lib/by_star/orm/mongoid/by_star.rb +13 -9
- data/lib/by_star/version.rb +1 -1
- data/spec/fixtures/active_record/models.rb +4 -0
- data/spec/fixtures/active_record/schema.rb +8 -0
- data/spec/fixtures/mongoid/models.rb +14 -0
- data/spec/fixtures/shared/seeds.rb +13 -3
- data/spec/integration/active_record/active_record_spec.rb +3 -0
- data/spec/integration/mongoid/mongoid_spec.rb +3 -0
- data/spec/integration/shared/by_calendar_month.rb +5 -5
- data/spec/integration/shared/by_day.rb +29 -5
- data/spec/integration/shared/by_direction.rb +61 -2
- data/spec/integration/shared/by_fortnight.rb +3 -3
- data/spec/integration/shared/by_month.rb +4 -4
- data/spec/integration/shared/by_quarter.rb +4 -4
- data/spec/integration/shared/by_week.rb +3 -3
- data/spec/integration/shared/by_weekend.rb +1 -1
- data/spec/integration/shared/by_year.rb +6 -6
- data/spec/integration/shared/offset_parameter.rb +5 -5
- data/spec/integration/shared/relative.rb +174 -0
- data/spec/integration/shared/scope_parameter.rb +42 -0
- data/spec/unit/kernel_time_spec.rb +20 -20
- metadata +20 -37
@@ -6,18 +6,38 @@ shared_examples_for 'by direction' do
|
|
6
6
|
|
7
7
|
context 'point-in-time' do
|
8
8
|
subject { Post.before(Date.parse '2014-01-05') }
|
9
|
-
its(:count){ should eq
|
9
|
+
its(:count){ should eq 12 }
|
10
10
|
end
|
11
11
|
|
12
12
|
context 'timespan' do
|
13
13
|
subject { Event.before(Time.parse '2014-01-05') }
|
14
|
-
its(:count){ should eq
|
14
|
+
its(:count){ should eq 13 }
|
15
15
|
end
|
16
16
|
|
17
17
|
context 'timespan strict' do
|
18
18
|
subject { Event.before('2014-01-05', strict: true) }
|
19
|
+
its(:count){ should eq 13 }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'alternative field' do
|
23
|
+
subject { Event.before('2014-01-05', field: 'created_at') }
|
24
|
+
its(:count){ should eq 12 }
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with default scope' do
|
28
|
+
subject { Appointment.before('2014-01-05', field: 'created_at') }
|
19
29
|
its(:count){ should eq 4 }
|
20
30
|
end
|
31
|
+
|
32
|
+
context 'with scope as a query criteria' do
|
33
|
+
subject { Post.before('2014-01-05', field: 'created_at', scope: Post.where(day_of_month: 5)) }
|
34
|
+
its(:count){ should eq 1 }
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with scope as a proc' do
|
38
|
+
subject { Post.before('2014-01-05', field: 'created_at', scope: ->{ where(day_of_month: 5) }) }
|
39
|
+
its(:count){ should eq 1 }
|
40
|
+
end
|
21
41
|
end
|
22
42
|
|
23
43
|
describe '#after' do
|
@@ -36,6 +56,26 @@ shared_examples_for 'by direction' do
|
|
36
56
|
subject { Event.after('2014-01-05', strict: true) }
|
37
57
|
its(:count){ should eq 9 }
|
38
58
|
end
|
59
|
+
|
60
|
+
context 'alternative field' do
|
61
|
+
subject { Event.after('2014-01-05', field: 'created_at') }
|
62
|
+
its(:count){ should eq 10 }
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'with default scope' do
|
66
|
+
subject { Appointment.after('2014-01-05', field: 'created_at') }
|
67
|
+
its(:count){ should eq 3 }
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'with scope as a query criteria' do
|
71
|
+
subject { Post.after('2014-01-05', field: 'created_at', scope: Post.where(day_of_month: 5)) }
|
72
|
+
its(:count){ should eq 1 }
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'with scope as a proc' do
|
76
|
+
subject { Post.after('2014-01-05', field: 'created_at', scope: ->{ where(day_of_month: 5) }) }
|
77
|
+
its(:count){ should eq 1 }
|
78
|
+
end
|
39
79
|
end
|
40
80
|
|
41
81
|
describe '#previous and #next' do
|
@@ -51,5 +91,24 @@ shared_examples_for 'by direction' do
|
|
51
91
|
it{ subject.previous.start_time.should eq Time.zone.parse('2013-12-31 17:00:00') }
|
52
92
|
it{ subject.next.start_time.should eq Time.zone.parse('2014-01-07 17:00:00') }
|
53
93
|
end
|
94
|
+
|
95
|
+
context 'with default scope' do
|
96
|
+
subject { Appointment.where(created_at: Time.zone.parse('2014-01-05 17:00:00')).first }
|
97
|
+
it{ subject.previous.created_at.should eq Time.zone.parse('2014-01-01 17:00:00') }
|
98
|
+
it{ subject.next.created_at.should eq Time.zone.parse('2014-02-01 17:00:00') }
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'with scope as a query criteria' do
|
102
|
+
subject { Post.where(created_at: Time.zone.parse('2014-01-05 17:00:00')).first }
|
103
|
+
it{ subject.previous({ scope: Post.where(day_of_month: 5) }).created_at.should eq Time.zone.parse('2013-12-05 17:00:00') }
|
104
|
+
it{ subject.next({ scope: Post.where(day_of_month: 1) }).created_at.should eq Time.zone.parse('2014-02-01 17:00:00') }
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'with scope as a proc' do
|
108
|
+
subject { Post.where(created_at: Time.zone.parse('2014-01-05 17:00:00')).first }
|
109
|
+
it{ subject.previous({ scope: Proc.new{ where(day_of_month: 5) } }).created_at.should eq Time.zone.parse('2013-12-05 17:00:00') }
|
110
|
+
it{ subject.next({ scope: ->{ where(day_of_month: 1) } }).created_at.should eq Time.zone.parse('2014-02-01 17:00:00') }
|
111
|
+
it{ subject.next({ scope: ->(klass){ klass.where(day_of_month: 1) } }).created_at.should eq Time.zone.parse('2014-02-01 17:00:00') }
|
112
|
+
end
|
54
113
|
end
|
55
114
|
end
|
@@ -11,7 +11,7 @@ shared_examples_for 'by fortnight' do
|
|
11
11
|
|
12
12
|
context 'timespan' do
|
13
13
|
subject { Event.by_fortnight(0) }
|
14
|
-
its(:count){ should eq
|
14
|
+
its(:count){ should eq 7 }
|
15
15
|
end
|
16
16
|
|
17
17
|
context 'timespan strict' do
|
@@ -28,7 +28,7 @@ shared_examples_for 'by fortnight' do
|
|
28
28
|
|
29
29
|
context 'timespan' do
|
30
30
|
subject { Event.by_fortnight(26, year: 2013) }
|
31
|
-
its(:count){ should eq
|
31
|
+
its(:count){ should eq 7 }
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'timespan strict' do
|
@@ -42,7 +42,7 @@ shared_examples_for 'by fortnight' do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should be able to use an alternative field' do
|
45
|
-
Event.by_fortnight(:field => 'end_time').count.should eq
|
45
|
+
Event.by_fortnight(:field => 'end_time').count.should eq 5
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -11,7 +11,7 @@ shared_examples_for 'by month' do
|
|
11
11
|
|
12
12
|
context 'timespan' do
|
13
13
|
subject { Event.by_month(1) }
|
14
|
-
its(:count){ should eq
|
14
|
+
its(:count){ should eq 9 }
|
15
15
|
end
|
16
16
|
|
17
17
|
context 'timespan strict' do
|
@@ -23,17 +23,17 @@ shared_examples_for 'by month' do
|
|
23
23
|
|
24
24
|
context 'point-in-time' do
|
25
25
|
subject { Post.by_month(12, year: 2013) }
|
26
|
-
its(:count){ should eq
|
26
|
+
its(:count){ should eq 8 }
|
27
27
|
end
|
28
28
|
|
29
29
|
context 'timespan' do
|
30
30
|
subject { Event.by_month('December', year: 2013) }
|
31
|
-
its(:count){ should eq
|
31
|
+
its(:count){ should eq 12 }
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'timespan strict' do
|
35
35
|
subject { Event.by_month('Dec', year: 2013, strict: true) }
|
36
|
-
its(:count){ should eq
|
36
|
+
its(:count){ should eq 4 }
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -11,7 +11,7 @@ shared_examples_for 'by quarter' do
|
|
11
11
|
|
12
12
|
context 'timespan' do
|
13
13
|
subject { Event.by_quarter(1) }
|
14
|
-
its(:count){ should eq
|
14
|
+
its(:count){ should eq 13 }
|
15
15
|
end
|
16
16
|
|
17
17
|
context 'timespan strict' do
|
@@ -23,17 +23,17 @@ shared_examples_for 'by quarter' do
|
|
23
23
|
|
24
24
|
context 'point-in-time' do
|
25
25
|
subject { Post.by_quarter(4, year: 2013) }
|
26
|
-
its(:count){ should eq
|
26
|
+
its(:count){ should eq 10 }
|
27
27
|
end
|
28
28
|
|
29
29
|
context 'timespan' do
|
30
30
|
subject { Event.by_quarter(4, year: 2013) }
|
31
|
-
its(:count){ should eq
|
31
|
+
its(:count){ should eq 13 }
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'timespan strict' do
|
35
35
|
subject { Event.by_quarter(4, year: 2013, strict: true) }
|
36
|
-
its(:count){ should eq
|
36
|
+
its(:count){ should eq 8 }
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -11,7 +11,7 @@ shared_examples_for 'by week' do
|
|
11
11
|
|
12
12
|
context 'timespan' do
|
13
13
|
subject { Event.by_week(0) }
|
14
|
-
its(:count){ should eq
|
14
|
+
its(:count){ should eq 7 }
|
15
15
|
end
|
16
16
|
|
17
17
|
context 'timespan strict' do
|
@@ -28,7 +28,7 @@ shared_examples_for 'by week' do
|
|
28
28
|
|
29
29
|
context 'timespan' do
|
30
30
|
subject { Event.by_week(52, year: 2013) }
|
31
|
-
its(:count){ should eq
|
31
|
+
its(:count){ should eq 7 }
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'timespan strict' do
|
@@ -43,7 +43,7 @@ shared_examples_for 'by week' do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'should be able to use an alternative field' do
|
46
|
-
Event.by_week(:field => 'end_time').count.should eq
|
46
|
+
Event.by_week(:field => 'end_time').count.should eq 3
|
47
47
|
end
|
48
48
|
|
49
49
|
context ':start_day option' do
|
@@ -11,7 +11,7 @@ shared_examples_for 'by year' do
|
|
11
11
|
|
12
12
|
context 'timespan' do
|
13
13
|
subject { Event.by_year(13) }
|
14
|
-
its(:count){ should eq
|
14
|
+
its(:count){ should eq 13 }
|
15
15
|
end
|
16
16
|
|
17
17
|
context 'timespan strict' do
|
@@ -23,26 +23,26 @@ shared_examples_for 'by year' do
|
|
23
23
|
|
24
24
|
context 'point-in-time' do
|
25
25
|
subject { Post.by_year(year: 2013) }
|
26
|
-
its(:count){ should eq
|
26
|
+
its(:count){ should eq 10 }
|
27
27
|
end
|
28
28
|
|
29
29
|
context 'timespan' do
|
30
30
|
subject { Event.by_year(year: 2014) }
|
31
|
-
its(:count){ should eq
|
31
|
+
its(:count){ should eq 14 }
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'timespan strict' do
|
35
35
|
subject { Event.by_year(year: 2013, strict: true) }
|
36
|
-
its(:count){ should eq
|
36
|
+
its(:count){ should eq 8 }
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'should be able to use an alternative field' do
|
41
|
-
Event.by_year(:field => 'end_time').count.should eq
|
41
|
+
Event.by_year(:field => 'end_time').count.should eq 14
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'can use a 2-digit year' do
|
45
|
-
Post.by_year(13).count.should eq
|
45
|
+
Post.by_year(13).count.should eq 10
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -8,19 +8,19 @@ shared_examples_for 'offset parameter' do
|
|
8
8
|
Post.instance_variable_get(:@by_star_offset).should be_nil
|
9
9
|
end
|
10
10
|
|
11
|
-
context 'between_times with
|
11
|
+
context 'between_times with default offset' do
|
12
12
|
subject { Event.between_times(Time.parse('2014-01-01'), Time.parse('2014-01-10')) }
|
13
|
-
its(:count) { should eq
|
13
|
+
its(:count) { should eq 7 }
|
14
14
|
end
|
15
15
|
|
16
16
|
context 'between_times with offset override' do
|
17
17
|
subject { Event.between_times(Time.parse('2014-01-01'), Time.parse('2014-01-10'), offset: 16.hours) }
|
18
|
-
its(:count) { should eq
|
18
|
+
its(:count) { should eq 7 }
|
19
19
|
end
|
20
20
|
|
21
|
-
context 'by_day with
|
21
|
+
context 'by_day with default offset' do
|
22
22
|
subject { Event.by_day(Time.parse('2014-01-01')) }
|
23
|
-
its(:count) { should eq
|
23
|
+
its(:count) { should eq 5 }
|
24
24
|
end
|
25
25
|
|
26
26
|
context 'by_day with offset override' do
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for 'relative' do
|
4
|
+
|
5
|
+
describe '#past_day' do
|
6
|
+
context 'point-in-time' do
|
7
|
+
subject { Post.past_day }
|
8
|
+
its(:count){ should eq 1 }
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'timespan' do
|
12
|
+
subject { Event.past_day }
|
13
|
+
its(:count){ should eq 5 }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'timespan strict' do
|
17
|
+
subject { Event.past_day(strict: true) }
|
18
|
+
its(:count){ should eq 0 }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#past_week' do
|
23
|
+
context 'point-in-time' do
|
24
|
+
subject { Post.past_week }
|
25
|
+
its(:count){ should eq 3 }
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'timespan' do
|
29
|
+
subject { Event.past_week }
|
30
|
+
its(:count){ should eq 7 }
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'timespan strict' do
|
34
|
+
subject { Event.past_week(strict: true) }
|
35
|
+
its(:count){ should eq 0 }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#past_fortnight' do
|
40
|
+
context 'point-in-time' do
|
41
|
+
subject { Post.past_fortnight }
|
42
|
+
its(:count){ should eq 4 }
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'timespan' do
|
46
|
+
subject { Event.past_fortnight }
|
47
|
+
its(:count){ should eq 8 }
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'timespan strict' do
|
51
|
+
subject { Event.past_fortnight(strict: true) }
|
52
|
+
its(:count){ should eq 1 }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#past_month' do
|
57
|
+
context 'point-in-time' do
|
58
|
+
subject { Post.past_month }
|
59
|
+
its(:count){ should eq 8 }
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'timespan' do
|
63
|
+
subject { Event.past_month }
|
64
|
+
its(:count){ should eq 12 }
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'timespan strict' do
|
68
|
+
subject { Event.past_month(strict: true) }
|
69
|
+
its(:count){ should eq 4 }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#past_year' do
|
74
|
+
context 'point-in-time' do
|
75
|
+
subject { Post.past_year }
|
76
|
+
its(:count){ should eq 10 }
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'timespan' do
|
80
|
+
subject { Event.past_year }
|
81
|
+
its(:count){ should eq 13 }
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'timespan strict' do
|
85
|
+
subject { Event.past_year(strict: true) }
|
86
|
+
its(:count){ should eq 8 }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#next_day' do
|
91
|
+
context 'point-in-time' do
|
92
|
+
subject { Post.next_day }
|
93
|
+
its(:count){ should eq 2 }
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'timespan' do
|
97
|
+
subject { Event.next_day }
|
98
|
+
its(:count){ should eq 5 }
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'timespan strict' do
|
102
|
+
subject { Event.next_day(strict: true) }
|
103
|
+
its(:count){ should eq 0 }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#next_week' do
|
108
|
+
context 'point-in-time' do
|
109
|
+
subject { Post.next_week }
|
110
|
+
its(:count){ should eq 3 }
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'timespan' do
|
114
|
+
subject { Event.next_week }
|
115
|
+
its(:count){ should eq 7 }
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'timespan strict' do
|
119
|
+
subject { Event.next_week(strict: true) }
|
120
|
+
its(:count){ should eq 0 }
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#next_fortnight' do
|
125
|
+
context 'point-in-time' do
|
126
|
+
subject { Post.next_fortnight }
|
127
|
+
its(:count){ should eq 5 }
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'timespan' do
|
131
|
+
subject { Event.next_fortnight }
|
132
|
+
its(:count){ should eq 7 }
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'timespan strict' do
|
136
|
+
subject { Event.next_fortnight(strict: true) }
|
137
|
+
its(:count){ should eq 0 }
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe '#next_month' do
|
142
|
+
context 'point-in-time' do
|
143
|
+
subject { Post.next_month }
|
144
|
+
its(:count){ should eq 6 }
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'timespan' do
|
148
|
+
subject { Event.next_month }
|
149
|
+
its(:count){ should eq 9 }
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'timespan strict' do
|
153
|
+
subject { Event.next_month(strict: true) }
|
154
|
+
its(:count){ should eq 3 }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe '#next_year' do
|
159
|
+
context 'point-in-time' do
|
160
|
+
subject { Post.next_year }
|
161
|
+
its(:count){ should eq 12 }
|
162
|
+
end
|
163
|
+
|
164
|
+
context 'timespan' do
|
165
|
+
subject { Event.next_year }
|
166
|
+
its(:count){ should eq 14 }
|
167
|
+
end
|
168
|
+
|
169
|
+
context 'timespan strict' do
|
170
|
+
subject { Event.next_year(strict: true) }
|
171
|
+
its(:count){ should eq 9 }
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|