datetime-scopes 1.0.0.alpha1 → 1.0.0.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -14
- data/Gemfile.lock +72 -0
- data/README.md +1 -0
- data/lib/datetime-scopes/abstract_proxy.rb +1 -2
- data/lib/datetime-scopes/active_record_extension.rb +1 -3
- data/lib/datetime-scopes/date_proxy.rb +62 -20
- data/lib/datetime-scopes/datetime_proxy.rb +79 -24
- data/lib/datetime-scopes/version.rb +1 -1
- data/log/.gitkeep +0 -0
- data/spec/datetime-scopes/date_scopes_spec.rb +22 -0
- data/spec/datetime-scopes/datetime_scopes_spec.rb +73 -0
- data/spec/spec_helper.rb +9 -1
- metadata +7 -7
- data/spec/datetime-scopes/active_record_extension_spec.rb +0 -43
- data/spec/datetime-scopes/date_proxy_spec.rb +0 -7
- data/spec/datetime-scopes/datetime_proxy_spec.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53e205161e3068b4f9368b2355f85a8c87fc16c2
|
4
|
+
data.tar.gz: 3eeffa04759797b6e45efe5cca1fc4df259cb927
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5694ef86f93f49affa201b8cc5b8e8bd7b7bdd633377efd3b80501a87ab3bc1786de391102ed685cb00eed9e58e3d6697c3915e05c1b0fe86c5ae380631134d2
|
7
|
+
data.tar.gz: ddd119e486a2bb37a0c24bccbb1584bc165af71b57e12b26cbf7bcb10c88f3ffdfad099f668b59fc91fa1a5f8b8ceb15890a93f80d28e6a6ca40c561a674d210
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
datetime-scopes (1.0.0.alpha2)
|
5
|
+
activerecord (>= 4.0)
|
6
|
+
activesupport (>= 4.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (4.2.5.1)
|
12
|
+
activesupport (= 4.2.5.1)
|
13
|
+
builder (~> 3.1)
|
14
|
+
activerecord (4.2.5.1)
|
15
|
+
activemodel (= 4.2.5.1)
|
16
|
+
activesupport (= 4.2.5.1)
|
17
|
+
arel (~> 6.0)
|
18
|
+
activesupport (4.2.5.1)
|
19
|
+
i18n (~> 0.7)
|
20
|
+
json (~> 1.7, >= 1.7.7)
|
21
|
+
minitest (~> 5.1)
|
22
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
23
|
+
tzinfo (~> 1.1)
|
24
|
+
arel (6.0.3)
|
25
|
+
builder (3.2.2)
|
26
|
+
codeclimate-test-reporter (0.4.7)
|
27
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
28
|
+
database_cleaner (1.4.0)
|
29
|
+
diff-lcs (1.2.5)
|
30
|
+
docile (1.1.5)
|
31
|
+
i18n (0.7.0)
|
32
|
+
json (1.8.3)
|
33
|
+
minitest (5.8.4)
|
34
|
+
multi_json (1.11.0)
|
35
|
+
rake (10.4.2)
|
36
|
+
rspec (3.4.0)
|
37
|
+
rspec-core (~> 3.4.0)
|
38
|
+
rspec-expectations (~> 3.4.0)
|
39
|
+
rspec-mocks (~> 3.4.0)
|
40
|
+
rspec-core (3.4.2)
|
41
|
+
rspec-support (~> 3.4.0)
|
42
|
+
rspec-expectations (3.4.0)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.4.0)
|
45
|
+
rspec-mocks (3.4.1)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.4.0)
|
48
|
+
rspec-support (3.4.1)
|
49
|
+
simplecov (0.9.2)
|
50
|
+
docile (~> 1.1.0)
|
51
|
+
multi_json (~> 1.0)
|
52
|
+
simplecov-html (~> 0.9.0)
|
53
|
+
simplecov-html (0.9.0)
|
54
|
+
sqlite3 (1.3.10)
|
55
|
+
thread_safe (0.3.5)
|
56
|
+
tzinfo (1.2.2)
|
57
|
+
thread_safe (~> 0.1)
|
58
|
+
|
59
|
+
PLATFORMS
|
60
|
+
ruby
|
61
|
+
|
62
|
+
DEPENDENCIES
|
63
|
+
bundler (~> 1.11.2)
|
64
|
+
codeclimate-test-reporter
|
65
|
+
database_cleaner
|
66
|
+
datetime-scopes!
|
67
|
+
rake (~> 10.4.2)
|
68
|
+
rspec (~> 3.4.0)
|
69
|
+
sqlite3
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
1.11.2
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Date/time scopes for ActiveRecord models
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/datetime-scopes.svg)](https://badge.fury.io/rb/datetime-scopes)
|
3
4
|
[![Build Status](https://travis-ci.org/907th/datetime-scopes.svg?branch=master)](https://travis-ci.org/907th/datetime-scopes)
|
4
5
|
[![Code Climate](https://codeclimate.com/github/907th/datetime-scopes/badges/gpa.svg)](https://codeclimate.com/github/907th/datetime-scopes)
|
5
6
|
[![Test Coverage](https://codeclimate.com/github/907th/datetime-scopes/badges/coverage.svg)](https://codeclimate.com/github/907th/datetime-scopes/coverage)
|
@@ -10,7 +10,6 @@ module DateTimeScopes
|
|
10
10
|
module ClassMethods
|
11
11
|
def datetime_scopes(attr, prefix: nil, time_zone: ::Time.zone)
|
12
12
|
proxy = DateTimeProxy.new(
|
13
|
-
klass: self,
|
14
13
|
attribute: "#{table_name}.#{attr}",
|
15
14
|
time_zone: time_zone
|
16
15
|
)
|
@@ -20,7 +19,6 @@ module DateTimeScopes
|
|
20
19
|
|
21
20
|
def date_scopes(attr, prefix: nil, time_zone: nil)
|
22
21
|
proxy = DateProxy.new(
|
23
|
-
klass: self,
|
24
22
|
attribute: "#{table_name}.#{attr}",
|
25
23
|
time_zone: time_zone
|
26
24
|
)
|
@@ -33,7 +31,7 @@ module DateTimeScopes
|
|
33
31
|
def declare_datetime_scopes(prefix, proxy)
|
34
32
|
proxy.proxy_methods.each do |method_name|
|
35
33
|
scope_name = "#{prefix}_#{method_name}"
|
36
|
-
scope scope_name, -> (*attrs) { proxy.send method_name, *attrs }
|
34
|
+
scope scope_name, -> (*attrs) { proxy.send method_name, self, *attrs }
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
@@ -29,24 +29,26 @@ module DateTimeScopes
|
|
29
29
|
|
30
30
|
# Intervals
|
31
31
|
|
32
|
-
def within_days(from, to, time_zone: @time_zone)
|
33
|
-
|
34
|
-
"#{@attribute}
|
32
|
+
def within_days(rel, from, to, time_zone: @time_zone)
|
33
|
+
rel.where(
|
34
|
+
"#{@attribute} >= ? AND #{@attribute} <= ?",
|
35
35
|
from.in_time_zone(time_zone).to_date,
|
36
36
|
to.in_time_zone(time_zone).to_date
|
37
37
|
)
|
38
38
|
end
|
39
39
|
|
40
|
-
def within_months(from, to, time_zone: @time_zone)
|
40
|
+
def within_months(rel, from, to, time_zone: @time_zone)
|
41
41
|
within_days(
|
42
|
+
rel,
|
42
43
|
from.in_time_zone(time_zone).beginning_of_month,
|
43
44
|
to.in_time_zone(time_zone).end_of_month,
|
44
45
|
time_zone: time_zone
|
45
46
|
)
|
46
47
|
end
|
47
48
|
|
48
|
-
def within_years(from, to, time_zone: @time_zone)
|
49
|
+
def within_years(rel, from, to, time_zone: @time_zone)
|
49
50
|
within_days(
|
51
|
+
rel,
|
50
52
|
from.in_time_zone(time_zone).beginning_of_year,
|
51
53
|
to.in_time_zone(time_zone).end_of_year,
|
52
54
|
time_zone: time_zone
|
@@ -55,28 +57,68 @@ module DateTimeScopes
|
|
55
57
|
|
56
58
|
# Specific day/month/year
|
57
59
|
|
58
|
-
def on_day(day, time_zone: @time_zone)
|
59
|
-
|
60
|
-
|
60
|
+
def on_day(rel, day, time_zone: @time_zone)
|
61
|
+
within_days rel, day, day, time_zone: time_zone
|
62
|
+
end
|
63
|
+
|
64
|
+
def on_month(rel, month, time_zone: @time_zone)
|
65
|
+
within_months rel, month, month, time_zone: time_zone
|
66
|
+
end
|
67
|
+
|
68
|
+
def on_year(rel, year, time_zone: @time_zone)
|
69
|
+
within_years rel, year, year, time_zone: time_zone
|
70
|
+
end
|
61
71
|
|
62
72
|
# Strict equations
|
63
73
|
|
64
|
-
def before_day(day, time_zone: @time_zone)
|
65
|
-
|
66
|
-
|
74
|
+
def before_day(rel, day, time_zone: @time_zone)
|
75
|
+
rel.where "#{@attribute} < ?", day.in_time_zone(time_zone).to_date
|
76
|
+
end
|
67
77
|
|
68
|
-
def
|
69
|
-
|
70
|
-
|
78
|
+
def before_month(rel, month, time_zone: @time_zone)
|
79
|
+
before_day rel, month.in_time_zone(time_zone).beginning_of_month, time_zone: time_zone
|
80
|
+
end
|
81
|
+
|
82
|
+
def before_year(rel, year, time_zone: @time_zone)
|
83
|
+
before_day rel, year.in_time_zone(time_zone).beginning_of_year, time_zone: time_zone
|
84
|
+
end
|
85
|
+
|
86
|
+
def after_day(rel, day, time_zone: @time_zone)
|
87
|
+
rel.where "#{@attribute} > ?", day.in_time_zone(time_zone).to_date
|
88
|
+
end
|
89
|
+
|
90
|
+
def after_month(rel, month, time_zone: @time_zone)
|
91
|
+
after_day rel, month.in_time_zone(time_zone).end_of_month, time_zone: time_zone
|
92
|
+
end
|
93
|
+
|
94
|
+
def after_year(rel, year, time_zone: @time_zone)
|
95
|
+
after_day rel, year.in_time_zone(time_zone).end_of_year, time_zone: time_zone
|
96
|
+
end
|
71
97
|
|
72
98
|
# Non-strict equations
|
73
99
|
|
74
|
-
def on_or_before_day(day, time_zone: @time_zone)
|
75
|
-
|
76
|
-
|
100
|
+
def on_or_before_day(rel, day, time_zone: @time_zone)
|
101
|
+
rel.where "#{@attribute} <= ?", day.in_time_zone(time_zone).to_date
|
102
|
+
end
|
103
|
+
|
104
|
+
def on_or_before_month(rel, month, time_zone: @time_zone)
|
105
|
+
on_or_before_day rel, month.in_time_zone(time_zone).end_of_month, time_zone: time_zone
|
106
|
+
end
|
107
|
+
|
108
|
+
def on_or_before_year(rel, year, time_zone: @time_zone)
|
109
|
+
on_or_before_day rel, year.in_time_zone(time_zone).end_of_year, time_zone: time_zone
|
110
|
+
end
|
111
|
+
|
112
|
+
def on_or_after_day(rel, day, time_zone: @time_zone)
|
113
|
+
rel.where "#{@attribute} >= ?", day.in_time_zone(time_zone).to_date
|
114
|
+
end
|
77
115
|
|
78
|
-
def
|
79
|
-
|
80
|
-
|
116
|
+
def on_or_after_month(rel, month, time_zone: @time_zone)
|
117
|
+
on_or_after_day rel, month.in_time_zone(time_zone).beginning_of_month, time_zone: time_zone
|
118
|
+
end
|
119
|
+
|
120
|
+
def on_or_after_year(rel, year, time_zone: @time_zone)
|
121
|
+
on_or_after_day rel, year.in_time_zone(time_zone).beginning_of_year, time_zone: time_zone
|
122
|
+
end
|
81
123
|
end
|
82
124
|
end
|
@@ -34,32 +34,35 @@ module DateTimeScopes
|
|
34
34
|
|
35
35
|
# Intervals
|
36
36
|
|
37
|
-
def within(from, to, time_zone: @time_zone)
|
38
|
-
|
37
|
+
def within(rel, from, to, time_zone: @time_zone)
|
38
|
+
rel.where(
|
39
39
|
"#{@attribute} >= ? AND #{@attribute} <= ?",
|
40
40
|
from.in_time_zone(time_zone),
|
41
41
|
to.in_time_zone(time_zone)
|
42
42
|
)
|
43
43
|
end
|
44
44
|
|
45
|
-
def within_days(from, to, time_zone: @time_zone)
|
45
|
+
def within_days(rel, from, to, time_zone: @time_zone)
|
46
46
|
within(
|
47
|
+
rel,
|
47
48
|
from.in_time_zone(time_zone).beginning_of_day,
|
48
49
|
to.in_time_zone(time_zone).end_of_day,
|
49
50
|
time_zone: time_zone
|
50
51
|
)
|
51
52
|
end
|
52
53
|
|
53
|
-
def within_months(from, to, time_zone: @time_zone)
|
54
|
+
def within_months(rel, from, to, time_zone: @time_zone)
|
54
55
|
within(
|
56
|
+
rel,
|
55
57
|
from.in_time_zone(time_zone).beginning_of_month,
|
56
58
|
to.in_time_zone(time_zone).end_of_month,
|
57
59
|
time_zone: time_zone
|
58
60
|
)
|
59
61
|
end
|
60
62
|
|
61
|
-
def within_years(from, to, time_zone: @time_zone)
|
63
|
+
def within_years(rel, from, to, time_zone: @time_zone)
|
62
64
|
within(
|
65
|
+
rel,
|
63
66
|
from.in_time_zone(time_zone).beginning_of_year,
|
64
67
|
to.in_time_zone(time_zone).end_of_year,
|
65
68
|
time_zone: time_zone
|
@@ -68,32 +71,84 @@ module DateTimeScopes
|
|
68
71
|
|
69
72
|
# Specific day/month/year
|
70
73
|
|
71
|
-
def on_day(day, time_zone: @time_zone)
|
72
|
-
|
73
|
-
|
74
|
+
def on_day(rel, day, time_zone: @time_zone)
|
75
|
+
within_days rel, day, day, time_zone: time_zone
|
76
|
+
end
|
77
|
+
|
78
|
+
def on_month(rel, month, time_zone: @time_zone)
|
79
|
+
within_months rel, month, month, time_zone: time_zone
|
80
|
+
end
|
81
|
+
|
82
|
+
def on_year(rel, year, time_zone: @time_zone)
|
83
|
+
within_years rel, year, year, time_zone: time_zone
|
84
|
+
end
|
74
85
|
|
75
86
|
# Strict equations
|
76
87
|
|
77
|
-
def before(time, time_zone: @time_zone)
|
78
|
-
|
79
|
-
|
80
|
-
|
88
|
+
def before(rel, time, time_zone: @time_zone)
|
89
|
+
rel.where "#{@attribute} < ?", time.in_time_zone(time_zone)
|
90
|
+
end
|
91
|
+
|
92
|
+
def before_day(rel, day, time_zone: @time_zone)
|
93
|
+
before rel, day.in_time_zone(time_zone).beginning_of_day, time_zone: time_zone
|
94
|
+
end
|
81
95
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
|
96
|
+
def before_month(rel, month, time_zone: @time_zone)
|
97
|
+
before rel, month.in_time_zone(time_zone).beginning_of_month, time_zone: time_zone
|
98
|
+
end
|
99
|
+
|
100
|
+
def before_year(rel, year, time_zone: @time_zone)
|
101
|
+
before rel, year.in_time_zone(time_zone).beginning_of_year, time_zone: time_zone
|
102
|
+
end
|
103
|
+
|
104
|
+
def after(rel, time, time_zone: @time_zone)
|
105
|
+
rel.where "#{@attribute} > ?", time.in_time_zone(time_zone)
|
106
|
+
end
|
107
|
+
|
108
|
+
def after_day(rel, day, time_zone: @time_zone)
|
109
|
+
after rel, day.in_time_zone(time_zone).end_of_day, time_zone: time_zone
|
110
|
+
end
|
111
|
+
|
112
|
+
def after_month(rel, month, time_zone: @time_zone)
|
113
|
+
after rel, month.in_time_zone(time_zone).end_of_month, time_zone: time_zone
|
114
|
+
end
|
115
|
+
|
116
|
+
def after_year(rel, year, time_zone: @time_zone)
|
117
|
+
after rel, year.in_time_zone(time_zone).end_of_year, time_zone: time_zone
|
118
|
+
end
|
86
119
|
|
87
120
|
# Non-strict equations
|
88
121
|
|
89
|
-
def on_or_before(time, time_zone: @time_zone)
|
90
|
-
|
91
|
-
|
92
|
-
|
122
|
+
def on_or_before(rel, time, time_zone: @time_zone)
|
123
|
+
rel.where "#{@attribute} <= ?", time.in_time_zone(time_zone)
|
124
|
+
end
|
125
|
+
|
126
|
+
def on_or_before_day(rel, day, time_zone: @time_zone)
|
127
|
+
on_or_before rel, day.in_time_zone(time_zone).end_of_day, time_zone: time_zone
|
128
|
+
end
|
129
|
+
|
130
|
+
def on_or_before_month(rel, month, time_zone: @time_zone)
|
131
|
+
on_or_before rel, month.in_time_zone(time_zone).end_of_month, time_zone: time_zone
|
132
|
+
end
|
133
|
+
|
134
|
+
def on_or_before_year(rel, year, time_zone: @time_zone)
|
135
|
+
on_or_before rel, year.in_time_zone(time_zone).end_of_year, time_zone: time_zone
|
136
|
+
end
|
137
|
+
|
138
|
+
def on_or_after(rel, time, time_zone: @time_zone)
|
139
|
+
rel.where "#{@attribute} >= ?", time.in_time_zone(time_zone)
|
140
|
+
end
|
141
|
+
|
142
|
+
def on_or_after_day(rel, day, time_zone: @time_zone)
|
143
|
+
on_or_after rel, day.in_time_zone(time_zone).beginning_of_day, time_zone: time_zone
|
144
|
+
end
|
145
|
+
|
146
|
+
def on_or_after_month(rel, month, time_zone: @time_zone)
|
147
|
+
on_or_after rel, month.in_time_zone(time_zone).beginning_of_month, time_zone: time_zone
|
148
|
+
end
|
93
149
|
|
94
|
-
def
|
95
|
-
|
96
|
-
|
97
|
-
def on_or_after_year(year, time_zone: @time_zone) ; on_or_after year.in_time_zone(time_zone).beginning_of_year, time_zone: time_zone ; end
|
150
|
+
def on_or_after_year(rel, year, time_zone: @time_zone)
|
151
|
+
on_or_after rel, year.in_time_zone(time_zone).beginning_of_year, time_zone: time_zone
|
152
|
+
end
|
98
153
|
end
|
99
154
|
end
|
data/log/.gitkeep
ADDED
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "date_scopes" do
|
4
|
+
pending "#within_days"
|
5
|
+
pending "#within_months"
|
6
|
+
pending "#within_years"
|
7
|
+
pending "#on_day"
|
8
|
+
pending "#on_month"
|
9
|
+
pending "#on_year"
|
10
|
+
pending "#before_day"
|
11
|
+
pending "#before_month"
|
12
|
+
pending "#before_year"
|
13
|
+
pending "#after_day"
|
14
|
+
pending "#after_month"
|
15
|
+
pending "#after_year"
|
16
|
+
pending "#on_or_before_day"
|
17
|
+
pending "#on_or_before_month"
|
18
|
+
pending "#on_or_before_year"
|
19
|
+
pending "#on_or_after_day"
|
20
|
+
pending "#on_or_after_month"
|
21
|
+
pending "#on_or_after_year"
|
22
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "datetime_scopes" do
|
4
|
+
def self.test(method_name, params:, matching:, not_matching:)
|
5
|
+
describe "##{method_name}" do
|
6
|
+
let!(:method_name) { "foo_#{method_name}" }
|
7
|
+
let!(:params) { params }
|
8
|
+
let!(:matching) { matching }
|
9
|
+
let!(:not_matching) { not_matching }
|
10
|
+
|
11
|
+
before do
|
12
|
+
(matching + not_matching).each do |t|
|
13
|
+
FooBar.create! foo: t.in_time_zone
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def perform
|
18
|
+
FooBar.send method_name, *params
|
19
|
+
end
|
20
|
+
|
21
|
+
it "includes matching times" do
|
22
|
+
ret = perform.to_a.map(&:foo)
|
23
|
+
matching.map(&:in_time_zone).each do |t|
|
24
|
+
expect(ret).to include(t)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "doesn't include not matching times" do
|
29
|
+
ret = perform.to_a.map(&:foo)
|
30
|
+
not_matching.map(&:in_time_zone).each do |t|
|
31
|
+
expect(ret).not_to include(t)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
test(
|
38
|
+
"within",
|
39
|
+
params: ["11.01.2015 23:41:35", "12.01.2015 01:00:23"],
|
40
|
+
matching: [
|
41
|
+
"11.01.2015 23:41:35",
|
42
|
+
"12.01.2015 00:40:01",
|
43
|
+
"12.01.2015 01:00:23"
|
44
|
+
],
|
45
|
+
not_matching: [
|
46
|
+
"11.01.2015 23:41:34",
|
47
|
+
"12.01.2015 01:00:24"
|
48
|
+
]
|
49
|
+
)
|
50
|
+
|
51
|
+
pending "#within_days"
|
52
|
+
pending "#within_months"
|
53
|
+
pending "#within_years"
|
54
|
+
pending "#on_day"
|
55
|
+
pending "#on_month"
|
56
|
+
pending "#on_year"
|
57
|
+
pending "#before"
|
58
|
+
pending "#before_day"
|
59
|
+
pending "#before_month"
|
60
|
+
pending "#before_year"
|
61
|
+
pending "#after"
|
62
|
+
pending "#after_day"
|
63
|
+
pending "#after_month"
|
64
|
+
pending "#after_year"
|
65
|
+
pending "#on_or_before"
|
66
|
+
pending "#on_or_before_day"
|
67
|
+
pending "#on_or_before_month"
|
68
|
+
pending "#on_or_before_year"
|
69
|
+
pending "#on_or_after"
|
70
|
+
pending "#on_or_after_day"
|
71
|
+
pending "#on_or_after_month"
|
72
|
+
pending "#on_or_after_year"
|
73
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
+
require "logger"
|
2
|
+
logger = Logger.new(File.expand_path "../../log/test.log", __FILE__)
|
3
|
+
logger.level = Logger::DEBUG
|
4
|
+
|
1
5
|
require "codeclimate-test-reporter"
|
6
|
+
CodeClimate::TestReporter.configure do |config|
|
7
|
+
config.logger = logger
|
8
|
+
end
|
2
9
|
CodeClimate::TestReporter.start
|
3
10
|
|
4
11
|
require "rspec/core"
|
@@ -6,6 +13,7 @@ require "database_cleaner"
|
|
6
13
|
require "datetime-scopes"
|
7
14
|
|
8
15
|
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
16
|
+
ActiveRecord::Base.logger = logger
|
9
17
|
DatabaseCleaner.strategy = :truncation
|
10
18
|
|
11
19
|
RSpec.configure do |c|
|
@@ -21,7 +29,7 @@ end
|
|
21
29
|
# Create table and declare AR model
|
22
30
|
|
23
31
|
ActiveRecord::Migration.verbose = false
|
24
|
-
ActiveRecord::Migration.create_table :
|
32
|
+
ActiveRecord::Migration.create_table :foo_bars do |t|
|
25
33
|
t.datetime :foo
|
26
34
|
t.date :bar
|
27
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datetime-scopes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.alpha2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Chernenkov
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- ".rspec"
|
78
78
|
- ".travis.yml"
|
79
79
|
- Gemfile
|
80
|
+
- Gemfile.lock
|
80
81
|
- LICENSE.txt
|
81
82
|
- README.md
|
82
83
|
- Rakefile
|
@@ -87,9 +88,9 @@ files:
|
|
87
88
|
- lib/datetime-scopes/date_proxy.rb
|
88
89
|
- lib/datetime-scopes/datetime_proxy.rb
|
89
90
|
- lib/datetime-scopes/version.rb
|
90
|
-
-
|
91
|
-
- spec/datetime-scopes/
|
92
|
-
- spec/datetime-scopes/
|
91
|
+
- log/.gitkeep
|
92
|
+
- spec/datetime-scopes/date_scopes_spec.rb
|
93
|
+
- spec/datetime-scopes/datetime_scopes_spec.rb
|
93
94
|
- spec/spec_helper.rb
|
94
95
|
homepage: https://github.com/907th/datetime-scopes
|
95
96
|
licenses:
|
@@ -116,7 +117,6 @@ signing_key:
|
|
116
117
|
specification_version: 4
|
117
118
|
summary: Date/time scopes for ActiveRecord models you always missed!
|
118
119
|
test_files:
|
119
|
-
- spec/datetime-scopes/
|
120
|
-
- spec/datetime-scopes/
|
121
|
-
- spec/datetime-scopes/datetime_proxy_spec.rb
|
120
|
+
- spec/datetime-scopes/date_scopes_spec.rb
|
121
|
+
- spec/datetime-scopes/datetime_scopes_spec.rb
|
122
122
|
- spec/spec_helper.rb
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe FooBar do
|
4
|
-
describe "::datetime_scopes" do
|
5
|
-
let!(:proxy_methods) { DateTimeScopes::DateTimeProxy::PROXY_METHODS }
|
6
|
-
|
7
|
-
it "defines datetime scopes" do
|
8
|
-
proxy_methods.each do |method_name|
|
9
|
-
expect(FooBar).to respond_to "foo_#{method_name}"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
it "delegates a scope call to a proxy" do
|
14
|
-
proxy_methods.each do |method_name|
|
15
|
-
dbl = double("result")
|
16
|
-
expect_any_instance_of(DateTimeScopes::DateTimeProxy).to receive(method_name).with(1, 2, 3).and_return(dbl)
|
17
|
-
res = FooBar.send("foo_#{method_name}", 1, 2, 3)
|
18
|
-
expect(res).to eq(dbl)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "::date_scopes" do
|
24
|
-
def proxy_methods
|
25
|
-
DateTimeScopes::DateProxy::PROXY_METHODS
|
26
|
-
end
|
27
|
-
|
28
|
-
it "defines date scopes" do
|
29
|
-
proxy_methods.each do |method_name|
|
30
|
-
expect(FooBar).to respond_to "bar_#{method_name}"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
it "delegates a scope call to a proxy" do
|
35
|
-
proxy_methods.each do |method_name|
|
36
|
-
dbl = double("result")
|
37
|
-
expect_any_instance_of(DateTimeScopes::DateProxy).to receive(method_name).with(1, 2, 3).and_return(dbl)
|
38
|
-
res = FooBar.send("bar_#{method_name}", 1, 2, 3)
|
39
|
-
expect(res).to eq(dbl)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|