rasti-form 2.1.0 → 2.2.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/types/io.rb +23 -0
- data/lib/rasti/form/version.rb +1 -1
- data/spec/form_spec.rb +7 -4
- data/spec/types/io_spec.rb +18 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c52204d2ee5fd0dec69e737cb54dcaadc0e1aefa
|
4
|
+
data.tar.gz: '08a1332b2f45c622de662393a551cda4797f1ce8'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d83646128669902f9d7bbfd367ac7b92f9a683258687675b15725f8fab3b0c6778f6fb1553f8c5b7149f419d9b2768f6a3004471ecb28b4b1463086bd6371af8
|
7
|
+
data.tar.gz: 3600ad2b86770649044ce09d55025d6d1b51dda7e772f016c7bd7f134a634100b6e0d7bce45a3028071b51cf3762685109bfe6820cfc91e9aeb19a48c0f47fcc
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Rasti
|
2
|
+
class Form
|
3
|
+
module Types
|
4
|
+
class IO
|
5
|
+
class << self
|
6
|
+
|
7
|
+
include Castable
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def valid?(value)
|
12
|
+
value.respond_to?(:read) && value.respond_to?(:write)
|
13
|
+
end
|
14
|
+
|
15
|
+
def transform(value)
|
16
|
+
value
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/rasti/form/version.rb
CHANGED
data/spec/form_spec.rb
CHANGED
@@ -195,16 +195,19 @@ describe Rasti::Form do
|
|
195
195
|
|
196
196
|
it 'Time range' do
|
197
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']
|
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
200
|
|
201
201
|
def validate
|
202
202
|
assert_time_range :from, :to
|
203
203
|
end
|
204
204
|
end
|
205
205
|
|
206
|
-
|
207
|
-
|
206
|
+
from = '2018-01-01 15:30:00 +0000'
|
207
|
+
to = '2018-01-01 03:10:00 +0000'
|
208
|
+
|
209
|
+
error = proc { form.new from: from, to: to }.must_raise Rasti::Form::ValidationError
|
210
|
+
error.message.must_equal "Validation error: #<Rasti::Form[from: #{from}, to: #{to}]> {\"from\":[\"invalid time range\"]}"
|
208
211
|
end
|
209
212
|
|
210
213
|
it 'Nested form' do
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
describe Rasti::Form::Types::IO do
|
4
|
+
|
5
|
+
[StringIO.new, File.new(__FILE__)].each do |value|
|
6
|
+
it "#{value.inspect} -> #{value}" do
|
7
|
+
Rasti::Form::Types::IO.cast(value).must_equal value
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
[nil, 'text', 123, :symbol, [1,2], {a: 1, b: 2}, Object.new].each do |value|
|
12
|
+
it "#{value.inspect} -> CastError" do
|
13
|
+
error = proc { Rasti::Form::Types::IO.cast(value) }.must_raise Rasti::Form::CastError
|
14
|
+
error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::IO"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
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.2.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-
|
11
|
+
date: 2018-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_require
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- lib/rasti/form/types/form.rb
|
171
171
|
- lib/rasti/form/types/hash.rb
|
172
172
|
- lib/rasti/form/types/integer.rb
|
173
|
+
- lib/rasti/form/types/io.rb
|
173
174
|
- lib/rasti/form/types/regexp.rb
|
174
175
|
- lib/rasti/form/types/string.rb
|
175
176
|
- lib/rasti/form/types/symbol.rb
|
@@ -188,6 +189,7 @@ files:
|
|
188
189
|
- spec/types/form_spec.rb
|
189
190
|
- spec/types/hash_spec.rb
|
190
191
|
- spec/types/integer_spec.rb
|
192
|
+
- spec/types/io_spec.rb
|
191
193
|
- spec/types/regexp_spec.rb
|
192
194
|
- spec/types/string_spec.rb
|
193
195
|
- spec/types/symbol_spec.rb
|
@@ -228,6 +230,7 @@ test_files:
|
|
228
230
|
- spec/types/form_spec.rb
|
229
231
|
- spec/types/hash_spec.rb
|
230
232
|
- spec/types/integer_spec.rb
|
233
|
+
- spec/types/io_spec.rb
|
231
234
|
- spec/types/regexp_spec.rb
|
232
235
|
- spec/types/string_spec.rb
|
233
236
|
- spec/types/symbol_spec.rb
|