include_date_scopes 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/spec/spec_helper.rb
CHANGED
@@ -27,11 +27,10 @@ ActiveRecord::Base.establish_connection(
|
|
27
27
|
:database => ':memory:'
|
28
28
|
)
|
29
29
|
ActiveRecord::Base.connection.create_table(:posts, :force => true) do |t|
|
30
|
-
t.string :body
|
31
30
|
t.timestamp :show_at
|
31
|
+
t.date :show_until
|
32
32
|
t.timestamp :created_at
|
33
33
|
t.timestamp :updated_at
|
34
|
-
t.boolean :flag
|
35
34
|
end
|
36
35
|
|
37
36
|
require "#{File.dirname(__FILE__)}/../lib/include_date_scopes/active_record"
|
@@ -1,185 +1,197 @@
|
|
1
1
|
|
2
|
-
shared_examples "
|
3
|
-
let
|
2
|
+
shared_examples "date scopes" do |date_column = :created_at, prefix = '' |
|
3
|
+
let(:test_class) { Post }
|
4
4
|
describe "date scopes" do
|
5
5
|
before(:all) { Timecop.freeze Time.local(2013,02,15,06,30) }
|
6
6
|
|
7
|
-
let
|
8
|
-
let
|
9
|
-
let
|
10
|
-
let
|
11
|
-
let
|
12
|
-
let
|
13
|
-
let
|
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.to_date }
|
9
|
+
let(:beginning_of_month_obj) { test_class.create! date_column => Date.today.beginning_of_month }
|
10
|
+
let(:last_week_obj) { test_class.create! date_column => 7.days.ago.to_date }
|
11
|
+
let(:beginning_of_week_obj) { test_class.create! date_column => Date.today.beginning_of_week }
|
12
|
+
let(:yesterday_obj) { test_class.create! date_column => Date.yesterday }
|
13
|
+
let(:today_obj) { test_class.create! date_column => Date.today }
|
14
14
|
|
15
15
|
describe ":between" do
|
16
|
-
|
17
|
-
subject { test_class.between(2.hours.ago, 1.minute.ago) }
|
16
|
+
subject { test_class.send("#{prefix}between", 2.days.ago.to_date, Date.yesterday) }
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
it { should include five_minute_ago_obj }
|
23
|
-
end
|
24
|
-
context "with Date" do
|
25
|
-
subject { test_class.between(2.days.ago.to_date, Date.today) }
|
26
|
-
|
27
|
-
it { should_not include last_week_obj }
|
28
|
-
it { should include yesterday_obj }
|
29
|
-
it { should include hour_ago_obj }
|
30
|
-
it { should include five_minute_ago_obj }
|
31
|
-
end
|
18
|
+
it { should_not include last_week_obj }
|
19
|
+
it { should include yesterday_obj }
|
20
|
+
it { should_not include today_obj }
|
32
21
|
end
|
33
22
|
|
34
23
|
describe ":after" do
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
it { should include hour_ago_obj }
|
41
|
-
it { should include five_minute_ago_obj }
|
42
|
-
end
|
43
|
-
context "with Date" do
|
44
|
-
subject { test_class.after(2.days.ago.to_date) }
|
45
|
-
|
46
|
-
it { should_not include last_week_obj }
|
47
|
-
it { should include yesterday_obj }
|
48
|
-
it { should include hour_ago_obj }
|
49
|
-
it { should include five_minute_ago_obj }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe ":on_or_after_date" do
|
54
|
-
context "with DateTime" do
|
55
|
-
subject { test_class.on_or_after_date(2.hours.ago) }
|
56
|
-
|
57
|
-
it { should_not include last_week_obj }
|
58
|
-
it { should_not include yesterday_obj }
|
59
|
-
it { should include hour_ago_obj }
|
60
|
-
it { should include five_minute_ago_obj }
|
61
|
-
end
|
62
|
-
context "with Date" do
|
63
|
-
subject { test_class.on_or_after_date(2.days.ago.to_date) }
|
64
|
-
|
65
|
-
it { should_not include last_week_obj }
|
66
|
-
it { should include yesterday_obj }
|
67
|
-
it { should include hour_ago_obj }
|
68
|
-
it { should include five_minute_ago_obj }
|
69
|
-
end
|
24
|
+
subject { test_class.send("#{prefix}after", 2.days.ago.to_date) }
|
25
|
+
|
26
|
+
it { should_not include last_week_obj }
|
27
|
+
it { should include yesterday_obj }
|
28
|
+
it { should include today_obj }
|
70
29
|
end
|
71
30
|
|
72
31
|
describe ":before" do
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
it { should_not include hour_ago_obj }
|
79
|
-
it { should_not include five_minute_ago_obj }
|
80
|
-
end
|
81
|
-
context "with Date" do
|
82
|
-
subject { test_class.before(Date.today) }
|
83
|
-
|
84
|
-
it { should include last_week_obj }
|
85
|
-
it { should include yesterday_obj }
|
86
|
-
it { should_not include hour_ago_obj }
|
87
|
-
it { should_not include five_minute_ago_obj }
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe ":on_or_before_date" do
|
92
|
-
context "with DateTime" do
|
93
|
-
subject { test_class.on_or_before_date(25.hours.ago) }
|
94
|
-
|
95
|
-
it { should include last_week_obj }
|
96
|
-
it { should include yesterday_obj }
|
97
|
-
it { should_not include hour_ago_obj }
|
98
|
-
it { should_not include five_minute_ago_obj }
|
99
|
-
end
|
100
|
-
context "with Date" do
|
101
|
-
subject { test_class.on_or_before_date(Date.yesterday) }
|
102
|
-
|
103
|
-
it { should include last_week_obj }
|
104
|
-
it { should include yesterday_obj }
|
105
|
-
it { should_not include hour_ago_obj }
|
106
|
-
it { should_not include five_minute_ago_obj }
|
107
|
-
end
|
32
|
+
subject { test_class.send("#{prefix}before", Date.today) }
|
33
|
+
|
34
|
+
it { should include last_week_obj }
|
35
|
+
it { should include yesterday_obj }
|
36
|
+
it { should_not include today_obj }
|
108
37
|
end
|
109
38
|
|
110
39
|
describe ":today" do
|
111
|
-
subject { test_class.today }
|
40
|
+
subject { test_class.send("#{prefix}today") }
|
112
41
|
|
113
42
|
it { should_not include last_week_obj }
|
114
43
|
it { should_not include yesterday_obj }
|
115
|
-
it { should include
|
116
|
-
it { should include five_minute_ago_obj }
|
44
|
+
it { should include today_obj }
|
117
45
|
end
|
118
46
|
|
119
47
|
describe ":yesterday" do
|
120
|
-
subject { test_class.yesterday }
|
48
|
+
subject { test_class.send("#{prefix}yesterday") }
|
121
49
|
|
122
50
|
it { should_not include last_week_obj }
|
123
51
|
it { should include yesterday_obj }
|
124
|
-
it { should_not include
|
125
|
-
it { should_not include five_minute_ago_obj }
|
52
|
+
it { should_not include today_obj }
|
126
53
|
end
|
127
54
|
|
128
|
-
describe ":
|
129
|
-
subject { test_class.
|
55
|
+
describe ":last_week" do
|
56
|
+
subject { test_class.send("#{prefix}last_week") }
|
130
57
|
|
131
58
|
it { should_not include last_week_obj }
|
132
|
-
it {
|
133
|
-
it { should include
|
134
|
-
it { should include five_minute_ago_obj }
|
59
|
+
it { should include yesterday_obj }
|
60
|
+
it { should include today_obj }
|
135
61
|
end
|
136
62
|
|
137
|
-
describe ":
|
138
|
-
subject { test_class.
|
63
|
+
describe ":last_month" do
|
64
|
+
subject { test_class.send("#{prefix}last_month") }
|
139
65
|
|
140
|
-
it { should_not include
|
141
|
-
it { should_not include
|
142
|
-
it {
|
143
|
-
it { should include
|
66
|
+
it { should_not include last_year_obj }
|
67
|
+
it { should_not include last_month_obj }
|
68
|
+
it { should include last_week_obj }
|
69
|
+
it { should include yesterday_obj }
|
144
70
|
end
|
145
71
|
|
146
|
-
describe ":
|
147
|
-
subject { test_class.
|
72
|
+
describe ":last_year" do
|
73
|
+
subject { test_class.send("#{prefix}last_year") }
|
148
74
|
|
149
|
-
it { should_not include
|
75
|
+
it { should_not include last_year_obj }
|
76
|
+
it { should include last_month_obj }
|
77
|
+
it { should include last_week_obj }
|
150
78
|
it { should include yesterday_obj }
|
151
|
-
|
152
|
-
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'last_n_days' do
|
82
|
+
subject { test_class.send("#{prefix}last_n_days", 3) }
|
83
|
+
|
84
|
+
let(:after_threshold_obj) { test_class.create! date_column => 4.days.ago }
|
85
|
+
let(:on_threshold_obj) { test_class.create! date_column => 3.days.ago }
|
86
|
+
let(:before_threshold_obj) { test_class.create! date_column => 2.days.ago }
|
87
|
+
|
88
|
+
it { should_not include after_threshold_obj }
|
89
|
+
it { should include on_threshold_obj }
|
90
|
+
it { should include before_threshold_obj }
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'last_n_months' do
|
94
|
+
subject { test_class.send("#{prefix}last_n_months", 3) }
|
95
|
+
|
96
|
+
let(:after_threshold_obj) { test_class.create! date_column => 4.months.ago }
|
97
|
+
let(:on_threshold_obj) { test_class.create! date_column => 3.months.ago }
|
98
|
+
let(:before_threshold_obj) { test_class.create! date_column => 2.months.ago }
|
99
|
+
|
100
|
+
it { should_not include after_threshold_obj }
|
101
|
+
it { should include on_threshold_obj }
|
102
|
+
it { should include before_threshold_obj }
|
103
|
+
end
|
104
|
+
|
105
|
+
describe 'last_n_years' do
|
106
|
+
subject { test_class.send("#{prefix}last_n_years", 3) }
|
107
|
+
|
108
|
+
let(:after_threshold_obj) { test_class.create! date_column => 4.years.ago }
|
109
|
+
let(:on_threshold_obj) { test_class.create! date_column => 3.years.ago }
|
110
|
+
let(:before_threshold_obj) { test_class.create! date_column => 2.years.ago }
|
111
|
+
|
112
|
+
it { should_not include after_threshold_obj }
|
113
|
+
it { should include on_threshold_obj }
|
114
|
+
it { should include before_threshold_obj }
|
115
|
+
end
|
116
|
+
|
117
|
+
describe 'next_n_days' do
|
118
|
+
subject { test_class.send("#{prefix}next_n_days", 3) }
|
119
|
+
|
120
|
+
let(:after_threshold_obj) { test_class.create! date_column => 2.days.from_now }
|
121
|
+
let(:on_threshold_obj) { test_class.create! date_column => 3.days.from_now }
|
122
|
+
let(:before_threshold_obj) { test_class.create! date_column => 4.days.from_now }
|
123
|
+
|
124
|
+
it { should include after_threshold_obj }
|
125
|
+
it { should include on_threshold_obj }
|
126
|
+
it { should_not include before_threshold_obj }
|
127
|
+
end
|
128
|
+
|
129
|
+
describe 'next_n_months' do
|
130
|
+
subject { test_class.send("#{prefix}next_n_months", 3) }
|
131
|
+
|
132
|
+
let(:after_threshold_obj) { test_class.create! date_column => 2.months.from_now }
|
133
|
+
let(:on_threshold_obj) { test_class.create! date_column => 3.months.from_now }
|
134
|
+
let(:before_threshold_obj) { test_class.create! date_column => 4.months.from_now }
|
135
|
+
|
136
|
+
it { should include after_threshold_obj }
|
137
|
+
it { should include on_threshold_obj }
|
138
|
+
it { should_not include before_threshold_obj }
|
139
|
+
end
|
140
|
+
|
141
|
+
describe 'next_n_years' do
|
142
|
+
subject { test_class.send("#{prefix}next_n_years", 3) }
|
143
|
+
|
144
|
+
let(:after_threshold_obj) { test_class.create! date_column => 2.years.from_now }
|
145
|
+
let(:on_threshold_obj) { test_class.create! date_column => 3.years.from_now }
|
146
|
+
let(:before_threshold_obj) { test_class.create! date_column => 4.years.from_now }
|
147
|
+
|
148
|
+
it { should include after_threshold_obj }
|
149
|
+
it { should include on_threshold_obj }
|
150
|
+
it { should_not include before_threshold_obj }
|
153
151
|
end
|
154
152
|
|
155
153
|
describe ":last_30_days" do
|
156
|
-
subject { test_class.last_30days }
|
154
|
+
subject { test_class.send("#{prefix}last_30days") }
|
157
155
|
|
158
156
|
it { should_not include last_month_obj }
|
159
157
|
it { should include last_week_obj }
|
160
158
|
it { should include yesterday_obj }
|
161
|
-
it { should include hour_ago_obj }
|
162
|
-
it { should include five_minute_ago_obj }
|
163
159
|
end
|
164
160
|
|
165
161
|
describe ":this_week" do
|
166
|
-
subject { test_class.this_week }
|
162
|
+
subject { test_class.send("#{prefix}this_week") }
|
167
163
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
it {
|
164
|
+
let(:before_week) { test_class.create! date_column => Date.today.beginning_of_week - 1.minute }
|
165
|
+
let(:at_beginning_of_week) { test_class.create! date_column => Date.today.beginning_of_week }
|
166
|
+
let(:after_week) { test_class.create! date_column => Date.today.beginning_of_week + 1.minute }
|
167
|
+
|
168
|
+
it { should_not include before_week }
|
169
|
+
it { should include at_beginning_of_week }
|
170
|
+
it { should include after_week }
|
173
171
|
end
|
174
172
|
|
175
173
|
describe ":this_month" do
|
176
|
-
subject { test_class.this_month }
|
174
|
+
subject { test_class.send("#{prefix}this_month") }
|
177
175
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
it {
|
176
|
+
let(:before_month) { test_class.create! date_column => Date.today.beginning_of_month - 1.minute }
|
177
|
+
let(:at_beginning_of_month) { test_class.create! date_column => Date.today.beginning_of_month }
|
178
|
+
let(:after_month) { test_class.create! date_column => Date.today.beginning_of_month + 1.minute }
|
179
|
+
|
180
|
+
it { should_not include before_month }
|
181
|
+
it { should include at_beginning_of_month }
|
182
|
+
it { should include after_month }
|
183
|
+
end
|
184
|
+
|
185
|
+
describe ":this_year" do
|
186
|
+
subject { test_class.send("#{prefix}this_year") }
|
187
|
+
|
188
|
+
let(:before_year) { test_class.create! date_column => Date.today.beginning_of_year - 1.minute }
|
189
|
+
let(:at_beginning_of_year) { test_class.create! date_column => Date.today.beginning_of_year }
|
190
|
+
let(:after_year) { test_class.create! date_column => Date.today.beginning_of_year + 1.minute }
|
191
|
+
|
192
|
+
it { should_not include before_year }
|
193
|
+
it { should include at_beginning_of_year }
|
194
|
+
it { should include after_year }
|
183
195
|
end
|
184
196
|
end
|
185
197
|
end
|
@@ -0,0 +1,422 @@
|
|
1
|
+
|
2
|
+
shared_examples "timestamp scopes" do |date_column = :created_at, prefix = '' |
|
3
|
+
let(:test_class) { Post }
|
4
|
+
describe "timestamp scopes" do
|
5
|
+
before(:all) { Timecop.freeze Time.local(2013,02,15,06,30) }
|
6
|
+
|
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
|
37
|
+
end
|
38
|
+
|
39
|
+
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) }
|
50
|
+
|
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
|
56
|
+
end
|
57
|
+
|
58
|
+
describe ':on_or_after' do
|
59
|
+
subject { test_class.send("#{prefix}on_or_after", 1.hour.ago) }
|
60
|
+
|
61
|
+
it { should_not include yesterday_obj }
|
62
|
+
it { should include hour_ago_obj }
|
63
|
+
it { should include five_minute_ago_obj }
|
64
|
+
end
|
65
|
+
|
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) }
|
69
|
+
|
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) }
|
77
|
+
|
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
|
83
|
+
end
|
84
|
+
|
85
|
+
describe ":before" do
|
86
|
+
context "with DateTime" do
|
87
|
+
subject { test_class.send("#{prefix}before", 1.hour.ago) }
|
88
|
+
|
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) }
|
96
|
+
|
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
|
102
|
+
end
|
103
|
+
|
104
|
+
describe ':on_or_before' do
|
105
|
+
subject { test_class.send("#{prefix}on_or_before", 1.hour.ago) }
|
106
|
+
|
107
|
+
it { should include yesterday_obj }
|
108
|
+
it { should include hour_ago_obj }
|
109
|
+
it { should_not include five_minute_ago_obj }
|
110
|
+
end
|
111
|
+
|
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) }
|
115
|
+
|
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 }
|
120
|
+
end
|
121
|
+
context "with Date" do
|
122
|
+
subject { test_class.send("#{prefix}on_or_before_date", Date.yesterday) }
|
123
|
+
|
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
|
129
|
+
end
|
130
|
+
|
131
|
+
describe ':on' do
|
132
|
+
subject { test_class.send("#{prefix}on", Date.today) }
|
133
|
+
|
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 }
|
138
|
+
end
|
139
|
+
|
140
|
+
describe ":today" do
|
141
|
+
subject { test_class.send("#{prefix}today") }
|
142
|
+
|
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
|
+
end
|
148
|
+
|
149
|
+
describe ":yesterday" do
|
150
|
+
subject { test_class.send("#{prefix}yesterday") }
|
151
|
+
|
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 }
|
156
|
+
end
|
157
|
+
|
158
|
+
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 }
|
165
|
+
end
|
166
|
+
|
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 }
|
174
|
+
end
|
175
|
+
|
176
|
+
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
|
+
end
|
184
|
+
|
185
|
+
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 }
|
194
|
+
end
|
195
|
+
|
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 }
|
205
|
+
end
|
206
|
+
|
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 }
|
217
|
+
end
|
218
|
+
|
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 }
|
229
|
+
end
|
230
|
+
|
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 }
|
241
|
+
end
|
242
|
+
|
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 }
|
253
|
+
end
|
254
|
+
|
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 }
|
265
|
+
end
|
266
|
+
|
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 }
|
277
|
+
end
|
278
|
+
|
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 }
|
289
|
+
end
|
290
|
+
|
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 }
|
301
|
+
end
|
302
|
+
|
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 }
|
313
|
+
end
|
314
|
+
|
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 }
|
325
|
+
end
|
326
|
+
|
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 }
|
337
|
+
end
|
338
|
+
|
339
|
+
describe 'next_n_years' do
|
340
|
+
subject { test_class.send("#{prefix}next_n_years", 3) }
|
341
|
+
|
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 }
|
345
|
+
|
346
|
+
it { should include after_threshold_obj }
|
347
|
+
it { should include on_threshold_obj }
|
348
|
+
it { should_not include before_threshold_obj }
|
349
|
+
end
|
350
|
+
|
351
|
+
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 }
|
359
|
+
end
|
360
|
+
|
361
|
+
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 }
|
371
|
+
end
|
372
|
+
|
373
|
+
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 }
|
379
|
+
|
380
|
+
it { should_not include before_hour }
|
381
|
+
it { should include at_beginning_of_hour }
|
382
|
+
it { should include after_hour }
|
383
|
+
end
|
384
|
+
|
385
|
+
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 }
|
395
|
+
end
|
396
|
+
|
397
|
+
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 }
|
407
|
+
end
|
408
|
+
|
409
|
+
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 }
|
419
|
+
end
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|