hash_validator 1.1.0 → 1.2.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.
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe HashValidator::Validator::JsonValidator do
4
+ let(:validator) { HashValidator::Validator::JsonValidator.new }
5
+
6
+ context 'valid JSON' do
7
+ it 'validates simple JSON objects' do
8
+ errors = {}
9
+ validator.validate('key', '{"name": "test"}', {}, errors)
10
+ expect(errors).to be_empty
11
+ end
12
+
13
+ it 'validates JSON arrays' do
14
+ errors = {}
15
+ validator.validate('key', '[1, 2, 3]', {}, errors)
16
+ expect(errors).to be_empty
17
+ end
18
+
19
+ it 'validates JSON strings' do
20
+ errors = {}
21
+ validator.validate('key', '"hello world"', {}, errors)
22
+ expect(errors).to be_empty
23
+ end
24
+
25
+ it 'validates JSON numbers' do
26
+ errors = {}
27
+ validator.validate('key', '42', {}, errors)
28
+ expect(errors).to be_empty
29
+ end
30
+
31
+ it 'validates JSON booleans' do
32
+ errors = {}
33
+ validator.validate('key', 'true', {}, errors)
34
+ expect(errors).to be_empty
35
+ end
36
+
37
+ it 'validates JSON null' do
38
+ errors = {}
39
+ validator.validate('key', 'null', {}, errors)
40
+ expect(errors).to be_empty
41
+ end
42
+
43
+ it 'validates complex nested JSON' do
44
+ errors = {}
45
+ json_string = '{"users": [{"name": "John", "age": 30}, {"name": "Jane", "age": 25}]}'
46
+ validator.validate('key', json_string, {}, errors)
47
+ expect(errors).to be_empty
48
+ end
49
+ end
50
+
51
+ context 'invalid JSON' do
52
+ it 'rejects non-string values' do
53
+ errors = {}
54
+ validator.validate('key', 123, {}, errors)
55
+ expect(errors['key']).to eq('is not valid JSON')
56
+ end
57
+
58
+ it 'rejects nil values' do
59
+ errors = {}
60
+ validator.validate('key', nil, {}, errors)
61
+ expect(errors['key']).to eq('is not valid JSON')
62
+ end
63
+
64
+ it 'rejects malformed JSON' do
65
+ errors = {}
66
+ validator.validate('key', '{"name": "test"', {}, errors)
67
+ expect(errors['key']).to eq('is not valid JSON')
68
+ end
69
+
70
+ it 'rejects invalid JSON syntax' do
71
+ errors = {}
72
+ validator.validate('key', '{name: "test"}', {}, errors)
73
+ expect(errors['key']).to eq('is not valid JSON')
74
+ end
75
+
76
+ it 'rejects empty strings' do
77
+ errors = {}
78
+ validator.validate('key', '', {}, errors)
79
+ expect(errors['key']).to eq('is not valid JSON')
80
+ end
81
+
82
+ it 'rejects plain text' do
83
+ errors = {}
84
+ validator.validate('key', 'hello world', {}, errors)
85
+ expect(errors['key']).to eq('is not valid JSON')
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe HashValidator::Validator::UrlValidator do
4
+ let(:validator) { HashValidator::Validator::UrlValidator.new }
5
+
6
+ context 'valid URLs' do
7
+ it 'validates http URLs' do
8
+ errors = {}
9
+ validator.validate('key', 'http://example.com', {}, errors)
10
+ expect(errors).to be_empty
11
+ end
12
+
13
+ it 'validates https URLs' do
14
+ errors = {}
15
+ validator.validate('key', 'https://example.com', {}, errors)
16
+ expect(errors).to be_empty
17
+ end
18
+
19
+ it 'validates ftp URLs' do
20
+ errors = {}
21
+ validator.validate('key', 'ftp://ftp.example.com', {}, errors)
22
+ expect(errors).to be_empty
23
+ end
24
+
25
+ it 'validates URLs with paths' do
26
+ errors = {}
27
+ validator.validate('key', 'https://example.com/path/to/resource', {}, errors)
28
+ expect(errors).to be_empty
29
+ end
30
+
31
+ it 'validates URLs with query parameters' do
32
+ errors = {}
33
+ validator.validate('key', 'https://example.com/search?q=test&page=1', {}, errors)
34
+ expect(errors).to be_empty
35
+ end
36
+ end
37
+
38
+ context 'invalid URLs' do
39
+ it 'rejects non-string values' do
40
+ errors = {}
41
+ validator.validate('key', 123, {}, errors)
42
+ expect(errors['key']).to eq('is not a valid URL')
43
+ end
44
+
45
+ it 'rejects nil values' do
46
+ errors = {}
47
+ validator.validate('key', nil, {}, errors)
48
+ expect(errors['key']).to eq('is not a valid URL')
49
+ end
50
+
51
+ it 'rejects malformed URLs' do
52
+ errors = {}
53
+ validator.validate('key', 'not a url', {}, errors)
54
+ expect(errors['key']).to eq('is not a valid URL')
55
+ end
56
+
57
+ it 'rejects URLs without schemes' do
58
+ errors = {}
59
+ validator.validate('key', 'example.com', {}, errors)
60
+ expect(errors['key']).to eq('is not a valid URL')
61
+ end
62
+
63
+ it 'rejects unsupported schemes' do
64
+ errors = {}
65
+ validator.validate('key', 'mailto:test@example.com', {}, errors)
66
+ expect(errors['key']).to eq('is not a valid URL')
67
+ end
68
+
69
+ it 'rejects empty strings' do
70
+ errors = {}
71
+ validator.validate('key', '', {}, errors)
72
+ expect(errors['key']).to eq('is not a valid URL')
73
+ end
74
+ end
75
+ end
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: 1.1.0
4
+ version: 1.2.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: 2022-11-23 00:00:00.000000000 Z
11
+ date: 2025-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.10'
55
- - !ruby/object:Gem::Dependency
56
- name: coveralls
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  description: Ruby library to validate hashes (Hash) against user-defined requirements
70
56
  email:
