include_date_scopes 0.9.1 → 0.9.2
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/include_date_scopes/date_scopes.rb +90 -221
- data/lib/include_date_scopes/version.rb +1 -1
- data/spec/lib/date_scopes_spec.rb +12 -180
- data/spec/spec_helper.rb +1 -2
- data/spec/support/date_scope_examples.rb +143 -131
- data/spec/support/timestamp_scope_examples.rb +422 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 021ad778ab98e5426f71ce97ed4b1f775a7ed7b6
|
4
|
+
data.tar.gz: 88b07877a83621f0e3635ecd6c5f56444dd2945f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb4eba3ef62ae0fd8ed4c7f6b38f3cd3687a731ef9d9f5bdf31dc52819d48a1811358dfd0fe724d7022712b5bc8fe73ce52f1114f1136d0b85fd51cf7b69629b
|
7
|
+
data.tar.gz: 275795d84b9139079aa45329190b8996ed812075856b82fbee4256fa28178c81974ca299f22b9e73e92a83d5dcbd557acb271e0d35ebef6eb5385293e107d7ef
|
data/Gemfile.lock
CHANGED
@@ -60,7 +60,7 @@ module IncludeDateScopes
|
|
60
60
|
end
|
61
61
|
|
62
62
|
define_singleton_method :"#{prefix}on_or_before" do |time|
|
63
|
-
where(t[column_name].
|
63
|
+
where(t[column_name].lteq (time.is_a?(Date) ? time.to_time : time))
|
64
64
|
end
|
65
65
|
|
66
66
|
define_singleton_method :"#{prefix}before" do |time|
|
@@ -80,7 +80,7 @@ module IncludeDateScopes
|
|
80
80
|
end
|
81
81
|
|
82
82
|
define_singleton_method :"#{prefix}on" do |day|
|
83
|
-
__send__(:"#{prefix}between", day.
|
83
|
+
__send__(:"#{prefix}between", day.beginning_of_day, day.end_of_day)
|
84
84
|
end
|
85
85
|
|
86
86
|
define_singleton_method :"#{prefix}day" do |day|
|
@@ -95,45 +95,63 @@ module IncludeDateScopes
|
|
95
95
|
__send__(:"#{prefix}after", 1.hour.ago)
|
96
96
|
end
|
97
97
|
|
98
|
-
define_singleton_method :"#{prefix}
|
99
|
-
__send__(:"#{prefix}
|
98
|
+
define_singleton_method :"#{prefix}last_n_seconds" do |count|
|
99
|
+
__send__(:"#{prefix}on_or_after", count.seconds.ago)
|
100
100
|
end
|
101
101
|
|
102
|
-
define_singleton_method :"#{prefix}
|
103
|
-
__send__(:"#{prefix}
|
102
|
+
define_singleton_method :"#{prefix}last_n_minutes" do |count|
|
103
|
+
__send__(:"#{prefix}on_or_after", count.minutes.ago)
|
104
104
|
end
|
105
105
|
|
106
|
-
define_singleton_method :"#{prefix}
|
107
|
-
__send__(:"#{prefix}
|
106
|
+
define_singleton_method :"#{prefix}last_n_hours" do |count|
|
107
|
+
__send__(:"#{prefix}on_or_after", count.hours.ago)
|
108
108
|
end
|
109
109
|
|
110
|
-
define_singleton_method :"#{prefix}
|
111
|
-
__send__(:"#{prefix}
|
110
|
+
define_singleton_method :"#{prefix}next_n_seconds" do |count|
|
111
|
+
__send__(:"#{prefix}on_or_before", count.seconds.from_now)
|
112
112
|
end
|
113
113
|
|
114
|
-
define_singleton_method :"#{prefix}
|
115
|
-
__send__(:"#{prefix}
|
114
|
+
define_singleton_method :"#{prefix}next_n_minutes" do |count|
|
115
|
+
__send__(:"#{prefix}on_or_before", count.minutes.from_now)
|
116
116
|
end
|
117
117
|
|
118
|
-
define_singleton_method :"#{prefix}
|
119
|
-
__send__(:"#{prefix}
|
118
|
+
define_singleton_method :"#{prefix}next_n_hours" do |count|
|
119
|
+
__send__(:"#{prefix}on_or_before", count.hours.from_now)
|
120
120
|
end
|
121
121
|
|
122
|
-
define_singleton_method :"#{prefix}
|
123
|
-
|
122
|
+
define_singleton_method :"#{prefix}this_minute" do
|
123
|
+
__send__(:"#{prefix}between", Time.now.change(sec: 0), Time.now.change(sec: 59, usec: Rational(999999999, 1000)))
|
124
|
+
end
|
125
|
+
|
126
|
+
define_singleton_method :"#{prefix}this_hour" do
|
127
|
+
__send__(:"#{prefix}between", 1.hour.ago.end_of_hour, Time.now.end_of_hour)
|
128
|
+
end
|
129
|
+
|
130
|
+
define_singleton_method :"#{prefix}this_week" do
|
131
|
+
__send__(:"#{prefix}between", 1.week.ago.end_of_week, Time.now.end_of_week)
|
132
|
+
end
|
133
|
+
|
134
|
+
define_singleton_method :"#{prefix}this_month" do
|
135
|
+
__send__(:"#{prefix}between", 1.month.ago.end_of_month, Time.now.end_of_month)
|
136
|
+
end
|
137
|
+
|
138
|
+
define_singleton_method :"#{prefix}this_year" do
|
139
|
+
__send__(:"#{prefix}between", 1.year.ago.end_of_year, Time.now.end_of_year)
|
124
140
|
end
|
125
141
|
|
142
|
+
define_common_scopes t, prefix, column_name
|
126
143
|
end
|
127
144
|
|
128
145
|
def define_date_scopes_for(column_name, prepend_name = false)
|
129
146
|
prefix = prepend_name ? "#{column_name}_" : ""
|
147
|
+
t = self.arel_table
|
130
148
|
|
131
149
|
define_singleton_method :"#{prefix}between" do |start_date, stop_date|
|
132
|
-
where(t[column_name].gteq(start_date).and(t[column_name].
|
150
|
+
where(t[column_name].gteq(start_date).and(t[column_name].lteq stop_date))
|
133
151
|
end
|
134
152
|
|
135
153
|
define_singleton_method :"#{prefix}on_or_before" do |date|
|
136
|
-
where( t[column_name].
|
154
|
+
where( t[column_name].lteq date )
|
137
155
|
end
|
138
156
|
|
139
157
|
define_singleton_method :"#{prefix}before" do |date|
|
@@ -152,6 +170,24 @@ module IncludeDateScopes
|
|
152
170
|
where(t[column_name].eq date)
|
153
171
|
end
|
154
172
|
|
173
|
+
define_singleton_method :"#{prefix}this_week" do
|
174
|
+
__send__(:"#{prefix}between", Date.today.beginning_of_week, Date.today.end_of_week)
|
175
|
+
end
|
176
|
+
|
177
|
+
define_singleton_method :"#{prefix}this_month" do
|
178
|
+
__send__(:"#{prefix}between", Date.today.beginning_of_month, Date.today.end_of_month)
|
179
|
+
end
|
180
|
+
|
181
|
+
define_singleton_method :"#{prefix}this_year" do
|
182
|
+
__send__(:"#{prefix}between", Date.today.beginning_of_year, Date.today.end_of_year)
|
183
|
+
end
|
184
|
+
|
185
|
+
define_common_scopes t, prefix, column_name
|
186
|
+
end
|
187
|
+
|
188
|
+
def define_common_scopes(arel, prefix, column_name)
|
189
|
+
t = arel
|
190
|
+
|
155
191
|
define_singleton_method :"#{prefix}day" do |day|
|
156
192
|
__send__(:"#{prefix}on", day)
|
157
193
|
end
|
@@ -160,222 +196,55 @@ module IncludeDateScopes
|
|
160
196
|
__send__(:"#{prefix}on", Date.today)
|
161
197
|
end
|
162
198
|
|
199
|
+
define_singleton_method :"#{prefix}yesterday" do
|
200
|
+
__send__(:"#{prefix}on", Date.yesterday)
|
201
|
+
end
|
202
|
+
|
163
203
|
define_singleton_method :"#{prefix}last_week" do
|
164
204
|
__send__(:"#{prefix}after", 1.week.ago)
|
165
205
|
end
|
166
206
|
|
167
|
-
define_singleton_method :"#{prefix}
|
168
|
-
__send__(:"#{prefix}after",
|
207
|
+
define_singleton_method :"#{prefix}last_month" do
|
208
|
+
__send__(:"#{prefix}after", 1.month.ago)
|
169
209
|
end
|
170
210
|
|
171
|
-
define_singleton_method :"#{prefix}
|
172
|
-
__send__(:"#{prefix}
|
211
|
+
define_singleton_method :"#{prefix}last_year" do
|
212
|
+
__send__(:"#{prefix}after", 1.year.ago)
|
213
|
+
end
|
214
|
+
|
215
|
+
define_singleton_method :"#{prefix}last_n_days" do |count|
|
216
|
+
__send__(:"#{prefix}on_or_after", count.days.ago)
|
217
|
+
end
|
218
|
+
|
219
|
+
define_singleton_method :"#{prefix}last_n_months" do |count|
|
220
|
+
__send__(:"#{prefix}on_or_after", count.months.ago)
|
221
|
+
end
|
222
|
+
|
223
|
+
define_singleton_method :"#{prefix}last_n_years" do |count|
|
224
|
+
__send__(:"#{prefix}on_or_after", count.years.ago)
|
225
|
+
end
|
226
|
+
|
227
|
+
define_singleton_method :"#{prefix}next_n_days" do |count|
|
228
|
+
__send__(:"#{prefix}on_or_before", count.days.from_now)
|
229
|
+
end
|
230
|
+
|
231
|
+
define_singleton_method :"#{prefix}next_n_months" do |count|
|
232
|
+
__send__(:"#{prefix}on_or_before", count.months.from_now)
|
233
|
+
end
|
234
|
+
|
235
|
+
define_singleton_method :"#{prefix}next_n_years" do |count|
|
236
|
+
__send__(:"#{prefix}on_or_before", count.years.from_now)
|
237
|
+
end
|
238
|
+
|
239
|
+
define_singleton_method :"#{prefix}last_30days" do
|
240
|
+
__send__(:"#{prefix}after", 30.days.ago)
|
173
241
|
end
|
174
242
|
|
175
243
|
define_singleton_method :"#{prefix}most_recent" do
|
176
244
|
order("#{column_name} desc")
|
177
245
|
end
|
178
|
-
|
179
246
|
end
|
180
247
|
end
|
181
248
|
end
|
182
249
|
end
|
183
|
-
#
|
184
|
-
# module DateScopes
|
185
|
-
# extend ActiveSupport::Concern
|
186
|
-
#
|
187
|
-
# module ClassMethods
|
188
|
-
# def include_date_scopes
|
189
|
-
# include_date_scopes_for :created_at
|
190
|
-
# end
|
191
|
-
#
|
192
|
-
# def include_date_scopes_for(column, prepend_name = false)
|
193
|
-
# return unless self.table_exists?
|
194
|
-
# if self.columns_hash[column.to_s].try(:type) == :datetime
|
195
|
-
# define_timestamp_scopes_for column, prepend_name
|
196
|
-
# elsif self.columns_hash[column.to_s].try(:type) == :date
|
197
|
-
# define_date_scopes_for column, prepend_name
|
198
|
-
# end
|
199
|
-
# end
|
200
|
-
#
|
201
|
-
# def include_named_date_scopes_for(column)
|
202
|
-
# include_date_scopes_for column, true
|
203
|
-
# end
|
204
|
-
#
|
205
|
-
# protected
|
206
|
-
#
|
207
|
-
# def process_timestamp_argument(arg, inclusive_range = false)
|
208
|
-
# if arg.is_a?(Time) || arg.is_a?(DateTime)
|
209
|
-
# return arg
|
210
|
-
# elsif arg.is_a?(Date) && inclusive_range
|
211
|
-
# return arg + 1.day
|
212
|
-
# elsif arg.is_a?(Date) && !inclusive_range
|
213
|
-
# return arg
|
214
|
-
# else
|
215
|
-
# raise ArgumentError, "Unexpected argument class for timestamp scope: #{arg.class.name}"
|
216
|
-
# end
|
217
|
-
# end
|
218
|
-
#
|
219
|
-
# def process_date_argument(arg)
|
220
|
-
# if arg.is_a?(Time) || arg.is_a?(DateTime)
|
221
|
-
# return arg.to_date
|
222
|
-
# elsif arg.is_a?(Date)
|
223
|
-
# return arg
|
224
|
-
# else
|
225
|
-
# raise ArgumentError, "Unexpected argument class for timestamp scope: #{arg.class.name}"
|
226
|
-
# end
|
227
|
-
# end
|
228
|
-
#
|
229
|
-
# def define_timestamp_scopes_for(column_name, prepend_name = false)
|
230
|
-
# prefix = prepend_name ? "#{column_name}_" : ""
|
231
|
-
#
|
232
|
-
# define_singleton_method :"#{prefix}before" do |time,inclusive=false|
|
233
|
-
# time = process_timestamp_argument(time, inclusive)
|
234
|
-
# if inclusive
|
235
|
-
# where{__send__(column_name).lte time}
|
236
|
-
# else
|
237
|
-
# where{__send__(column_name).lt time}
|
238
|
-
# end
|
239
|
-
# end
|
240
|
-
#
|
241
|
-
# define_singleton_method :"#{prefix}after" do |time, inclusive=false|
|
242
|
-
# time = process_timestamp_argument(time, inclusive)
|
243
|
-
# if inclusive
|
244
|
-
# where{__send__(column_name).gte time}
|
245
|
-
# else
|
246
|
-
# where{__send__(column_name).gt time}
|
247
|
-
# end
|
248
|
-
# end
|
249
|
-
#
|
250
|
-
# define_singleton_method :"#{prefix}between" do |start_time, stop_time|
|
251
|
-
# on_or_after(start_time).on_or_before(stop_time)
|
252
|
-
# end
|
253
|
-
#
|
254
|
-
# define_singleton_method :"#{prefix}on_or_after" do |time|
|
255
|
-
# after(time,true)
|
256
|
-
# end
|
257
|
-
#
|
258
|
-
# define_singleton_method :"#{prefix}on_or_before" do |time|
|
259
|
-
# before(time,true)
|
260
|
-
# end
|
261
|
-
#
|
262
|
-
# define_singleton_method :"#{prefix}on_or_before_date" do |time|
|
263
|
-
# on_or_before(time.to_date)
|
264
|
-
# end
|
265
|
-
#
|
266
|
-
# define_singleton_method :"#{prefix}on_or_after_date" do |time|
|
267
|
-
# on_or_after(time)
|
268
|
-
# end
|
269
|
-
#
|
270
|
-
# define_singleton_method :"#{prefix}on" do |day|
|
271
|
-
# between(day.midnight, (day + 1.day).midnight)
|
272
|
-
# end
|
273
|
-
#
|
274
|
-
# define_singleton_method :"#{prefix}day" do |day|
|
275
|
-
# on(day)
|
276
|
-
# end
|
277
|
-
#
|
278
|
-
# define_singleton_method :"#{prefix}last_24_hours" do
|
279
|
-
# after(24.hours.ago)
|
280
|
-
# end
|
281
|
-
#
|
282
|
-
# define_singleton_method :"#{prefix}last_hour" do
|
283
|
-
# after(1.hour.ago)
|
284
|
-
# end
|
285
|
-
#
|
286
|
-
# define_singleton_method :"#{prefix}last_week" do
|
287
|
-
# after(1.week.ago)
|
288
|
-
# end
|
289
|
-
#
|
290
|
-
# define_singleton_method :"#{prefix}last_30days" do
|
291
|
-
# after(30.days.ago)
|
292
|
-
# end
|
293
|
-
#
|
294
|
-
# define_singleton_method :"#{prefix}today" do
|
295
|
-
# on(Date.today)
|
296
|
-
# end
|
297
|
-
#
|
298
|
-
# define_singleton_method :"#{prefix}this_week" do
|
299
|
-
# between((Date.today - Date.today.wday.days).midnight, (Date.today + 1.day).midnight)
|
300
|
-
# end
|
301
|
-
#
|
302
|
-
# define_singleton_method :"#{prefix}this_month" do
|
303
|
-
# between((Date.today.at_beginning_of_month).midnight, (Date.today + 1.day).midnight)
|
304
|
-
# end
|
305
|
-
#
|
306
|
-
# define_singleton_method :"#{prefix}yesterday" do
|
307
|
-
# on(Date.yesterday)
|
308
|
-
# end
|
309
|
-
#
|
310
|
-
# define_singleton_method :"#{prefix}most_recent" do
|
311
|
-
# order("#{column_name} desc")
|
312
|
-
# end
|
313
|
-
#
|
314
|
-
# end
|
315
|
-
#
|
316
|
-
# def define_date_scopes_for(column_name, prepend_name = false)
|
317
|
-
# prefix = prepend_name ? "#{column_name}_" : ""
|
318
|
-
#
|
319
|
-
# define_singleton_method :"#{prefix}before" do |date,inclusive=false|
|
320
|
-
# date = process_date_argument(date)
|
321
|
-
# if inclusive
|
322
|
-
# where{__send__(column_name).lte date}
|
323
|
-
# else
|
324
|
-
# where{__send__(column_name).lt date}
|
325
|
-
# end
|
326
|
-
# end
|
327
|
-
#
|
328
|
-
# define_singleton_method :"#{prefix}after" do |date, inclusive=false|
|
329
|
-
# date = process_date_argument(date)
|
330
|
-
# if inclusive
|
331
|
-
# where{__send__(column_name).gte date}
|
332
|
-
# else
|
333
|
-
# where{__send__(column_name).gt date}
|
334
|
-
# end
|
335
|
-
# end
|
336
|
-
#
|
337
|
-
# define_singleton_method :"#{prefix}on" do |date|
|
338
|
-
# date = process_date_argument(date)
|
339
|
-
# where{__send__(column_name).eq date}
|
340
|
-
# end
|
341
|
-
#
|
342
|
-
# define_singleton_method :"#{prefix}between" do |start_date, stop_date|
|
343
|
-
# on_or_after(start_date).on_or_before(stop_date)
|
344
|
-
# end
|
345
|
-
#
|
346
|
-
# define_singleton_method :"#{prefix}on_or_before" do |date|
|
347
|
-
# before(date,true)
|
348
|
-
# end
|
349
|
-
#
|
350
|
-
# define_singleton_method :"#{prefix}on_or_after" do |date|
|
351
|
-
# after(date,true)
|
352
|
-
# end
|
353
|
-
#
|
354
|
-
# define_singleton_method :"#{prefix}day" do |day|
|
355
|
-
# on(day)
|
356
|
-
# end
|
357
|
-
#
|
358
|
-
# define_singleton_method :"#{prefix}today" do
|
359
|
-
# on(Date.today)
|
360
|
-
# end
|
361
|
-
#
|
362
|
-
# define_singleton_method :"#{prefix}last_week" do
|
363
|
-
# after(1.week.ago)
|
364
|
-
# end
|
365
|
-
#
|
366
|
-
# define_singleton_method :"#{prefix}last_30days" do
|
367
|
-
# after(30.days.ago)
|
368
|
-
# end
|
369
|
-
#
|
370
|
-
# define_singleton_method :"#{prefix}yesterday" do
|
371
|
-
# on(Date.yesterday)
|
372
|
-
# end
|
373
|
-
#
|
374
|
-
# define_singleton_method :"#{prefix}most_recent" do
|
375
|
-
# order("#{column_name} desc")
|
376
|
-
# end
|
377
|
-
#
|
378
|
-
# end
|
379
|
-
# end
|
380
|
-
# end
|
381
250
|
|
@@ -1,211 +1,43 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Post" do
|
4
|
-
describe 'default
|
4
|
+
describe 'default timestamp scopes' do
|
5
5
|
before(:all) do
|
6
6
|
define_model_class do
|
7
7
|
include_date_scopes
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
it_behaves_like "
|
11
|
+
it_behaves_like "timestamp scopes"
|
12
12
|
end
|
13
13
|
|
14
|
-
describe '
|
14
|
+
describe 'timestamp scopes on another column' do
|
15
15
|
before(:all) do
|
16
16
|
define_model_class do
|
17
17
|
include_date_scopes_for :updated_at
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
it_behaves_like "
|
21
|
+
it_behaves_like "timestamp scopes", :updated_at
|
22
22
|
end
|
23
23
|
|
24
|
-
describe '
|
24
|
+
describe 'timestamp scopes with name prepended' do
|
25
25
|
before(:all) do
|
26
26
|
define_model_class do
|
27
27
|
include_named_date_scopes_for :show_at
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
let!(:last_month_obj) { Post.create! :show_at => 1.month.ago }
|
34
|
-
let!(:last_week_obj) { Post.create! :show_at => 1.week.ago }
|
35
|
-
let!(:yesterday_obj) { Post.create! :show_at => 24.hours.ago }
|
36
|
-
let!(:hour_ago_obj) { Post.create! :show_at => 1.hour.ago }
|
37
|
-
let!(:five_minute_ago_obj) { Post.create! :show_at => 5.minutes.ago }
|
38
|
-
let!(:after_midnight_ago_obj) { Post.create! :show_at => Date.today.midnight + 5.minutes }
|
39
|
-
let!(:before_midnight_ago_obj) { Post.create! :show_at => Date.today.midnight - 5.minutes }
|
40
|
-
|
41
|
-
describe ":between" do
|
42
|
-
context "with DateTime" do
|
43
|
-
subject { Post.show_at_between(2.hours.ago, 1.minute.ago) }
|
44
|
-
|
45
|
-
it { should_not include last_week_obj }
|
46
|
-
it { should_not include yesterday_obj }
|
47
|
-
it { should include hour_ago_obj }
|
48
|
-
it { should include five_minute_ago_obj }
|
49
|
-
end
|
50
|
-
context "with Date" do
|
51
|
-
subject { Post.show_at_between(2.days.ago.to_date, Date.today) }
|
52
|
-
|
53
|
-
it { should_not include last_week_obj }
|
54
|
-
it { should include yesterday_obj }
|
55
|
-
it { should include hour_ago_obj }
|
56
|
-
it { should include five_minute_ago_obj }
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe ":after" do
|
61
|
-
context "with DateTime" do
|
62
|
-
subject { Post.show_at_after(2.hours.ago) }
|
63
|
-
|
64
|
-
it { should_not include last_week_obj }
|
65
|
-
it { should_not include yesterday_obj }
|
66
|
-
it { should include hour_ago_obj }
|
67
|
-
it { should include five_minute_ago_obj }
|
68
|
-
end
|
69
|
-
context "with Date" do
|
70
|
-
subject { Post.show_at_after(2.days.ago.to_date) }
|
71
|
-
|
72
|
-
it { should_not include last_week_obj }
|
73
|
-
it { should include yesterday_obj }
|
74
|
-
it { should include hour_ago_obj }
|
75
|
-
it { should include five_minute_ago_obj }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe ":on_or_after_date" do
|
80
|
-
context "with DateTime" do
|
81
|
-
subject { Post.show_at_on_or_after_date(2.hours.ago) }
|
82
|
-
|
83
|
-
it { should_not include last_week_obj }
|
84
|
-
it { should_not include yesterday_obj }
|
85
|
-
it { should include hour_ago_obj }
|
86
|
-
it { should include five_minute_ago_obj }
|
87
|
-
end
|
88
|
-
context "with Date" do
|
89
|
-
subject { Post.show_at_on_or_after_date(2.days.ago.to_date) }
|
90
|
-
|
91
|
-
it { should_not include last_week_obj }
|
92
|
-
it { should include yesterday_obj }
|
93
|
-
it { should include hour_ago_obj }
|
94
|
-
it { should include five_minute_ago_obj }
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe ":before" do
|
99
|
-
context "with DateTime" do
|
100
|
-
subject { Post.show_at_before(2.hours.ago) }
|
101
|
-
|
102
|
-
it { should include last_week_obj }
|
103
|
-
it { should include yesterday_obj }
|
104
|
-
it { should_not include hour_ago_obj }
|
105
|
-
it { should_not include five_minute_ago_obj }
|
106
|
-
end
|
107
|
-
context "with Date" do
|
108
|
-
subject { Post.show_at_before(Date.today) }
|
109
|
-
|
110
|
-
it { should include last_week_obj }
|
111
|
-
it { should include yesterday_obj }
|
112
|
-
it { should_not include hour_ago_obj }
|
113
|
-
it { should_not include five_minute_ago_obj }
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe ":on_or_before_date" do
|
118
|
-
context "with DateTime" do
|
119
|
-
subject { Post.show_at_on_or_before_date(25.hours.ago) }
|
120
|
-
|
121
|
-
it { should include last_week_obj }
|
122
|
-
it { should include yesterday_obj }
|
123
|
-
it { should_not include hour_ago_obj }
|
124
|
-
it { should_not include five_minute_ago_obj }
|
125
|
-
end
|
126
|
-
context "with Date" do
|
127
|
-
subject { Post.show_at_on_or_before_date(Date.yesterday) }
|
31
|
+
it_behaves_like "timestamp scopes", :show_at, 'show_at_'
|
32
|
+
end
|
128
33
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
34
|
+
describe 'date scopes' do
|
35
|
+
before(:all) do
|
36
|
+
define_model_class do
|
37
|
+
include_date_scopes_for :show_until
|
133
38
|
end
|
134
39
|
end
|
135
40
|
|
136
|
-
|
137
|
-
subject { Post.show_at_today }
|
138
|
-
|
139
|
-
it { should_not include last_week_obj }
|
140
|
-
it { should_not include yesterday_obj }
|
141
|
-
it { should include hour_ago_obj }
|
142
|
-
it { should include five_minute_ago_obj }
|
143
|
-
end
|
144
|
-
|
145
|
-
describe ":yesterday" do
|
146
|
-
subject { Post.show_at_yesterday }
|
147
|
-
|
148
|
-
it { should_not include last_week_obj }
|
149
|
-
it { should include yesterday_obj }
|
150
|
-
it { should_not include hour_ago_obj }
|
151
|
-
it { should_not include five_minute_ago_obj }
|
152
|
-
end
|
153
|
-
|
154
|
-
describe ":last_24_hours" do
|
155
|
-
subject { Post.show_at_last_24_hours }
|
156
|
-
|
157
|
-
it { should_not include last_week_obj }
|
158
|
-
it { should_not include yesterday_obj }
|
159
|
-
it { should include hour_ago_obj }
|
160
|
-
it { should include five_minute_ago_obj }
|
161
|
-
end
|
162
|
-
|
163
|
-
describe ":last_hour" do
|
164
|
-
subject { Post.show_at_last_hour }
|
165
|
-
|
166
|
-
it { should_not include last_week_obj }
|
167
|
-
it { should_not include yesterday_obj }
|
168
|
-
it { should_not include hour_ago_obj } # should not because this is exclusive
|
169
|
-
it { should include five_minute_ago_obj }
|
170
|
-
end
|
171
|
-
|
172
|
-
describe ":last_week" do
|
173
|
-
subject { Post.show_at_last_week }
|
174
|
-
|
175
|
-
it { should_not include last_week_obj }
|
176
|
-
it { should include yesterday_obj }
|
177
|
-
it { should include hour_ago_obj }
|
178
|
-
it { should include five_minute_ago_obj }
|
179
|
-
end
|
180
|
-
|
181
|
-
describe ":last_30_days" do
|
182
|
-
subject { Post.show_at_last_30days }
|
183
|
-
|
184
|
-
it { should_not include last_month_obj }
|
185
|
-
it { should include last_week_obj }
|
186
|
-
it { should include yesterday_obj }
|
187
|
-
it { should include hour_ago_obj }
|
188
|
-
it { should include five_minute_ago_obj }
|
189
|
-
end
|
190
|
-
|
191
|
-
describe ":this_week" do
|
192
|
-
subject { Post.show_at_this_week }
|
193
|
-
|
194
|
-
it { should_not include last_week_obj }
|
195
|
-
it { should include yesterday_obj }
|
196
|
-
it { should include hour_ago_obj }
|
197
|
-
it { should include five_minute_ago_obj }
|
198
|
-
it { should include before_midnight_ago_obj }
|
199
|
-
end
|
200
|
-
|
201
|
-
describe ":this_month" do
|
202
|
-
subject { Post.show_at_this_month }
|
203
|
-
|
204
|
-
it { should_not include last_month_obj }
|
205
|
-
it { should include last_week_obj }
|
206
|
-
it { should include yesterday_obj }
|
207
|
-
it { should include hour_ago_obj }
|
208
|
-
it { should include five_minute_ago_obj }
|
209
|
-
end
|
41
|
+
it_behaves_like 'date scopes', :show_until
|
210
42
|
end
|
211
43
|
end
|