include_date_scopes 0.9.2 → 0.9.3

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.
@@ -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
- let(:last_year_obj) { test_class.create! date_column => 1.year.ago }
8
- let(:last_month_obj) { test_class.create! date_column => 1.month.ago }
9
- let(:last_week_obj) { test_class.create! date_column => 1.week.ago }
10
- let(:next_year_obj) { test_class.create! date_column => 1.year.from_now }
11
- let(:next_month_obj) { test_class.create! date_column => 1.month.from_now }
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
- context "with DateTime" do
41
- subject { test_class.send("#{prefix}after", 2.hours.ago) }
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
- it { should_not include last_week_obj }
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 ':on_or_after' do
59
- subject { test_class.send("#{prefix}on_or_after", 1.hour.ago) }
52
+ describe ":before" do
53
+
54
+ subject { test_class.send("#{prefix}before", 5.minutes.ago) }
60
55
 
61
- it { should_not include yesterday_obj }
62
- it { should include hour_ago_obj }
63
- it { should include five_minute_ago_obj }
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 ":on_or_after_date" do
67
- context "with DateTime" do
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
- it { should_not include last_week_obj }
71
- it { should_not include yesterday_obj }
72
- it { should include hour_ago_obj }
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
- it { should_not include last_week_obj }
79
- it { should include yesterday_obj }
80
- it { should include hour_ago_obj }
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 ":before" do
86
- context "with DateTime" do
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
- it { should include last_week_obj }
90
- it { should include yesterday_obj }
91
- it { should_not include hour_ago_obj }
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
- it { should include last_week_obj }
98
- it { should include yesterday_obj }
99
- it { should_not include hour_ago_obj }
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 ':on_or_before' do
105
- subject { test_class.send("#{prefix}on_or_before", 1.hour.ago) }
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
- it { should include yesterday_obj }
108
- it { should include hour_ago_obj }
109
- it { should_not include five_minute_ago_obj }
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 ":on_or_before_date" do
113
- context "with DateTime" do
114
- subject { test_class.send("#{prefix}on_or_before_date", 25.hours.ago) }
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
- it { should include last_week_obj }
117
- it { should include yesterday_obj }
118
- it { should_not include hour_ago_obj }
119
- it { should_not include five_minute_ago_obj }
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
- context "with Date" do
122
- subject { test_class.send("#{prefix}on_or_before_date", Date.yesterday) }
117
+ end
123
118
 
