hash_validator 0.5.0 → 0.6.0

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: d01484b5d387d49f0b2dcf62ca144f09fd5e6aa9
4
- data.tar.gz: 50de42b9c7bdbc0369b771e40fa08bd08eb24522
3
+ metadata.gz: cf1be444ed797f5eb29cf69a168d6954c06ecfe9
4
+ data.tar.gz: 4bd3fc6857245aacb1f60e046e5fbb200ab0c5ab
5
5
  SHA512:
6
- metadata.gz: 5a96a9c75edfbc5818b408f6da927d4ac8bf0d3e833921f269961c55c49070eeaac2b5fe12291f66644b6838c83f6fcbd3493404928f812dcf6496739225747b
7
- data.tar.gz: 3b08657aa451d38bcacef3a4bf940e228c5ba534045d486fe9813c5a87ed5ff16e9c31691e4dc3a8e5dca41e815d05c0b6daf0fed0d0d603a6008c9fdea4f3f0
6
+ metadata.gz: dfd2fb4cd260de7e6c5af4c303fef12cc6787707cb2048317a790acdbbebbbbc7f9e8e9ada6603c99b540ceeb995a5f7141b933e0a030c1bead07f5e1d1d2793
7
+ data.tar.gz: 0fe4873c5a5fd271ed2fc79d28db3fa90523d1f835845932096faaa23ded1cda2c9f9d301cf4e2d7efca13b87bb090f8d2d69f90e64d1783dbb57fc2a1991c58
data/.travis.yml CHANGED
@@ -1,4 +1,7 @@
1
1
  language: ruby
2
+ before_install:
3
+ - "gem install bundler"
4
+ cache: bundler
2
5
  rvm:
3
6
  - 1.9.2
4
7
  - 1.9.3
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Build Status](https://travis-ci.org/jamesbrooks/hash_validator.svg)](https://travis-ci.org/jamesbrooks/hash_validator)
5
5
  [![Coverage Status](https://coveralls.io/repos/jamesbrooks/hash_validator/badge.svg?branch=master)](https://coveralls.io/r/jamesbrooks/hash_validator)
6
6
  [![Code Climate](https://codeclimate.com/github/JamesBrooks/hash_validator.svg)](https://codeclimate.com/github/JamesBrooks/hash_validator)
7
- [![Dependency Status](https://gemnasium.com/jamesbrooks/hash_validator.png)](https://gemnasium.com/jamesbrooks/hash_validator)
7
+ [![Dependency Status](https://gemnasium.com/badges/github.com/JamesBrooks/hash_validator.svg)](https://gemnasium.com/github.com/JamesBrooks/hash_validator)
8
8
 
9
9
  Ruby library to validate hashes (Hash) against user-defined requirements
10
10
 
@@ -3,15 +3,15 @@ class HashValidator::Validator::Base
3
3
 
4
4
 
5
5
  def initialize(name)
6
- unless name.is_a?(String) && name.size > 0
7
- raise StandardError.new('Validator must be initialized with a valid name (string with length greater than zero)')
8
- end
6
+ self.name = name.to_s
9
7
 
10
- self.name = name
8
+ unless self.name.size > 0
9
+ raise StandardError.new('Validator must be initialized with a valid name (length greater than zero)')
10
+ end
11
11
  end
12
12
 
13
13
  def should_validate?(name)
14
- self.name == name
14
+ self.name == name.to_s
15
15
  end
16
16
 
17
17
  def presence_error_message
@@ -1,3 +1,3 @@
1
1
  module HashValidator
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -71,6 +71,16 @@ describe HashValidator do
71
71
  end
72
72
  end
73
73
 
74
+ describe 'validator syntax' do
75
+ it 'should allow strings as validator names' do
76
+ expect(validate({ v: 'test' }, { v: 'string' }).valid?).to eq true
77
+ end
78
+
79
+ it 'should allow symbols as validator names' do
80
+ expect(validate({ v: 'test' }, { v: :string }).valid?).to eq true
81
+ end
82
+ end
83
+
74
84
  describe 'full validations' do
75
85
  let(:empty_hash) {{}}
76
86
 
@@ -226,7 +236,7 @@ end
226
236
 
227
237
  describe 'Strict Validation' do
228
238
  let(:simple_hash) { { foo: 'bar', bar: 'foo' } }
229
-
239
+
230
240
  let(:complex_hash) {{
231
241
  foo: 1,
232
242
  user: {
@@ -236,26 +246,26 @@ describe 'Strict Validation' do
236
246
  likes: [ 'Ruby', 'Kendo', 'Board Games' ]
237
247
  }
238
248
  }}
239
-
249
+
240
250
  let(:validations) { { foo: 'string' } }
241
-
251
+
242
252
  let(:complex_validations) {{
243
253
  foo: 'integer',
244
254
  user: {
245
255
  first_name: 'string', age: 'integer'
246
256
  }
247
257
  }}
248
-
258
+
249
259
  it 'reports which keys are not expected for a simple hash' do
250
260
  v = validate(simple_hash, validations, true)
251
261
  expect(v.valid?).to eq false
252
262
  expect(v.errors).to eq({ bar: 'key not expected' })
253
263
  end
254
-
264
+
255
265
  it 'reports which keys are not expected for a complex hash' do
256
266
  v = validate(complex_hash, complex_validations, true)
257
267
  expect(v.valid?).to eq false
258
268
  expect(v.errors).to eq(user: { last_name: 'key not expected', likes: 'key not expected' })
259
269
  end
260
-
270
+
261
271
  end
@@ -9,9 +9,8 @@ describe HashValidator::Validator::Base do
9
9
  end
10
10
 
11
11
  it 'does not allow a validator to be created with an invalid name' do
12
- expect { HashValidator::Validator::Base.new(nil) }.to raise_error(StandardError, 'Validator must be initialized with a valid name (string with length greater than zero)')
13
- expect { HashValidator::Validator::Base.new(123) }.to raise_error(StandardError, 'Validator must be initialized with a valid name (string with length greater than zero)')
14
- expect { HashValidator::Validator::Base.new('') }.to raise_error(StandardError, 'Validator must be initialized with a valid name (string with length greater than zero)')
12
+ expect { HashValidator::Validator::Base.new(nil) }.to raise_error(StandardError, 'Validator must be initialized with a valid name (length greater than zero)')
13
+ expect { HashValidator::Validator::Base.new('') }.to raise_error(StandardError, 'Validator must be initialized with a valid name (length greater than zero)')
15
14
  end
16
15
 
17
16
  describe '#validate' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Brooks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-24 00:00:00.000000000 Z
11
+ date: 2016-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler