by_star 2.2.0.rc1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for 'scope parameter' do
|
4
|
+
|
5
|
+
describe 'scope' do
|
6
|
+
it 'should memoize the scope variable' do
|
7
|
+
Event.instance_variable_get(:@by_star_scope).should be_nil
|
8
|
+
Post.instance_variable_get(:@by_star_scope).should be_nil
|
9
|
+
Appointment.instance_variable_get(:@by_star_scope).should be_a Proc
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'between_times with default scope' do
|
13
|
+
subject { Appointment.between_times(Date.parse('2013-12-01'), Date.parse('2014-02-01')) }
|
14
|
+
its(:count) { should eq 3 }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'between_times with scope override as a query criteria' do
|
18
|
+
subject { Appointment.between_times(Date.parse('2013-12-01'), Date.parse('2014-02-01'), scope: Appointment.unscoped) }
|
19
|
+
its(:count) { should eq 14 }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'between_times with scope override as a Proc' do
|
23
|
+
subject { Appointment.between_times(Date.parse('2013-12-01'), Date.parse('2014-02-01'), scope: ->{ unscoped }) }
|
24
|
+
its(:count) { should eq 14 }
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'by_month with default scope' do
|
28
|
+
subject { Appointment.by_month(Date.parse('2014-01-01')) }
|
29
|
+
its(:count) { should eq 2 }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'by_month with scope override as a query criteria' do
|
33
|
+
subject { Appointment.by_month(Date.parse('2014-01-01'), scope: Appointment.unscoped) }
|
34
|
+
its(:count) { should eq 6 }
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'by_month with scope override as a Proc' do
|
38
|
+
subject { Appointment.by_month(Date.parse('2014-01-01'), scope: ->{ unscoped }) }
|
39
|
+
its(:count) { should eq 6 }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -6,9 +6,9 @@ describe Time do
|
|
6
6
|
|
7
7
|
(0..6).each do |n|
|
8
8
|
context "Monday plus #{n} days" do
|
9
|
-
subject { Time.parse('2014-01-06') + n.days }
|
10
|
-
its(:beginning_of_weekend){ should eq Time.parse('2014-01-10 15:00') }
|
11
|
-
its(:end_of_weekend){ should eq Time.parse('2014-01-13 02:00').end_of_hour }
|
9
|
+
subject { Time.zone.parse('2014-01-06') + n.days }
|
10
|
+
its(:beginning_of_weekend){ should eq Time.zone.parse('2014-01-10 15:00') }
|
11
|
+
its(:end_of_weekend){ should eq Time.zone.parse('2014-01-13 02:00').end_of_hour }
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -16,42 +16,42 @@ describe Time do
|
|
16
16
|
describe 'fortnight' do
|
17
17
|
|
18
18
|
context 'first day of year' do
|
19
|
-
subject { Time.parse '2014-01-01' }
|
20
|
-
its(:beginning_of_fortnight){ should eq Time.parse('2014-01-01') }
|
21
|
-
its(:end_of_fortnight){ should eq Time.parse('2014-01-14').end_of_day }
|
19
|
+
subject { Time.zone.parse '2014-01-01' }
|
20
|
+
its(:beginning_of_fortnight){ should eq Time.zone.parse('2014-01-01') }
|
21
|
+
its(:end_of_fortnight){ should eq Time.zone.parse('2014-01-14').end_of_day }
|
22
22
|
end
|
23
23
|
|
24
24
|
context 'second fortnight of year' do
|
25
|
-
subject { Time.parse '2014-01-16' }
|
26
|
-
its(:beginning_of_fortnight){ should eq Time.parse('2014-01-15') }
|
27
|
-
its(:end_of_fortnight){ should eq Time.parse('2014-01-28').end_of_day }
|
25
|
+
subject { Time.zone.parse '2014-01-16' }
|
26
|
+
its(:beginning_of_fortnight){ should eq Time.zone.parse('2014-01-15') }
|
27
|
+
its(:end_of_fortnight){ should eq Time.zone.parse('2014-01-28').end_of_day }
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'middle of year' do
|
31
|
-
subject { Time.parse '2014-06-13' }
|
32
|
-
its(:beginning_of_fortnight){ should eq Time.parse('2014-06-04') }
|
33
|
-
its(:end_of_fortnight){ should eq Time.parse('2014-06-17').end_of_day }
|
31
|
+
subject { Time.zone.parse '2014-06-13' }
|
32
|
+
its(:beginning_of_fortnight){ should eq Time.zone.parse('2014-06-04') }
|
33
|
+
its(:end_of_fortnight){ should eq Time.zone.parse('2014-06-17').end_of_day }
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'last day of year' do
|
37
|
-
subject { Time.parse '2014-12-31' }
|
38
|
-
its(:beginning_of_fortnight){ should eq Time.parse('2014-12-31') }
|
39
|
-
its(:end_of_fortnight){ should eq Time.parse('2015-01-13').end_of_day }
|
37
|
+
subject { Time.zone.parse '2014-12-31' }
|
38
|
+
its(:beginning_of_fortnight){ should eq Time.zone.parse('2014-12-31') }
|
39
|
+
its(:end_of_fortnight){ should eq Time.zone.parse('2015-01-13').end_of_day }
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
describe 'calendar_month' do
|
44
44
|
|
45
|
-
subject { Time.parse '2014-01-01' }
|
45
|
+
subject { Time.zone.parse '2014-01-01' }
|
46
46
|
|
47
47
|
context 'week begins Monday' do
|
48
|
-
its(:beginning_of_calendar_month){ should eq Time.parse('2013-12-30') }
|
49
|
-
its(:end_of_calendar_month){ should eq Time.parse('2014-02-02').end_of_day }
|
48
|
+
its(:beginning_of_calendar_month){ should eq Time.zone.parse('2013-12-30') }
|
49
|
+
its(:end_of_calendar_month){ should eq Time.zone.parse('2014-02-02').end_of_day }
|
50
50
|
end
|
51
51
|
|
52
52
|
context 'week begins Sunday' do
|
53
|
-
it { subject.beginning_of_calendar_month(:sunday).should eq Time.parse('2013-12-29') }
|
54
|
-
it { subject.end_of_calendar_month(:sunday).should eq Time.parse('2014-02-01').end_of_day }
|
53
|
+
it { subject.beginning_of_calendar_month(:sunday).should eq Time.zone.parse('2013-12-29') }
|
54
|
+
it { subject.end_of_calendar_month(:sunday).should eq Time.zone.parse('2014-02-01').end_of_day }
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: by_star
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.0
|
5
|
-
prerelease: 6
|
4
|
+
version: 2.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ryan Bigg
|
@@ -10,12 +9,11 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2014-01
|
12
|
+
date: 2014-04-01 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: activesupport
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
18
|
- - ! '>='
|
21
19
|
- !ruby/object:Gem::Version
|
@@ -23,7 +21,6 @@ dependencies:
|
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
25
|
- - ! '>='
|
29
26
|
- !ruby/object:Gem::Version
|
@@ -31,7 +28,6 @@ dependencies:
|
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
29
|
name: chronic
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
32
|
- - ! '>='
|
37
33
|
- !ruby/object:Gem::Version
|
@@ -39,7 +35,6 @@ dependencies:
|
|
39
35
|
type: :development
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
39
|
- - ! '>='
|
45
40
|
- !ruby/object:Gem::Version
|
@@ -47,7 +42,6 @@ dependencies:
|
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
43
|
name: bundler
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
45
|
requirements:
|
52
46
|
- - ! '>='
|
53
47
|
- !ruby/object:Gem::Version
|
@@ -55,7 +49,6 @@ dependencies:
|
|
55
49
|
type: :development
|
56
50
|
prerelease: false
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
52
|
requirements:
|
60
53
|
- - ! '>='
|
61
54
|
- !ruby/object:Gem::Version
|
@@ -63,7 +56,6 @@ dependencies:
|
|
63
56
|
- !ruby/object:Gem::Dependency
|
64
57
|
name: sqlite3
|
65
58
|
requirement: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
59
|
requirements:
|
68
60
|
- - ! '>='
|
69
61
|
- !ruby/object:Gem::Version
|
@@ -71,7 +63,6 @@ dependencies:
|
|
71
63
|
type: :development
|
72
64
|
prerelease: false
|
73
65
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
66
|
requirements:
|
76
67
|
- - ! '>='
|
77
68
|
- !ruby/object:Gem::Version
|
@@ -79,7 +70,6 @@ dependencies:
|
|
79
70
|
- !ruby/object:Gem::Dependency
|
80
71
|
name: activerecord
|
81
72
|
requirement: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
73
|
requirements:
|
84
74
|
- - ! '>='
|
85
75
|
- !ruby/object:Gem::Version
|
@@ -87,7 +77,6 @@ dependencies:
|
|
87
77
|
type: :development
|
88
78
|
prerelease: false
|
89
79
|
version_requirements: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
80
|
requirements:
|
92
81
|
- - ! '>='
|
93
82
|
- !ruby/object:Gem::Version
|
@@ -95,7 +84,6 @@ dependencies:
|
|
95
84
|
- !ruby/object:Gem::Dependency
|
96
85
|
name: mongoid
|
97
86
|
requirement: !ruby/object:Gem::Requirement
|
98
|
-
none: false
|
99
87
|
requirements:
|
100
88
|
- - ! '>='
|
101
89
|
- !ruby/object:Gem::Version
|
@@ -103,7 +91,6 @@ dependencies:
|
|
103
91
|
type: :development
|
104
92
|
prerelease: false
|
105
93
|
version_requirements: !ruby/object:Gem::Requirement
|
106
|
-
none: false
|
107
94
|
requirements:
|
108
95
|
- - ! '>='
|
109
96
|
- !ruby/object:Gem::Version
|
@@ -111,7 +98,6 @@ dependencies:
|
|
111
98
|
- !ruby/object:Gem::Dependency
|
112
99
|
name: pg
|
113
100
|
requirement: !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
101
|
requirements:
|
116
102
|
- - ! '>='
|
117
103
|
- !ruby/object:Gem::Version
|
@@ -119,7 +105,6 @@ dependencies:
|
|
119
105
|
type: :development
|
120
106
|
prerelease: false
|
121
107
|
version_requirements: !ruby/object:Gem::Requirement
|
122
|
-
none: false
|
123
108
|
requirements:
|
124
109
|
- - ! '>='
|
125
110
|
- !ruby/object:Gem::Version
|
@@ -127,7 +112,6 @@ dependencies:
|
|
127
112
|
- !ruby/object:Gem::Dependency
|
128
113
|
name: mysql2
|
129
114
|
requirement: !ruby/object:Gem::Requirement
|
130
|
-
none: false
|
131
115
|
requirements:
|
132
116
|
- - ! '>='
|
133
117
|
- !ruby/object:Gem::Version
|
@@ -135,7 +119,6 @@ dependencies:
|
|
135
119
|
type: :development
|
136
120
|
prerelease: false
|
137
121
|
version_requirements: !ruby/object:Gem::Requirement
|
138
|
-
none: false
|
139
122
|
requirements:
|
140
123
|
- - ! '>='
|
141
124
|
- !ruby/object:Gem::Version
|
@@ -143,7 +126,6 @@ dependencies:
|
|
143
126
|
- !ruby/object:Gem::Dependency
|
144
127
|
name: rspec-rails
|
145
128
|
requirement: !ruby/object:Gem::Requirement
|
146
|
-
none: false
|
147
129
|
requirements:
|
148
130
|
- - ~>
|
149
131
|
- !ruby/object:Gem::Version
|
@@ -151,7 +133,6 @@ dependencies:
|
|
151
133
|
type: :development
|
152
134
|
prerelease: false
|
153
135
|
version_requirements: !ruby/object:Gem::Requirement
|
154
|
-
none: false
|
155
136
|
requirements:
|
156
137
|
- - ~>
|
157
138
|
- !ruby/object:Gem::Version
|
@@ -159,7 +140,6 @@ dependencies:
|
|
159
140
|
- !ruby/object:Gem::Dependency
|
160
141
|
name: timecop
|
161
142
|
requirement: !ruby/object:Gem::Requirement
|
162
|
-
none: false
|
163
143
|
requirements:
|
164
144
|
- - ~>
|
165
145
|
- !ruby/object:Gem::Version
|
@@ -167,7 +147,6 @@ dependencies:
|
|
167
147
|
type: :development
|
168
148
|
prerelease: false
|
169
149
|
version_requirements: !ruby/object:Gem::Requirement
|
170
|
-
none: false
|
171
150
|
requirements:
|
172
151
|
- - ~>
|
173
152
|
- !ruby/object:Gem::Version
|
@@ -175,7 +154,6 @@ dependencies:
|
|
175
154
|
- !ruby/object:Gem::Dependency
|
176
155
|
name: pry
|
177
156
|
requirement: !ruby/object:Gem::Requirement
|
178
|
-
none: false
|
179
157
|
requirements:
|
180
158
|
- - ! '>='
|
181
159
|
- !ruby/object:Gem::Version
|
@@ -183,7 +161,6 @@ dependencies:
|
|
183
161
|
type: :development
|
184
162
|
prerelease: false
|
185
163
|
version_requirements: !ruby/object:Gem::Requirement
|
186
|
-
none: false
|
187
164
|
requirements:
|
188
165
|
- - ! '>='
|
189
166
|
- !ruby/object:Gem::Version
|
@@ -231,25 +208,30 @@ files:
|
|
231
208
|
- spec/integration/shared/by_weekend.rb
|
232
209
|
- spec/integration/shared/by_year.rb
|
233
210
|
- spec/integration/shared/offset_parameter.rb
|
211
|
+
- spec/integration/shared/relative.rb
|
212
|
+
- spec/integration/shared/scope_parameter.rb
|
234
213
|
- spec/spec_helper.rb
|
235
214
|
- spec/unit/kernel_time_spec.rb
|
236
215
|
- spec/unit/normalization_spec.rb
|
237
216
|
- tmp/.gitignore
|
238
217
|
homepage: http://github.com/radar/by_star
|
239
218
|
licenses: []
|
219
|
+
metadata: {}
|
240
220
|
post_install_message: ! 'Upgrading to ByStar 2.2.0
|
241
221
|
|
242
222
|
-------------------------
|
243
223
|
|
244
224
|
|
245
|
-
*
|
246
|
-
|
225
|
+
* ActiveRecord: the `between` method has been deprecated as of version 2.2.0, and
|
226
|
+
will be removed in version 3.3.0.
|
247
227
|
|
248
|
-
|
249
|
-
a native `.between`
|
228
|
+
Please use `between_times` instead.
|
250
229
|
|
251
|
-
|
252
|
-
|
230
|
+
|
231
|
+
* Mongoid: the `between` method has been removed as of version 2.2.0, as it conflicts
|
232
|
+
with the native Mongoid `between`
|
233
|
+
|
234
|
+
method. Please use `between_times` instead.
|
253
235
|
|
254
236
|
|
255
237
|
* Chronic gem (used for time string parsing) has been removed as a hard dependency
|
@@ -265,22 +247,20 @@ rdoc_options: []
|
|
265
247
|
require_paths:
|
266
248
|
- lib
|
267
249
|
required_ruby_version: !ruby/object:Gem::Requirement
|
268
|
-
none: false
|
269
250
|
requirements:
|
270
251
|
- - ! '>='
|
271
252
|
- !ruby/object:Gem::Version
|
272
253
|
version: '0'
|
273
254
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
274
|
-
none: false
|
275
255
|
requirements:
|
276
|
-
- - ! '
|
256
|
+
- - ! '>='
|
277
257
|
- !ruby/object:Gem::Version
|
278
|
-
version:
|
258
|
+
version: '0'
|
279
259
|
requirements: []
|
280
260
|
rubyforge_project:
|
281
|
-
rubygems_version:
|
261
|
+
rubygems_version: 2.2.1
|
282
262
|
signing_key:
|
283
|
-
specification_version:
|
263
|
+
specification_version: 4
|
284
264
|
summary: ActiveRecord and Mongoid extension for easier date scopes and time ranges
|
285
265
|
test_files:
|
286
266
|
- spec/database.yml
|
@@ -300,6 +280,9 @@ test_files:
|
|
300
280
|
- spec/integration/shared/by_weekend.rb
|
301
281
|
- spec/integration/shared/by_year.rb
|
302
282
|
- spec/integration/shared/offset_parameter.rb
|
283
|
+
- spec/integration/shared/relative.rb
|
284
|
+
- spec/integration/shared/scope_parameter.rb
|
303
285
|
- spec/spec_helper.rb
|
304
286
|
- spec/unit/kernel_time_spec.rb
|
305
287
|
- spec/unit/normalization_spec.rb
|
288
|
+
has_rdoc:
|