rack-json_schema 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/rack/json_schema/response_validation.rb +7 -2
- data/lib/rack/json_schema/version.rb +1 -1
- data/spec/rack/spec_spec.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 276eb5729514a350ea04991833eb262d34ed663b
|
4
|
+
data.tar.gz: c9d398ae44ccc2ca33813fb210830552e81a876b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1edd0f145b7b97ee5364e6c3e358df7ae21a47f93c6037c3411a69bf178880867347f446d510186888d8b0b1afc6da178ab5904bdd176336fc509655bbd3782
|
7
|
+
data.tar.gz: 2bd34182a08c20b032c55634413bb67746f53f35b61befa6d9e41a5569c01d6ad652f8a948551729ef47a3950a26140c11aa2de70192b3447946596948fda048
|
data/CHANGELOG.md
CHANGED
@@ -33,7 +33,7 @@ module Rack
|
|
33
33
|
def call
|
34
34
|
if !has_redirection_or_error_status? && has_link_for_current_action? && has_link_of_media_type_json?
|
35
35
|
case
|
36
|
-
when !has_json_content_type?
|
36
|
+
when has_body? && !has_json_content_type?
|
37
37
|
raise InvalidResponseContentType
|
38
38
|
when !valid?
|
39
39
|
raise InvalidResponseType, validator.errors
|
@@ -41,6 +41,11 @@ module Rack
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
# @return [true, false] True if any bytes are included in response body
|
45
|
+
def has_body?
|
46
|
+
!body.size.zero?
|
47
|
+
end
|
48
|
+
|
44
49
|
# @return [true, false] True if Link mediaType is for JSON
|
45
50
|
def has_link_of_media_type_json?
|
46
51
|
mime_type_json?(link.media_type)
|
@@ -53,7 +58,7 @@ module Rack
|
|
53
58
|
|
54
59
|
# @return [true, false] True if given data is valid to the JSON schema
|
55
60
|
def valid?
|
56
|
-
(has_list_data? && data.empty?) || validator.validate(example_item)
|
61
|
+
!has_body? || (has_list_data? && data.empty?) || validator.validate(example_item)
|
57
62
|
end
|
58
63
|
|
59
64
|
# @return [Hash] Choose an item from response data, to be validated
|
data/spec/rack/spec_spec.rb
CHANGED
@@ -271,5 +271,17 @@ describe Rack::JsonSchema do
|
|
271
271
|
|
272
272
|
it { should == 200 }
|
273
273
|
end
|
274
|
+
|
275
|
+
context "with empty response body without JSON Content-Type" do
|
276
|
+
let(:response_body) do
|
277
|
+
""
|
278
|
+
end
|
279
|
+
|
280
|
+
let(:response_headers) do
|
281
|
+
{}
|
282
|
+
end
|
283
|
+
|
284
|
+
it { should == 200 }
|
285
|
+
end
|
274
286
|
end
|
275
287
|
end
|