by_star 3.0.0 → 4.0.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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/mysql.yml +92 -0
  3. data/.github/workflows/postgresql.yml +99 -0
  4. data/.gitignore +1 -0
  5. data/.travis.yml +67 -36
  6. data/CHANGELOG.md +15 -0
  7. data/README.md +172 -133
  8. data/UPGRADING +1 -3
  9. data/by_star.gemspec +2 -2
  10. data/lib/by_star/base.rb +16 -15
  11. data/lib/by_star/between.rb +81 -52
  12. data/lib/by_star/directional.rb +2 -4
  13. data/lib/by_star/kernel/date.rb +0 -9
  14. data/lib/by_star/kernel/in_time_zone.rb +20 -0
  15. data/lib/by_star/normalization.rb +52 -23
  16. data/lib/by_star/orm/active_record/by_star.rb +20 -6
  17. data/lib/by_star/orm/mongoid/by_star.rb +20 -6
  18. data/lib/by_star/version.rb +1 -1
  19. data/lib/by_star.rb +1 -0
  20. data/spec/database.yml +1 -1
  21. data/spec/fixtures/active_record/models.rb +2 -2
  22. data/spec/fixtures/mongoid/models.rb +1 -1
  23. data/spec/fixtures/shared/seeds.rb +10 -0
  24. data/spec/gemfiles/Gemfile.rails +5 -0
  25. data/spec/gemfiles/Gemfile.rails32 +7 -0
  26. data/spec/gemfiles/Gemfile.rails40 +1 -1
  27. data/spec/gemfiles/Gemfile.rails41 +1 -1
  28. data/spec/gemfiles/Gemfile.rails42 +2 -2
  29. data/spec/gemfiles/Gemfile.rails50 +1 -4
  30. data/spec/gemfiles/Gemfile.rails51 +1 -4
  31. data/spec/gemfiles/Gemfile.rails52 +7 -0
  32. data/spec/gemfiles/Gemfile.rails60 +7 -0
  33. data/spec/gemfiles/Gemfile.rails61 +7 -0
  34. data/spec/integration/active_record/active_record_spec.rb +6 -3
  35. data/spec/integration/mongoid/mongoid_spec.rb +3 -1
  36. data/spec/integration/shared/at_time.rb +53 -0
  37. data/spec/integration/shared/between_dates.rb +99 -0
  38. data/spec/integration/shared/between_times.rb +27 -10
  39. data/spec/integration/shared/by_day.rb +24 -0
  40. data/spec/integration/shared/by_direction.rb +11 -57
  41. data/spec/integration/shared/index_scope_parameter.rb +111 -0
  42. data/spec/spec_helper.rb +4 -0
  43. data/spec/unit/kernel_date_spec.rb +6 -6
  44. data/spec/unit/normalization_spec.rb +128 -49
  45. metadata +33 -21
  46. data/spec/gemfiles/Gemfile.master +0 -6
  47. data/spec/integration/shared/scope_parameter.rb +0 -73
@@ -4,7 +4,66 @@ describe ByStar::Normalization do
4
4
 
5
5
  let(:options){ {} }
6
6
 
