by_star 2.2.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +5 -5
- data/.travis.yml +61 -35
- data/CHANGELOG.md +44 -35
- data/Gemfile +18 -25
- data/MIT-LICENSE +20 -20
- data/README.md +577 -540
- data/Rakefile +18 -18
- data/UPGRADING +6 -12
- data/by_star.gemspec +34 -32
- data/cleaner.rb +24 -24
- data/lib/by_star.rb +17 -16
- data/lib/by_star/base.rb +68 -70
- data/lib/by_star/between.rb +156 -120
- data/lib/by_star/directional.rb +37 -33
- data/lib/by_star/kernel/date.rb +50 -19
- data/lib/by_star/kernel/time.rb +41 -41
- data/lib/by_star/normalization.rb +127 -118
- data/lib/by_star/orm/active_record/by_star.rb +61 -69
- data/lib/by_star/orm/mongoid/by_star.rb +76 -73
- data/lib/by_star/orm/mongoid/reorder.rb +23 -0
- data/lib/by_star/version.rb +3 -3
- data/spec/database.yml +15 -15
- data/spec/fixtures/active_record/models.rb +12 -10
- data/spec/fixtures/active_record/schema.rb +19 -19
- data/spec/fixtures/mongoid/models.rb +31 -29
- data/spec/fixtures/shared/seeds.rb +26 -26
- data/spec/gemfiles/Gemfile.master +6 -0
- data/spec/gemfiles/Gemfile.rails40 +7 -0
- data/spec/gemfiles/Gemfile.rails41 +7 -0
- data/spec/gemfiles/Gemfile.rails42 +7 -0
- data/spec/gemfiles/Gemfile.rails50 +10 -0
- data/spec/gemfiles/Gemfile.rails51 +10 -0
- data/spec/integration/active_record/active_record_spec.rb +38 -53
- data/spec/integration/mongoid/mongoid_spec.rb +37 -46
- data/spec/integration/shared/between_times.rb +82 -0
- data/spec/integration/shared/by_calendar_month.rb +55 -55
- data/spec/integration/shared/by_cweek.rb +54 -0
- data/spec/integration/shared/by_day.rb +96 -108
- data/spec/integration/shared/by_direction.rb +172 -153
- data/spec/integration/shared/by_fortnight.rb +48 -48
- data/spec/integration/shared/by_month.rb +50 -50
- data/spec/integration/shared/by_quarter.rb +49 -49
- data/spec/integration/shared/by_week.rb +54 -54
- data/spec/integration/shared/by_weekend.rb +49 -49
- data/spec/integration/shared/by_year.rb +48 -48
- data/spec/integration/shared/offset_parameter.rb +32 -31
- data/spec/integration/shared/order_parameter.rb +36 -0
- data/spec/integration/shared/relative.rb +174 -174
- data/spec/integration/shared/scope_parameter.rb +73 -72
- data/spec/spec_helper.rb +29 -29
- data/spec/unit/kernel_date_spec.rb +113 -60
- data/spec/unit/kernel_time_spec.rb +57 -57
- data/spec/unit/normalization_spec.rb +305 -255
- metadata +61 -62
@@ -1,48 +1,48 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
shared_examples_for 'by year' do
|
4
|
-
|
5
|
-
describe '#by_year' do
|
6
|
-
|
7
|
-
context 'point-in-time' do
|
8
|
-
subject { Post.by_year('2014') }
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'timespan' do
|
13
|
-
subject { Event.by_year(13) }
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'timespan strict' do
|
18
|
-
subject { Event.by_year(Date.parse('2014-02-01'), strict: true) }
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
context '
|
23
|
-
|
24
|
-
context 'point-in-time' do
|
25
|
-
subject { Post.by_year(
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'timespan' do
|
30
|
-
subject { Event.by_year(
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'timespan strict' do
|
35
|
-
subject { Event.by_year(
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should be able to use an alternative field' do
|
41
|
-
Event.by_year(:
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'can use a 2-digit year' do
|
45
|
-
Post.by_year(13).count.
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for 'by year' do
|
4
|
+
|
5
|
+
describe '#by_year' do
|
6
|
+
|
7
|
+
context 'point-in-time' do
|
8
|
+
subject { Post.by_year('2014') }
|
9
|
+
it { expect(subject.count).to eql(12) }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'timespan' do
|
13
|
+
subject { Event.by_year(13) }
|
14
|
+
it { expect(subject.count).to eql(13) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'timespan strict' do
|
18
|
+
subject { Event.by_year(Date.parse('2014-02-01'), strict: true) }
|
19
|
+
it { expect(subject.count).to eql(9) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'integer' do
|
23
|
+
|
24
|
+
context 'point-in-time' do
|
25
|
+
subject { Post.by_year(2013) }
|
26
|
+
it { expect(subject.count).to eql(10) }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'timespan' do
|
30
|
+
subject { Event.by_year(2014) }
|
31
|
+
it { expect(subject.count).to eql(14) }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'timespan strict' do
|
35
|
+
subject { Event.by_year(2013, strict: true) }
|
36
|
+
it { expect(subject.count).to eql(8) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should be able to use an alternative field' do
|
41
|
+
expect(Event.by_year(field: 'end_time').count).to eq 14
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'can use a 2-digit year' do
|
45
|
+
expect(Post.by_year(13).count).to eq 10
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,31 +1,32 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
shared_examples_for 'offset parameter' do
|
4
|
-
|
5
|
-
describe 'offset' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for 'offset parameter' do
|
4
|
+
|
5
|
+
describe ':offset' do
|
6
|
+
|
7
|
+
it 'should memoize the offset variable' do
|
8
|
+
expect(Event.instance_variable_get(:@by_star_offset)).to eq 3.hours
|
9
|
+
expect(Post.instance_variable_get(:@by_star_offset)).to be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'between_times with default offset' do
|
13
|
+
subject { Event.between_times(Time.zone.parse('2014-01-01'), Time.zone.parse('2014-01-10')) }
|
14
|
+
it { expect(subject.count).to eql(7) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'between_times with offset override' do
|
18
|
+
subject { Event.between_times(Time.zone.parse('2014-01-01')..Time.zone.parse('2014-01-10'), offset: 16.hours) }
|
19
|
+
it { expect(subject.count).to eql(7) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'by_day with default offset' do
|
23
|
+
subject { Event.by_day(Time.zone.parse('2014-01-01')) }
|
24
|
+
it { expect(subject.count).to eql(5) }
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'by_day with offset override' do
|
28
|
+
subject { Event.by_day(Time.zone.parse('2014-12-26'), field: :start_time, offset: 5.hours) }
|
29
|
+
it { expect(subject.count).to eql(0) }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for 'order parameter' do
|
4
|
+
|
5
|
+
describe ':order' do
|
6
|
+
|
7
|
+
if testing_active_record?
|
8
|
+
|
9
|
+
it 'should be able to order the result set asc' do
|
10
|
+
scope = Post.by_year(Time.zone.now.year, order: 'created_at ASC')
|
11
|
+
expect(scope.order_values).to eq ['created_at ASC']
|
12
|
+
expect(scope.first.created_at).to eq Time.zone.parse('2014-01-01 17:00:00')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should be able to order the result set desc' do
|
16
|
+
scope = Post.by_year(Time.zone.now.year, order: 'created_at DESC')
|
17
|
+
expect(scope.order_values).to eq ['created_at DESC']
|
18
|
+
expect(scope.first.created_at).to eq Time.zone.parse('2014-04-15 17:00:00')
|
19
|
+
end
|
20
|
+
|
21
|
+
elsif testing_mongoid?
|
22
|
+
|
23
|
+
it 'should be able to order the result set asc' do
|
24
|
+
scope = Post.by_year(Time.zone.now.year, order: {created_at: :asc})
|
25
|
+
expect(scope.options[:sort]).to eq({'created_at' => 1})
|
26
|
+
expect(scope.first.created_at).to eq Time.zone.parse('2014-01-01 17:00:00')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should be able to order the result set desc' do
|
30
|
+
scope = Post.by_year(Time.zone.now.year, order: {created_at: :desc})
|
31
|
+
expect(scope.options[:sort]).to eq({'created_at' => -1})
|
32
|
+
expect(scope.first.created_at).to eq Time.zone.parse('2014-04-15 17:00:00')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,174 +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
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'timespan' do
|
12
|
-
subject { Event.past_day }
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'timespan strict' do
|
17
|
-
subject { Event.past_day(strict: true) }
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#past_week' do
|
23
|
-
context 'point-in-time' do
|
24
|
-
subject { Post.past_week }
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'timespan' do
|
29
|
-
subject { Event.past_week }
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'timespan strict' do
|
34
|
-
subject { Event.past_week(strict: true) }
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe '#past_fortnight' do
|
40
|
-
context 'point-in-time' do
|
41
|
-
subject { Post.past_fortnight }
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'timespan' do
|
46
|
-
subject { Event.past_fortnight }
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'timespan strict' do
|
51
|
-
subject { Event.past_fortnight(strict: true) }
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '#past_month' do
|
57
|
-
context 'point-in-time' do
|
58
|
-
subject { Post.past_month }
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'timespan' do
|
63
|
-
subject { Event.past_month }
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'timespan strict' do
|
68
|
-
subject { Event.past_month(strict: true) }
|
69
|
-
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe '#past_year' do
|
74
|
-
context 'point-in-time' do
|
75
|
-
subject { Post.past_year }
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
context 'timespan' do
|
80
|
-
subject { Event.past_year }
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
context 'timespan strict' do
|
85
|
-
subject { Event.past_year(strict: true) }
|
86
|
-
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe '#next_day' do
|
91
|
-
context 'point-in-time' do
|
92
|
-
subject { Post.next_day }
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
context 'timespan' do
|
97
|
-
subject { Event.next_day }
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
context 'timespan strict' do
|
102
|
-
subject { Event.next_day(strict: true) }
|
103
|
-
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe '#next_week' do
|
108
|
-
context 'point-in-time' do
|
109
|
-
subject { Post.next_week }
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
context 'timespan' do
|
114
|
-
subject { Event.next_week }
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
context 'timespan strict' do
|
119
|
-
subject { Event.next_week(strict: true) }
|
120
|
-
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe '#next_fortnight' do
|
125
|
-
context 'point-in-time' do
|
126
|
-
subject { Post.next_fortnight }
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
context 'timespan' do
|
131
|
-
subject { Event.next_fortnight }
|
132
|
-
|
133
|
-
end
|
134
|
-
|
135
|
-
context 'timespan strict' do
|
136
|
-
subject { Event.next_fortnight(strict: true) }
|
137
|
-
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe '#next_month' do
|
142
|
-
context 'point-in-time' do
|
143
|
-
subject { Post.next_month }
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
|
-
context 'timespan' do
|
148
|
-
subject { Event.next_month }
|
149
|
-
|
150
|
-
end
|
151
|
-
|
152
|
-
context 'timespan strict' do
|
153
|
-
subject { Event.next_month(strict: true) }
|
154
|
-
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
describe '#next_year' do
|
159
|
-
context 'point-in-time' do
|
160
|
-
subject { Post.next_year }
|
161
|
-
|
162
|
-
end
|
163
|
-
|
164
|
-
context 'timespan' do
|
165
|
-
subject { Event.next_year }
|
166
|
-
|
167
|
-
end
|
168
|
-
|
169
|
-
context 'timespan strict' do
|
170
|
-
subject { Event.next_year(strict: true) }
|
171
|
-
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
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
|
+
it { expect(subject.count).to eql(1) }
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'timespan' do
|
12
|
+
subject { Event.past_day }
|
13
|
+
it { expect(subject.count).to eql(5) }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'timespan strict' do
|
17
|
+
subject { Event.past_day(strict: true) }
|
18
|
+
it { expect(subject.count).to eql(0) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#past_week' do
|
23
|
+
context 'point-in-time' do
|
24
|
+
subject { Post.past_week }
|
25
|
+
it { expect(subject.count).to eql(3) }
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'timespan' do
|
29
|
+
subject { Event.past_week }
|
30
|
+
it { expect(subject.count).to eql(7) }
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'timespan strict' do
|
34
|
+
subject { Event.past_week(strict: true) }
|
35
|
+
it { expect(subject.count).to eql(0) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#past_fortnight' do
|
40
|
+
context 'point-in-time' do
|
41
|
+
subject { Post.past_fortnight }
|
42
|
+
it { expect(subject.count).to eql(4) }
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'timespan' do
|
46
|
+
subject { Event.past_fortnight }
|
47
|
+
it { expect(subject.count).to eql(8) }
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'timespan strict' do
|
51
|
+
subject { Event.past_fortnight(strict: true) }
|
52
|
+
it { expect(subject.count).to eql(1) }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#past_month' do
|
57
|
+
context 'point-in-time' do
|
58
|
+
subject { Post.past_month }
|
59
|
+
it { expect(subject.count).to eql(8) }
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'timespan' do
|
63
|
+
subject { Event.past_month }
|
64
|
+
it { expect(subject.count).to eql(12) }
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'timespan strict' do
|
68
|
+
subject { Event.past_month(strict: true) }
|
69
|
+
it { expect(subject.count).to eql(4) }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#past_year' do
|
74
|
+
context 'point-in-time' do
|
75
|
+
subject { Post.past_year }
|
76
|
+
it { expect(subject.count).to eql(10) }
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'timespan' do
|
80
|
+
subject { Event.past_year }
|
81
|
+
it { expect(subject.count).to eql(13) }
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'timespan strict' do
|
85
|
+
subject { Event.past_year(strict: true) }
|
86
|
+
it { expect(subject.count).to eql(8) }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#next_day' do
|
91
|
+
context 'point-in-time' do
|
92
|
+
subject { Post.next_day }
|
93
|
+
it { expect(subject.count).to eql(2) }
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'timespan' do
|
97
|
+
subject { Event.next_day }
|
98
|
+
it { expect(subject.count).to eql(5) }
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'timespan strict' do
|
102
|
+
subject { Event.next_day(strict: true) }
|
103
|
+
it { expect(subject.count).to eql(0) }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#next_week' do
|
108
|
+
context 'point-in-time' do
|
109
|
+
subject { Post.next_week }
|
110
|
+
it { expect(subject.count).to eql(3) }
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'timespan' do
|
114
|
+
subject { Event.next_week }
|
115
|
+
it { expect(subject.count).to eql(7) }
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'timespan strict' do
|
119
|
+
subject { Event.next_week(strict: true) }
|
120
|
+
it { expect(subject.count).to eql(0) }
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#next_fortnight' do
|
125
|
+
context 'point-in-time' do
|
126
|
+
subject { Post.next_fortnight }
|
127
|
+
it { expect(subject.count).to eql(5) }
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'timespan' do
|
131
|
+
subject { Event.next_fortnight }
|
132
|
+
it { expect(subject.count).to eql(7) }
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'timespan strict' do
|
136
|
+
subject { Event.next_fortnight(strict: true) }
|
137
|
+
it { expect(subject.count).to eql(0) }
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe '#next_month' do
|
142
|
+
context 'point-in-time' do
|
143
|
+
subject { Post.next_month }
|
144
|
+
it { expect(subject.count).to eql(6) }
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'timespan' do
|
148
|
+
subject { Event.next_month }
|
149
|
+
it { expect(subject.count).to eql(9) }
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'timespan strict' do
|
153
|
+
subject { Event.next_month(strict: true) }
|
154
|
+
it { expect(subject.count).to eql(3) }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe '#next_year' do
|
159
|
+
context 'point-in-time' do
|
160
|
+
subject { Post.next_year }
|
161
|
+
it { expect(subject.count).to eql(12) }
|
162
|
+
end
|
163
|
+
|
164
|
+
context 'timespan' do
|
165
|
+
subject { Event.next_year }
|
166
|
+
it { expect(subject.count).to eql(14) }
|
167
|
+
end
|
168
|
+
|
169
|
+
context 'timespan strict' do
|
170
|
+
subject { Event.next_year(strict: true) }
|
171
|
+
it { expect(subject.count).to eql(9) }
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|