rasti-form 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rasti/form.rb +4 -0
- data/lib/rasti/form/version.rb +1 -1
- data/spec/form_spec.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c78c5baf69510d591b5724297c49840c1a17f59
|
4
|
+
data.tar.gz: 3eff085937071179d8164e209447a04930c2c810
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f58b495ff6f77d2ed52c8e2932642d2353a32f73ec602882f86b66f2f5a267b93384617e8bee60687000bcf9cc7ea92c39505a0a60759dbb9a3d3ea727f25c5b
|
7
|
+
data.tar.gz: dd7375a659151115d589666e5211e766cbc0cffd8dfe7dab8505409fa72a7361efe172945f567c2275cab35275e8a90756b444fd267e624d0a44edcf62b9558e
|
data/lib/rasti/form.rb
CHANGED
@@ -155,6 +155,10 @@ module Rasti
|
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
|
+
def assert_time_range(attribute_from, attribute_to)
|
159
|
+
assert attribute_from, public_send(attribute_from) <= public_send(attribute_to), 'invalid time range'
|
160
|
+
end
|
161
|
+
|
158
162
|
def assert_included_in(attribute, set)
|
159
163
|
if assert_present attribute
|
160
164
|
assert attribute, set.include?(fetch(attribute)), "not included in #{set.map { |e| e.is_a?(::String) ? "'#{e}'" : e.inspect }.join(', ')}"
|
data/lib/rasti/form/version.rb
CHANGED
data/spec/form_spec.rb
CHANGED
@@ -193,6 +193,20 @@ describe Rasti::Form do
|
|
193
193
|
error.message.must_equal 'Validation error: #<Rasti::Form[text: "xyz"]> {"text":["not included in \'value_1\', \'value_2\'"]}'
|
194
194
|
end
|
195
195
|
|
196
|
+
it 'Time range' do
|
197
|
+
form = build_form do
|
198
|
+
attribute :from, Rasti::Form::Types::Time['%Y-%m-%d %H:%M:%S%Z']
|
199
|
+
attribute :to, Rasti::Form::Types::Time['%Y-%m-%d %H:%M:%S%Z']
|
200
|
+
|
201
|
+
def validate
|
202
|
+
assert_time_range :from, :to
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
error = proc { form.new from: '2018-01-01 15:30:00-0600', to: '2018-01-01 03:10:00-0600' }.must_raise Rasti::Form::ValidationError
|
207
|
+
error.message.must_equal 'Validation error: #<Rasti::Form[from: 2018-01-01 15:30:00 -0600, to: 2018-01-01 03:10:00 -0600]> {"from":["invalid time range"]}'
|
208
|
+
end
|
209
|
+
|
196
210
|
it 'Nested form' do
|
197
211
|
form = build_form do
|
198
212
|
attribute :range, Rasti::Form::Types::Form[min: Rasti::Form::Types::Integer, max: Rasti::Form::Types::Integer]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rasti-form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_require
|