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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f97cfbd598b1e453a7e2dcf3de583f60ba462d75
4
- data.tar.gz: 525cbf547ee580ada1da81cbf4da119361a0c353
3
+ metadata.gz: ab59aa173d3006e292c62c663aef7e2a324cd541
4
+ data.tar.gz: 633b645d25e35b55976aa23930dca65ea338a503
5
5
  SHA512:
6
- metadata.gz: cfa42575c3b40cec0f6aa7f531f6db3192009dd44599ab600ef800ca196d65c6b147b1c3825e4daf9799276f699464ec945ba0afdbfc463b6fd5919849fb13ec
7
- data.tar.gz: eb0da907423c6d21a4b44c2ca4a8be8de670b4758b06947709dbaa8aadd55fb0a9b272a118376807524ab2c34f58e2a9e442c6f3e00ddea0befbd795f9989c93
6
+ metadata.gz: 224f78a3f5b8dacf2a587456249361279f43e2a4d96d203af8f44d1801d02a17f65cd031fa00721f975d578b33592239ad318ea85e2dc4104cf17b29fe2a711c
7
+ data.tar.gz: 47d8ce1bcce6c40e68bd895baf84462609d0f95a149b249f13465f275b75ddd58fea4762f6cb0b7cd9dd5928b5418787adffa685b58c971ec7012158d979d150
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- icu_utils (1.2.0)
4
+ icu_utils (1.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -59,6 +59,7 @@ module ICU
59
59
  private
60
60
 
61
61
  def to_date(thing)
62
+ thing = thing.call if thing.respond_to?(:call)
62
63
  if thing.is_a?(Date)
63
64
  thing.dup
64
65
  else
@@ -1,3 +1,3 @@
1
1
  module IcuUtils
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
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
- today = ICU::Date.new(::Date.today)
8
- expect(today).to be_valid
9
- expect(today.date).to eq ::Date.today
10
- expect(today.reasons).to be_empty
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
- now = ICU::Date.new(Time.now)
15
- expect(now).to be_valid
16
- expect(now.date).to eq ::Date.today
17
- expect(now.reasons).to be_empty
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
- now = ICU::Date.new("9th November 1955")
22
- expect(now).to be_valid
23
- expect(now.date).to eq ::Date.new(1955, 11, 9)
24
- expect(now.reasons).to be_empty
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
- now = ICU::Date.new("June 16 1986")
29
- expect(now).to be_valid
30
- expect(now.date).to eq ::Date.new(1986, 6, 16)
31
- expect(now.reasons).to be_empty
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
- invalid = ICU::Date.new("rubbish")
36
- expect(invalid).to_not be_valid
37
- expect(invalid.reasons).to_not be_empty
38
- expect(invalid.reasons.size).to eq 1
39
- expect(invalid.reasons.first).to eq "errors.messages.invalid_date"
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
- invalid = ICU::Date.new("2014-02-30")
44
- expect(invalid).to_not be_valid
45
- expect(invalid.reasons).to_not be_empty
46
- expect(invalid.reasons.size).to eq 1
47
- expect(invalid.reasons.first).to eq "errors.messages.invalid_date"
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(::Date.today, after: ::Date.today - 1)
58
+ d = ICU::Date.new(today, after: yesterday)
54
59
  expect(d).to be_valid
55
- expect(d.date).to eq ::Date.today
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(::Date.today - 1, after: ::Date.today)
65
+ d = ICU::Date.new(yesterday, after: today)
61
66
  expect(d).to_not be_valid
62
- expect(d.date).to eq ::Date.today - 1
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: ::Date.today.to_s
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(::Date.today, after: ::Date.today)
73
+ d = ICU::Date.new(today, after: today)
69
74
  expect(d).to_not be_valid
70
- expect(d.date).to eq ::Date.today
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: ::Date.today.to_s
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(::Date.today, after: "rubbish")}.to raise_error(/invalid/)
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(::Date.today, on_or_after: ::Date.today - 1)
87
+ d = ICU::Date.new(today, on_or_after: yesterday)
83
88
  expect(d).to be_valid
84
- expect(d.date).to eq ::Date.today
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(::Date.today - 1, on_or_after: ::Date.today)
94
+ d = ICU::Date.new(yesterday, on_or_after: today)
90
95
  expect(d).to_not be_valid
91
- expect(d.date).to eq ::Date.today - 1
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: ::Date.today.to_s
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(::Date.today, on_or_after: ::Date.today)
102
+ d = ICU::Date.new(today, on_or_after: today)
98
103
  expect(d).to be_valid
99
- expect(d.date).to eq ::Date.today
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(::Date.today, on_or_after: ::Date.new(1955, 2, 29))}.to raise_error(/invalid/)
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(::Date.today - 1, before: ::Date.today)
115
+ d = ICU::Date.new(yesterday, before: today)
111
116
  expect(d).to be_valid
112
- expect(d.date).to eq ::Date.today - 1
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(::Date.today, before: ::Date.today - 1)
122
+ d = ICU::Date.new(today, before: yesterday)
118
123
  expect(d).to_not be_valid
119
- expect(d.date).to eq ::Date.today
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: (::Date.today - 1).to_s
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(::Date.today, before: ::Date.today.to_s)
130
+ d = ICU::Date.new(today, before: today.to_s)
126
131
  expect(d).to_not be_valid
127
- expect(d.date).to eq ::Date.today
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: ::Date.today.to_s
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(::Date.today, before: "")}.to raise_error(/invalid/)
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(::Date.today - 1, on_or_before: ::Date.today.to_s)
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 ::Date.today - 1
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(::Date.today, on_or_before: ::Date.today - 1)
151
+ d = ICU::Date.new(today, on_or_before: yesterday)
147
152
  expect(d).to_not be_valid
148
- expect(d.date).to eq ::Date.today
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: (::Date.today - 1).to_s
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(::Date.today, on_or_before: ::Date.today)
159
+ d = ICU::Date.new(today, on_or_before: today)
155
160
  expect(d).to be_valid
156
- expect(d.date).to eq ::Date.today
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(::Date.today, on_or_before: "2014-06-31")}.to raise_error(/invalid/)
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
- context "multiple constraints" do
167
- it "today/today" do
168
- d = ICU::Date.new(::Date.today, on_or_after: ::Date.today.to_s, on_or_before: ::Date.today)
169
- expect(d).to be_valid
170
- expect(d.date).to eq ::Date.today
171
- expect(d.reasons).to be_empty
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icu_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Orr