compel 0.3.1 → 0.3.2

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: 258250ae836758b145cc384b581c628a696260b8
4
- data.tar.gz: 1298e32dee4358430f051fcb378785e487b4123a
3
+ metadata.gz: dd41d8ef8ee213b7c02d1ba4d465fa3d9e3afbca
4
+ data.tar.gz: 7443f067c1f523c1b455b68f1257eda3abc1df06
5
5
  SHA512:
6
- metadata.gz: 69e0028f7dc235d8a8cf5e8a2bd3af74c59c11c7c37cf933a041447360444774e0590d38bad735ee8cf8463f602f48d38981394c7f109519ef604effc0da9d60
7
- data.tar.gz: a580c0ff252daecc215142f323ca35f4d874cd62893da793ff5175f7f4c1d1491ba1272608043681dbed2ee87c9db17077407718c78b7556ba076ef5223404c9
6
+ metadata.gz: 44c69252f56c16deb155cdfdc75f4da36bbf212f3cf114959f7b9d69eb9449c38bb9d3769aeb0ad10351ef6ae18362d3e1696a80bdfbe8ca9fc85e53953a01a6
7
+ data.tar.gz: e66cda22c5cb242fbe548667dde04529fdd37b48c5049be7311420d03a2209fb3e2e5a5f7da1d6617b603bfa7b96ab536708d5ac1250e5d627dfb7b8272bfef2
data/README.md CHANGED
@@ -62,14 +62,14 @@ Will return an [Hashie::Mash](https://github.com/intridea/hashie) object:
62
62
  }
63
63
  ```
64
64
 
65
- There are 3 ways to run validations:
65
+ There are 4 ways to run validations:
66
66
 
67
67
  Method | Behaviour
68
68
  ------------- | -------------
69
69
  `#run` | Validates and returns an Hash with coerced params plus a `:errors` key with a _Rails like_ Hash of errors if any.
70
70
  `#run!` | Validates and raises `Compel::InvalidObjectError` exception with the coerced params and errors.
71
71
  `#run?` | Validates and returns true or false.
72
- `schema#validate` | Chech below
72
+ `schema#validate` | Check below
73
73
 
74
74
  ==========================
75
75
 
@@ -43,9 +43,16 @@ module Compel
43
43
  if !result.valid?
44
44
  # TODO: ArrayValidator should do this for me:
45
45
  # remove invalid coerced index,
46
- # and set the original value
46
+ # and set the original value.
47
+ # If it's an Hash, keep errors key
47
48
  result.errors.keys.each do |index|
48
- @output[index.to_i] = values[index.to_i]
49
+ if @output[index.to_i].is_a?(Hash)
50
+ # Keep errors key on hash if exists
51
+ @output[index.to_i].merge!(values[index.to_i])
52
+ else
53
+ # Array, Integer, String, Float, Dates.. etc
54
+ @output[index.to_i] = values[index.to_i]
55
+ end
49
56
  end
50
57
 
51
58
  @errors = result.errors
@@ -1,3 +1,3 @@
1
1
  module Compel
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
@@ -393,6 +393,31 @@ describe Compel::Builder do
393
393
  include("'a' is not a valid Integer")
394
394
  end
395
395
 
396
+ it 'should coerce hash with array of hashes with errors' do
397
+ schema = Compel.hash.keys(
398
+ actions: Compel.array.items(
399
+ Compel.hash.keys(
400
+ a: Compel.string.required,
401
+ b: Compel.string.format(/^abc$/)
402
+ )
403
+ )
404
+ )
405
+
406
+ object = {
407
+ other_key: 1,
408
+ actions: [
409
+ { a: 'A', b: 'abc' },
410
+ { a: 'B' },
411
+ { a: 'C', b: 'abcd' }
412
+ ]
413
+ }
414
+
415
+ result = schema.validate(object)
416
+
417
+ expect(result.value[:actions][2][:errors][:b]).to \
418
+ include('must match format ^abc$')
419
+ end
420
+
396
421
  end
397
422
 
398
423
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joaquim Adráz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-29 00:00:00.000000000 Z
11
+ date: 2015-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie