committee 0.4 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -79,20 +79,22 @@ module Committee
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
def check_type(
|
83
|
-
|
82
|
+
def check_type(allowed_types, value, key)
|
83
|
+
types = case value
|
84
84
|
when NilClass
|
85
|
-
"null"
|
85
|
+
["null"]
|
86
86
|
when TrueClass, FalseClass
|
87
|
-
"boolean"
|
88
|
-
when Bignum, Fixnum
|
89
|
-
"number"
|
87
|
+
["boolean"]
|
88
|
+
when Bignum, Fixnum
|
89
|
+
["integer", "number"]
|
90
|
+
when Float
|
91
|
+
["number"]
|
90
92
|
when String
|
91
|
-
"string"
|
93
|
+
["string"]
|
92
94
|
else
|
93
|
-
"unknown"
|
95
|
+
["unknown"]
|
94
96
|
end
|
95
|
-
types.
|
97
|
+
!(allowed_types & types).empty?
|
96
98
|
end
|
97
99
|
|
98
100
|
def check_type!(types, value, key)
|
@@ -81,26 +81,24 @@ module Committee
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
def check_type!(
|
85
|
-
|
84
|
+
def check_type!(allowed_types, value, path)
|
85
|
+
types = case value
|
86
86
|
when NilClass
|
87
|
-
"null"
|
87
|
+
["null"]
|
88
88
|
when TrueClass, FalseClass
|
89
|
-
"boolean"
|
90
|
-
when Bignum, Fixnum
|
91
|
-
"number"
|
89
|
+
["boolean"]
|
90
|
+
when Bignum, Fixnum
|
91
|
+
["integer", "number"]
|
92
|
+
when Float
|
93
|
+
["number"]
|
92
94
|
when String
|
93
|
-
"string"
|
94
|
-
when Hash
|
95
|
-
"object"
|
96
|
-
when Array
|
97
|
-
"array"
|
95
|
+
["string"]
|
98
96
|
else
|
99
|
-
"unknown"
|
97
|
+
["unknown"]
|
100
98
|
end
|
101
|
-
|
99
|
+
if (allowed_types & types).empty?
|
102
100
|
raise InvalidResponse,
|
103
|
-
%{Invalid type at "#{path.join(":")}": expected #{value} to be #{
|
101
|
+
%{Invalid type at "#{path.join(":")}": expected #{value} to be #{allowed_types} (was: #{types}).}
|
104
102
|
end
|
105
103
|
end
|
106
104
|
|
@@ -44,7 +44,7 @@ describe Committee::ResponseValidator do
|
|
44
44
|
it "detects mismatched types" do
|
45
45
|
@data.merge!("maintenance" => "not-bool")
|
46
46
|
e = assert_raises(Committee::InvalidResponse) { call }
|
47
|
-
message = %{Invalid type at "maintenance": expected not-bool to be ["boolean"] (was: string).}
|
47
|
+
message = %{Invalid type at "maintenance": expected not-bool to be ["boolean"] (was: ["string"]).}
|
48
48
|
assert_equal message, e.message
|
49
49
|
end
|
50
50
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: committee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-02-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
@@ -124,7 +124,7 @@ files:
|
|
124
124
|
- test/schema_test.rb
|
125
125
|
- test/test_helper.rb
|
126
126
|
- bin/committee-stub
|
127
|
-
homepage: https://github.com/
|
127
|
+
homepage: https://github.com/heroku/rack-committee
|
128
128
|
licenses:
|
129
129
|
- MIT
|
130
130
|
post_install_message:
|
@@ -145,9 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
145
|
version: '0'
|
146
146
|
requirements: []
|
147
147
|
rubyforge_project:
|
148
|
-
rubygems_version: 1.8.
|
148
|
+
rubygems_version: 1.8.24
|
149
149
|
signing_key:
|
150
150
|
specification_version: 3
|
151
151
|
summary: A collection of middleware to support JSON Schema.
|
152
152
|
test_files: []
|
153
|
-
has_rdoc:
|