rasti-form 3.1.0 → 3.1.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
  SHA256:
3
- metadata.gz: d866f9b7a43e27b5a12fbe5044672018066e99d45c2cce45bc7cb80baef095c1
4
- data.tar.gz: 9c24281985c31043750f3998c6ddc857c30830abba2a6f6128d0cfe45c5d8432
3
+ metadata.gz: 30eebb17e0a18f1c4ea84fb4dc617742325e38876cb03f6b85af4a29b2a6bcd6
4
+ data.tar.gz: 2e3ebc2338f62e608cec51a596db988b3f59751be11572a92216542f37fbb23f
5
5
  SHA512:
6
- metadata.gz: ff8eab55df69a186a42353248bb9218ae79352057642db8ea96af007c3a2717ed908d7b1219e803af11ed87e2d0166557e22ab58c849bdffa1638353f66bc3c7
7
- data.tar.gz: 3e102c9dae971bb5482665db5471bbf1420ba35b2c81960bcd02583b119970dd5ba54df79450fe19ab50a3134b619809d1d234a21380725375460b86b59dcd37
6
+ metadata.gz: dc4a4484961c15e7b054d5aabadcacf61a4ec2e9d40973ee8f226dc3bcb62bd2c46a07e710c84bfb97bfe31fd78bef256009ec34b554f789ea1e4f6c3ea7d57b
7
+ data.tar.gz: 5e46bfdfdd2a5cf657f30e901cd68dd43f8aefada51c1fbfd52a9eee09bf1bb232c0f86f07a4bf67430dbbc48e8043d9b1e50157a0cc620fa37d249675ac3bc4
@@ -18,13 +18,13 @@ module Rasti
18
18
  attributes.each do |name, type, options={}|
19
19
  attribute name, type, options
20
20
  end
21
-
22
- def self.inherited(subclass)
23
- subclass.instance_variable_set :@attributes, attributes.dup
24
- end
25
21
  end
26
22
  end
27
23
 
24
+ def inherited(subclass)
25
+ subclass.instance_variable_set :@attributes, attributes.dup
26
+ end
27
+
28
28
  def attribute(name, type, options={})
29
29
  attributes[name.to_sym] = options.merge(type: type)
30
30
  attr_reader name
@@ -53,7 +53,15 @@ module Rasti
53
53
  end
54
54
 
55
55
  def message
56
- "Validation error: #{scope} #{JSON.dump(errors)}"
56
+ lines = ['Validation errors:']
57
+
58
+ errors.each do |key, value|
59
+ lines << "- #{key}: #{value}"
60
+ end
61
+
62
+ lines << scope.inspect
63
+
64
+ lines.join("\n")
57
65
  end
58
66
 
59
67
  end
@@ -1,5 +1,5 @@
1
1
  module Rasti
2
2
  class Form
3
- VERSION = '3.1.0'
3
+ VERSION = '3.1.1'
4
4
  end
5
5
  end
@@ -40,7 +40,7 @@ describe Rasti::Form do
40
40
 
41
41
  it 'Invalid attributes' do
42
42
  error = proc { point_class.new z: 3 }.must_raise Rasti::Form::ValidationError
43
- error.message.must_equal 'Validation error: #<Rasti::Form[]> {"z":["unexpected attribute"]}'
43
+ error.message.must_equal "Validation errors:\n- z: [\"unexpected attribute\"]\n#<Rasti::Form[]>"
44
44
  end
45
45
 
46
46
  describe 'Casting' do
@@ -86,7 +86,7 @@ describe Rasti::Form do
86
86
  end
87
87
 
88
88
  error = proc { form.new boolean: 'x', number: 'y' }.must_raise Rasti::Form::ValidationError
89
- error.message.must_equal 'Validation error: #<Rasti::Form[]> {"boolean":["Invalid cast: \'x\' -> Rasti::Form::Types::Boolean"],"number":["Invalid cast: \'y\' -> Rasti::Form::Types::Integer"]}'
89
+ error.message.must_equal "Validation errors:\n- boolean: [\"Invalid cast: \'x\' -> Rasti::Form::Types::Boolean\"]\n- number: [\"Invalid cast: \'y\' -> Rasti::Form::Types::Integer\"]\n#<Rasti::Form[]>"
90
90
  end
91
91
 
92
92
  it 'Invalid nested attributes' do
@@ -95,7 +95,7 @@ describe Rasti::Form do
95
95
  end
96
96
 
97
97
  error = proc { form.new range: {min: 'x', max: 'y'} }.must_raise Rasti::Form::ValidationError
