include_date_scopes 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -51
- data/include_date_scopes.gemspec +1 -1
- data/lib/include_date_scopes/date_scopes.rb +14 -203
- data/lib/include_date_scopes/define_common_scopes.rb +45 -0
- data/lib/include_date_scopes/define_date_scopes.rb +31 -0
- data/lib/include_date_scopes/define_timestamp_scopes.rb +92 -0
- data/lib/include_date_scopes/version.rb +1 -1
- data/spec/lib/date_scopes_spec.rb +14 -0
- data/spec/support/date_scope_examples.rb +197 -131
- data/spec/support/timestamp_scope_examples.rb +250 -321
- metadata +6 -3
@@ -1,421 +1,350 @@
|
|
1
1
|
|
2
|
+
shared_examples "between time scope" do |name, difference = 1.second|
|
3
|
+
subject do
|
4
|
+
test_class.send "#{prefix}#{name}", *arguments
|
5
|
+
end
|
6
|
+
|
7
|
+
let(:after_threshold_obj) { test_class.create! date_column => top_threshold - difference }
|
8
|
+
let(:at_top_threshold_obj) { test_class.create! date_column => top_threshold }
|
9
|
+
let(:at_bottom_threshold_obj) { test_class.create! date_column => bottom_threshold }
|
10
|
+
let(:before_threshold_obj) { test_class.create! date_column => bottom_threshold + difference }
|
11
|
+
|
12
|
+
it { should_not include after_threshold_obj }
|
13
|
+
it { should include at_top_threshold_obj }
|
14
|
+
it { should include at_bottom_threshold_obj }
|
15
|
+
it { should_not include before_threshold_obj }
|
16
|
+
end
|
17
|
+
|
18
|
+
shared_examples "open ended time scope (exclusive)" do |name|
|
19
|
+
subject { test_class.send("#{prefix}#{name}", *arguments) }
|
20
|
+
|
21
|
+
let(:after_threshold_obj) { test_class.create! date_column => threshold + 1.second }
|
22
|
+
let(:on_threshold_obj) { test_class.create! date_column => threshold }
|
23
|
+
let(:before_threshold_obj) { test_class.create! date_column => threshold - 1.second }
|
24
|
+
|
25
|
+
it { should include after_threshold_obj }
|
26
|
+
it { should_not include on_threshold_obj }
|
27
|
+
it { should_not include before_threshold_obj }
|
28
|
+
end
|
29
|
+
|
2
30
|
shared_examples "timestamp scopes" do |date_column = :created_at, prefix = '' |
|
3
31
|
let(:test_class) { Post }
|
32
|
+
let(:prefix) { prefix }
|
33
|
+
let(:date_column) { date_column }
|
34
|
+
|
4
35
|
describe "timestamp scopes" do
|
5
36
|
before(:all) { Timecop.freeze Time.local(2013,02,15,06,30) }
|
6
37
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
let(:next_week_obj) { test_class.create! date_column => 1.week.from_now }
|
13
|
-
let(:yesterday_obj) { test_class.create! date_column => 24.hours.ago }
|
14
|
-
let(:hour_ago_obj) { test_class.create! date_column => 1.hour.ago }
|
15
|
-
let(:five_minute_ago_obj) { test_class.create! date_column => 5.minutes.ago }
|
16
|
-
let(:after_midnight_ago_obj) { test_class.create! date_column => Date.today.beginning_of_day + 5.minutes }
|
17
|
-
let(:before_midnight_ago_obj) { test_class.create! date_column => Date.today.beginning_of_day - 5.minutes }
|
18
|
-
let(:tomorrow_obj) { test_class.create! date_column => Date.today.end_of_day + 5.minutes }
|
19
|
-
|
20
|
-
describe ":between" do
|
21
|
-
context "with DateTime" do
|
22
|
-
subject { test_class.send("#{prefix}between", 2.hours.ago, 1.minute.ago) }
|
23
|
-
|
24
|
-
it { should_not include last_week_obj }
|
25
|
-
it { should_not include yesterday_obj }
|
26
|
-
it { should include hour_ago_obj }
|
27
|
-
it { should include five_minute_ago_obj }
|
28
|
-
end
|
29
|
-
context "with Date" do
|
30
|
-
subject { test_class.send("#{prefix}between", 2.days.ago.to_date, Date.today) }
|
31
|
-
|
32
|
-
it { should_not include last_week_obj }
|
33
|
-
it { should include yesterday_obj }
|
34
|
-
it { should include hour_ago_obj }
|
35
|
-
it { should include five_minute_ago_obj }
|
36
|
-
end
|
38
|
+
describe ':between' do
|
39
|
+
let(:top_threshold) { 5.minutes.ago }
|
40
|
+
let(:bottom_threshold) { 5.minutes.from_now }
|
41
|
+
let(:arguments) { [5.minutes.ago, 5.minutes.from_now] }
|
42
|
+
include_examples "between time scope", 'between'
|
37
43
|
end
|
38
44
|
|
39
45
|
describe ":after" do
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
it { should_not include last_week_obj }
|
44
|
-
it { should_not include yesterday_obj }
|
45
|
-
it { should include hour_ago_obj }
|
46
|
-
it { should include five_minute_ago_obj }
|
47
|
-
end
|
48
|
-
context "with Date" do
|
49
|
-
subject { test_class.send("#{prefix}after", 2.days.ago.to_date) }
|
46
|
+
let(:threshold) { 5.minutes.ago }
|
47
|
+
let(:arguments) { [ 5.minutes.ago ] }
|
50
48
|
|
51
|
-
|
52
|
-
it { should include yesterday_obj }
|
53
|
-
it { should include hour_ago_obj }
|
54
|
-
it { should include five_minute_ago_obj }
|
55
|
-
end
|
49
|
+
include_examples 'open ended time scope (exclusive)', 'after'
|
56
50
|
end
|
57
51
|
|
58
|
-
describe
|
59
|
-
|
52
|
+
describe ":before" do
|
53
|
+
|
54
|
+
subject { test_class.send("#{prefix}before", 5.minutes.ago) }
|
60
55
|
|
61
|
-
|
62
|
-
|
63
|
-
|
56
|
+
let(:after_threshold_obj) { test_class.create! date_column => 5.minutes.ago + 1.second }
|
57
|
+
let(:on_threshold_obj) { test_class.create! date_column => 5.minutes.ago }
|
58
|
+
let(:before_threshold_obj) { test_class.create! date_column => 5.minutes.ago - 1.second }
|
59
|
+
|
60
|
+
it { should_not include after_threshold_obj }
|
61
|
+
it { should_not include on_threshold_obj }
|
62
|
+
it { should include before_threshold_obj }
|
64
63
|
end
|
65
64
|
|
66
|
-
describe ":
|
67
|
-
|
68
|
-
subject { test_class.send("#{prefix}on_or_after_date", 1.hour.ago) }
|
65
|
+
describe ":on_or_after" do
|
66
|
+
subject { test_class.send("#{prefix}on_or_after", 5.minutes.ago) }
|
69
67
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
it { should include five_minute_ago_obj }
|
74
|
-
end
|
75
|
-
context "with Date" do
|
76
|
-
subject { test_class.send("#{prefix}on_or_after_date", 2.days.ago.to_date) }
|
68
|
+
let(:after_threshold_obj) { test_class.create! date_column => 5.minutes.ago + 1.second }
|
69
|
+
let(:on_threshold_obj) { test_class.create! date_column => 5.minutes.ago }
|
70
|
+
let(:before_threshold_obj) { test_class.create! date_column => 5.minutes.ago - 1.second }
|
77
71
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
it { should include five_minute_ago_obj }
|
82
|
-
end
|
72
|
+
it { should include after_threshold_obj }
|
73
|
+
it { should include on_threshold_obj }
|
74
|
+
it { should_not include before_threshold_obj }
|
83
75
|
end
|
84
76
|
|
85
|
-
describe ":
|
86
|
-
|
87
|
-
subject { test_class.send("#{prefix}before", 1.hour.ago) }
|
77
|
+
describe ":on_or_before" do
|
78
|
+
subject { test_class.send("#{prefix}on_or_before", 5.minutes.ago) }
|
88
79
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
it { should_not include five_minute_ago_obj }
|
93
|
-
end
|
94
|
-
context "with Date" do
|
95
|
-
subject { test_class.send("#{prefix}before", Date.today) }
|
80
|
+
let(:after_threshold_obj) { test_class.create! date_column => 5.minutes.ago + 1.second }
|
81
|
+
let(:on_threshold_obj) { test_class.create! date_column => 5.minutes.ago }
|
82
|
+
let(:before_threshold_obj) { test_class.create! date_column => 5.minutes.ago - 1.second }
|
96
83
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
it { should_not include five_minute_ago_obj }
|
101
|
-
end
|
84
|
+
it { should_not include after_threshold_obj }
|
85
|
+
it { should include on_threshold_obj }
|
86
|
+
it { should include before_threshold_obj }
|
102
87
|
end
|
103
88
|
|
104
|
-
describe
|
105
|
-
|
89
|
+
describe ":today" do
|
90
|
+
let(:top_threshold) { Time.now.beginning_of_day }
|
91
|
+
let(:bottom_threshold) { Time.now.end_of_day }
|
92
|
+
let(:arguments) { [] }
|
93
|
+
include_examples 'between time scope','today'
|
94
|
+
end
|
106
95
|
|
107
|
-
|
108
|
-
|
109
|
-
|
96
|
+
describe ":yesterday" do
|
97
|
+
let(:top_threshold) { 1.day.ago.beginning_of_day }
|
98
|
+
let(:bottom_threshold) { 1.day.ago.end_of_day }
|
99
|
+
let(:arguments) { [] }
|
100
|
+
include_examples 'between time scope','yesterday'
|
110
101
|
end
|
111
102
|
|
112
|
-
describe ":
|
113
|
-
|
114
|
-
|
103
|
+
describe ":tomorrow" do
|
104
|
+
let(:top_threshold) { 1.day.from_now.beginning_of_day }
|
105
|
+
let(:bottom_threshold) { 1.day.from_now.end_of_day }
|
106
|
+
let(:arguments) { [] }
|
107
|
+
include_examples 'between time scope','tomorrow'
|
108
|
+
end
|
115
109
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
110
|
+
[:second, :minute, :hour, :day, :week, :month, :year].each do |interval|
|
111
|
+
describe ":next_#{interval}" do
|
112
|
+
let(:bottom_threshold) { 1."#{interval}".from_now }
|
113
|
+
let(:top_threshold) { Time.now }
|
114
|
+
let(:arguments) { [] }
|
115
|
+
include_examples 'between time scope',"next_#{interval}"
|
120
116
|
end
|
121
|
-
|
122
|
-
subject { test_class.send("#{prefix}on_or_before_date", Date.yesterday) }
|
117
|
+
end
|
123
118
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
119
|
+
describe ":next_hour" do
|
120
|
+
let(:bottom_threshold) { 1.hour.from_now }
|
121
|
+
let(:top_threshold) { Time.now }
|
122
|
+
let(:arguments) { [] }
|
123
|
+
include_examples 'between time scope','next_hour'
|
129
124
|
end
|
130
125
|
|
131
|
-
describe
|
132
|
-
|
126
|
+
describe ":next_day" do
|
127
|
+
let(:bottom_threshold) { 1.day.from_now }
|
128
|
+
let(:top_threshold) { Time.now }
|
129
|
+
let(:arguments) { [] }
|
130
|
+
include_examples 'between time scope','next_day'
|
131
|
+
end
|
133
132
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
133
|
+
describe ":next_week" do
|
134
|
+
let(:bottom_threshold) { 1.week.from_now }
|
135
|
+
let(:top_threshold) { Time.now }
|
136
|
+
let(:arguments) { [] }
|
137
|
+
include_examples 'between time scope','next_week'
|
138
138
|
end
|
139
139
|
|
140
|
-
describe ":
|
141
|
-
|
140
|
+
describe ":next_month" do
|
141
|
+
let(:bottom_threshold) { 1.month.from_now }
|
142
|
+
let(:top_threshold) { Time.now }
|
143
|
+
let(:arguments) { [] }
|
144
|
+
include_examples 'between time scope','next_month'
|
145
|
+
end
|
142
146
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
+
describe ":next_year" do
|
148
|
+
let(:bottom_threshold) { 1.year.from_now }
|
149
|
+
let(:top_threshold) { Time.now }
|
150
|
+
let(:arguments) { [] }
|
151
|
+
include_examples 'between time scope','next_year'
|
147
152
|
end
|
148
153
|
|
149
|
-
describe ":
|
150
|
-
|
154
|
+
describe ":last_minute" do
|
155
|
+
let(:top_threshold) { 1.minute.ago }
|
156
|
+
let(:bottom_threshold) { Time.now }
|
157
|
+
let(:arguments) { [] }
|
158
|
+
include_examples 'between time scope','last_minute'
|
159
|
+
end
|
151
160
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
161
|
+
describe ":last_hour" do
|
162
|
+
let(:top_threshold) { 1.hour.ago }
|
163
|
+
let(:bottom_threshold) { Time.now }
|
164
|
+
let(:arguments) { [] }
|
165
|
+
include_examples 'between time scope','last_hour'
|
156
166
|
end
|
157
167
|
|
158
168
|
describe ":last_24_hours" do
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
it { should include hour_ago_obj }
|
164
|
-
it { should include five_minute_ago_obj }
|
169
|
+
let(:top_threshold) { 1.day.ago }
|
170
|
+
let(:bottom_threshold) { Time.now }
|
171
|
+
let(:arguments) { [] }
|
172
|
+
include_examples 'between time scope','last_24_hours'
|
165
173
|
end
|
166
174
|
|
167
|
-
describe ":
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
it { should_not include hour_ago_obj } # should not because this is exclusive
|
173
|
-
it { should include five_minute_ago_obj }
|
175
|
+
describe ":last_day" do
|
176
|
+
let(:top_threshold) { 1.day.ago }
|
177
|
+
let(:bottom_threshold) { Time.now }
|
178
|
+
let(:arguments) { [] }
|
179
|
+
include_examples 'between time scope','last_day'
|
174
180
|
end
|
175
181
|
|
176
182
|
describe ":last_week" do
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
it { should include hour_ago_obj }
|
182
|
-
it { should include five_minute_ago_obj }
|
183
|
+
let(:top_threshold) { 1.week.ago }
|
184
|
+
let(:bottom_threshold) { Time.now }
|
185
|
+
let(:arguments) { [] }
|
186
|
+
include_examples 'between time scope','last_week'
|
183
187
|
end
|
184
188
|
|
185
189
|
describe ":last_month" do
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
it { should include last_week_obj }
|
191
|
-
it { should include yesterday_obj }
|
192
|
-
it { should include hour_ago_obj }
|
193
|
-
it { should include five_minute_ago_obj }
|
190
|
+
let(:top_threshold) { 1.month.ago }
|
191
|
+
let(:bottom_threshold) { Time.now }
|
192
|
+
let(:arguments) { [] }
|
193
|
+
include_examples 'between time scope','last_month'
|
194
194
|
end
|
195
195
|
|
196
196
|
describe ":last_year" do
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
it { should include last_week_obj }
|
202
|
-
it { should include yesterday_obj }
|
203
|
-
it { should include hour_ago_obj }
|
204
|
-
it { should include five_minute_ago_obj }
|
197
|
+
let(:top_threshold) { 1.year.ago }
|
198
|
+
let(:bottom_threshold) { Time.now }
|
199
|
+
let(:arguments) { [] }
|
200
|
+
include_examples 'between time scope','last_year'
|
205
201
|
end
|
206
202
|
|
207
|
-
describe
|
208
|
-
|
209
|
-
|
210
|
-
let(:
|
211
|
-
|
212
|
-
let(:before_threshold_obj) { test_class.create! date_column => 2.seconds.ago }
|
213
|
-
|
214
|
-
it { should_not include after_threshold_obj }
|
215
|
-
it { should include on_threshold_obj }
|
216
|
-
it { should include before_threshold_obj }
|
203
|
+
describe ":last_n_seconds" do
|
204
|
+
let(:top_threshold) { 3.seconds.ago }
|
205
|
+
let(:bottom_threshold) { Time.now }
|
206
|
+
let(:arguments) { [3] }
|
207
|
+
include_examples 'between time scope','last_n_seconds'
|
217
208
|
end
|
218
209
|
|
219
|
-
describe
|
220
|
-
|
221
|
-
|
222
|
-
let(:
|
223
|
-
|
224
|
-
let(:before_threshold_obj) { test_class.create! date_column => 2.minutes.ago }
|
225
|
-
|
226
|
-
it { should_not include after_threshold_obj }
|
227
|
-
it { should include on_threshold_obj }
|
228
|
-
it { should include before_threshold_obj }
|
210
|
+
describe ":last_n_minutes" do
|
211
|
+
let(:top_threshold) { 3.minutes.ago }
|
212
|
+
let(:bottom_threshold) { Time.now }
|
213
|
+
let(:arguments) { [3] }
|
214
|
+
include_examples 'between time scope','last_n_minutes'
|
229
215
|
end
|
230
216
|
|
231
|
-
describe
|
232
|
-
|
233
|
-
|
234
|
-
let(:
|
235
|
-
|
236
|
-
let(:before_threshold_obj) { test_class.create! date_column => 2.hours.ago }
|
237
|
-
|
238
|
-
it { should_not include after_threshold_obj }
|
239
|
-
it { should include on_threshold_obj }
|
240
|
-
it { should include before_threshold_obj }
|
217
|
+
describe ":last_n_hours" do
|
218
|
+
let(:top_threshold) { 3.hours.ago }
|
219
|
+
let(:bottom_threshold) { Time.now }
|
220
|
+
let(:arguments) { [3] }
|
221
|
+
include_examples 'between time scope','last_n_hours'
|
241
222
|
end
|
242
223
|
|
243
|
-
describe
|
244
|
-
|
245
|
-
|
246
|
-
let(:
|
247
|
-
|
248
|
-
let(:before_threshold_obj) { test_class.create! date_column => 2.days.ago }
|
249
|
-
|
250
|
-
it { should_not include after_threshold_obj }
|
251
|
-
it { should include on_threshold_obj }
|
252
|
-
it { should include before_threshold_obj }
|
224
|
+
describe ":last_n_days" do
|
225
|
+
let(:top_threshold) { 3.days.ago }
|
226
|
+
let(:bottom_threshold) { Time.now }
|
227
|
+
let(:arguments) { [3] }
|
228
|
+
include_examples 'between time scope','last_n_days'
|
253
229
|
end
|
254
230
|
|
255
|
-
describe
|
256
|
-
|
257
|
-
|
258
|
-
let(:
|
259
|
-
|
260
|
-
let(:before_threshold_obj) { test_class.create! date_column => 2.months.ago }
|
261
|
-
|
262
|
-
it { should_not include after_threshold_obj }
|
263
|
-
it { should include on_threshold_obj }
|
264
|
-
it { should include before_threshold_obj }
|
231
|
+
describe ":last_n_weeks" do
|
232
|
+
let(:top_threshold) { 3.weeks.ago }
|
233
|
+
let(:bottom_threshold) { Time.now }
|
234
|
+
let(:arguments) { [3] }
|
235
|
+
include_examples 'between time scope','last_n_weeks'
|
265
236
|
end
|
266
237
|
|
267
|
-
describe
|
268
|
-
|
269
|
-
|
270
|
-
let(:
|
271
|
-
|
272
|
-
let(:before_threshold_obj) { test_class.create! date_column => 2.years.ago }
|
273
|
-
|
274
|
-
it { should_not include after_threshold_obj }
|
275
|
-
it { should include on_threshold_obj }
|
276
|
-
it { should include before_threshold_obj }
|
238
|
+
describe ":last_n_months" do
|
239
|
+
let(:top_threshold) { 3.months.ago }
|
240
|
+
let(:bottom_threshold) { Time.now }
|
241
|
+
let(:arguments) { [3] }
|
242
|
+
include_examples 'between time scope','last_n_months'
|
277
243
|
end
|
278
244
|
|
279
|
-
describe
|
280
|
-
|
281
|
-
|
282
|
-
let(:
|
283
|
-
|
284
|
-
let(:before_threshold_obj) { test_class.create! date_column => 4.seconds.from_now }
|
285
|
-
|
286
|
-
it { should include after_threshold_obj }
|
287
|
-
it { should include on_threshold_obj }
|
288
|
-
it { should_not include before_threshold_obj }
|
245
|
+
describe ":last_n_years" do
|
246
|
+
let(:top_threshold) { 3.years.ago }
|
247
|
+
let(:bottom_threshold) { Time.now }
|
248
|
+
let(:arguments) { [3] }
|
249
|
+
include_examples 'between time scope','last_n_years'
|
289
250
|
end
|
290
251
|
|
291
|
-
describe
|
292
|
-
|
293
|
-
|
294
|
-
let(:
|
295
|
-
|
296
|
-
let(:before_threshold_obj) { test_class.create! date_column => 4.minutes.from_now }
|
297
|
-
|
298
|
-
it { should include after_threshold_obj }
|
299
|
-
it { should include on_threshold_obj }
|
300
|
-
it { should_not include before_threshold_obj }
|
252
|
+
describe ":next_n_seconds" do
|
253
|
+
let(:top_threshold) { Time.now }
|
254
|
+
let(:bottom_threshold) { 3.seconds.from_now }
|
255
|
+
let(:arguments) { [3] }
|
256
|
+
include_examples 'between time scope','next_n_seconds'
|
301
257
|
end
|
302
258
|
|
303
|
-
describe
|
304
|
-
|
305
|
-
|
306
|
-
let(:
|
307
|
-
|
308
|
-
let(:before_threshold_obj) { test_class.create! date_column => 4.hours.from_now }
|
309
|
-
|
310
|
-
it { should include after_threshold_obj }
|
311
|
-
it { should include on_threshold_obj }
|
312
|
-
it { should_not include before_threshold_obj }
|
259
|
+
describe ":next_n_minutes" do
|
260
|
+
let(:top_threshold) { Time.now }
|
261
|
+
let(:bottom_threshold) { 3.minutes.from_now }
|
262
|
+
let(:arguments) { [3] }
|
263
|
+
include_examples 'between time scope','next_n_minutes'
|
313
264
|
end
|
314
265
|
|
315
|
-
describe
|
316
|
-
|
317
|
-
|
318
|
-
let(:
|
319
|
-
|
320
|
-
let(:before_threshold_obj) { test_class.create! date_column => 4.days.from_now }
|
321
|
-
|
322
|
-
it { should include after_threshold_obj }
|
323
|
-
it { should include on_threshold_obj }
|
324
|
-
it { should_not include before_threshold_obj }
|
266
|
+
describe ":next_n_hours" do
|
267
|
+
let(:top_threshold) { Time.now }
|
268
|
+
let(:bottom_threshold) { 3.hours.from_now }
|
269
|
+
let(:arguments) { [3] }
|
270
|
+
include_examples 'between time scope','next_n_hours'
|
325
271
|
end
|
326
272
|
|
327
|
-
describe
|
328
|
-
|
329
|
-
|
330
|
-
let(:
|
331
|
-
|
332
|
-
let(:before_threshold_obj) { test_class.create! date_column => 4.months.from_now }
|
333
|
-
|
334
|
-
it { should include after_threshold_obj }
|
335
|
-
it { should include on_threshold_obj }
|
336
|
-
it { should_not include before_threshold_obj }
|
273
|
+
describe ":next_n_days" do
|
274
|
+
let(:top_threshold) { Time.now }
|
275
|
+
let(:bottom_threshold) { 3.days.from_now }
|
276
|
+
let(:arguments) { [3] }
|
277
|
+
include_examples 'between time scope','next_n_days'
|
337
278
|
end
|
338
279
|
|
339
|
-
describe
|
340
|
-
|
280
|
+
describe ":next_n_weeks" do
|
281
|
+
let(:top_threshold) { Time.now }
|
282
|
+
let(:bottom_threshold) { 3.weeks.from_now }
|
283
|
+
let(:arguments) { [3] }
|
284
|
+
include_examples 'between time scope','next_n_weeks'
|
285
|
+
end
|
341
286
|
|
342
|
-
|
343
|
-
let(:
|
344
|
-
let(:
|
287
|
+
describe ":next_n_months" do
|
288
|
+
let(:top_threshold) { Time.now }
|
289
|
+
let(:bottom_threshold) { 3.months.from_now }
|
290
|
+
let(:arguments) { [3] }
|
291
|
+
include_examples 'between time scope','next_n_months'
|
292
|
+
end
|
345
293
|
|
346
|
-
|
347
|
-
|
348
|
-
|
294
|
+
describe ":next_n_years" do
|
295
|
+
let(:top_threshold) { Time.now }
|
296
|
+
let(:bottom_threshold) { 3.years.from_now }
|
297
|
+
let(:arguments) { [3] }
|
298
|
+
include_examples 'between time scope','next_n_years'
|
349
299
|
end
|
350
300
|
|
351
301
|
describe ":last_30_days" do
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
it { should include yesterday_obj }
|
357
|
-
it { should include hour_ago_obj }
|
358
|
-
it { should include five_minute_ago_obj }
|
302
|
+
let(:top_threshold) { 30.days.ago }
|
303
|
+
let(:bottom_threshold) { Time.now }
|
304
|
+
let(:arguments) { [] }
|
305
|
+
include_examples 'between time scope','last_30_days'
|
359
306
|
end
|
360
307
|
|
361
308
|
describe ":this_minute" do
|
362
|
-
|
363
|
-
|
364
|
-
let(:
|
365
|
-
|
366
|
-
let(:after_minute) { test_class.create! date_column => Time.now.change(sec: 0) + 1.second }
|
367
|
-
|
368
|
-
it { should_not include before_minute }
|
369
|
-
it { should include at_beginning_of_minute }
|
370
|
-
it { should include after_minute }
|
309
|
+
let(:top_threshold) { Time.now.change(sec: 0) }
|
310
|
+
let(:bottom_threshold) { Time.now.change(sec: 59, usec: Rational(999999999, 1000)) }
|
311
|
+
let(:arguments) { [] }
|
312
|
+
include_examples 'between time scope','this_minute'
|
371
313
|
end
|
372
314
|
|
373
315
|
describe ":this_hour" do
|
374
|
-
|
375
|
-
|
376
|
-
let(:
|
377
|
-
|
378
|
-
|
316
|
+
let(:top_threshold) { Time.now.beginning_of_hour }
|
317
|
+
let(:bottom_threshold) { Time.now.end_of_hour }
|
318
|
+
let(:arguments) { [] }
|
319
|
+
include_examples 'between time scope','this_hour'
|
320
|
+
end
|
379
321
|
|
380
|
-
|
381
|
-
|
382
|
-
|
322
|
+
describe ":this_day" do
|
323
|
+
let(:top_threshold) { Time.now.beginning_of_day }
|
324
|
+
let(:bottom_threshold) { Time.now.end_of_day }
|
325
|
+
let(:arguments) { [] }
|
326
|
+
include_examples 'between time scope','this_day'
|
383
327
|
end
|
384
328
|
|
385
329
|
describe ":this_week" do
|
386
|
-
|
387
|
-
|
388
|
-
let(:
|
389
|
-
|
390
|
-
let(:after_week) { test_class.create! date_column => Date.today.beginning_of_week + 1.minute }
|
391
|
-
|
392
|
-
it { should_not include before_week }
|
393
|
-
it { should include at_beginning_of_week }
|
394
|
-
it { should include after_week }
|
330
|
+
let(:top_threshold) { Time.now.beginning_of_week }
|
331
|
+
let(:bottom_threshold) { Time.now.end_of_week }
|
332
|
+
let(:arguments) { [] }
|
333
|
+
include_examples 'between time scope','this_week'
|
395
334
|
end
|
396
335
|
|
397
336
|
describe ":this_month" do
|
398
|
-
|
399
|
-
|
400
|
-
let(:
|
401
|
-
|
402
|
-
let(:after_month) { test_class.create! date_column => Date.today.beginning_of_month + 1.minute }
|
403
|
-
|
404
|
-
it { should_not include before_month }
|
405
|
-
it { should include at_beginning_of_month }
|
406
|
-
it { should include after_month }
|
337
|
+
let(:top_threshold) { Time.now.beginning_of_month }
|
338
|
+
let(:bottom_threshold) { Time.now.end_of_month }
|
339
|
+
let(:arguments) { [] }
|
340
|
+
include_examples 'between time scope','this_month'
|
407
341
|
end
|
408
342
|
|
409
343
|
describe ":this_year" do
|
410
|
-
|
411
|
-
|
412
|
-
let(:
|
413
|
-
|
414
|
-
let(:after_year) { test_class.create! date_column => Date.today.beginning_of_year + 1.minute }
|
415
|
-
|
416
|
-
it { should_not include before_year }
|
417
|
-
it { should include at_beginning_of_year }
|
418
|
-
it { should include after_year }
|
344
|
+
let(:top_threshold) { Time.now.beginning_of_year }
|
345
|
+
let(:bottom_threshold) { Time.now.end_of_year }
|
346
|
+
let(:arguments) { [] }
|
347
|
+
include_examples 'between time scope','this_year'
|
419
348
|
end
|
420
349
|
end
|
421
350
|
end
|