7
- shared_examples_for 'time normalization from string' do
7
+ shared_examples_for 'date normalization from string' do
8
+
9
+ context 'when Chronic is defined' do
10
+
11
+ context 'date String' do
12
+ let(:input){ '2014-01-01' }
13
+ it { should eq Date.parse('2014-01-01') }
14
+ end
15
+
16
+ context 'time String' do
17
+ let(:input){ '2014-01-01 15:00:00' }
18
+ it { should eq Date.parse('2014-01-01') }
19
+ end
20
+
21
+ context 'natural language String' do
22
+ let(:input){ 'tomorrow at 3:30 pm' }
23
+ it { should eq Date.parse('2014-01-02') }
24
+ end
25
+ end
26
+
27
+ context 'when Chronic is not defined' do
28
+
29
+ before { hide_const('Chronic') }
30
+
31
+ context 'date String' do
32
+ let(:input){ '2014-01-01' }
33
+ it { should eq Date.parse('2014-01-01') }
34
+ end
35
+
36
+ context 'time String' do
37
+ let(:input){ '2014-01-01 15:00:00' }
38
+ it { should eq Date.parse('2014-01-01') }
39
+ end
40
+
41
+ context 'natural language String' do
42
+ let(:input){ 'tomorrow at noon' }
43
+ it { expect{ subject }.to raise_error(ByStar::ParseError, "Cannot parse String #{input.inspect}") }
44
+ end
45
+ end
46
+ end
47
+
48
+ shared_examples_for 'date normalization from time value' do
49
+ context 'Date' do
50
+ let(:input){ Date.parse('2014-01-01') }
51
+ it { expect eq Date.parse('2014-01-01') }
52
+ end
53
+
54
+ context 'DateTime' do
55
+ let(:input){ Date.parse('2014-01-01').to_datetime }
56
+ it { expect eq Date.parse('2014-01-01') }
57
+ end
58
+
59
+ context 'Time' do
60
+ let(:input){ Date.parse('2014-01-01') }
61
+ it { expect eq Date.parse('2014-01-01') }
62
+ end
63
+ end
64
+
65
+ describe '#time' do
66
+ subject { ByStar::Normalization.time(input) }
8
67
 
9
68
  context 'when Chronic is defined' do
10
69
 
@@ -43,9 +102,7 @@ describe ByStar::Normalization do
43
102
  it { expect{ subject }.to raise_error(ByStar::ParseError, "Cannot parse String #{input.inspect}") }
44
103
  end
45
104
  end
46
- end
47
105
 
48
- shared_examples_for 'time normalization from date/time' do
49
106
  context 'Date' do
50
107
  let(:input){ Date.parse('2014-01-01') }
51
108
  it { expect eq Time.zone.parse('2014-01-01 00:00:00') }
@@ -62,16 +119,10 @@ describe ByStar::Normalization do
62
119
  end
63
120
  end
64
121
 
65
- describe '#time' do
66
- subject { ByStar::Normalization.time(input) }
67
- it_behaves_like 'time normalization from string'
68
- it_behaves_like 'time normalization from date/time'
69
- end
70
-
71
122
  describe '#week' do
72
123
  subject { ByStar::Normalization.week(input, options) }
73
- it_behaves_like 'time normalization from string'
74
- it_behaves_like 'time normalization from date/time'
124
+ it_behaves_like 'date normalization from string'
125
+ it_behaves_like 'date normalization from time value'
75
126
 
76
127
  context 'Integer -1' do
77
128
  let(:input){ -1 }
@@ -80,12 +131,12 @@ describe ByStar::Normalization do
80
131
 
81
132
  context 'Integer 0' do
82
133
  let(:input){ 0 }
83
- it { expect eq Time.zone.parse('2014-01-01 00:00:00') }
134
+ it { expect eq Date.parse('2014-01-01') }
84
135
  end
85
136
 
86
137
  context 'Integer 20' do
87
138
  let(:input){ 20 }
88
- it { expect eq Time.zone.parse('2014-05-21 00:00:00') }
139
+ it { expect eq Date.parse('2014-05-21') }
89
140
  end
90
141
 
91
142
  context 'Integer 53' do
@@ -98,20 +149,20 @@ describe ByStar::Normalization do
98
149
 
99
150
  context 'Integer 0' do
100
151
  let(:input){ 0 }
101
- it { expect eq Time.zone.parse('2011-01-01 00:00:00') }
152
+ it { expect eq Date.parse('2011-01-01') }
102
153
  end
103
154
 
104
155
  context 'Integer 20' do
105
156
  let(:input){ 20 }
106
- it { expect eq Time.zone.parse('2011-05-21 00:00:00') }
157
+ it { expect eq Date.parse('2011-05-21') }
107
158
  end
108
159
  end
109
160
  end
110
161
 
111
162
  describe '#cweek' do
112
163
  subject { ByStar::Normalization.cweek(input, options) }
113
- it_behaves_like 'time normalization from string'
114
- it_behaves_like 'time normalization from date/time'
164
+ it_behaves_like 'date normalization from string'
165
+ it_behaves_like 'date normalization from time value'
115
166
 
