rasti-form 3.1.2 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +36 -0
- data/README.md +6 -61
- data/lib/rasti/form/errors.rb +6 -52
- data/lib/rasti/form/validable.rb +10 -7
- data/lib/rasti/form.rb +40 -131
- data/rasti-form.gemspec +2 -12
- data/spec/coverage_helper.rb +1 -3
- data/spec/minitest_helper.rb +1 -7
- data/spec/validations_spec.rb +333 -0
- metadata +19 -48
- data/.travis.yml +0 -20
- data/lib/rasti/form/castable.rb +0 -25
- data/lib/rasti/form/types/array.rb +0 -54
- data/lib/rasti/form/types/boolean.rb +0 -42
- data/lib/rasti/form/types/enum.rb +0 -48
- data/lib/rasti/form/types/float.rb +0 -33
- data/lib/rasti/form/types/form.rb +0 -40
- data/lib/rasti/form/types/hash.rb +0 -39
- data/lib/rasti/form/types/integer.rb +0 -21
- data/lib/rasti/form/types/io.rb +0 -23
- data/lib/rasti/form/types/regexp.rb +0 -23
- data/lib/rasti/form/types/string.rb +0 -40
- data/lib/rasti/form/types/symbol.rb +0 -23
- data/lib/rasti/form/types/time.rb +0 -40
- data/lib/rasti/form/types/uuid.rb +0 -7
- data/lib/rasti/form/version.rb +0 -5
- data/spec/form_spec.rb +0 -411
- data/spec/types/array_spec.rb +0 -54
- data/spec/types/boolean_spec.rb +0 -24
- data/spec/types/enum_spec.rb +0 -28
- data/spec/types/float_spec.rb +0 -18
- data/spec/types/form_spec.rb +0 -41
- data/spec/types/hash_spec.rb +0 -20
- data/spec/types/integer_spec.rb +0 -18
- data/spec/types/io_spec.rb +0 -18
- data/spec/types/regexp_spec.rb +0 -18
- data/spec/types/string_formatted_spec.rb +0 -20
- data/spec/types/string_spec.rb +0 -16
- data/spec/types/symbol_spec.rb +0 -16
- data/spec/types/time_spec.rb +0 -25
- data/spec/types/uuid_spec.rb +0 -18
data/spec/types/boolean_spec.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'minitest_helper'
|
2
|
-
|
3
|
-
describe Rasti::Form::Types::Boolean do
|
4
|
-
|
5
|
-
[true, 'true', 'True', 'TRUE', 'T'].each do |value|
|
6
|
-
it "#{value.inspect} -> true" do
|
7
|
-
Rasti::Form::Types::Boolean.cast(value).must_equal true
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
[false, 'false', 'False', 'FALSE', 'F'].each do |value|
|
12
|
-
it "#{value.inspect} -> false" do
|
13
|
-
Rasti::Form::Types::Boolean.cast(value).must_equal false
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
[nil, 'text', 123, :false, :true, Time.now, [1,2], {a: 1, b: 2}, Object.new].each do |value|
|
18
|
-
it "#{value.inspect} -> CastError" do
|
19
|
-
error = proc { Rasti::Form::Types::Boolean.cast(value) }.must_raise Rasti::Form::CastError
|
20
|
-
error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::Boolean"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
data/spec/types/enum_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'minitest_helper'
|
2
|
-
|
3
|
-
describe Rasti::Form::Types::Enum do
|
4
|
-
|
5
|
-
enum = Rasti::Form::Types::Enum[:a,:b,:c]
|
6
|
-
|
7
|
-
[:a, 'b', "c"].each do |value|
|
8
|
-
it "#{value.inspect} -> #{enum}" do
|
9
|
-
Rasti::Form::Types::Enum[:a,:b,:c].cast(value).must_equal value.to_s
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
[nil, 'text', :symbol, '999'.to_sym, [1,2], {a: 1, b: 2}, Object.new].each do |value|
|
14
|
-
it "#{value.inspect} -> CastError" do
|
15
|
-
error = proc { Rasti::Form::Types::Enum[:a,:b,:c].cast(value) }.must_raise Rasti::Form::CastError
|
16
|
-
error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::Enum[\"a\", \"b\", \"c\"]"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'Constants' do
|
21
|
-
enum = Rasti::Form::Types::Enum[:first_value, 'SecondValue', 'THIRD_VALUE']
|
22
|
-
|
23
|
-
enum.first_value.must_equal 'first_value'
|
24
|
-
enum.second_value.must_equal 'SecondValue'
|
25
|
-
enum.third_value.must_equal 'THIRD_VALUE'
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
data/spec/types/float_spec.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'minitest_helper'
|
2
|
-
|
3
|
-
describe Rasti::Form::Types::Float do
|
4
|
-
|
5
|
-
[100, '200', Time.now,2.0,"12.5"].each do |value|
|
6
|
-
it "#{value.inspect} -> #{value.to_i}" do
|
7
|
-
Rasti::Form::Types::Float.cast(value).must_equal value.to_f
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
[nil, 'text', :symbol, '999'.to_sym, [1,2], {a: 1, b: 2}, Object.new, "1.", ".2","."].each do |value|
|
12
|
-
it "#{value.inspect} -> CastError" do
|
13
|
-
error = proc { Rasti::Form::Types::Float.cast(value) }.must_raise Rasti::Form::CastError
|
14
|
-
error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::Float"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
data/spec/types/form_spec.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'minitest_helper'
|
2
|
-
|
3
|
-
describe Rasti::Form::Types::Form do
|
4
|
-
|
5
|
-
form = Rasti::Form[x: Rasti::Form::Types::Integer, y: Rasti::Form::Types::Integer]
|
6
|
-
|
7
|
-
hash = {x: '1', y: '2'}
|
8
|
-
|
9
|
-
it 'Class' do
|
10
|
-
result = Rasti::Form::Types::Form[form].cast hash
|
11
|
-
result.must_be_instance_of form
|
12
|
-
result.x.must_equal 1
|
13
|
-
result.y.must_equal 2
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'Inline' do
|
17
|
-
type = Rasti::Form::Types::Form[x: Rasti::Form::Types::Integer, y: Rasti::Form::Types::Integer]
|
18
|
-
result = type.cast hash
|
19
|
-
result.must_be_instance_of type.form_class
|
20
|
-
result.x.must_equal 1
|
21
|
-
result.y.must_equal 2
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'Invalid form class' do
|
25
|
-
error = proc { Rasti::Form::Types::Form[1] }.must_raise ArgumentError
|
26
|
-
error.message.must_equal 'Invalid form specification: 1'
|
27
|
-
end
|
28
|
-
|
29
|
-
[nil, 'text', :symbol, 1, [1,2], Object.new].each do |value|
|
30
|
-
it "#{value.inspect} -> CastError" do
|
31
|
-
error = proc { Rasti::Form::Types::Form[form].cast(value) }.must_raise Rasti::Form::CastError
|
32
|
-
error.message.must_equal "Invalid cast: #{as_string(value)} -> #{Rasti::Form::Types::Form[form]}"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it '{x: "text"} -> ValidationError' do
|
37
|
-
error = proc { Rasti::Form::Types::Form[form].cast x: 'test' }.must_raise Rasti::Form::ValidationError
|
38
|
-
error.message.must_equal "Validation errors:\n- x: [\"Invalid cast: 'test' -> Rasti::Form::Types::Integer\"]"
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
data/spec/types/hash_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'minitest_helper'
|
2
|
-
|
3
|
-
describe Rasti::Form::Types::Hash do
|
4
|
-
|
5
|
-
it "{'a' => '123'} -> {a: 123}" do
|
6
|
-
Rasti::Form::Types::Hash[Rasti::Form::Types::Symbol, Rasti::Form::Types::Integer].cast('a' => '123').must_equal a: 123
|
7
|
-
end
|
8
|
-
|
9
|
-
it "{'1' => :abc} -> {1 => 'abc'}" do
|
10
|
-
Rasti::Form::Types::Hash[Rasti::Form::Types::Integer, Rasti::Form::Types::String].cast('1' => :abc).must_equal 1 => 'abc'
|
11
|
-
end
|
12
|
-
|
13
|
-
[nil, 1, 'text', :symbol, {a: true}, Object.new].each do |value|
|
14
|
-
it "#{value.inspect} -> CastError" do
|
15
|
-
error = proc { Rasti::Form::Types::Hash[Rasti::Form::Types::Symbol, Rasti::Form::Types::Integer].cast(value) }.must_raise Rasti::Form::CastError
|
16
|
-
error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::Hash[Rasti::Form::Types::Symbol, Rasti::Form::Types::Integer]"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
data/spec/types/integer_spec.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'minitest_helper'
|
2
|
-
|
3
|
-
describe Rasti::Form::Types::Integer do
|
4
|
-
|
5
|
-
[100, '200', Time.now, 2.1, "12.5"].each do |value|
|
6
|
-
it "#{value.inspect} -> #{value.to_i}" do
|
7
|
-
Rasti::Form::Types::Integer.cast(value).must_equal value.to_i
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
[nil, 'text', :symbol, '999'.to_sym, [1,2], {a: 1, b: 2}, Object.new].each do |value|
|
12
|
-
it "#{value.inspect} -> CastError" do
|
13
|
-
error = proc { Rasti::Form::Types::Integer.cast(value) }.must_raise Rasti::Form::CastError
|
14
|
-
error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::Integer"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
data/spec/types/io_spec.rb
DELETED
@@ -1,18 +0,0 @@
|
|
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
|
data/spec/types/regexp_spec.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'minitest_helper'
|
2
|
-
|
3
|
-
describe Rasti::Form::Types::Regexp do
|
4
|
-
|
5
|
-
['[a-z]', /[a-z]/].each do |value|
|
6
|
-
it "#{value.inspect} -> #{Regexp.new(value).inspect}" do
|
7
|
-
Rasti::Form::Types::Regexp.cast(value).must_equal Regexp.new(value).source
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
[nil, '[a-z', :symbol, [1,2], {a: 1, b: 2}, Object.new, 5].each do |value|
|
12
|
-
it "#{value.inspect} -> CastError" do
|
13
|
-
error = proc { Rasti::Form::Types::Regexp.cast(value) }.must_raise Rasti::Form::CastError
|
14
|
-
error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::Regexp"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'minitest_helper'
|
2
|
-
|
3
|
-
describe Rasti::Form::Types::String, 'Formatted' do
|
4
|
-
|
5
|
-
email_regexp = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
|
6
|
-
|
7
|
-
['user@mail.com'.to_sym, 'user.name-123@mail-test.com.ar'].each do |value|
|
8
|
-
it "#{value.inspect} -> #{value.to_s}" do
|
9
|
-
Rasti::Form::Types::String[email_regexp].cast(value).must_equal value.to_s
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
[nil, 'text', :symbol, '999'.to_sym, [1,2], {a: 1, b: 2}, Object.new, 5].each do |value|
|
14
|
-
it "#{value.inspect} -> CastError" do
|
15
|
-
error = proc { Rasti::Form::Types::String[email_regexp].cast(value) }.must_raise Rasti::Form::CastError
|
16
|
-
error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::String[#{as_string(email_regexp)}]"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
data/spec/types/string_spec.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'minitest_helper'
|
2
|
-
|
3
|
-
describe Rasti::Form::Types::String do
|
4
|
-
|
5
|
-
['text', :symbol, true, false, 100, Time.now, [1,2], {a: 1, b: 2}, Object.new].each do |value|
|
6
|
-
it "#{value.inspect} -> \"#{value.to_s}\"" do
|
7
|
-
Rasti::Form::Types::String.cast(value).must_equal value.to_s
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'nil -> CastError' do
|
12
|
-
error = proc { Rasti::Form::Types::String.cast(nil) }.must_raise Rasti::Form::CastError
|
13
|
-
error.message.must_equal 'Invalid cast: nil -> Rasti::Form::Types::String'
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
data/spec/types/symbol_spec.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'minitest_helper'
|
2
|
-
|
3
|
-
describe Rasti::Form::Types::Symbol do
|
4
|
-
|
5
|
-
['text', :symbol, true, false, 100, Time.now, [1,2], {a: 1, b: 2}, Object.new].each do |value|
|
6
|
-
it "#{value.inspect} -> \"#{value.to_s.to_sym}\"" do
|
7
|
-
Rasti::Form::Types::Symbol.cast(value).must_equal value.to_s.to_sym
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'nil -> CastError' do
|
12
|
-
error = proc { Rasti::Form::Types::Symbol.cast(nil) }.must_raise Rasti::Form::CastError
|
13
|
-
error.message.must_equal 'Invalid cast: nil -> Rasti::Form::Types::Symbol'
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
data/spec/types/time_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'minitest_helper'
|
2
|
-
|
3
|
-
describe Rasti::Form::Types::Time do
|
4
|
-
|
5
|
-
time = Time.new 2016, 8, 18
|
6
|
-
|
7
|
-
it "#{time.inspect} -> #{time.inspect}" do
|
8
|
-
Rasti::Form::Types::Time['%F %T %z'].cast(time).must_equal time
|
9
|
-
end
|
10
|
-
|
11
|
-
['%d/%m/%y', '%Y-%m-%d'].each do |format|
|
12
|
-
time_string = time.strftime(format)
|
13
|
-
it "#{time_string.inspect} -> #{time.inspect}" do
|
14
|
-
Rasti::Form::Types::Time[format].cast(time_string).must_equal time
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
[time.strftime('%d/%m/%y'), 'text', nil, 1, :symbol, [1,2], {a: 1, b: 2}, Object.new].each do |value|
|
19
|
-
it "#{value.inspect} -> CastError" do
|
20
|
-
error = proc { Rasti::Form::Types::Time['%F'].cast(value) }.must_raise Rasti::Form::CastError
|
21
|
-
error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::Time['%F']"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
data/spec/types/uuid_spec.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'minitest_helper'
|
2
|
-
|
3
|
-
describe Rasti::Form::Types::UUID do
|
4
|
-
|
5
|
-
['f09b7716-81a9-11e6-a549-bb8f165bcf02', '12345678-1234-1234-1234-123456789123'].each do |value|
|
6
|
-
it "#{value.inspect} -> #{value.to_s}" do
|
7
|
-
Rasti::Form::Types::UUID.cast(value).must_equal value.to_s
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
[nil, 'text', :symbol, '999'.to_sym, [1,2], {a: 1, b: 2}, Object.new, 5, 'f09b7716-81a9-11e6-a549-bb16502', 'f09b7716-11e6-a549-bb8f16502', '-84a9-11e6-a549-bb8f16502', 'f09b7716-81a9-11e6-a549-bh16502'].each do |value|
|
12
|
-
it "#{value.inspect} -> CastError" do
|
13
|
-
error = proc { Rasti::Form::Types::UUID.cast(value) }.must_raise Rasti::Form::CastError
|
14
|
-
error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::UUID"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|