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.
- data/lib/committee/response_validator.rb +7 -1
 - data/lib/committee/schema.rb +8 -7
 - data/lib/committee/validation.rb +2 -0
 - data/test/response_validator_test.rb +21 -0
 - data/test/test_helper.rb +2 -1
 - metadata +2 -2
 
| 
         @@ -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
         
     | 
    
        data/lib/committee/schema.rb
    CHANGED
    
    | 
         @@ -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 
     | 
    
         
            -
                   
     | 
| 
       47 
     | 
    
         
            -
                    type_schema 
     | 
| 
       48 
     | 
    
         
            -
                       
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
    
        data/lib/committee/validation.rb
    CHANGED
    
    
| 
         @@ -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. 
     | 
| 
      
 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- 
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2014-04-24 00:00:00.000000000 Z
         
     | 
| 
       14 
14 
     | 
    
         
             
            dependencies:
         
     | 
| 
       15 
15 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       16 
16 
     | 
    
         
             
              name: multi_json
         
     |