116
167
  context 'Integer 9' do
117
168
  let(:input){ 0 }
@@ -120,12 +171,12 @@ describe ByStar::Normalization do
120
171
 
121
172
  context 'Integer 1' do
122
173
  let(:input){ 1 }
123
- it { expect eq Time.zone.parse('2014-01-01 00:00:00') }
174
+ it { expect eq Date.parse('2014-01-01') }
124
175
  end
125
176
 
126
177
  context 'Integer 21' do
127
178
  let(:input){ 21 }
128
- it { expect eq Time.zone.parse('2014-05-21 00:00:00') }
179
+ it { expect eq Date.parse('2014-05-21') }
129
180
  end
130
181
 
131
182
  context 'Integer 54' do
@@ -138,29 +189,29 @@ describe ByStar::Normalization do
138
189
 
139
190
  context 'Integer 1' do
140
191
  let(:input){ 1 }
141
- it { expect eq Time.zone.parse('2011-01-01 00:00:00') }
192
+ it { expect eq Date.parse('2011-01-01') }
142
193
  end
143
194
 
144
195
  context 'Integer 21' do
145
196
  let(:input){ 21 }
146
- it { expect eq Time.zone.parse('2011-05-21 00:00:00') }
197
+ it { expect eq Date.parse('2011-05-21') }
147
198
  end
148
199
  end
149
200
  end
150
201
 
151
202
  describe '#fortnight' do
152
203
  subject { ByStar::Normalization.fortnight(input, options) }
153
- it_behaves_like 'time normalization from string'
154
- it_behaves_like 'time normalization from date/time'
204
+ it_behaves_like 'date normalization from string'
205
+ it_behaves_like 'date normalization from time value'
155
206
 
156
207
  context 'Integer 0' do
157
208
  let(:input){ 0 }
158
- it { expect eq Time.zone.parse('2014-01-01 00:00:00') }
209
+ it { expect eq Date.parse('2014-01-01') }
159
210
  end
160
211
 
161
212
  context 'Integer 26' do
162
213
  let(:input){ 26 }
163
- it { expect eq Time.zone.parse('2014-12-31 00:00:00') }
214
+ it { expect eq Date.parse('2014-12-31') }
164
215
  end
165
216
 
166
217
  context 'out of range' do
@@ -173,38 +224,38 @@ describe ByStar::Normalization do
173
224
 
174
225
  context 'Integer 0' do
175
226
  let(:input){ 0 }
176
- it { expect eq Time.zone.parse('2011-01-01 00:00:00') }
227
+ it { expect eq Date.parse('2011-01-01') }
177
228
  end
178
229
 
179
230
  context 'Integer 26' do
180
231
  let(:input){ 26 }
181
- it { expect eq Time.zone.parse('2011-12-31 00:00:00') }
232
+ it { expect eq Date.parse('2011-12-31') }
182
233
  end
183
234
  end
184
235
  end
185
236
 
186
237
  describe '#month' do
187
238
  subject { ByStar::Normalization.month(input, options) }
188
- it_behaves_like 'time normalization from date/time'
239
+ it_behaves_like 'date normalization from time value'
189
240
 
190
241
  context 'month abbr String' do
191
242
  let(:input){ 'Feb' }
192
- it { expect eq Time.zone.parse('2014-02-01 00:00:00') }
243
+ it { expect eq Date.parse('2014-02-01') }
193
244
  end
194
245
 
195
246
  context 'month full String' do
196
247
  let(:input){ 'February' }
197
- it { expect eq Time.zone.parse('2014-02-01 00:00:00') }
248
+ it { expect eq Date.parse('2014-02-01') }
198
249
  end
199
250
 
200
251
  context 'number String' do
201
252
  let(:input){ '2' }
202
- it { expect eq Time.zone.parse('2014-02-01 00:00:00') }
253
+ it { expect eq Date.parse('2014-02-01') }
203
254
  end
204
255
 
205
256
  context 'Integer' do
206
257
  let(:input){ 2 }
207
- it { expect eq Time.zone.parse('2014-02-01 00:00:00') }
258
+ it { expect eq Date.parse('2014-02-01') }
208
259
  end
