include_date_scopes 0.9.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +3 -4
- data/README.md +94 -0
- data/include_date_scopes.gemspec +1 -0
- data/lib/include_date_scopes/define_common_scopes.rb +8 -4
- data/lib/include_date_scopes/define_date_scopes.rb +10 -2
- data/lib/include_date_scopes/define_timestamp_scopes.rb +33 -16
- data/lib/include_date_scopes/version.rb +1 -1
- data/spec/lib/date_scopes_spec.rb +18 -8
- data/spec/spec_helper.rb +5 -4
- data/spec/support/date_scope_examples.rb +126 -120
- data/spec/support/timestamp_scope_examples.rb +155 -62
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c585c13b5ffafee45ecf2db6c37812c8c003a7ae
|
4
|
+
data.tar.gz: 77647c80fd039022fe644e5ba3d06da80b6401b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cba126e9c7ff5920d166a91d2e3403bd3918e4ad7633bed6822f06a6e4c8357799cf8634468bc9f2a8097cdc5a515d56829a801ba583a35946216cb79db89e41
|
7
|
+
data.tar.gz: cf563efd3e8820b8f3f43d9d4eef60d92a56b5ea562e30039f8949e026c93415a6ea2696b96e53ad5aec1cebd29cc91561a207da650cee16a1800c6528c2f7f0
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.2.4
|
data/Gemfile
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
gem 'appraisal'
|
4
3
|
gemspec
|
5
4
|
|
6
5
|
# *************************************
|
@@ -8,7 +7,7 @@ gemspec
|
|
8
7
|
# * If you have any local gems to include, create a new Gemfile at ~/.Gemfile
|
9
8
|
# * This code will import anything in there.
|
10
9
|
# *************************************
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
if File.exists? File.join(Dir.home,'.Gemfile')
|
11
|
+
eval File.read File.join(Dir.home,'.Gemfile')
|
12
|
+
end
|
14
13
|
|
data/README.md
CHANGED
@@ -30,3 +30,97 @@ class Post < ActiveRecord::Base
|
|
30
30
|
end
|
31
31
|
```
|
32
32
|
Now the scopes will all be prepended with `updated_at_`. So `Post.yesterday` would become `Post.updated_at_yesterday`.
|
33
|
+
|
34
|
+
Date Scopes
|
35
|
+
-------
|
36
|
+
|
37
|
+
| Method | Description |
|
38
|
+
| --- | --- |
|
39
|
+
| `between(start_date,stop_date)` | On or after start_date and on or before stop_date |
|
40
|
+
| `on(date)` | |
|
41
|
+
| `on_or_before(date)` | |
|
42
|
+
| `on_or_before_date(date)` | |
|
43
|
+
| `on_or_after(date)` | |
|
44
|
+
| `on_or_after_date(date)` | |
|
45
|
+
| `before(date)` | |
|
46
|
+
| `after(date)` | |
|
47
|
+
| `day(date)` | Syonym for `on(date)` |
|
48
|
+
| `today` | |
|
49
|
+
| `yesterday` | |
|
50
|
+
| `tomorrow` | |
|
51
|
+
| `this_day` | On the current day |
|
52
|
+
| `this_week` | Within the current week (Monday thru Sunday) |
|
53
|
+
| `this_month` | Within the current month |
|
54
|
+
| `this_year` | Within the current year |
|
55
|
+
| `next_day` | Today or tomorrow |
|
56
|
+
| `next_week` | Today through the next 7 days |
|
57
|
+
| `next_month` | Today through the same day next month |
|
58
|
+
| `next_year` | Today through the same day next year |
|
59
|
+
| `last_day` | Yesterday or today |
|
60
|
+
| `last_week` | Last 7 days through today |
|
61
|
+
| `last_month` | Same day last month through today |
|
62
|
+
| `last_year` | Same day last year through today |
|
63
|
+
| `next_n_days(number)` | Within the next `number` days |
|
64
|
+
| `next_n_weeks(number)` | |
|
65
|
+
| `next_n_months(number)` | |
|
66
|
+
| `next_n_years(number)` | |
|
67
|
+
| `last_n_days(number)` | Within the last `number` days |
|
68
|
+
| `last_n_weeks(number)` | |
|
69
|
+
| `last_n_months(number)` | |
|
70
|
+
| `last_n_years(number)` | |
|
71
|
+
| `last_30_days` | Synonym for `last_n_days(30)` |
|
72
|
+
| `most_recent` | Orders most recent first |
|
73
|
+
|
74
|
+
Timestamp Scopes
|
75
|
+
----------------
|
76
|
+
|
77
|
+
| Method | Description |
|
78
|
+
| --- | --- |
|
79
|
+
| `between(start_time_or_date,stop_time_or_date)` | If start_date_or_time is a Date, the interval INCLUDES the start of the day; otherwise, the interval INCLUDES the argument time. If stop_date_or_time is a Date, the interval INCLUDES the end date; otherwise, the interval EXCLUDES the argument time. |
|
80
|
+
| `on(date)` | |
|
81
|
+
| `on_or_before(time_or_date)` | At or before a Time argument, or on or before a Date argument |
|
82
|
+
| `on_or_before_date(time_or_date)` | Converts a Time argument to Date |
|
83
|
+
| `on_or_after(time_or_date)` | At or after a Time argument, or on or after a Date argument |
|
84
|
+
| `on_or_after_date(time_or_date)` | Converts a Time argument to Date |
|
85
|
+
| `before(time_or_date)` | |
|
86
|
+
| `after(time_or_date)` | |
|
87
|
+
| `day(date)` | Synonym for `on(date)` |
|
88
|
+
| `today` | |
|
89
|
+
| `yesterday` | |
|
90
|
+
| `tomorrow` | |
|
91
|
+
| `this_minute` | Within the current minute |
|
92
|
+
| `this_hour` | Within the current hour |
|
93
|
+
| `this_day` | Within the current day |
|
94
|
+
| `this_week` | Within the current week (Monday thru Sunday) |
|
95
|
+
| `this_month` | Within the current month |
|
96
|
+
| `this_year` | Within the current year |
|
97
|
+
| `next_minute` | Within the next 60 seconds |
|
98
|
+
| `next_hour` | Within the next 3600 seconds |
|
99
|
+
| `next_day` | Within the next 86400 seconds |
|
100
|
+
| `next_week` | Within the next 604800 seconds |
|
101
|
+
| `next_month` | Until the same time next month |
|
102
|
+
| `next_year` | Until the same time next year |
|
103
|
+
| `last_minute` | From 60 seconds ago until the next second |
|
104
|
+
| `last_hour` | From 3600 seconds ago until the next second |
|
105
|
+
| `last_day` | From 86400 seconds ago until the next second |
|
106
|
+
| `last_24_hours` | Synonym for `last_day` |
|
107
|
+
| `last_week` | From 604800 seconds ago until the next second |
|
108
|
+
| `last_month` | From the same time last month until the next second |
|
109
|
+
| `last_year` | From the same time last year until the next second |
|
110
|
+
| `next_n_seconds(number)` | Within the next `number` seconds |
|
111
|
+
| `next_n_minutes(number)` | |
|
112
|
+
| `next_n_hours(number)` | |
|
113
|
+
| `next_n_days(number)` | |
|
114
|
+
| `next_n_weeks(number)` | |
|
115
|
+
| `next_n_months(number)` | |
|
116
|
+
| `next_n_years(number)` | |
|
117
|
+
| `last_n_seconds(number)` | Within the last `number` seconds |
|
118
|
+
| `last_n_minutes(number)` | |
|
119
|
+
| `last_n_hours(number)` | |
|
120
|
+
| `last_n_days(number)` | |
|
121
|
+
| `last_n_weeks(number)` | |
|
122
|
+
| `last_n_months(number)` | |
|
123
|
+
| `last_n_years(number)` | |
|
124
|
+
| `last_30_days` | Synonym for `last_n_days(30)` |
|
125
|
+
| `most_recent` | Orders most recent first |
|
126
|
+
|
data/include_date_scopes.gemspec
CHANGED
@@ -23,5 +23,6 @@ DESCRIPTION
|
|
23
23
|
s.add_dependency "railties"
|
24
24
|
s.add_development_dependency "rspec-rails", "2.14.2"
|
25
25
|
s.add_development_dependency "sqlite3", "1.3.9"
|
26
|
+
# s.add_development_dependency "mysql2", "~> 0.3.10" # TODO: How to dynamically choose sqlite or mysql?
|
26
27
|
s.add_development_dependency 'timecop', "0.7.1"
|
27
28
|
end
|
@@ -20,16 +20,20 @@ module IncludeDateScopes
|
|
20
20
|
|
21
21
|
[:day, :week, :month, :year].each do |time_unit|
|
22
22
|
define_singleton_method :"#{prefix}next_#{time_unit}" do
|
23
|
-
|
23
|
+
now = Time.now
|
24
|
+
__send__(:"#{prefix}between", now, now + 1.send(time_unit))
|
24
25
|
end
|
25
26
|
define_singleton_method :"#{prefix}last_#{time_unit}" do
|
26
|
-
|
27
|
+
now = Time.now
|
28
|
+
__send__(:"#{prefix}between", now - 1.send(time_unit), now + 1.second)
|
27
29
|
end
|
28
30
|
define_singleton_method :"#{prefix}next_n_#{time_unit}s" do |count|
|
29
|
-
|
31
|
+
now = Time.now
|
32
|
+
__send__(:"#{prefix}between", now, now + count.send(time_unit))
|
30
33
|
end
|
31
34
|
define_singleton_method :"#{prefix}last_n_#{time_unit}s" do |count|
|
32
|
-
|
35
|
+
now = Time.now
|
36
|
+
__send__(:"#{prefix}between", now - count.send(time_unit), now + 1.second)
|
33
37
|
end
|
34
38
|
end
|
35
39
|
|
@@ -10,7 +10,14 @@ module IncludeDateScopes
|
|
10
10
|
end
|
11
11
|
|
12
12
|
{:on_or_before => :lteq, :before => :lt, :on_or_after => :gteq, :after => :gt, :on => :eq}.each do |label, op|
|
13
|
-
define_singleton_method :"#{prefix}#{label}" do |
|
13
|
+
define_singleton_method :"#{prefix}#{label}" do |date_or_time|
|
14
|
+
if date_or_time.kind_of? Time
|
15
|
+
date = date_or_time.to_date
|
16
|
+
elsif date_or_time.kind_of? DateTime
|
17
|
+
date = date_or_time.to_date
|
18
|
+
else
|
19
|
+
date = date_or_time
|
20
|
+
end
|
14
21
|
where t[column_name].send op, date
|
15
22
|
end
|
16
23
|
end
|
@@ -21,7 +28,8 @@ module IncludeDateScopes
|
|
21
28
|
|
22
29
|
[:week, :month, :year].each do |time_unit|
|
23
30
|
define_singleton_method :"#{prefix}this_#{time_unit}" do
|
24
|
-
|
31
|
+
today = Date.today
|
32
|
+
__send__(:"#{prefix}between", today.send(:"beginning_of_#{time_unit}"), today.send(:"end_of_#{time_unit}"))
|
25
33
|
end
|
26
34
|
end
|
27
35
|
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module IncludeDateScopes
|
3
2
|
module DefineTimestampScopes
|
4
3
|
|
@@ -7,37 +6,49 @@ module IncludeDateScopes
|
|
7
6
|
t = self.arel_table
|
8
7
|
|
9
8
|
define_singleton_method :"#{prefix}between" do |start_date_or_time, stop_date_or_time|
|
9
|
+
# If start_date_or_time is a Date, the interval INCLUDES the start of the day; otherwise, the interval INCLUDES the argument time.
|
10
|
+
# If stop_date_or_time is a Date, the interval INCLUDES the end date; otherwise, the interval EXCLUDES the argument time.
|
11
|
+
# For example between(Date.today, Date.today) is equivalent to between(Date.today.midnight, Date.tomorrow.midnight).
|
10
12
|
start_time = (start_date_or_time.is_a?(Date) ? start_date_or_time.to_time : start_date_or_time)
|
11
13
|
stop_time = (stop_date_or_time.is_a?(Date) ? stop_date_or_time.to_time + 1.day : stop_date_or_time )
|
12
14
|
where(t[column_name].gteq(start_time).and(t[column_name].lt stop_time))
|
13
15
|
end
|
14
16
|
|
15
17
|
define_singleton_method :"#{prefix}on_or_before_date" do |date|
|
16
|
-
where(
|
18
|
+
where(t[column_name].lt date.to_date.tomorrow.midnight)
|
17
19
|
end
|
18
20
|
|
19
|
-
define_singleton_method :"#{prefix}on_or_before" do |time|
|
20
|
-
|
21
|
+
define_singleton_method :"#{prefix}on_or_before" do |time|
|
22
|
+
if time.is_a?(Date)
|
23
|
+
where(t[column_name].lt time.to_time + 1.day)
|
24
|
+
else
|
25
|
+
where(t[column_name].lteq time)
|
26
|
+
end
|
21
27
|
end
|
22
28
|
|
23
|
-
define_singleton_method :"#{prefix}before" do |time|
|
24
|
-
|
29
|
+
define_singleton_method :"#{prefix}before" do |time|
|
30
|
+
time = time.to_time if time.kind_of? Date
|
31
|
+
where(t[column_name].lt time)
|
25
32
|
end
|
26
33
|
|
27
34
|
define_singleton_method :"#{prefix}on_or_after_date" do |time|
|
28
|
-
where(t[column_name].gteq time.to_date.midnight
|
35
|
+
where(t[column_name].gteq time.to_date.midnight)
|
29
36
|
end
|
30
37
|
|
31
38
|
define_singleton_method :"#{prefix}on_or_after" do |time|
|
32
|
-
where(t[column_name].gteq
|
39
|
+
where(t[column_name].gteq time.to_time)
|
33
40
|
end
|
34
41
|
|
35
42
|
define_singleton_method :"#{prefix}after" do |time|
|
36
|
-
|
43
|
+
if time.is_a?(Date)
|
44
|
+
where(t[column_name].gteq time.to_time + 1.day)
|
45
|
+
else
|
46
|
+
where(t[column_name].gt time)
|
47
|
+
end
|
37
48
|
end
|
38
49
|
|
39
50
|
define_singleton_method :"#{prefix}on" do |day|
|
40
|
-
__send__(:"#{prefix}between", day.
|
51
|
+
__send__(:"#{prefix}between", day.to_date, day.to_date)
|
41
52
|
end
|
42
53
|
|
43
54
|
define_singleton_method :"#{prefix}last_24_hours" do
|
@@ -46,31 +57,37 @@ module IncludeDateScopes
|
|
46
57
|
|
47
58
|
[:minute, :hour].each do |time_unit|
|
48
59
|
define_singleton_method :"#{prefix}next_#{time_unit}" do
|
49
|
-
|
60
|
+
start_time = Time.now
|
61
|
+
__send__(:"#{prefix}between", start_time, start_time + 1.send(time_unit))
|
50
62
|
end
|
51
63
|
|
52
64
|
define_singleton_method :"#{prefix}last_#{time_unit}" do
|
53
|
-
|
65
|
+
now = Time.now
|
66
|
+
__send__(:"#{prefix}between", now - 1.send(time_unit), now + 1.second)
|
54
67
|
end
|
55
68
|
end
|
56
69
|
|
57
70
|
[:seconds, :minutes, :hours].each do |time_unit|
|
58
71
|
define_singleton_method :"#{prefix}last_n_#{time_unit}" do |count|
|
59
|
-
|
72
|
+
now = Time.now
|
73
|
+
__send__(:"#{prefix}between", now - count.send(time_unit), now + 1.second)
|
60
74
|
end
|
61
75
|
|
62
76
|
define_singleton_method :"#{prefix}next_n_#{time_unit}" do |count|
|
63
|
-
|
77
|
+
start_time = Time.now
|
78
|
+
__send__(:"#{prefix}between", start_time, start_time + count.send(time_unit))
|
64
79
|
end
|
65
80
|
end
|
66
81
|
|
67
82
|
define_singleton_method :"#{prefix}this_minute" do
|
68
|
-
|
83
|
+
start_time = Time.now.change(sec: 0)
|
84
|
+
__send__(:"#{prefix}between", start_time, start_time + 1.minute)
|
69
85
|
end
|
70
86
|
|
71
87
|
[:hour, :day, :week, :month, :year].each do |time_unit|
|
72
88
|
define_singleton_method :"#{prefix}this_#{time_unit}" do
|
73
|
-
|
89
|
+
start_time = Time.now.send(:"beginning_of_#{time_unit}")
|
90
|
+
__send__(:"#{prefix}between", start_time, start_time + 1.send(:"#{time_unit}"))
|
74
91
|
end
|
75
92
|
end
|
76
93
|
|
@@ -1,6 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Model" do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
# puts "Local time: #{Time.now}"
|
7
|
+
# puts "UTC time: #{Time.now.gmtime}"
|
8
|
+
end
|
9
|
+
|
4
10
|
describe 'default timestamp scopes' do
|
5
11
|
before(:all) do
|
6
12
|
define_model_class do
|
@@ -34,17 +40,19 @@ describe "Model" do
|
|
34
40
|
describe 'date scopes' do
|
35
41
|
before(:all) do
|
36
42
|
define_model_class do
|
37
|
-
|
43
|
+
include_named_date_scopes_for :show_until
|
38
44
|
end
|
39
45
|
end
|
40
46
|
|
41
|
-
it_behaves_like 'date scopes', :show_until
|
47
|
+
it_behaves_like 'date scopes', :show_until, 'show_until_'
|
42
48
|
end
|
43
49
|
|
44
50
|
describe 'providing column type' do
|
45
51
|
before(:all) do
|
46
52
|
define_model_class do
|
47
|
-
|
53
|
+
# Note that using date scopes to query a datetime column will yield incorrect results unless
|
54
|
+
# the database timezone is the same as the local timezone.
|
55
|
+
include_date_scopes_for :show_at, true, :date
|
48
56
|
end
|
49
57
|
end
|
50
58
|
|
@@ -52,7 +60,9 @@ describe "Model" do
|
|
52
60
|
expect(Post).not_to respond_to(:last_n_minutes)
|
53
61
|
end
|
54
62
|
|
55
|
-
|
63
|
+
# Note that these specs succeed because the test threshold has only date granularity.
|
64
|
+
# For a true datetime column the thresholds should have second granularity.
|
65
|
+
it_behaves_like('date scopes', :show_at, 'show_at_')
|
56
66
|
end
|
57
67
|
|
58
68
|
describe 'using a non-date argument' do
|
@@ -62,11 +72,11 @@ describe "Model" do
|
|
62
72
|
# word that's also used by my framework.
|
63
73
|
it 'does not raise an error' do
|
64
74
|
define_model_class do
|
65
|
-
|
75
|
+
include_named_date_scopes_for :show_at
|
76
|
+
include_named_date_scopes_for :show_until
|
66
77
|
end
|
67
|
-
expect {
|
68
|
-
|
69
|
-
}.to_not raise_error
|
78
|
+
expect { Post.show_at_before('abc') }.to_not raise_error
|
79
|
+
expect { Post.show_until_before('abc') }.to_not raise_error
|
70
80
|
end
|
71
81
|
end
|
72
82
|
|
data/spec/spec_helper.rb
CHANGED
@@ -17,17 +17,18 @@ if RUBY_PLATFORM == "java"
|
|
17
17
|
database_adapter = "jdbcsqlite3"
|
18
18
|
else
|
19
19
|
database_adapter = "sqlite3"
|
20
|
+
# database_adapter = "mysql2"
|
20
21
|
end
|
21
22
|
|
22
|
-
ActiveRecord::Base.default_timezone = :
|
23
|
+
ActiveRecord::Base.default_timezone = :utc
|
23
24
|
ActiveRecord::Base.logger = Logger.new(STDERR)
|
24
25
|
ActiveRecord::Base.logger.level = Logger::WARN
|
25
26
|
ActiveRecord::Base.establish_connection(
|
26
27
|
:adapter => database_adapter,
|
27
|
-
:database => ':memory:'
|
28
|
+
:database => (database_adapter == "sqlite3" ? ':memory:' : 'include_date_scopes_test')
|
28
29
|
)
|
29
30
|
ActiveRecord::Base.connection.create_table(:posts, :force => true) do |t|
|
30
|
-
t.
|
31
|
+
t.datetime :show_at
|
31
32
|
t.date :show_until
|
32
33
|
t.timestamp :created_at
|
33
34
|
t.timestamp :updated_at
|
@@ -45,7 +46,7 @@ RSpec.configure do |config|
|
|
45
46
|
Post.delete_all
|
46
47
|
end
|
47
48
|
|
48
|
-
config.before(:suite) { Timecop.freeze Time.local(2013,02,15,
|
49
|
+
config.before(:suite) { Timecop.freeze Time.local(2013,02,15,18,30,47) } # next day as utc
|
49
50
|
end
|
50
51
|
|
51
52
|
def define_model_class(name = "Post", parent_class_name = "ActiveRecord::Base", &block)
|
@@ -1,259 +1,265 @@
|
|
1
|
-
|
2
1
|
shared_examples "between date scope" do |name|
|
3
|
-
|
4
|
-
|
5
|
-
# include_examples 'between time scope', name, 1.day
|
6
|
-
end
|
7
|
-
|
8
|
-
context 'with date argument' do
|
9
|
-
subject do
|
10
|
-
test_class.send("#{prefix}#{name}", *arguments).to_a
|
11
|
-
end
|
2
|
+
# agruments may be Date or Time values
|
3
|
+
# top_threshold and bottom_threshold should be Date values
|
12
4
|
|
13
|
-
|
14
|
-
let(:at_top_threshold_obj) { test_class.create! date_column => top_threshold.to_date }
|
15
|
-
let(:at_bottom_threshold_obj) { test_class.create! date_column => bottom_threshold.to_date }
|
16
|
-
let(:before_threshold_obj) { test_class.create! date_column => bottom_threshold.to_date + 1.day }
|
5
|
+
subject { test_class.send("#{prefix}#{name}", *arguments).to_a }
|
17
6
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
it { should_not include before_threshold_obj }
|
7
|
+
before do
|
8
|
+
# puts "#{prefix}#{name}: #{arguments.to_s}"
|
9
|
+
# puts test_class.send("#{prefix}#{name}", *arguments).to_sql
|
22
10
|
end
|
23
|
-
end
|
24
11
|
|
25
|
-
|
26
|
-
let(:
|
27
|
-
let(:
|
28
|
-
let(:
|
12
|
+
let(:before_threshold_obj) { test_class.create! date_column => top_threshold.to_date - 1.day }
|
13
|
+
let(:at_top_threshold_obj) { test_class.create! date_column => top_threshold.to_date }
|
14
|
+
let(:at_bottom_threshold_obj) { test_class.create! date_column => bottom_threshold.to_date }
|
15
|
+
let(:after_threshold_obj) { test_class.create! date_column => bottom_threshold.to_date + 1.day }
|
29
16
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
let(:at_top_threshold_obj) { test_class.create! date_column => 3.days.ago.to_date }
|
36
|
-
let(:at_bottom_threshold_obj) { test_class.create! date_column => 6.days.ago.to_date }
|
37
|
-
let(:before_threshold_obj) { test_class.create! date_column => 7.days.ago.to_date }
|
38
|
-
|
39
|
-
it { should_not include after_threshold_obj }
|
40
|
-
it { should include at_top_threshold_obj }
|
41
|
-
it { should include at_bottom_threshold_obj }
|
42
|
-
it { should_not include before_threshold_obj }
|
43
|
-
end
|
17
|
+
it { should_not include before_threshold_obj }
|
18
|
+
it { should include at_top_threshold_obj }
|
19
|
+
it { should include at_bottom_threshold_obj }
|
20
|
+
it { should_not include after_threshold_obj }
|
21
|
+
end
|
44
22
|
|
45
|
-
|
46
|
-
|
23
|
+
shared_examples "before date scope" do |name|
|
24
|
+
# agruments may be Date or Time values
|
25
|
+
# threshold should be a Date value
|
47
26
|
|
48
|
-
|
49
|
-
let(:on_threshold_obj) { test_class.create! date_column => 3.days.ago.to_date }
|
50
|
-
let(:before_threshold_obj) { test_class.create! date_column => 4.days.ago.to_date }
|
27
|
+
subject { test_class.send("#{prefix}#{name}", *arguments).to_a }
|
51
28
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
29
|
+
# threshold is most recent date NOT included in the interval
|
30
|
+
let(:before_top_threshold_obj) { test_class.create! date_column => threshold - 1.day }
|
31
|
+
let(:at_top_threshold_obj) { test_class.create! date_column => threshold }
|
56
32
|
|
57
|
-
|
58
|
-
|
33
|
+
before do
|
34
|
+
# puts "#{prefix}#{name}: #{arguments.to_s}"
|
35
|
+
# puts test_class.send("#{prefix}#{name}", *arguments).to_sql
|
36
|
+
end
|
59
37
|
|
60
|
-
|
61
|
-
|
62
|
-
|
38
|
+
it { should include before_top_threshold_obj }
|
39
|
+
it { should_not include at_top_threshold_obj }
|
40
|
+
end
|
63
41
|
|
64
|
-
|
65
|
-
|
66
|
-
it { should_not include before_threshold_obj }
|
67
|
-
end
|
42
|
+
shared_examples "after date scope" do |name|
|
43
|
+
subject { test_class.send("#{prefix}#{name}", *arguments).to_a }
|
68
44
|
|
69
|
-
|
70
|
-
|
45
|
+
# threshold is oldest date included in the interval
|
46
|
+
let(:before_top_threshold_obj) { test_class.create! date_column => threshold - 1.day }
|
47
|
+
let(:at_top_threshold_obj) { test_class.create! date_column => threshold }
|
71
48
|
|
72
|
-
|
73
|
-
|
74
|
-
|
49
|
+
before do
|
50
|
+
# puts "#{prefix}#{name}: #{arguments.to_s}"
|
51
|
+
# puts test_class.send("#{prefix}#{name}", *arguments).to_sql
|
52
|
+
end
|
75
53
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
54
|
+
it { should_not include before_top_threshold_obj }
|
55
|
+
it { should include at_top_threshold_obj }
|
56
|
+
end
|
80
57
|
|
81
|
-
|
82
|
-
|
58
|
+
shared_examples "date scopes" do |date_column = :show_until, prefix = '' |
|
59
|
+
let(:test_class) { Post }
|
60
|
+
let(:prefix) { prefix }
|
61
|
+
let(:date_column) { date_column }
|
83
62
|
|
84
|
-
|
85
|
-
|
86
|
-
|
63
|
+
[:to_date, :to_time].each do |postfix|
|
64
|
+
describe ":between" do
|
65
|
+
let(:top_threshold) { 6.days.ago.to_date }
|
66
|
+
let(:bottom_threshold) { 3.days.ago.to_date }
|
67
|
+
let(:arguments) { [6.days.ago.send(postfix), 3.day.ago.send(postfix)] }
|
68
|
+
include_examples 'between date scope','between'
|
69
|
+
end
|
70
|
+
|
71
|
+
describe ":before" do
|
72
|
+
let(:threshold) { 3.days.ago.to_date }
|
73
|
+
let(:arguments) { [ 3.days.ago.send(postfix) ] }
|
74
|
+
include_examples 'before date scope','before'
|
75
|
+
end
|
76
|
+
|
77
|
+
describe ":on_or_before" do
|
78
|
+
let(:threshold) { 2.days.ago.to_date }
|
79
|
+
let(:arguments) { [ 3.days.ago.send(postfix) ] }
|
80
|
+
include_examples 'before date scope','on_or_before'
|
81
|
+
end
|
82
|
+
|
83
|
+
describe ":after" do
|
84
|
+
let(:threshold) { 2.days.ago.to_date }
|
85
|
+
let(:arguments) { [ 3.days.ago.send(postfix) ] }
|
86
|
+
include_examples 'after date scope','after'
|
87
|
+
end
|
88
|
+
|
89
|
+
describe ":on_or_after" do
|
90
|
+
let(:threshold) { 3.days.ago.to_date }
|
91
|
+
let(:arguments) { [ 3.days.ago.send(postfix) ] }
|
92
|
+
include_examples 'after date scope','on_or_after'
|
93
|
+
end
|
87
94
|
|
88
|
-
it { should include after_threshold_obj }
|
89
|
-
it { should include on_threshold_obj }
|
90
|
-
it { should_not include before_threshold_obj }
|
91
95
|
end
|
92
96
|
|
97
|
+
describe "date scopes" do
|
98
|
+
|
93
99
|
describe ":today" do
|
94
|
-
let(:top_threshold) {
|
95
|
-
let(:bottom_threshold) {
|
100
|
+
let(:top_threshold) { Date.today }
|
101
|
+
let(:bottom_threshold) { Date.today }
|
96
102
|
let(:arguments) { [] }
|
97
103
|
include_examples 'between date scope','today'
|
98
104
|
end
|
99
105
|
|
100
106
|
describe ":yesterday" do
|
101
|
-
let(:top_threshold) {
|
102
|
-
let(:bottom_threshold) {
|
107
|
+
let(:top_threshold) { Date.yesterday }
|
108
|
+
let(:bottom_threshold) { Date.yesterday }
|
103
109
|
let(:arguments) { [] }
|
104
110
|
include_examples 'between date scope','yesterday'
|
105
111
|
end
|
106
112
|
|
107
113
|
describe ":tomorrow" do
|
108
|
-
let(:top_threshold) {
|
109
|
-
let(:bottom_threshold) {
|
114
|
+
let(:top_threshold) { Date.tomorrow }
|
115
|
+
let(:bottom_threshold) { Date.tomorrow }
|
110
116
|
let(:arguments) { [] }
|
111
117
|
include_examples 'between date scope','tomorrow'
|
112
118
|
end
|
113
119
|
|
114
120
|
describe ":next_day" do
|
115
|
-
let(:
|
116
|
-
let(:
|
121
|
+
let(:top_threshold) { Date.today }
|
122
|
+
let(:bottom_threshold) { Date.tomorrow }
|
117
123
|
let(:arguments) { [] }
|
118
124
|
include_examples 'between date scope','next_day'
|
119
125
|
end
|
120
126
|
|
121
127
|
describe ":next_week" do
|
122
|
-
let(:
|
123
|
-
let(:
|
128
|
+
let(:top_threshold) { Date.today }
|
129
|
+
let(:bottom_threshold) { Date.today + 1.week }
|
124
130
|
let(:arguments) { [] }
|
125
131
|
include_examples 'between date scope','next_week'
|
126
132
|
end
|
127
133
|
|
128
134
|
describe ":next_month" do
|
129
|
-
let(:
|
130
|
-
let(:
|
135
|
+
let(:top_threshold) { Date.today }
|
136
|
+
let(:bottom_threshold) { Date.today + 1.month }
|
131
137
|
let(:arguments) { [] }
|
132
138
|
include_examples 'between date scope','next_month'
|
133
139
|
end
|
134
140
|
|
135
141
|
describe ":next_year" do
|
136
|
-
let(:
|
137
|
-
let(:
|
142
|
+
let(:top_threshold) { Date.today }
|
143
|
+
let(:bottom_threshold) { Date.today + 1.year }
|
138
144
|
let(:arguments) { [] }
|
139
145
|
include_examples 'between date scope','next_year'
|
140
146
|
end
|
141
147
|
|
142
148
|
describe ":last_day" do
|
143
|
-
let(:top_threshold) {
|
144
|
-
let(:bottom_threshold) {
|
149
|
+
let(:top_threshold) { Date.yesterday }
|
150
|
+
let(:bottom_threshold) { Date.today }
|
145
151
|
let(:arguments) { [] }
|
146
152
|
include_examples 'between date scope','last_day'
|
147
153
|
end
|
148
154
|
|
149
155
|
describe ":last_week" do
|
150
|
-
let(:top_threshold) { 1.week
|
151
|
-
let(:bottom_threshold) {
|
156
|
+
let(:top_threshold) { Date.today - 1.week }
|
157
|
+
let(:bottom_threshold) { Date.today }
|
152
158
|
let(:arguments) { [] }
|
153
159
|
include_examples 'between date scope','last_week'
|
154
160
|
end
|
155
161
|
|
156
162
|
describe ":last_month" do
|
157
|
-
let(:top_threshold) { 1.month
|
158
|
-
let(:bottom_threshold) {
|
163
|
+
let(:top_threshold) { Date.today - 1.month }
|
164
|
+
let(:bottom_threshold) { Date.today }
|
159
165
|
let(:arguments) { [] }
|
160
166
|
include_examples 'between date scope','last_month'
|
161
167
|
end
|
162
168
|
|
163
169
|
describe ":last_year" do
|
164
|
-
let(:top_threshold) { 1.year
|
165
|
-
let(:bottom_threshold) {
|
170
|
+
let(:top_threshold) { Date.today - 1.year }
|
171
|
+
let(:bottom_threshold) { Date.today }
|
166
172
|
let(:arguments) { [] }
|
167
173
|
include_examples 'between date scope','last_year'
|
168
174
|
end
|
169
175
|
|
170
176
|
describe ":last_n_days" do
|
171
|
-
let(:top_threshold) { 3.days
|
172
|
-
let(:bottom_threshold) {
|
177
|
+
let(:top_threshold) { Date.today - 3.days }
|
178
|
+
let(:bottom_threshold) { Date.today }
|
173
179
|
let(:arguments) { [3] }
|
174
180
|
include_examples 'between date scope','last_n_days'
|
175
181
|
end
|
176
182
|
|
177
183
|
describe ":last_n_weeks" do
|
178
|
-
let(:top_threshold) { 3.weeks
|
179
|
-
let(:bottom_threshold) {
|
184
|
+
let(:top_threshold) { Date.today - 3.weeks }
|
185
|
+
let(:bottom_threshold) { Date.today }
|
180
186
|
let(:arguments) { [3] }
|
181
187
|
include_examples 'between date scope','last_n_weeks'
|
182
188
|
end
|
183
189
|
|
184
190
|
describe ":last_n_months" do
|
185
|
-
let(:top_threshold) { 3.months
|
186
|
-
let(:bottom_threshold) {
|
191
|
+
let(:top_threshold) { Date.today - 3.months }
|
192
|
+
let(:bottom_threshold) { Date.today }
|
187
193
|
let(:arguments) { [3] }
|
188
194
|
include_examples 'between date scope','last_n_months'
|
189
195
|
end
|
190
196
|
|
191
197
|
describe ":last_n_years" do
|
192
|
-
let(:top_threshold) { 3.years
|
193
|
-
let(:bottom_threshold) {
|
198
|
+
let(:top_threshold) { Date.today - 3.years }
|
199
|
+
let(:bottom_threshold) { Date.today }
|
194
200
|
let(:arguments) { [3] }
|
195
201
|
include_examples 'between date scope','last_n_years'
|
196
202
|
end
|
197
203
|
|
198
204
|
describe ":next_n_days" do
|
199
|
-
let(:top_threshold) {
|
200
|
-
let(:bottom_threshold) { 3.days
|
205
|
+
let(:top_threshold) { Date.today }
|
206
|
+
let(:bottom_threshold) { Date.today + 3.days }
|
201
207
|
let(:arguments) { [3] }
|
202
208
|
include_examples 'between date scope','next_n_days'
|
203
209
|
end
|
204
210
|
|
205
211
|
describe ":next_n_weeks" do
|
206
|
-
let(:top_threshold) {
|
207
|
-
let(:bottom_threshold) { 3.weeks
|
212
|
+
let(:top_threshold) { Date.today }
|
213
|
+
let(:bottom_threshold) { Date.today + 3.weeks }
|
208
214
|
let(:arguments) { [3] }
|
209
215
|
include_examples 'between date scope','next_n_weeks'
|
210
216
|
end
|
211
217
|
|
212
218
|
describe ":next_n_months" do
|
213
|
-
let(:top_threshold) {
|
214
|
-
let(:bottom_threshold) { 3.months
|
219
|
+
let(:top_threshold) { Date.today }
|
220
|
+
let(:bottom_threshold) { Date.today + 3.months }
|
215
221
|
let(:arguments) { [3] }
|
216
222
|
include_examples 'between date scope','next_n_months'
|
217
223
|
end
|
218
224
|
|
219
225
|
describe ":next_n_years" do
|
220
|
-
let(:top_threshold) {
|
221
|
-
let(:bottom_threshold) { 3.years
|
226
|
+
let(:top_threshold) { Date.today }
|
227
|
+
let(:bottom_threshold) { Date.today + 3.years }
|
222
228
|
let(:arguments) { [3] }
|
223
229
|
include_examples 'between date scope','next_n_years'
|
224
230
|
end
|
225
231
|
|
226
232
|
describe ":last_30_days" do
|
227
|
-
let(:top_threshold) { 30.days
|
228
|
-
let(:bottom_threshold) {
|
233
|
+
let(:top_threshold) { Date.today - 30.days }
|
234
|
+
let(:bottom_threshold) { Date.today }
|
229
235
|
let(:arguments) { [] }
|
230
236
|
include_examples 'between date scope','last_30_days'
|
231
237
|
end
|
232
238
|
|
233
239
|
describe ":this_day" do
|
234
|
-
let(:top_threshold) {
|
235
|
-
let(:bottom_threshold) {
|
240
|
+
let(:top_threshold) { Date.today }
|
241
|
+
let(:bottom_threshold) { Date.today }
|
236
242
|
let(:arguments) { [] }
|
237
243
|
include_examples 'between date scope','this_day'
|
238
244
|
end
|
239
245
|
|
240
246
|
describe ":this_week" do
|
241
|
-
let(:top_threshold) {
|
242
|
-
let(:bottom_threshold) {
|
247
|
+
let(:top_threshold) { Date.today.beginning_of_week }
|
248
|
+
let(:bottom_threshold) { Date.today.end_of_week }
|
243
249
|
let(:arguments) { [] }
|
244
250
|
include_examples 'between date scope','this_week'
|
245
251
|
end
|
246
252
|
|
247
253
|
describe ":this_month" do
|
248
|
-
let(:top_threshold) {
|
249
|
-
let(:bottom_threshold) {
|
254
|
+
let(:top_threshold) { Date.today.beginning_of_month }
|
255
|
+
let(:bottom_threshold) { Date.today.end_of_month }
|
250
256
|
let(:arguments) { [] }
|
251
257
|
include_examples 'between date scope','this_month'
|
252
258
|
end
|
253
259
|
|
254
260
|
describe ":this_year" do
|
255
|
-
let(:top_threshold) {
|
256
|
-
let(:bottom_threshold) {
|
261
|
+
let(:top_threshold) { Date.today.beginning_of_year }
|
262
|
+
let(:bottom_threshold) { Date.today.end_of_year }
|
257
263
|
let(:arguments) { [] }
|
258
264
|
include_examples 'between date scope','this_year'
|
259
265
|
end
|
@@ -1,30 +1,56 @@
|
|
1
|
-
|
2
1
|
shared_examples "between time scope" do |name, difference = 1.second|
|
3
2
|
subject do
|
4
3
|
test_class.send("#{prefix}#{name}", *arguments).to_a
|
5
4
|
end
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
let(:
|
10
|
-
let(:
|
6
|
+
# In tests top_threshold and bottom_threshold should have time values,
|
7
|
+
# where the interval includes top_threshold but EXCLUDES bottom_threshold
|
8
|
+
let(:before_top_threshold_obj) { test_class.create! date_column => top_threshold.to_time - difference }
|
9
|
+
let(:at_top_threshold_obj) { test_class.create! date_column => top_threshold.to_time }
|
10
|
+
let(:before_bottom_threshold_obj) { test_class.create! date_column => bottom_threshold.to_time - difference }
|
11
|
+
let(:at_bottom_threshold_obj) { test_class.create! date_column => bottom_threshold.to_time }
|
12
|
+
|
13
|
+
before do
|
14
|
+
# puts "#{prefix}#{name}: #{arguments.to_s}"
|
15
|
+
# puts test_class.send("#{prefix}#{name}", *arguments).to_sql
|
16
|
+
end
|
11
17
|
|
12
|
-
it { should_not include
|
18
|
+
it { should_not include before_top_threshold_obj }
|
13
19
|
it { should include at_top_threshold_obj }
|
20
|
+
it { should include before_bottom_threshold_obj }
|
14
21
|
it { should_not include at_bottom_threshold_obj }
|
15
|
-
it { should_not include before_threshold_obj }
|
16
22
|
end
|
17
23
|
|
18
|
-
shared_examples "
|
24
|
+
shared_examples "before time scope" do |name|
|
25
|
+
subject { test_class.send("#{prefix}#{name}", *arguments).to_a }
|
26
|
+
|
27
|
+
# threshold is NOT included in the interval
|
28
|
+
let(:before_top_threshold_obj) { test_class.create! date_column => threshold - 1.second }
|
29
|
+
let(:at_top_threshold_obj) { test_class.create! date_column => threshold }
|
30
|
+
|
31
|
+
before do
|
32
|
+
# puts "#{prefix}#{name}: #{arguments.to_s}"
|
33
|
+
# puts test_class.send("#{prefix}#{name}", *arguments).to_sql
|
34
|
+
end
|
35
|
+
|
36
|
+
it { should include before_top_threshold_obj }
|
37
|
+
it { should_not include at_top_threshold_obj }
|
38
|
+
end
|
39
|
+
|
40
|
+
shared_examples "after time scope" do |name|
|
19
41
|
subject { test_class.send("#{prefix}#{name}", *arguments).to_a }
|
20
42
|
|
21
|
-
|
22
|
-
let(:
|
23
|
-
let(:
|
43
|
+
# threshold is included in the interval
|
44
|
+
let(:before_top_threshold_obj) { test_class.create! date_column => threshold - 1.second }
|
45
|
+
let(:at_top_threshold_obj) { test_class.create! date_column => threshold }
|
24
46
|
|
25
|
-
|
26
|
-
|
27
|
-
|
47
|
+
before do
|
48
|
+
# puts "#{prefix}#{name}: #{arguments.to_s}"
|
49
|
+
# puts test_class.send("#{prefix}#{name}", *arguments).to_sql
|
50
|
+
end
|
51
|
+
|
52
|
+
it { should_not include before_top_threshold_obj }
|
53
|
+
it { should include at_top_threshold_obj }
|
28
54
|
end
|
29
55
|
|
30
56
|
shared_examples "timestamp scopes" do |date_column = :created_at, prefix = '' |
|
@@ -32,7 +58,7 @@ shared_examples "timestamp scopes" do |date_column = :created_at, prefix = '' |
|
|
32
58
|
let(:prefix) { prefix }
|
33
59
|
let(:date_column) { date_column }
|
34
60
|
|
35
|
-
describe "
|
61
|
+
describe "Time arguments" do
|
36
62
|
describe ':between' do
|
37
63
|
let(:top_threshold) { 5.minutes.ago }
|
38
64
|
let(:bottom_threshold) { 5.minutes.from_now }
|
@@ -41,66 +67,133 @@ shared_examples "timestamp scopes" do |date_column = :created_at, prefix = '' |
|
|
41
67
|
end
|
42
68
|
|
43
69
|
describe ":after" do
|
44
|
-
let(:threshold) { 5.minutes.ago }
|
70
|
+
let(:threshold) { 5.minutes.ago + 1.second }
|
45
71
|
let(:arguments) { [ 5.minutes.ago ] }
|
46
72
|
|
47
|
-
include_examples '
|
73
|
+
include_examples 'after time scope', 'after'
|
48
74
|
end
|
49
75
|
|
50
76
|
describe ":before" do
|
77
|
+
let(:threshold) { 5.minutes.ago }
|
78
|
+
let(:arguments) { [ 5.minutes.ago ] }
|
51
79
|
|
52
|
-
|
80
|
+
include_examples 'before time scope', 'before'
|
81
|
+
end
|
53
82
|
|
54
|
-
|
55
|
-
let(:
|
56
|
-
let(:
|
83
|
+
describe ":on" do
|
84
|
+
let(:top_threshold) { Date.today.midnight }
|
85
|
+
let(:bottom_threshold) { Date.tomorrow.midnight }
|
86
|
+
let(:arguments) { [ Time.now ] }
|
57
87
|
|
58
|
-
|
59
|
-
it { should_not include on_threshold_obj }
|
60
|
-
it { should include before_threshold_obj }
|
88
|
+
include_examples "between time scope", 'on'
|
61
89
|
end
|
62
90
|
|
63
91
|
describe ":on_or_after" do
|
64
|
-
|
92
|
+
let(:threshold) { 5.minutes.ago }
|
93
|
+
let(:arguments) { [ 5.minutes.ago ] }
|
65
94
|
|
66
|
-
|
67
|
-
|
68
|
-
|
95
|
+
include_examples 'after time scope', 'on_or_after'
|
96
|
+
end
|
97
|
+
|
98
|
+
describe ":on_or_after_date" do
|
99
|
+
let(:threshold) { Date.today.midnight }
|
100
|
+
let(:arguments) { [ Time.now ] }
|
69
101
|
|
70
|
-
|
71
|
-
it { should include on_threshold_obj }
|
72
|
-
it { should_not include before_threshold_obj }
|
102
|
+
include_examples 'after time scope', 'on_or_after_date'
|
73
103
|
end
|
74
104
|
|
75
105
|
describe ":on_or_before" do
|
76
|
-
|
106
|
+
let(:threshold) { 5.minutes.ago + 1.second }
|
107
|
+
let(:arguments) { [ 5.minutes.ago ] }
|
77
108
|
|
78
|
-
|
79
|
-
|
80
|
-
|
109
|
+
include_examples 'before time scope', 'on_or_before'
|
110
|
+
end
|
111
|
+
|
112
|
+
describe ":on_or_before_date" do
|
113
|
+
let(:threshold) { Date.tomorrow.midnight }
|
114
|
+
let(:arguments) { [ Time.now ] }
|
115
|
+
|
116
|
+
include_examples 'before time scope', 'on_or_before_date'
|
117
|
+
end
|
118
|
+
end
|
81
119
|
|
82
|
-
|
83
|
-
|
84
|
-
|
120
|
+
describe "Date arguments" do
|
121
|
+
describe ":between" do
|
122
|
+
let(:top_threshold) { Date.today.midnight }
|
123
|
+
let(:bottom_threshold) { Date.today.midnight + 1.day }
|
124
|
+
let(:arguments) { [Date.today, Date.today] }
|
125
|
+
include_examples "between time scope", 'between'
|
85
126
|
end
|
86
127
|
|
128
|
+
describe ":on_or_before_date" do
|
129
|
+
let(:threshold) { Date.tomorrow.midnight }
|
130
|
+
let(:arguments) { [ Date.today ] }
|
131
|
+
|
132
|
+
include_examples 'before time scope', 'on_or_before_date'
|
133
|
+
end
|
134
|
+
|
135
|
+
describe ":on_or_before" do
|
136
|
+
let(:threshold) { Date.tomorrow.midnight }
|
137
|
+
let(:arguments) { [ Date.today ] }
|
138
|
+
|
139
|
+
include_examples 'before time scope', 'on_or_before'
|
140
|
+
end
|
141
|
+
|
142
|
+
describe ":before" do
|
143
|
+
let(:threshold) { Date.today.midnight }
|
144
|
+
let(:arguments) { [ Date.today ] }
|
145
|
+
|
146
|
+
include_examples 'before time scope', 'before'
|
147
|
+
end
|
148
|
+
|
149
|
+
describe ":on_or_after_date" do
|
150
|
+
let(:threshold) { Date.today.midnight }
|
151
|
+
let(:arguments) { [ Date.today ] }
|
152
|
+
|
153
|
+
include_examples 'after time scope', 'on_or_after_date'
|
154
|
+
end
|
155
|
+
|
156
|
+
describe ":on_or_after" do
|
157
|
+
let(:threshold) { Date.today.midnight }
|
158
|
+
let(:arguments) { [ Date.today ] }
|
159
|
+
|
160
|
+
include_examples 'after time scope', 'on_or_after'
|
161
|
+
end
|
162
|
+
|
163
|
+
describe ":after" do
|
164
|
+
let(:threshold) { Date.tomorrow.midnight }
|
165
|
+
let(:arguments) { [ Date.today ] }
|
166
|
+
|
167
|
+
include_examples 'after time scope', 'after'
|
168
|
+
end
|
169
|
+
|
170
|
+
describe ":on" do
|
171
|
+
let(:top_threshold) { Date.today.midnight }
|
172
|
+
let(:bottom_threshold) { Date.tomorrow.midnight }
|
173
|
+
let(:arguments) { [ Date.today ] }
|
174
|
+
|
175
|
+
include_examples "between time scope", 'on'
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "implicit argument" do
|
87
180
|
describe ":today" do
|
88
181
|
let(:top_threshold) { Time.now.beginning_of_day }
|
89
|
-
let(:bottom_threshold) { Time.now.
|
182
|
+
let(:bottom_threshold) { Time.now.beginning_of_day + 1.day }
|
90
183
|
let(:arguments) { [] }
|
91
184
|
include_examples 'between time scope','today'
|
92
185
|
end
|
93
186
|
|
94
187
|
describe ":yesterday" do
|
95
188
|
let(:top_threshold) { 1.day.ago.beginning_of_day }
|
96
|
-
let(:bottom_threshold) {
|
189
|
+
let(:bottom_threshold) { Time.now.beginning_of_day }
|
97
190
|
let(:arguments) { [] }
|
98
191
|
include_examples 'between time scope','yesterday'
|
99
192
|
end
|
100
193
|
|
101
194
|
describe ":tomorrow" do
|
102
195
|
let(:top_threshold) { 1.day.from_now.beginning_of_day }
|
103
|
-
let(:bottom_threshold) {
|
196
|
+
let(:bottom_threshold) { 2.day.from_now.beginning_of_day }
|
104
197
|
let(:arguments) { [] }
|
105
198
|
include_examples 'between time scope','tomorrow'
|
106
199
|
end
|
@@ -149,98 +242,98 @@ shared_examples "timestamp scopes" do |date_column = :created_at, prefix = '' |
|
|
149
242
|
|
150
243
|
describe ":last_minute" do
|
151
244
|
let(:top_threshold) { 1.minute.ago }
|
152
|
-
let(:bottom_threshold) { Time.now }
|
245
|
+
let(:bottom_threshold) { Time.now + 1.second }
|
153
246
|
let(:arguments) { [] }
|
154
247
|
include_examples 'between time scope','last_minute'
|
155
248
|
end
|
156
249
|
|
157
250
|
describe ":last_hour" do
|
158
251
|
let(:top_threshold) { 1.hour.ago }
|
159
|
-
let(:bottom_threshold) { Time.now }
|
252
|
+
let(:bottom_threshold) { Time.now + 1.second }
|
160
253
|
let(:arguments) { [] }
|
161
254
|
include_examples 'between time scope','last_hour'
|
162
255
|
end
|
163
256
|
|
164
257
|
describe ":last_24_hours" do
|
165
258
|
let(:top_threshold) { 1.day.ago }
|
166
|
-
let(:bottom_threshold) { Time.now }
|
259
|
+
let(:bottom_threshold) { Time.now + 1.second }
|
167
260
|
let(:arguments) { [] }
|
168
261
|
include_examples 'between time scope','last_24_hours'
|
169
262
|
end
|
170
263
|
|
171
264
|
describe ":last_day" do
|
172
265
|
let(:top_threshold) { 1.day.ago }
|
173
|
-
let(:bottom_threshold) { Time.now }
|
266
|
+
let(:bottom_threshold) { Time.now + 1.second }
|
174
267
|
let(:arguments) { [] }
|
175
268
|
include_examples 'between time scope','last_day'
|
176
269
|
end
|
177
270
|
|
178
271
|
describe ":last_week" do
|
179
272
|
let(:top_threshold) { 1.week.ago }
|
180
|
-
let(:bottom_threshold) { Time.now }
|
273
|
+
let(:bottom_threshold) { Time.now + 1.second }
|
181
274
|
let(:arguments) { [] }
|
182
275
|
include_examples 'between time scope','last_week'
|
183
276
|
end
|
184
277
|
|
185
278
|
describe ":last_month" do
|
186
279
|
let(:top_threshold) { 1.month.ago }
|
187
|
-
let(:bottom_threshold) { Time.now }
|
280
|
+
let(:bottom_threshold) { Time.now + 1.second }
|
188
281
|
let(:arguments) { [] }
|
189
282
|
include_examples 'between time scope','last_month'
|
190
283
|
end
|
191
284
|
|
192
285
|
describe ":last_year" do
|
193
286
|
let(:top_threshold) { 1.year.ago }
|
194
|
-
let(:bottom_threshold) { Time.now }
|
287
|
+
let(:bottom_threshold) { Time.now + 1.second }
|
195
288
|
let(:arguments) { [] }
|
196
289
|
include_examples 'between time scope','last_year'
|
197
290
|
end
|
198
291
|
|
199
292
|
describe ":last_n_seconds" do
|
200
293
|
let(:top_threshold) { 3.seconds.ago }
|
201
|
-
let(:bottom_threshold) { Time.now }
|
294
|
+
let(:bottom_threshold) { Time.now + 1.second }
|
202
295
|
let(:arguments) { [3] }
|
203
296
|
include_examples 'between time scope','last_n_seconds'
|
204
297
|
end
|
205
298
|
|
206
299
|
describe ":last_n_minutes" do
|
207
300
|
let(:top_threshold) { 3.minutes.ago }
|
208
|
-
let(:bottom_threshold) { Time.now }
|
301
|
+
let(:bottom_threshold) { Time.now + 1.second }
|
209
302
|
let(:arguments) { [3] }
|
210
303
|
include_examples 'between time scope','last_n_minutes'
|
211
304
|
end
|
212
305
|
|
213
306
|
describe ":last_n_hours" do
|
214
307
|
let(:top_threshold) { 3.hours.ago }
|
215
|
-
let(:bottom_threshold) { Time.now }
|
308
|
+
let(:bottom_threshold) { Time.now + 1.second }
|
216
309
|
let(:arguments) { [3] }
|
217
310
|
include_examples 'between time scope','last_n_hours'
|
218
311
|
end
|
219
312
|
|
220
313
|
describe ":last_n_days" do
|
221
314
|
let(:top_threshold) { 3.days.ago }
|
222
|
-
let(:bottom_threshold) { Time.now }
|
315
|
+
let(:bottom_threshold) { Time.now + 1.second }
|
223
316
|
let(:arguments) { [3] }
|
224
317
|
include_examples 'between time scope','last_n_days'
|
225
318
|
end
|
226
319
|
|
227
320
|
describe ":last_n_weeks" do
|
228
321
|
let(:top_threshold) { 3.weeks.ago }
|
229
|
-
let(:bottom_threshold) { Time.now }
|
322
|
+
let(:bottom_threshold) { Time.now + 1.second }
|
230
323
|
let(:arguments) { [3] }
|
231
324
|
include_examples 'between time scope','last_n_weeks'
|
232
325
|
end
|
233
326
|
|
234
327
|
describe ":last_n_months" do
|
235
328
|
let(:top_threshold) { 3.months.ago }
|
236
|
-
let(:bottom_threshold) { Time.now }
|
329
|
+
let(:bottom_threshold) { Time.now + 1.second }
|
237
330
|
let(:arguments) { [3] }
|
238
331
|
include_examples 'between time scope','last_n_months'
|
239
332
|
end
|
240
333
|
|
241
334
|
describe ":last_n_years" do
|
242
335
|
let(:top_threshold) { 3.years.ago }
|
243
|
-
let(:bottom_threshold) { Time.now }
|
336
|
+
let(:bottom_threshold) { Time.now + 1.second }
|
244
337
|
let(:arguments) { [3] }
|
245
338
|
include_examples 'between time scope','last_n_years'
|
246
339
|
end
|
@@ -296,49 +389,49 @@ shared_examples "timestamp scopes" do |date_column = :created_at, prefix = '' |
|
|
296
389
|
|
297
390
|
describe ":last_30_days" do
|
298
391
|
let(:top_threshold) { 30.days.ago }
|
299
|
-
let(:bottom_threshold) { Time.now }
|
392
|
+
let(:bottom_threshold) { Time.now + 1.second }
|
300
393
|
let(:arguments) { [] }
|
301
394
|
include_examples 'between time scope','last_30_days'
|
302
395
|
end
|
303
396
|
|
304
397
|
describe ":this_minute" do
|
305
398
|
let(:top_threshold) { Time.now.change(sec: 0) }
|
306
|
-
let(:bottom_threshold) { Time.now.change(sec:
|
399
|
+
let(:bottom_threshold) { Time.now.change(sec: 0) + 1.minute }
|
307
400
|
let(:arguments) { [] }
|
308
401
|
include_examples 'between time scope','this_minute'
|
309
402
|
end
|
310
403
|
|
311
404
|
describe ":this_hour" do
|
312
405
|
let(:top_threshold) { Time.now.beginning_of_hour }
|
313
|
-
let(:bottom_threshold) { Time.now.
|
406
|
+
let(:bottom_threshold) { Time.now.beginning_of_hour + 1.hour }
|
314
407
|
let(:arguments) { [] }
|
315
408
|
include_examples 'between time scope','this_hour'
|
316
409
|
end
|
317
410
|
|
318
411
|
describe ":this_day" do
|
319
412
|
let(:top_threshold) { Time.now.beginning_of_day }
|
320
|
-
let(:bottom_threshold) { Time.now.
|
413
|
+
let(:bottom_threshold) { Time.now.beginning_of_day + 1.day }
|
321
414
|
let(:arguments) { [] }
|
322
415
|
include_examples 'between time scope','this_day'
|
323
416
|
end
|
324
417
|
|
325
418
|
describe ":this_week" do
|
326
419
|
let(:top_threshold) { Time.now.beginning_of_week }
|
327
|
-
let(:bottom_threshold) { Time.now.
|
420
|
+
let(:bottom_threshold) { Time.now.beginning_of_week + 1.week }
|
328
421
|
let(:arguments) { [] }
|
329
422
|
include_examples 'between time scope','this_week'
|
330
423
|
end
|
331
424
|
|
332
425
|
describe ":this_month" do
|
333
426
|
let(:top_threshold) { Time.now.beginning_of_month }
|
334
|
-
let(:bottom_threshold) { Time.now.
|
427
|
+
let(:bottom_threshold) { Time.now.beginning_of_month + 1.month }
|
335
428
|
let(:arguments) { [] }
|
336
429
|
include_examples 'between time scope','this_month'
|
337
430
|
end
|
338
431
|
|
339
432
|
describe ":this_year" do
|
340
433
|
let(:top_threshold) { Time.now.beginning_of_year }
|
341
|
-
let(:bottom_threshold) { Time.now.
|
434
|
+
let(:bottom_threshold) { Time.now.beginning_of_year + 1.year }
|
342
435
|
let(:arguments) { [] }
|
343
436
|
include_examples 'between time scope','this_year'
|
344
437
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: include_date_scopes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Todd
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-02-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
138
|
version: '0'
|
139
139
|
requirements: []
|
140
140
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.4.8
|
142
142
|
signing_key:
|
143
143
|
specification_version: 4
|
144
144
|
summary: Include scopes for searching on a date column
|