committee 1.11.1 → 1.12.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.
- checksums.yaml +4 -4
- data/lib/committee/middleware/base.rb +11 -6
- data/test/middleware/base_test.rb +41 -0
- metadata +4 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: fa85c91924d305a304a54ad64c055d237fa1d497
         | 
| 4 | 
            +
              data.tar.gz: eeaf629c7d4a3ba4c4f5928722771c2d41bbf3c3
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 69cf9b11c8e820f30e7fbf6c17d409aee52650cda21e39237dea0d97e1efeaafbf82083f3bdc321e69edb9af307db509d33fb512d782ab028277fff4cae4515d
         | 
| 7 | 
            +
              data.tar.gz: 716618189cb9a7accbc45b485a63837600311c99c793ba435ef2bf0a720ec8f0abe5d5267173ee1d7e71c827206245636a97df205fdafa93cf348c2405d97998
         | 
| @@ -5,14 +5,19 @@ module Committee::Middleware | |
| 5 5 |  | 
| 6 6 | 
             
                  @error_class = options.fetch(:error_class, Committee::ValidationError)
         | 
| 7 7 | 
             
                  @params_key = options[:params_key] || "committee.params"
         | 
| 8 | 
            -
                   | 
| 9 | 
            -
             | 
| 8 | 
            +
                  @raise = options[:raise]
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  schema = options[:schema] || raise("need option `schema`")
         | 
| 11 | 
            +
                  if schema.is_a?(String)
         | 
| 10 12 | 
             
                    warn_string_deprecated
         | 
| 11 | 
            -
                     | 
| 13 | 
            +
                    schema = JSON.parse(schema)
         | 
| 12 14 | 
             
                  end
         | 
| 13 | 
            -
                   | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 15 | 
            +
                  if schema.is_a?(Hash)
         | 
| 16 | 
            +
                    schema = JsonSchema.parse!(schema)
         | 
| 17 | 
            +
                    schema.expand_references!
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                  @schema = schema
         | 
| 20 | 
            +
             | 
| 16 21 | 
             
                  @router = Committee::Router.new(@schema, options)
         | 
| 17 22 | 
             
                end
         | 
| 18 23 |  | 
| @@ -0,0 +1,41 @@ | |
| 1 | 
            +
            require_relative "../test_helper"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Committee::Middleware::Base do
         | 
| 4 | 
            +
              include Rack::Test::Methods
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              def app
         | 
| 7 | 
            +
                @app
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              it "accepts schema hash" do
         | 
| 11 | 
            +
                @app = new_rack_app(schema: JSON.parse(File.read("./test/data/schema.json")))
         | 
| 12 | 
            +
                params = {
         | 
| 13 | 
            +
                  "name" => "cloudnasium"
         | 
| 14 | 
            +
                }
         | 
| 15 | 
            +
                header "Content-Type", "application/json"
         | 
| 16 | 
            +
                post "/apps", JSON.generate(params)
         | 
| 17 | 
            +
                assert_equal 200, last_response.status
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              it "accepts schema object" do
         | 
| 21 | 
            +
                schema = JsonSchema.parse!(JSON.parse(File.read("./test/data/schema.json")))
         | 
| 22 | 
            +
                @app = new_rack_app(schema: schema)
         | 
| 23 | 
            +
                params = {
         | 
| 24 | 
            +
                  "name" => "cloudnasium"
         | 
| 25 | 
            +
                }
         | 
| 26 | 
            +
                header "Content-Type", "application/json"
         | 
| 27 | 
            +
                post "/apps", JSON.generate(params)
         | 
| 28 | 
            +
                assert_equal 200, last_response.status
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              private
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              def new_rack_app(options = {})
         | 
| 34 | 
            +
                Rack::Builder.new {
         | 
| 35 | 
            +
                  use Committee::Middleware::RequestValidation, options
         | 
| 36 | 
            +
                  run lambda { |_|
         | 
| 37 | 
            +
                    [200, {}, []]
         | 
| 38 | 
            +
                  }
         | 
| 39 | 
            +
                }
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
            end
         | 
    
        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: 1. | 
| 4 | 
            +
              version: 1.12.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Brandur
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2015-10- | 
| 12 | 
            +
            date: 2015-10-30 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: json_schema
         | 
| @@ -124,6 +124,7 @@ files: | |
| 124 124 | 
             
            - lib/committee/router.rb
         | 
| 125 125 | 
             
            - lib/committee/test/methods.rb
         | 
| 126 126 | 
             
            - lib/committee/validation_error.rb
         | 
| 127 | 
            +
            - test/middleware/base_test.rb
         | 
| 127 128 | 
             
            - test/middleware/request_validation_test.rb
         | 
| 128 129 | 
             
            - test/middleware/response_validation_test.rb
         | 
| 129 130 | 
             
            - test/middleware/stub_test.rb
         | 
| @@ -155,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 155 156 | 
             
                  version: '0'
         | 
| 156 157 | 
             
            requirements: []
         | 
| 157 158 | 
             
            rubyforge_project: 
         | 
| 158 | 
            -
            rubygems_version: 2. | 
| 159 | 
            +
            rubygems_version: 2.4.5.1
         | 
| 159 160 | 
             
            signing_key: 
         | 
| 160 161 | 
             
            specification_version: 4
         | 
| 161 162 | 
             
            summary: A collection of Rack middleware to support JSON Schema.
         |