71
57
  - james@gooddogdesign.com
@@ -73,12 +59,13 @@ executables: []
73
59
  extensions: []
74
60
  extra_rdoc_files: []
75
61
  files:
62
+ - ".github/workflows/ruby.yml"
76
63
  - ".gitignore"
77
64
  - ".rspec"
78
65
  - ".ruby-version"
79
- - ".travis.yml"
80
66
  - Gemfile
81
67
  - LICENSE.txt
68
+ - Plan.md
82
69
  - README.md
83
70
  - Rakefile
84
71
  - hash_validator.gemspec
@@ -89,13 +76,18 @@ files:
89
76
  - lib/hash_validator/validations/multiple.rb
90
77
  - lib/hash_validator/validations/optional.rb
91
78
  - lib/hash_validator/validators.rb
79
+ - lib/hash_validator/validators/alpha_validator.rb
80
+ - lib/hash_validator/validators/alphanumeric_validator.rb
92
81
  - lib/hash_validator/validators/array_validator.rb
93
82
  - lib/hash_validator/validators/base.rb
94
83
  - lib/hash_validator/validators/boolean_validator.rb
95
84
  - lib/hash_validator/validators/class_validator.rb
85
+ - lib/hash_validator/validators/digits_validator.rb
96
86
  - lib/hash_validator/validators/email_validator.rb
97
87
  - lib/hash_validator/validators/enumerable_validator.rb
98
88
  - lib/hash_validator/validators/hash_validator.rb
89
+ - lib/hash_validator/validators/hex_color_validator.rb
90
+ - lib/hash_validator/validators/json_validator.rb
99
91
  - lib/hash_validator/validators/lambda_validator.rb
100
92
  - lib/hash_validator/validators/many_validator.rb
101
93
  - lib/hash_validator/validators/multiple_validator.rb
@@ -104,16 +96,23 @@ files:
104
96
  - lib/hash_validator/validators/regex_validator.rb
105
97
  - lib/hash_validator/validators/simple_type_validators.rb
106
98
  - lib/hash_validator/validators/simple_validator.rb
99
+ - lib/hash_validator/validators/url_validator.rb
107
100
  - lib/hash_validator/version.rb
108
101
  - spec/hash_validator_spec.rb
109
102
  - spec/hash_validator_spec_helper.rb
110
103
  - spec/spec_helper.rb
104
+ - spec/validators/alpha_validator_spec.rb
105
+ - spec/validators/alphanumeric_validator_spec.rb
111
106
  - spec/validators/array_spec.rb
112
107
  - spec/validators/base_spec.rb
113
108
  - spec/validators/boolean_spec.rb
114
109
  - spec/validators/class_spec.rb
110
+ - spec/validators/digits_validator_spec.rb
115
111
  - spec/validators/email_spec.rb
112
+ - spec/validators/hash_validator_spec.rb
113
+ - spec/validators/hex_color_validator_spec.rb
116
114
  - spec/validators/in_enumerable_spec.rb
115
+ - spec/validators/json_validator_spec.rb
117
116
  - spec/validators/lambda_spec.rb
118
117
  - spec/validators/many_spec.rb
119
118
  - spec/validators/multiple_spec.rb
@@ -122,6 +121,7 @@ files:
122
121
  - spec/validators/regexp_spec.rb
123
122
  - spec/validators/simple_spec.rb
124
123
  - spec/validators/simple_types_spec.rb
124
+ - spec/validators/url_validator_spec.rb
125
125
  - spec/validators/user_defined_spec.rb
126
126
  homepage: https://github.com/JamesBrooks/hash_validator
127
127
  licenses:
@@ -135,14 +135,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: '0'
138
+ version: 3.0.0
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  requirements:
141
141
  - - ">="
142
142
  - !ruby/object:Gem::Version
143
143
  version: '0'
144
144
  requirements: []
145
- rubygems_version: 3.1.2
145
+ rubygems_version: 3.2.33
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: Ruby library to validate hashes (Hash) against user-defined requirements
@@ -150,12 +150,18 @@ test_files:
150
150
  - spec/hash_validator_spec.rb
151
151
  - spec/hash_validator_spec_helper.rb
152
152
  - spec/spec_helper.rb
153
+ - spec/validators/alpha_validator_spec.rb
154
+ - spec/validators/alphanumeric_validator_spec.rb
153
155
  - spec/validators/array_spec.rb
154
156
  - spec/validators/base_spec.rb
155
157
  - spec/validators/boolean_spec.rb
156
158
  - spec/validators/class_spec.rb
159
+ - spec/validators/digits_validator_spec.rb
157
160
  - spec/validators/email_spec.rb
161
+ - spec/validators/hash_validator_spec.rb
162
+ - spec/validators/hex_color_validator_spec.rb
158
163
  - spec/validators/in_enumerable_spec.rb
164
+ - spec/validators/json_validator_spec.rb
159
165
  - spec/validators/lambda_spec.rb
160
166
  - spec/validators/many_spec.rb
161
167
  - spec/validators/multiple_spec.rb
@@ -164,4 +170,5 @@ test_files:
164
170
  - spec/validators/regexp_spec.rb
165
171
  - spec/validators/simple_spec.rb
166
172
  - spec/validators/simple_types_spec.rb
173
+ - spec/validators/url_validator_spec.rb
167
174
  - spec/validators/user_defined_spec.rb
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.0.0
4
- - 2.6.6
5
- - 2.7.2