98
- error.message.must_equal "Validation error: #<Rasti::Form[]> {\"range.min\":[\"Invalid cast: 'x' -> Rasti::Form::Types::Integer\"],\"range.max\":[\"Invalid cast: 'y' -> Rasti::Form::Types::Integer\"]}"
98
+ error.message.must_equal "Validation errors:\n- range.min: [\"Invalid cast: 'x' -> Rasti::Form::Types::Integer\"]\n- range.max: [\"Invalid cast: 'y' -> Rasti::Form::Types::Integer\"]\n#<Rasti::Form[]>"
99
99
  end
100
100
 
101
101
  it 'Invalid form attributes' do
@@ -109,7 +109,7 @@ describe Rasti::Form do
109
109
  end
110
110
 
111
111
  error = proc { form.new range: {min: 'x', max: 'y'} }.must_raise Rasti::Form::ValidationError
112
- error.message.must_equal "Validation error: #<Rasti::Form[]> {\"range.min\":[\"Invalid cast: 'x' -> Rasti::Form::Types::Integer\"],\"range.max\":[\"Invalid cast: 'y' -> Rasti::Form::Types::Integer\"]}"
112
+ error.message.must_equal "Validation errors:\n- range.min: [\"Invalid cast: 'x' -> Rasti::Form::Types::Integer\"]\n- range.max: [\"Invalid cast: 'y' -> Rasti::Form::Types::Integer\"]\n#<Rasti::Form[]>"
113
113
  end
114
114
 
115
115
  end
@@ -155,7 +155,7 @@ describe Rasti::Form do
155
155
  proc { form.new text: 'text' }.must_be_silent
156
156
 
157
157
  error = proc { form.new }.must_raise Rasti::Form::ValidationError
158
- error.message.must_equal 'Validation error: #<Rasti::Form[]> {"text":["Invalid text"]}'
158
+ error.message.must_equal "Validation errors:\n- text: [\"Invalid text\"]\n#<Rasti::Form[]>"
159
159
  end
160
160
 
161
161
  it 'Required' do
@@ -170,7 +170,7 @@ describe Rasti::Form do
170
170
  proc { form.new text: 'text' }.must_be_silent
171
171
 
172
172
  error = proc { form.new }.must_raise Rasti::Form::ValidationError
173
- error.message.must_equal 'Validation error: #<Rasti::Form[]> {"text":["not present"]}'
173
+ error.message.must_equal "Validation errors:\n- text: [\"not present\"]\n#<Rasti::Form[]>"
174
174
  end
175
175
 
176
176
  it 'Required when cast failed' do
@@ -185,7 +185,7 @@ describe Rasti::Form do
185
185
  proc { form.new number: 1 }.must_be_silent
186
186
 
187
187
  error = proc { form.new number: 'text' }.must_raise Rasti::Form::ValidationError
188
- error.message.must_equal "Validation error: #<Rasti::Form[]> {\"number\":[\"Invalid cast: 'text' -> Rasti::Form::Types::Integer\"]}"
188
+ error.message.must_equal "Validation errors:\n- number: [\"Invalid cast: 'text' -> Rasti::Form::Types::Integer\"]\n#<Rasti::Form[]>"
189
189
  end
190
190
 
191
191
  it 'Not required' do
@@ -200,7 +200,7 @@ describe Rasti::Form do
200
200
  proc { form.new }.must_be_silent
201
201
 
202
202
  error = proc { form.new text: 'text' }.must_raise Rasti::Form::ValidationError
203
- error.message.must_equal 'Validation error: #<Rasti::Form[text: "text"]> {"text":["is present"]}'
203
+ error.message.must_equal "Validation errors:\n- text: [\"is present\"]\n#<Rasti::Form[text: \"text\"]>"
204
204
  end
205
205
 
206
206
  it 'Not empty string' do
@@ -215,7 +215,7 @@ describe Rasti::Form do
215
215
  proc { form.new text: 'text' }.must_be_silent
216
216
 
217
217
  error = proc { form.new text: ' ' }.must_raise Rasti::Form::ValidationError
218
- error.message.must_equal 'Validation error: #<Rasti::Form[text: " "]> {"text":["is empty"]}'
218
+ error.message.must_equal "Validation errors:\n- text: [\"is empty\"]\n#<Rasti::Form[text: \" \"]>"
219
219
  end
220
220
 
221
221
  it 'Not empty array' do
@@ -230,7 +230,7 @@ describe Rasti::Form do
230
230
  proc { form.new array: ['text'] }.must_be_silent
231
231
 
232
232
  error = proc { form.new array: [] }.must_raise Rasti::Form::ValidationError
233
- error.message.must_equal 'Validation error: #<Rasti::Form[array: []]> {"array":["is empty"]}'
233
+ error.message.must_equal "Validation errors:\n- array: [\"is empty\"]\n#<Rasti::Form[array: []]>"
234
234
  end
235
235
 
236
236
  it 'Included in values list' do
@@ -245,7 +245,7 @@ describe Rasti::Form do
245
245
  proc { form.new text: 'value_1' }.must_be_silent
246
246
 
247
247
  error = proc { form.new text: 'xyz' }.must_raise Rasti::Form::ValidationError
248
- error.message.must_equal 'Validation error: #<Rasti::Form[text: "xyz"]> {"text":["not included in \'value_1\', \'value_2\'"]}'
248
+ error.message.must_equal "Validation errors:\n- text: [\"not included in \'value_1\', \'value_2\'\"]\n#<Rasti::Form[text: \"xyz\"]>"
249
249
  end
250
250
 
251
251
  it 'Time range' do
@@ -264,7 +264,7 @@ describe Rasti::Form do
264
264
  proc { form.new from: from, to: to }.must_be_silent
265
265
 
266
266
  error = proc { form.new from: to.to_s, to: from.to_s }.must_raise Rasti::Form::ValidationError
267
- error.message.must_equal "Validation error: #<Rasti::Form[from: #{to}, to: #{from}]> {\"from\":[\"invalid time range\"]}"
267
+ error.message.must_equal "Validation errors:\n- from: [\"invalid time range\"]\n#<Rasti::Form[from: #{to}, to: #{from}]>"
268
268
  end
269
269
 
270
270
  it 'Nested form' do
@@ -280,7 +280,7 @@ describe Rasti::Form do
280
280
  proc { form.new range: {min: 1, max: 2} }.must_be_silent
281
281
 
282
282
  error = proc { form.new }.must_raise Rasti::Form::ValidationError
283
- error.message.must_equal 'Validation error: #<Rasti::Form[]> {"range.min":["not present"],"range.max":["not present"]}'
283
+ error.message.must_equal "Validation errors:\n- range.min: [\"not present\"]\n- range.max: [\"not present\"]\n#<Rasti::Form[]>"
284
284
  end
285
285
 
286
286
  it 'Nested validation' do
@@ -300,7 +300,7 @@ describe Rasti::Form do
300
300
  proc { form.new range: {min: 1, max: 2} }.must_be_silent
301
301
 
302
302
  error = proc { form.new range: {min: 2, max: 1} }.must_raise Rasti::Form::ValidationError
303
- error.message.must_equal 'Validation error: #<Rasti::Form[]> {"range.min":["Min must be less than Max"]}'
303
+ error.message.must_equal "Validation errors:\n- range.min: [\"Min must be less than Max\"]\n#<Rasti::Form[]>"
304
304
  end
305
305
 
306
306
  end
@@ -46,7 +46,7 @@ describe Rasti::Form::Types::Array do
46
46
 
47
47
  error.errors.must_equal 'points.2.x' => ["Invalid cast: 'a' -> Rasti::Form::Types::Integer"],
48
48
  'points.3.y' => ["Invalid cast: 'b' -> Rasti::Form::Types::Integer"]
49
- error.message.must_equal "Validation error: #<Rasti::Form[]> {\"points.2.x\":[\"Invalid cast: 'a' -> Rasti::Form::Types::Integer\"],\"points.3.y\":[\"Invalid cast: 'b' -> Rasti::Form::Types::Integer\"]}"
49
+ error.message.must_equal "Validation errors:\n- points.2.x: [\"Invalid cast: 'a' -> Rasti::Form::Types::Integer\"]\n- points.3.y: [\"Invalid cast: 'b' -> Rasti::Form::Types::Integer\"]\n#<Rasti::Form[]>"
50
50
  end
51
51
 
52
52
  end
@@ -35,7 +35,7 @@ describe Rasti::Form::Types::Form do
35
35
 
36
36
  it '{x: "text"} -> ValidationError' do
37
37
  error = proc { Rasti::Form::Types::Form[form].cast x: 'test' }.must_raise Rasti::Form::ValidationError
38
- error.message.must_equal "Validation error: #<Rasti::Form[]> {\"x\":[\"Invalid cast: 'test' -> Rasti::Form::Types::Integer\"]}"
38
+ error.message.must_equal "Validation errors:\n- x: [\"Invalid cast: 'test' -> Rasti::Form::Types::Integer\"]\n#<Rasti::Form[]>"
39
39
  end
40
40
 
41
41
  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: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Naiman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-03 00:00:00.000000000 Z
11
+ date: 2020-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_require