committee 1.11.1 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b11943ee5136c0c5701b28fe02db42ed4a0c60bd
4
- data.tar.gz: 117ecc80d07762514d0ae9537fd42b7d6dde1794
3
+ metadata.gz: fa85c91924d305a304a54ad64c055d237fa1d497
4
+ data.tar.gz: eeaf629c7d4a3ba4c4f5928722771c2d41bbf3c3
5
5
  SHA512:
6
- metadata.gz: 709a6d22546cf1e46887748af1b8b3bbf0a8dfde8fdf7600bc446b9b60fb9d1612cd2b01c72f5326fda3917c1fb4c8852cfda2dad736a5883b30b83e7d60b8fe
7
- data.tar.gz: c527fdee143d2eae065df1523e5127d504d2b744ecb22bbf6087867e9b23bb26448e116ae00ec642cbbdc31b253bbbaed19eba37f2012510a5c2b219aadedde6
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
- data = options[:schema] || raise("need option `schema`")
9
- if data.is_a?(String)
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
- data = JSON.parse(data)
13
+ schema = JSON.parse(schema)
12
14
  end
13
- @raise = options[:raise]
14
- @schema = JsonSchema.parse!(data)
15
- @schema.expand_references!
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.11.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-29 00:00:00.000000000 Z
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.2.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.