icu_utils 1.2.0 → 1.2.1
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/icu_utils/date.rb +1 -0
- data/lib/icu_utils/version.rb +1 -1
- data/spec/date_spec.rb +105 -67
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab59aa173d3006e292c62c663aef7e2a324cd541
|
4
|
+
data.tar.gz: 633b645d25e35b55976aa23930dca65ea338a503
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 224f78a3f5b8dacf2a587456249361279f43e2a4d96d203af8f44d1801d02a17f65cd031fa00721f975d578b33592239ad318ea85e2dc4104cf17b29fe2a711c
|
7
|
+
data.tar.gz: 47d8ce1bcce6c40e68bd895baf84462609d0f95a149b249f13465f275b75ddd58fea4762f6cb0b7cd9dd5928b5418787adffa685b58c971ec7012158d979d150
|
data/Gemfile.lock
CHANGED
data/lib/icu_utils/date.rb
CHANGED
data/lib/icu_utils/version.rb
CHANGED
data/spec/date_spec.rb
CHANGED
@@ -2,173 +2,211 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
3
3
|
module ICU
|
4
4
|
describe Date do
|
5
|
+
let(:penny) { ::Date.new(1986, 6, 16) }
|
6
|
+
let(:mark) { ::Date.new(1955, 11, 9) }
|
7
|
+
let(:today) { ::Date.today }
|
8
|
+
let(:yesterday) { ::Date.today - 1 }
|
9
|
+
|
5
10
|
context "no constraints" do
|
6
11
|
it "today" do
|
7
|
-
|
8
|
-
expect(
|
9
|
-
expect(
|
10
|
-
expect(
|
12
|
+
d = ICU::Date.new(today)
|
13
|
+
expect(d).to be_valid
|
14
|
+
expect(d.date).to eq today
|
15
|
+
expect(d.reasons).to be_empty
|
11
16
|
end
|
12
17
|
|
13
18
|
it "now" do
|
14
|
-
|
15
|
-
expect(
|
16
|
-
expect(
|
17
|
-
expect(
|
19
|
+
d = ICU::Date.new(Time.now)
|
20
|
+
expect(d).to be_valid
|
21
|
+
expect(d.date).to eq today
|
22
|
+
expect(d.reasons).to be_empty
|
18
23
|
end
|
19
24
|
|
20
25
|
it "human" do
|
21
|
-
|
22
|
-
expect(
|
23
|
-
expect(
|
24
|
-
expect(
|
26
|
+
d = ICU::Date.new("9th November 1955")
|
27
|
+
expect(d).to be_valid
|
28
|
+
expect(d.date).to eq mark
|
29
|
+
expect(d.reasons).to be_empty
|
25
30
|
end
|
26
31
|
|
27
32
|
it "abbreviated" do
|
28
|
-
|
29
|
-
expect(
|
30
|
-
expect(
|
31
|
-
expect(
|
33
|
+
d = ICU::Date.new("June 16 1986")
|
34
|
+
expect(d).to be_valid
|
35
|
+
expect(d.date).to eq penny
|
36
|
+
expect(d.reasons).to be_empty
|
32
37
|
end
|
33
38
|
|
34
39
|
it "invalid" do
|
35
|
-
|
36
|
-
expect(
|
37
|
-
expect(
|
38
|
-
expect(
|
39
|
-
expect(
|
40
|
+
d = ICU::Date.new("rubbish")
|
41
|
+
expect(d).to_not be_valid
|
42
|
+
expect(d.reasons).to_not be_empty
|
43
|
+
expect(d.reasons.size).to eq 1
|
44
|
+
expect(d.reasons.first).to eq "errors.messages.invalid_date"
|
40
45
|
end
|
41
46
|
|
42
47
|
it "impossible" do
|
43
|
-
|
44
|
-
expect(
|
45
|
-
expect(
|
46
|
-
expect(
|
47
|
-
expect(
|
48
|
+
d = ICU::Date.new("2014-02-30")
|
49
|
+
expect(d).to_not be_valid
|
50
|
+
expect(d.reasons).to_not be_empty
|
51
|
+
expect(d.reasons.size).to eq 1
|
52
|
+
expect(d.reasons.first).to eq "errors.messages.invalid_date"
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
51
56
|
context "after" do
|
52
57
|
it "today/yesterday" do
|
53
|
-
d = ICU::Date.new(
|
58
|
+
d = ICU::Date.new(today, after: yesterday)
|
54
59
|
expect(d).to be_valid
|
55
|
-
expect(d.date).to eq
|
60
|
+
expect(d.date).to eq today
|
56
61
|
expect(d.reasons).to be_empty
|
57
62
|
end
|
58
63
|
|
59
64
|
it "yesterday/today" do
|
60
|
-
d = ICU::Date.new(
|
65
|
+
d = ICU::Date.new(yesterday, after: today)
|
61
66
|
expect(d).to_not be_valid
|
62
|
-
expect(d.date).to eq
|
67
|
+
expect(d.date).to eq yesterday
|
63
68
|
expect(d.reasons[0]).to eq "errors.messages.after"
|
64
|
-
expect(d.reasons[1]).to eq restriction:
|
69
|
+
expect(d.reasons[1]).to eq restriction: today.to_s
|
65
70
|
end
|
66
71
|
|
67
72
|
it "today/today" do
|
68
|
-
d = ICU::Date.new(
|
73
|
+
d = ICU::Date.new(today, after: today)
|
69
74
|
expect(d).to_not be_valid
|
70
|
-
expect(d.date).to eq
|
75
|
+
expect(d.date).to eq today
|
71
76
|
expect(d.reasons[0]).to eq "errors.messages.after"
|
72
|
-
expect(d.reasons[1]).to eq restriction:
|
77
|
+
expect(d.reasons[1]).to eq restriction: today.to_s
|
73
78
|
end
|
74
79
|
|
75
80
|
it "invalid" do
|
76
|
-
expect{ICU::Date.new(
|
81
|
+
expect{ICU::Date.new(today, after: "rubbish")}.to raise_error(/invalid/)
|
77
82
|
end
|
78
83
|
end
|
79
84
|
|
80
85
|
context "on or after" do
|
81
86
|
it "today/yesterday" do
|
82
|
-
d = ICU::Date.new(
|
87
|
+
d = ICU::Date.new(today, on_or_after: yesterday)
|
83
88
|
expect(d).to be_valid
|
84
|
-
expect(d.date).to eq
|
89
|
+
expect(d.date).to eq today
|
85
90
|
expect(d.reasons).to be_empty
|
86
91
|
end
|
87
92
|
|
88
93
|
it "yesterday/today" do
|
89
|
-
d = ICU::Date.new(
|
94
|
+
d = ICU::Date.new(yesterday, on_or_after: today)
|
90
95
|
expect(d).to_not be_valid
|
91
|
-
expect(d.date).to eq
|
96
|
+
expect(d.date).to eq yesterday
|
92
97
|
expect(d.reasons[0]).to eq "errors.messages.on_or_after"
|
93
|
-
expect(d.reasons[1]).to eq restriction:
|
98
|
+
expect(d.reasons[1]).to eq restriction: today.to_s
|
94
99
|
end
|
95
100
|
|
96
101
|
it "today/today" do
|
97
|
-
d = ICU::Date.new(
|
102
|
+
d = ICU::Date.new(today, on_or_after: today)
|
98
103
|
expect(d).to be_valid
|
99
|
-
expect(d.date).to eq
|
104
|
+
expect(d.date).to eq today
|
100
105
|
expect(d.reasons).to be_empty
|
101
106
|
end
|
102
107
|
|
103
108
|
it "impossible" do
|
104
|
-
expect{ICU::Date.new(
|
109
|
+
expect{ICU::Date.new(today, on_or_after: ::Date.new(1955, 2, 29))}.to raise_error(/invalid/)
|
105
110
|
end
|
106
111
|
end
|
107
112
|
|
108
113
|
context "before" do
|
109
114
|
it "yesterday/today" do
|
110
|
-
d = ICU::Date.new(
|
115
|
+
d = ICU::Date.new(yesterday, before: today)
|
111
116
|
expect(d).to be_valid
|
112
|
-
expect(d.date).to eq
|
117
|
+
expect(d.date).to eq yesterday
|
113
118
|
expect(d.reasons).to be_empty
|
114
119
|
end
|
115
120
|
|
116
121
|
it "today/yesterday" do
|
117
|
-
d = ICU::Date.new(
|
122
|
+
d = ICU::Date.new(today, before: yesterday)
|
118
123
|
expect(d).to_not be_valid
|
119
|
-
expect(d.date).to eq
|
124
|
+
expect(d.date).to eq today
|
120
125
|
expect(d.reasons[0]).to eq "errors.messages.before"
|
121
|
-
expect(d.reasons[1]).to eq restriction:
|
126
|
+
expect(d.reasons[1]).to eq restriction: yesterday.to_s
|
122
127
|
end
|
123
128
|
|
124
129
|
it "today/today" do
|
125
|
-
d = ICU::Date.new(
|
130
|
+
d = ICU::Date.new(today, before: today.to_s)
|
126
131
|
expect(d).to_not be_valid
|
127
|
-
expect(d.date).to eq
|
132
|
+
expect(d.date).to eq today
|
128
133
|
expect(d.reasons[0]).to eq "errors.messages.before"
|
129
|
-
expect(d.reasons[1]).to eq restriction:
|
134
|
+
expect(d.reasons[1]).to eq restriction: today.to_s
|
130
135
|
end
|
131
136
|
|
132
137
|
it "invalid" do
|
133
|
-
expect{ICU::Date.new(
|
138
|
+
expect{ICU::Date.new(today, before: "")}.to raise_error(/invalid/)
|
134
139
|
end
|
135
140
|
end
|
136
141
|
|
137
142
|
context "on or before" do
|
138
143
|
it "yesterday/today" do
|
139
|
-
d = ICU::Date.new(
|
144
|
+
d = ICU::Date.new(yesterday, on_or_before: today.to_s)
|
140
145
|
expect(d).to be_valid
|
141
|
-
expect(d.date).to eq
|
146
|
+
expect(d.date).to eq yesterday
|
142
147
|
expect(d.reasons).to be_empty
|
143
148
|
end
|
144
149
|
|
145
150
|
it "today/yesterday" do
|
146
|
-
d = ICU::Date.new(
|
151
|
+
d = ICU::Date.new(today, on_or_before: yesterday)
|
147
152
|
expect(d).to_not be_valid
|
148
|
-
expect(d.date).to eq
|
153
|
+
expect(d.date).to eq today
|
149
154
|
expect(d.reasons[0]).to eq "errors.messages.on_or_before"
|
150
|
-
expect(d.reasons[1]).to eq restriction:
|
155
|
+
expect(d.reasons[1]).to eq restriction: yesterday.to_s
|
151
156
|
end
|
152
157
|
|
153
158
|
it "today/today" do
|
154
|
-
d = ICU::Date.new(
|
159
|
+
d = ICU::Date.new(today, on_or_before: today)
|
155
160
|
expect(d).to be_valid
|
156
|
-
expect(d.date).to eq
|
161
|
+
expect(d.date).to eq today
|
157
162
|
expect(d.reasons).to be_empty
|
158
163
|
end
|
159
164
|
|
160
165
|
it "impossible" do
|
161
|
-
expect{ICU::Date.new(
|
166
|
+
expect{ICU::Date.new(today, on_or_before: "2014-06-31")}.to raise_error(/invalid/)
|
162
167
|
end
|
163
168
|
end
|
164
|
-
end
|
165
169
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
170
|
+
context "multiple constraints" do
|
171
|
+
it "today/today" do
|
172
|
+
d = ICU::Date.new(today, on_or_after: today.to_s, on_or_before: today)
|
173
|
+
expect(d).to be_valid
|
174
|
+
expect(d.date).to eq today
|
175
|
+
expect(d.reasons).to be_empty
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context "proc constraints" do
|
180
|
+
it "before" do
|
181
|
+
d = ICU::Date.new(penny, before: -> { ::Date.today })
|
182
|
+
expect(d).to be_valid
|
183
|
+
expect(d.date).to eq penny
|
184
|
+
expect(d.reasons).to be_empty
|
185
|
+
end
|
186
|
+
|
187
|
+
it "after" do
|
188
|
+
d = ICU::Date.new(yesterday, after: -> { ::Date.today })
|
189
|
+
expect(d).to_not be_valid
|
190
|
+
expect(d.date).to eq yesterday
|
191
|
+
expect(d.reasons[0]).to eq "errors.messages.after"
|
192
|
+
expect(d.reasons[1]).to eq restriction: today.to_s
|
193
|
+
end
|
194
|
+
|
195
|
+
it "on or before" do
|
196
|
+
d = ICU::Date.new(today, on_or_before: -> { ::Date.today - 1 })
|
197
|
+
expect(d).to_not be_valid
|
198
|
+
expect(d.date).to eq today
|
199
|
+
expect(d.reasons[0]).to eq "errors.messages.on_or_before"
|
200
|
+
expect(d.reasons[1]).to eq restriction: yesterday.to_s
|
201
|
+
end
|
202
|
+
|
203
|
+
it "on or after" do
|
204
|
+
d = ICU::Date.new(mark, on_or_after: -> { ::Date.new(1986, 6, 16) })
|
205
|
+
expect(d).to_not be_valid
|
206
|
+
expect(d.date).to eq mark
|
207
|
+
expect(d.reasons[0]).to eq "errors.messages.on_or_after"
|
208
|
+
expect(d.reasons[1]).to eq restriction: penny.to_s
|
209
|
+
end
|
172
210
|
end
|
173
211
|
end
|
174
212
|
end
|