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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26c1c1f5dc1233ecbda35f3e19c0a6b8e286405c
4
- data.tar.gz: 465729370df0070a7c536b6fc39c11d92a3b27fc
3
+ metadata.gz: 7c78c5baf69510d591b5724297c49840c1a17f59
4
+ data.tar.gz: 3eff085937071179d8164e209447a04930c2c810
5
5
  SHA512:
6
- metadata.gz: ae1a7c147d82af7c2a3095a682e80899746fcc3b00aa44a0c4fb88842895f01daf577056be8b1eaa06351c0e85c12a03f4d0abe82db0ec910c97f789c98deb58
7
- data.tar.gz: 40e2ffc9f4287a1c726c15f469575c5ed14bef3ae8a5f47eef0a49abd97b4ea127e78544cb831c7cf834bac2f1aedb30f717aba5aa1c75374847d388eb715a98
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(', ')}"
@@ -1,5 +1,5 @@
1
1
  module Rasti
2
2
  class Form
3
- VERSION = '2.0.0'
3
+ VERSION = '2.1.0'
4
4
  end
5
5
  end
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.0.0
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-15 00:00:00.000000000 Z
11
+ date: 2018-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_require