209
260
 
210
261
  context 'out of range' do
@@ -217,39 +268,39 @@ describe ByStar::Normalization do
217
268
 
218
269
  context 'month abbr String' do
219
270
  let(:input){ 'Dec' }
220
- it { expect eq Time.zone.parse('2011-12-01 00:00:00') }
271
+ it { expect eq Date.parse('2011-12-01') }
221
272
  end
222
273
 
223
274
  context 'Integer 12' do
224
275
  let(:input){ 10 }
225
- it { expect eq Time.zone.parse('2011-10-01 00:00:00') }
276
+ it { expect eq Date.parse('2011-10-01') }
226
277
  end
227
278
  end
228
279
  end
229
280
 
230
281
  describe '#quarter' do
231
282
  subject { ByStar::Normalization.quarter(input, options) }
232
- it_behaves_like 'time normalization from string'
233
- it_behaves_like 'time normalization from date/time'
283
+ it_behaves_like 'date normalization from string'
284
+ it_behaves_like 'date normalization from time value'
234
285
 
235
286
  context 'Integer 1' do
236
287
  let(:input){ 1 }
237
- it { expect eq Time.zone.parse('2014-01-01 00:00:00') }
288
+ it { expect eq Date.parse('2014-01-01') }
238
289
  end
239
290
 
240
291
  context 'Integer 2' do
241
292
  let(:input){ 2 }
242
- it { expect eq Time.zone.parse('2014-04-01 00:00:00') }
293
+ it { expect eq Date.parse('2014-04-01') }
243
294
  end
244
295
 
245
296
  context 'Integer 3' do
246
297
  let(:input){ 3 }
247
- it { expect eq Time.zone.parse('2014-07-01 00:00:00') }
298
+ it { expect eq Date.parse('2014-07-01') }
248
299
  end
249
300
 
250
301
  context 'Integer 4' do
251
302
  let(:input){ 4 }
252
- it { expect eq Time.zone.parse('2014-10-01 00:00:00') }
303
+ it { expect eq Date.parse('2014-10-01') }
253
304
  end
254
305
 
255
306
  context 'with year option' do
@@ -257,7 +308,7 @@ describe ByStar::Normalization do
257
308
 
258
309
  context 'Integer 3' do
259
310
  let(:input){ 3 }
260
- it { expect eq Time.zone.parse('2011-07-01 00:00:00') }
311
+ it { expect eq Date.parse('2011-07-01') }
261
312
  end
262
313
  end
263
314
 
@@ -269,37 +320,65 @@ describe ByStar::Normalization do
269
320
 
270
321
  describe '#year' do
271
322
  subject { ByStar::Normalization.year(input, options) }
272
- it_behaves_like 'time normalization from string'
273
- it_behaves_like 'time normalization from date/time'
323
+ it_behaves_like 'date normalization from string'
324
+ it_behaves_like 'date normalization from time value'
274
325
 
275
326
  context 'Integer 69' do
276
327
  let(:input){ 69 }
277
- it { expect eq Time.zone.parse('2069-01-01 00:00:00') }
328
+ it { expect eq Date.parse('2069-01-01') }
278
329
  end
279
330
 
280
331
  context 'Integer 99' do
281
332
  let(:input){ 99 }
282
- it { expect eq Time.zone.parse('1999-01-01 00:00:00') }
333
+ it { expect eq Date.parse('1999-01-01') }
283
334
  end
284
335
 
285
336
  context 'Integer 2001' do
286
337
  let(:input){ 1 }
287
- it { expect eq Time.zone.parse('2001-01-01 00:00:00') }
338
+ it { expect eq Date.parse('2001-01-01') }
288
339
  end
289
340
 
290
341
  context 'String 01' do
291
342
  let(:input){ '01' }
292
- it { expect eq Time.zone.parse('2001-01-01 00:00:00') }
343
+ it { expect eq Date.parse('2001-01-01') }
293
344
  end
294
345
 
295
346
  context 'String 70' do
296
347
  let(:input){ '70' }
297
- it { expect eq Time.zone.parse('1970-01-01 00:00:00') }
348
+ it { expect eq Date.parse('1970-01-01') }
298
349
  end
299
350
 
300
351
  context 'String 2001' do
301
352
  let(:input){ '2001' }
302
- it { expect eq Time.zone.parse('2001-01-01 00:00:00') }
353
+ it { expect eq Date.parse('2001-01-01') }
303
354
  end
304
355
  end
356
+
357
+ describe '#time_in_units' do
358
+ subject { ByStar::Normalization.time_in_units(input) }
359
+
360
+ context 'when less than a day' do
361
+ let(:input) { 34876 }
362
+ it { is_expected.to eq(days: 0, hour: 9, min: 41, sec: 16) }
363
+ end
364
+
365
+ context 'when more than a day' do
366
+ let(:input) { 97532 }
367
+ it { is_expected.to eq(days: 1, hour: 3, min: 5, sec: 32) }
368
+ end
369
+ end
370
+
371
+ describe '#apply_offset_start' do
372
+ subject { ByStar::Normalization.apply_offset_start(input, offset) }
373
+ let(:input) { Time.zone.parse('2020-04-05 00:00:00') }
374
+ let(:offset) { 5.hours }
375
+ it { is_expected.to eq Time.zone.parse('2020-04-05 05:00:00') }
376
+ end
377
+
378
+ describe '#apply_offset_end' do
379
+ subject { ByStar::Normalization.apply_offset_end(input, offset) }
380
+ let(:input) { Time.zone.parse('2020-10-04 00:00:00') }
381
+ let(:offset) { 5.hours }
382
+ it { is_expected.to eq Time.zone.parse('2020-10-05 04:59:59') }
383
+ end
305
384
  end
metadata CHANGED
@@ -1,30 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: by_star
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
8
8
  - Johnny Shields
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-02-01 00:00:00.000000000 Z
12
+ date: 2022-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '3'
20
+ version: 3.2.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '3'
27
+ version: 3.2.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: chronic
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -113,16 +113,16 @@ dependencies:
113
113
  name: mysql2
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - "~>"
116
+ - - ">="
117
117
  - !ruby/object:Gem::Version
118
- version: 0.3.10
118
+ version: '0'
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - "~>"
123
+ - - ">="
124
124
  - !ruby/object:Gem::Version
125
- version: 0.3.10
125
+ version: '0'
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: rspec-rails
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -172,6 +172,8 @@ executables: []
172
172
  extensions: []
173
173
  extra_rdoc_files: []
174
174
  files:
175
+ - ".github/workflows/mysql.yml"
176
+ - ".github/workflows/postgresql.yml"
175
177
  - ".gitignore"
176
178
  - ".travis.yml"
177
179
  - CHANGELOG.md
@@ -187,6 +189,7 @@ files:
187
189
  - lib/by_star/between.rb
188
190
  - lib/by_star/directional.rb
189
191
  - lib/by_star/kernel/date.rb
192
+ - lib/by_star/kernel/in_time_zone.rb
190
193
  - lib/by_star/kernel/time.rb
191
194
  - lib/by_star/normalization.rb
192
195
  - lib/by_star/orm/active_record/by_star.rb
@@ -198,14 +201,20 @@ files:
198
201
  - spec/fixtures/active_record/schema.rb
199
202
  - spec/fixtures/mongoid/models.rb
200
203
  - spec/fixtures/shared/seeds.rb
201
- - spec/gemfiles/Gemfile.master
204
+ - spec/gemfiles/Gemfile.rails
205
+ - spec/gemfiles/Gemfile.rails32
202
206
  - spec/gemfiles/Gemfile.rails40
203
207
  - spec/gemfiles/Gemfile.rails41
204
208
  - spec/gemfiles/Gemfile.rails42
205
209
  - spec/gemfiles/Gemfile.rails50
206
210
  - spec/gemfiles/Gemfile.rails51
211
+ - spec/gemfiles/Gemfile.rails52
212
+ - spec/gemfiles/Gemfile.rails60
213
+ - spec/gemfiles/Gemfile.rails61
207
214
  - spec/integration/active_record/active_record_spec.rb
208
215
  - spec/integration/mongoid/mongoid_spec.rb
216
+ - spec/integration/shared/at_time.rb
217
+ - spec/integration/shared/between_dates.rb
209
218
  - spec/integration/shared/between_times.rb
210
219
  - spec/integration/shared/by_calendar_month.rb
211
220
  - spec/integration/shared/by_cweek.rb
@@ -217,10 +226,10 @@ files:
217
226
  - spec/integration/shared/by_week.rb
218
227
  - spec/integration/shared/by_weekend.rb
219
228
  - spec/integration/shared/by_year.rb
229
+ - spec/integration/shared/index_scope_parameter.rb
220
230
  - spec/integration/shared/offset_parameter.rb
221
231
  - spec/integration/shared/order_parameter.rb
222
232
  - spec/integration/shared/relative.rb
223
- - spec/integration/shared/scope_parameter.rb
224
233
  - spec/spec_helper.rb
225
234
  - spec/unit/kernel_date_spec.rb
226
235
  - spec/unit/kernel_time_spec.rb
@@ -233,9 +242,7 @@ post_install_message: |
233
242
  Upgrading ByStar
234
243
  ----------------
235
244
 
236
- * Chronic gem (used for time string parsing) has been removed as a hard dependency for ByStar,
237
- however it is still supported. If you would like to use Chronic with ByStar, please explicitly
238
- include `gem chronic` into your Gemfile.
245
+ * As of version 4.0.0, ByStar changes the way it handles `Date` arg to the `#between_times` method. If a `Date` is given as the second (end) arg, the query will use `Date.end_of_day` to include all time values which fall inside that date.
239
246
  rdoc_options: []
240
247
  require_paths:
241
248
  - lib
@@ -250,9 +257,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
257
  - !ruby/object:Gem::Version
251
258
  version: '0'
252
259
  requirements: []
253
- rubyforge_project:
254
- rubygems_version: 2.7.4
255
- signing_key:
260
+ rubygems_version: 3.1.6
261
+ signing_key:
256
262
  specification_version: 4
257
263
  summary: ActiveRecord and Mongoid extension for easier date scopes and time ranges
258
264
  test_files:
@@ -261,14 +267,20 @@ test_files:
261
267
  - spec/fixtures/active_record/schema.rb
262
268
  - spec/fixtures/mongoid/models.rb
263
269
  - spec/fixtures/shared/seeds.rb
264
- - spec/gemfiles/Gemfile.master
270
+ - spec/gemfiles/Gemfile.rails
271
+ - spec/gemfiles/Gemfile.rails32
265
272
  - spec/gemfiles/Gemfile.rails40
266
273
  - spec/gemfiles/Gemfile.rails41
267
274
  - spec/gemfiles/Gemfile.rails42
268
275
  - spec/gemfiles/Gemfile.rails50
269
276
  - spec/gemfiles/Gemfile.rails51
277
+ - spec/gemfiles/Gemfile.rails52
278
+ - spec/gemfiles/Gemfile.rails60
279
+ - spec/gemfiles/Gemfile.rails61
270
280
  - spec/integration/active_record/active_record_spec.rb
271
281
  - spec/integration/mongoid/mongoid_spec.rb
282
+ - spec/integration/shared/at_time.rb
283
+ - spec/integration/shared/between_dates.rb
272
284
  - spec/integration/shared/between_times.rb
273
285
  - spec/integration/shared/by_calendar_month.rb
274
286
  - spec/integration/shared/by_cweek.rb
@@ -280,10 +292,10 @@ test_files:
280
292
  - spec/integration/shared/by_week.rb
281
293
  - spec/integration/shared/by_weekend.rb
282
294
  - spec/integration/shared/by_year.rb
295
+ - spec/integration/shared/index_scope_parameter.rb
283
296
  - spec/integration/shared/offset_parameter.rb
284
297
  - spec/integration/shared/order_parameter.rb
285
298
  - spec/integration/shared/relative.rb
286
- - spec/integration/shared/scope_parameter.rb
287
299
  - spec/spec_helper.rb
288
300
  - spec/unit/kernel_date_spec.rb
289
301
  - spec/unit/kernel_time_spec.rb
@@ -1,6 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- gemspec path: '../../'
4
-
5
- gem 'activerecord', github: 'rails'
6
- gem 'mongoid', github: 'mongoid'
@@ -1,73 +0,0 @@
1
- require 'spec_helper'
2
-
3
- shared_examples_for 'scope parameter' do
4
-
5
- describe ':scope' do
6
-
7
- it 'should memoize the scope variable' do
8
- expect(Event.instance_variable_get(:@by_star_scope)).to be_nil
9
- expect(Post.instance_variable_get(:@by_star_scope)).to be_nil
10
- expect(Appointment.instance_variable_get(:@by_star_scope)).to be_a Proc
11
- end
12
-
13
- context 'between_times with default scope' do
14
- subject { Appointment.between_times(Date.parse('2013-12-01'), Date.parse('2014-02-01')) }
15
- it { expect(subject.count).to eql(3) }
16
- end
17
-
18
- context 'between_times with scope override as a query criteria' do
19
- subject { Appointment.between_times(Date.parse('2013-12-01')..Date.parse('2014-02-01'), scope: Appointment.unscoped) }
20
- it { expect(subject.count).to eql(14) }
21
- end
22
-
23
- context 'between_times with scope override as a Lambda' do
24
- subject { Appointment.between_times([Date.parse('2013-12-01'), Date.parse('2014-02-01')], scope: ->{ unscoped }) }
25
- it { expect(subject.count).to eql(14) }
26
- end
27
-
28
- context 'between_times with scope override as a Lambda' do
29
- subject { Appointment.between_times(Date.parse('2013-12-01')..Date.parse('2014-02-01'), scope: ->(x){ unscoped }) }
30
- it{ expect{ subject }.to raise_error(RuntimeError, 'ByStar :scope Proc requires :scope_args to be specified.') }
31
- end
32
-
33
- context 'between_times with scope override as a Proc with arguments' do
34
- subject { Appointment.between_times(Date.parse('2013-12-01'), Date.parse('2014-02-01'), scope: Proc.new{ unscoped }) }
35
- it { expect(subject.count).to eql(14) }
36
- end
37
-
38
- context 'between_times with scope override as a Proc with arguments' do
39
- subject { Appointment.between_times([Date.parse('2013-12-01'), Date.parse('2014-02-01')], scope: Proc.new{|x,y| unscoped }) }
40
- it{ expect{ subject }.to raise_error(RuntimeError, 'ByStar :scope Proc requires :scope_args to be specified.') }
41
- end
42
-
43
- context 'by_month with default scope' do
44
- subject { Appointment.by_month(Date.parse('2014-01-01')) }
45
- it { expect(subject.count).to eql(2) }
46
- end
47
-
48
- context 'by_month with scope override as a query criteria' do
49
- subject { Appointment.by_month(Date.parse('2014-01-01'), scope: Appointment.unscoped) }
50
- it { expect(subject.count).to eql(6) }
51
- end
52
-
53
- context 'by_month with scope override as a Lambda' do
54
- subject { Appointment.by_month(Date.parse('2014-01-01'), scope: ->{ unscoped }) }
55
- it { expect(subject.count).to eql(6) }
56
- end
57
-
58
- context 'by_month with scope override as a Lambda with arguments' do
59
- subject { Appointment.by_month(Date.parse('2014-01-01'), scope: ->(x){ unscoped }) }
60
- it{ expect{ subject }.to raise_error(RuntimeError, 'ByStar :scope Proc requires :scope_args to be specified.') }
61
- end
62
-
63
- context 'by_month with scope override as a Proc' do
64
- subject { Appointment.by_month(Date.parse('2014-01-01'), scope: Proc.new{ unscoped }) }
65
- it { expect(subject.count).to eql(6) }
66
- end
67
-
68
- context 'by_month with scope override as a Proc with arguments' do
69
- subject { Appointment.by_month(Date.parse('2014-01-01'), scope: Proc.new{|x| unscoped }) }
70
- it{ expect{ subject }.to raise_error(RuntimeError, 'ByStar :scope Proc requires :scope_args to be specified.') }
71
- end
72
- end
73
- end