committee 0.4.6 → 0.4.7

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.
@@ -52,6 +52,7 @@ module Committee
52
52
  definition = @schema.find(value["items"]["$ref"])
53
53
  data[key].each do |datum|
54
54
  check_type!(definition["type"], datum, path + [key])
55
+ check_data!(definition, datum, path + [key]) if definition["type"] == ["object"]
55
56
  unless definition["type"].include?("null") && datum.nil?
56
57
  check_format!(definition["format"], datum, path + [key])
57
58
  check_pattern!(definition["pattern"], datum, path + [key])
@@ -89,7 +90,12 @@ module Committee
89
90
  data = if info["properties"]
90
91
  info
91
92
  elsif info["type"] == ["array"]
92
- @schema.find(info["items"]["$ref"])
93
+ array_schema = @schema.find(info["items"]["$ref"])
94
+ unless array_schema["type"] == ["object"]
95
+ array_schema
96
+ else
97
+ {} # satisfy data['properties'] check below
98
+ end
93
99
  elsif info["$ref"]
94
100
  @schema.find(info["$ref"])
95
101
  end
@@ -5,7 +5,7 @@ module Committee
5
5
  def initialize(data)
6
6
  @cache = {}
7
7
  @schema = MultiJson.decode(data)
8
- manifest_regex
8
+ manifest_regex(@schema)
9
9
  end
10
10
 
11
11
  def [](type)
@@ -42,12 +42,13 @@ module Committee
42
42
  end
43
43
  end
44
44
 
45
- def manifest_regex
46
- @schema["definitions"].each do |_, type_schema|
47
- type_schema["definitions"].each do |_, property_schema|
48
- if pattern = property_schema["pattern"]
49
- property_schema["pattern"] = Regexp.new(pattern)
50
- end
45
+ def manifest_regex(schema_part)
46
+ schema_part["definitions"].each do |_, type_schema|
47
+ if type_schema.has_key?("definitions")
48
+ manifest_regex(type_schema)
49
+ end
50
+ if pattern = type_schema["pattern"]
51
+ type_schema["pattern"] = Regexp.new(pattern)
51
52
  end
52
53
  end
53
54
  end
@@ -54,6 +54,8 @@ module Committee
54
54
  ["object"]
55
55
  when String
56
56
  ["string"]
57
+ when Array
58
+ ["array"]
57
59
  else
58
60
  ["unknown"]
59
61
  end
@@ -100,6 +100,15 @@ describe Committee::ResponseValidator do
100
100
  call
101
101
  end
102
102
 
103
+ it "validates an array of objects" do
104
+ @data = ValidAccount.dup
105
+ @data["credit_cards"] = @data["credit_cards"].dup
106
+ @link_schema = @schema["account"]["links"][0]
107
+ @type_schema = @schema["account"]
108
+
109
+ call
110
+ end
111
+
103
112
  it "detects a simple array with an item of the wrong type" do
104
113
  @data = ValidAccount.dup
105
114
  @data["flags"] = @data["flags"].dup
@@ -112,6 +121,18 @@ describe Committee::ResponseValidator do
112
121
  assert_equal message, e.message
113
122
  end
114
123
 
124
+ it "rejects an invalid pattern match" do
125
+ @data = ValidAccount.dup
126
+ @data["credit_cards"] = @data["credit_cards"].dup
127
+ @data["credit_cards"] << {"account_number" => "1234-1234-1234-HUGZ", "name" => "Rodney Mullen", "security_code" => 123}
128
+ @link_schema = @schema["account"]["links"][0]
129
+ @type_schema = @schema["account"]
130
+
131
+ e = assert_raises(Committee::InvalidPattern) { call }
132
+ message = %{Invalid pattern at "credit_cards:account_number": expected 1234-1234-1234-HUGZ to match "(?-mix:[0-9]{4}\\-[0-9]{4}\\-[0-9]{4}\\-[0-9]{4}$)".}
133
+ assert_equal message, e.message
134
+ end
135
+
115
136
  private
116
137
 
117
138
  def call
data/test/test_helper.rb CHANGED
@@ -43,5 +43,6 @@ ValidAccount = {
43
43
  "last_login" => "2012-01-01T12:00:00Z",
44
44
  "updated_at" => "2012-01-01T12:00:00Z",
45
45
  "verified" => true,
46
- "flags" => ["foo", "bar"]
46
+ "flags" => ["foo", "bar"],
47
+ "credit_cards" => [{"account_number" => "1234-1234-1234-1234", "name" => "Rodney Mullen", "security_code" => 123}]
47
48
  }.freeze
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: 0.4.6
4
+ version: 0.4.7
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-04-23 00:00:00.000000000 Z
13
+ date: 2014-04-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json