124
- it { should include last_week_obj }
125
- it { should include yesterday_obj }
126
- it { should_not include hour_ago_obj }
127
- it { should_not include five_minute_ago_obj }
128
- end
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 ':on' do
132
- subject { test_class.send("#{prefix}on", Date.today) }
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
- it { should_not include before_midnight_ago_obj }
135
- it { should include after_midnight_ago_obj }
136
- it { should include five_minute_ago_obj }
137
- it { should_not include tomorrow_obj }
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 ":today" do
141
- subject { test_class.send("#{prefix}today") }
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
- it { should_not include last_week_obj }
144
- it { should_not include yesterday_obj }
145
- it { should include hour_ago_obj }
146
- it { should include five_minute_ago_obj }
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 ":yesterday" do
150
- subject { test_class.send("#{prefix}yesterday") }
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
- it { should_not include last_week_obj }
153
- it { should include yesterday_obj }
154
- it { should_not include hour_ago_obj }
155
- it { should_not include five_minute_ago_obj }
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
- subject { test_class.send("#{prefix}last_24_hours") }
160
-
161
- it { should_not include last_week_obj }
162
- it { should_not include yesterday_obj }
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 ":last_hour" do
168
- subject { test_class.send("#{prefix}last_hour") }
169
-
170
- it { should_not include last_week_obj }
171
- it { should_not include yesterday_obj }
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
- subject { test_class.send("#{prefix}last_week") }
178
-
179
- it { should_not include last_week_obj }
180
- it { should include yesterday_obj }
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
- subject { test_class.send("#{prefix}last_month") }
187
-
188
- it { should_not include last_year_obj }
189
- it { should_not include last_month_obj }
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
- subject { test_class.send("#{prefix}last_year") }
198
-
199
- it { should_not include last_year_obj }
200
- it { should include last_month_obj }
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 'last_n_seconds' do
208
- subject { test_class.send("#{prefix}last_n_seconds", 3) }
209
-
210
- let(:after_threshold_obj) { test_class.create! date_column => 4.seconds.ago }
211
- let(:on_threshold_obj) { test_class.create! date_column => 3.seconds.ago }
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 'last_n_minutes' do
220
- subject { test_class.send("#{prefix}last_n_minutes", 3) }
221
-
222
- let(:after_threshold_obj) { test_class.create! date_column => 4.minutes.ago }
223
- let(:on_threshold_obj) { test_class.create! date_column => 3.minutes.ago }
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 'last_n_hours' do
232
- subject { test_class.send("#{prefix}last_n_hours", 3) }
233
-
234
- let(:after_threshold_obj) { test_class.create! date_column => 4.hours.ago }
235
- let(:on_threshold_obj) { test_class.create! date_column => 3.hours.ago }
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 'last_n_days' do
244
- subject { test_class.send("#{prefix}last_n_days", 3) }
245
-
246
- let(:after_threshold_obj) { test_class.create! date_column => 4.days.ago }
247
- let(:on_threshold_obj) { test_class.create! date_column => 3.days.ago }
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 'last_n_months' do
256
- subject { test_class.send("#{prefix}last_n_months", 3) }
257
-
258
- let(:after_threshold_obj) { test_class.create! date_column => 4.months.ago }
259
- let(:on_threshold_obj) { test_class.create! date_column => 3.months.ago }
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 'last_n_years' do
268
- subject { test_class.send("#{prefix}last_n_years", 3) }
269
-
270
- let(:after_threshold_obj) { test_class.create! date_column => 4.years.ago }
271
- let(:on_threshold_obj) { test_class.create! date_column => 3.years.ago }
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 'next_n_seconds' do
280
- subject { test_class.send("#{prefix}next_n_seconds", 3) }
281
-
282
- let(:after_threshold_obj) { test_class.create! date_column => 2.seconds.from_now }
283
- let(:on_threshold_obj) { test_class.create! date_column => 3.seconds.from_now }
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 'next_n_minutes' do
292
- subject { test_class.send("#{prefix}next_n_minutes", 3) }
293
-
294
- let(:after_threshold_obj) { test_class.create! date_column => 2.minutes.from_now }
295
- let(:on_threshold_obj) { test_class.create! date_column => 3.minutes.from_now }
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 'next_n_hours' do
304
- subject { test_class.send("#{prefix}next_n_hours", 3) }
305
-
306
- let(:after_threshold_obj) { test_class.create! date_column => 2.hours.from_now }
307
- let(:on_threshold_obj) { test_class.create! date_column => 3.hours.from_now }
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 'next_n_days' do
316
- subject { test_class.send("#{prefix}next_n_days", 3) }
317
-
318
- let(:after_threshold_obj) { test_class.create! date_column => 2.days.from_now }
319
- let(:on_threshold_obj) { test_class.create! date_column => 3.days.from_now }
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 'next_n_months' do
328
- subject { test_class.send("#{prefix}next_n_months", 3) }
329
-
330
- let(:after_threshold_obj) { test_class.create! date_column => 2.months.from_now }
331
- let(:on_threshold_obj) { test_class.create! date_column => 3.months.from_now }
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 'next_n_years' do
340
- subject { test_class.send("#{prefix}next_n_years", 3) }
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
- let(:after_threshold_obj) { test_class.create! date_column => 2.years.from_now }
343
- let(:on_threshold_obj) { test_class.create! date_column => 3.years.from_now }
344
- let(:before_threshold_obj) { test_class.create! date_column => 4.years.from_now }
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
- it { should include after_threshold_obj }
347
- it { should include on_threshold_obj }
348
- it { should_not include before_threshold_obj }
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
- subject { test_class.send("#{prefix}last_30days") }
353
-
354
- it { should_not include last_month_obj }
355
- it { should include last_week_obj }
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
- subject { test_class.send("#{prefix}this_minute") }
363
-
364
- let(:before_minute) { test_class.create! date_column => Time.now.change(sec: 0) - 1.second }
365
- let(:at_beginning_of_minute) { test_class.create! date_column => Time.now.change(sec: 0) }
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
- subject { test_class.send("#{prefix}this_hour") }
375
-
376
- let(:before_hour) { test_class.create! date_column => Time.now.beginning_of_hour - 1.minute }
377
- let(:at_beginning_of_hour) { test_class.create! date_column => Time.now.beginning_of_hour }
378
- let(:after_hour) { test_class.create! date_column => Time.now.beginning_of_hour + 1.minute }
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
- it { should_not include before_hour }
381
- it { should include at_beginning_of_hour }
382
- it { should include after_hour }
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
- subject { test_class.send("#{prefix}this_week") }
387
-
388
- let(:before_week) { test_class.create! date_column => Date.today.beginning_of_week - 1.minute }
389
- let(:at_beginning_of_week) { test_class.create! date_column => Date.today.beginning_of_week }
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
- subject { test_class.send("#{prefix}this_month") }
399
-
400
- let(:before_month) { test_class.create! date_column => Date.today.beginning_of_month - 1.minute }
401
- let(:at_beginning_of_month) { test_class.create! date_column => Date.today.beginning_of_month }
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
- subject { test_class.send("#{prefix}this_year") }
411
-
412
- let(:before_year) { test_class.create! date_column => Date.today.beginning_of_year - 1.minute }
413
- let(:at_beginning_of_year) { test_class.create! date_column => Date.today.beginning_of_year }
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