parameters_schema 0.42 → 1.0.1

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.
@@ -1,126 +1,126 @@
1
- require 'minitest/autorun'
2
- require 'parameters_schema'
3
- require_relative 'helpers'
4
-
5
- describe 'Complex types' do
6
- describe 'Multiple' do
7
- it 'allows multiple types for a parameter' do
8
- schema = ParametersSchema::Schema.new do
9
- param :potatoe, type: [String, :boolean]
10
- end
11
-
12
- schema
13
- .validate!(potatoe: 'Eramosa')
14
- .must_equal_hash(potatoe: 'Eramosa')
15
-
16
- schema
17
- .validate!(potatoe: true)
18
- .must_equal_hash(potatoe: true)
19
-
20
- [2, 3.0, Date.today, DateTime.now, [1], { nope: true }].each do |value|
21
- Proc
22
- .new{ schema.validate!(potatoe: value) }
23
- .must_raise(ParametersSchema::InvalidParameters)
24
- .errors.must_equal_hash(potatoe: :disallowed)
25
- end
26
- end
27
-
28
- it 'is swallowed by the :any keyword' do
29
- schema = ParametersSchema::Schema.new do
30
- param :potatoe, type: [String, :any]
31
- end
32
-
33
- [1, 1.0, Date.today, DateTime.now, [1], { nope: true }, 'Eramosa', true].each do |value|
34
- schema
35
- .validate!(potatoe: value)
36
- .must_equal_hash(potatoe: value)
37
- end
38
- end
39
- end
40
-
41
- describe 'Array of something' do
42
- it 'allows the type' do
43
- schema = ParametersSchema::Schema.new do
44
- param :potatoe, type: { Array => String }
45
- end
46
-
47
- schema
48
- .validate!(potatoe: ['Eramosa', 'Kennebec', 'Conestoga'])
49
- .must_equal_hash(potatoe: ['Eramosa', 'Kennebec', 'Conestoga'])
50
-
51
- [2, 3.0, Date.today, DateTime.now, [1], { nope: true }, [true, false, true]].each do |value|
52
- Proc
53
- .new{ schema.validate!(potatoe: value) }
54
- .must_raise(ParametersSchema::InvalidParameters)
55
- .errors.must_equal_hash(potatoe: :disallowed)
56
- end
57
- end
58
-
59
- it 'requires all values to be of the same type by default' do
60
- schema = ParametersSchema::Schema.new do
61
- param :potatoe, type: { Array => :boolean }
62
- end
63
-
64
- schema
65
- .validate!(potatoe: [true, false, false, true])
66
- .must_equal_hash(potatoe: [true, false, false, true])
67
-
68
- Proc
69
- .new{ schema.validate!(potatoe: [true, false, false, 4]) }
70
- .must_raise(ParametersSchema::InvalidParameters)
71
- .errors.must_equal_hash(potatoe: :disallowed)
72
- end
73
-
74
- it 'accepts multiple values' do
75
- schema = ParametersSchema::Schema.new do
76
- param :potatoe, type: { Array => [:boolean, Fixnum, Symbol] }
77
- end
78
-
79
- schema
80
- .validate!(potatoe: [true, 2, :working, false, 2, :still_working])
81
- .must_equal_hash(potatoe: [true, 2, :working, false, 2, :still_working])
82
- end
83
-
84
- it 'accepts an array of arrays of :any' do
85
- schema = ParametersSchema::Schema.new do
86
- param :potatoe, type: { Array => Array }
87
- end
88
-
89
- schema
90
- .validate!(potatoe: [[1, 2], [true, false], ['a', 'b', 'c'], [{ name: 'Eramosa' }]])
91
- .must_equal_hash(potatoe: [[1, 2], [true, false], ['a', 'b', 'c'], [{ name: 'Eramosa' }]])
92
- end
93
-
94
- it 'accepts an array of arrays' do
95
- schema = ParametersSchema::Schema.new do
96
- param :potatoe, type: { Array => { Array => Fixnum } }
97
- end
98
-
99
- schema
100
- .validate!(potatoe: [[1, 2], [3, 4, 5], [6, 7]])
101
- .must_equal_hash(potatoe: [[1, 2], [3, 4, 5], [6, 7]])
102
- end
103
-
104
- it 'can be used in conjunction with array: true' do
105
- schema = ParametersSchema::Schema.new do
106
- param :potatoe, type: { Array => :boolean }, array: true
107
- end
108
-
109
- schema
110
- .validate!(potatoe: [true, true, false])
111
- .must_equal_hash(potatoe: [true, true, false])
112
- end
113
-
114
- it 'doesnt make sense for any other type so fallback to the key' do
115
- schema = ParametersSchema::Schema.new do
116
- param :potatoe, type: { Date => Fixnum }
117
- end
118
-
119
- today = Date.today
120
-
121
- schema
122
- .validate!(potatoe: today)
123
- .must_equal_hash(potatoe: today)
124
- end
125
- end
126
- end
1
+ require 'minitest/autorun'
2
+ require 'parameters_schema'
3
+ require_relative 'helpers'
4
+
5
+ describe 'Complex types' do
6
+ describe 'Multiple' do
7
+ it 'allows multiple types for a parameter' do
8
+ schema = ParametersSchema::Schema.new do
9
+ param :potatoe, type: [String, :boolean]
10
+ end
11
+
12
+ schema
13
+ .validate!(potatoe: 'Eramosa')
14
+ .must_equal_hash(potatoe: 'Eramosa')
15
+
16
+ schema
17
+ .validate!(potatoe: true)
18
+ .must_equal_hash(potatoe: true)
19
+
20
+ [2, 3.0, Date.today, DateTime.now, [1], { nope: true }].each do |value|
21
+ Proc
22
+ .new{ schema.validate!(potatoe: value) }
23
+ .must_raise(ParametersSchema::InvalidParameters)
24
+ .errors.must_equal_hash(potatoe: :disallowed)
25
+ end
26
+ end
27
+
28
+ it 'is swallowed by the :any keyword' do
29
+ schema = ParametersSchema::Schema.new do
30
+ param :potatoe, type: [String, :any]
31
+ end
32
+
33
+ [1, 1.0, Date.today, DateTime.now, [1], { nope: true }, 'Eramosa', true].each do |value|
34
+ schema
35
+ .validate!(potatoe: value)
36
+ .must_equal_hash(potatoe: value)
37
+ end
38
+ end
39
+ end
40
+
41
+ describe 'Array of something' do
42
+ it 'allows the type' do
43
+ schema = ParametersSchema::Schema.new do
44
+ param :potatoe, type: { Array => String }
45
+ end
46
+
47
+ schema
48
+ .validate!(potatoe: ['Eramosa', 'Kennebec', 'Conestoga'])
49
+ .must_equal_hash(potatoe: ['Eramosa', 'Kennebec', 'Conestoga'])
50
+
51
+ [2, 3.0, Date.today, DateTime.now, [1], { nope: true }, [true, false, true]].each do |value|
52
+ Proc
53
+ .new{ schema.validate!(potatoe: value) }
54
+ .must_raise(ParametersSchema::InvalidParameters)
55
+ .errors.must_equal_hash(potatoe: :disallowed)
56
+ end
57
+ end
58
+
59
+ it 'requires all values to be of the same type by default' do
60
+ schema = ParametersSchema::Schema.new do
61
+ param :potatoe, type: { Array => :boolean }
62
+ end
63
+
64
+ schema
65
+ .validate!(potatoe: [true, false, false, true])
66
+ .must_equal_hash(potatoe: [true, false, false, true])
67
+
68
+ Proc
69
+ .new{ schema.validate!(potatoe: [true, false, false, 4]) }
70
+ .must_raise(ParametersSchema::InvalidParameters)
71
+ .errors.must_equal_hash(potatoe: :disallowed)
72
+ end
73
+
74
+ it 'accepts multiple values' do
75
+ schema = ParametersSchema::Schema.new do
76
+ param :potatoe, type: { Array => [:boolean, Fixnum, Symbol] }
77
+ end
78
+
79
+ schema
80
+ .validate!(potatoe: [true, 2, :working, false, 2, :still_working])
81
+ .must_equal_hash(potatoe: [true, 2, :working, false, 2, :still_working])
82
+ end
83
+
84
+ it 'accepts an array of arrays of :any' do
85
+ schema = ParametersSchema::Schema.new do
86
+ param :potatoe, type: { Array => Array }
87
+ end
88
+
89
+ schema
90
+ .validate!(potatoe: [[1, 2], [true, false], ['a', 'b', 'c'], [{ name: 'Eramosa' }]])
91
+ .must_equal_hash(potatoe: [[1, 2], [true, false], ['a', 'b', 'c'], [{ name: 'Eramosa' }]])
92
+ end
93
+
94
+ it 'accepts an array of arrays' do
95
+ schema = ParametersSchema::Schema.new do
96
+ param :potatoe, type: { Array => { Array => Fixnum } }
97
+ end
98
+
99
+ schema
100
+ .validate!(potatoe: [[1, 2], [3, 4, 5], [6, 7]])
101
+ .must_equal_hash(potatoe: [[1, 2], [3, 4, 5], [6, 7]])
102
+ end
103
+
104
+ it 'can be used in conjunction with array: true' do
105
+ schema = ParametersSchema::Schema.new do
106
+ param :potatoe, type: { Array => :boolean }, array: true
107
+ end
108
+
109
+ schema
110
+ .validate!(potatoe: [true, true, false])
111
+ .must_equal_hash(potatoe: [true, true, false])
112
+ end
113
+
114
+ it 'doesnt make sense for any other type so fallback to the key' do
115
+ schema = ParametersSchema::Schema.new do
116
+ param :potatoe, type: { Date => Fixnum }
117
+ end
118
+
119
+ today = Date.today
120
+
121
+ schema
122
+ .validate!(potatoe: today)
123
+ .must_equal_hash(potatoe: today)
124
+ end
125
+ end
126
+ end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parameters_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.42'
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jodi Giordano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-01 00:00:00.000000000 Z
11
+ date: 2015-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  description: Validates parameters of requests using a schema defined with a simple
@@ -32,13 +32,13 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - Gemfile
35
- - Rakefile
36
35
  - README.md
36
+ - Rakefile
37
+ - lib/parameters_schema.rb
37
38
  - lib/parameters_schema/core_ext.rb
38
39
  - lib/parameters_schema/exceptions.rb
39
40
  - lib/parameters_schema/options.rb
40
41
  - lib/parameters_schema/schema.rb
41
- - lib/parameters_schema.rb
42
42
  - test/helpers.rb
43
43
  - test/test_options.rb
44
44
  - test/test_schema_allow.rb
@@ -59,19 +59,18 @@ require_paths:
59
59
  - lib
60
60
  required_ruby_version: !ruby/object:Gem::Requirement
61
61
  requirements:
62
- - - '>='
62
+ - - ">="
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
65
  required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - '>='
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  requirements: []
71
71
  rubyforge_project:
72
- rubygems_version: 2.0.3
72
+ rubygems_version: 2.4.6
73
73
  signing_key:
74
74
  specification_version: 4
75
75
  summary: Strict schema for request parameters
76
76
  test_files: []
77
- has_rdoc: