compel 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68ba3b85759b0fddf7579d70d30d62f311ce365e
4
- data.tar.gz: a250017bbdf6de848efcbdae5cd4664bd6261501
3
+ metadata.gz: babd567c6c66e9826606f628417eb16599a30f43
4
+ data.tar.gz: 3abbd9005a7aeb99146677491cd5a9d9b59add3a
5
5
  SHA512:
6
- metadata.gz: 5ce4e60243142f7f0b6312c4e80ff5e09068b029c54e989fc8149f84740d62383ed952a1db685e1a97f62a2842efa221c14562d67d8692260ca76fc97f545eb8
7
- data.tar.gz: 728d7340542f63acea00f5e40da20c90ff93b591c07f132a2a18ff8c85bca7176df4527a2d83944455d1b603bbe742f8cfacf399e8014e4bdbc8bfa61bf287a4
6
+ metadata.gz: b326bc4046b7844f027a5cde2ed1316dfe32180a5b2a804a93b368221740f05f88cb43d1c9781080aa80ea00391845ac16f1602fc94c637d7e51bba9daee352f
7
+ data.tar.gz: 77f93f863cd71d5779d7e76d0d658c41f47ca9e0766fc38fbfd8ba08a1a390c946c75bd3621549cff20708711a6c24101c4e7f2ea04b7f0c34a7a0dec09d7dc1
@@ -26,9 +26,9 @@ module Compel
26
26
  # build a new Compel::Contract form inner conditions
27
27
  if (param.hash? && param.conditions?)
28
28
 
29
- # If this param is required, build the Compel::Contract,
29
+ # If this param is required, a value must be given to build the Compel::Contract
30
30
  # otherwise, only build it if is given a value for the param
31
- if param.required? || !param.value.nil?
31
+ if (param.required? && !param.value.nil?) || !param.value.nil?
32
32
  contract = Contract.new(param.value, &param.conditions).validate
33
33
 
34
34
  @errors.add(param.name, contract.errors)
@@ -44,7 +44,6 @@ module Compel
44
44
 
45
45
  # If the param value has already been coerced from digging into child Hash
46
46
  # use that value instead, so we don't lose the previous coerced values
47
-
48
47
  coerced_value = Coercion.coerce! \
49
48
  (@coerced_params[param.name].nil? ? param.value : @coerced_params[param.name]), param.type, param.options
50
49
 
@@ -1,3 +1,3 @@
1
1
  module Compel
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -204,7 +204,7 @@ describe Compel do
204
204
  errors: {
205
205
  address: {
206
206
  line_one: ['is required'],
207
- post_code: ['params must be an Hash']
207
+ post_code: ['is required']
208
208
  }
209
209
  }
210
210
  })
@@ -304,6 +304,29 @@ describe Compel do
304
304
  }
305
305
  }
306
306
  })
307
+
308
+ end
309
+
310
+ it 'should not compel 4' do
311
+ params = {
312
+ address: nil
313
+ }
314
+
315
+ expect(make_the_call(:run, params)).to eq \
316
+ Hashie::Mash.new({
317
+ errors: {
318
+ address: ['is required']
319
+ }
320
+ })
321
+ end
322
+
323
+ it 'should not compel 5' do
324
+ expect(make_the_call(:run, {})).to eq \
325
+ Hashie::Mash.new({
326
+ errors: {
327
+ address: ['is required']
328
+ }
329
+ })
307
330
  end
308
331
 
309
332
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joaquim Adráz