committee 1.6.4 → 1.6.5

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: 6ac4862a247a545f17b0c5838d564fa541c3a17d
4
- data.tar.gz: dfa29382e51d4eacd43d05a14ed09dbc8fa13381
3
+ metadata.gz: 5e19343ffb0ef2e64ac07c4cac4b0cfea513dfb1
4
+ data.tar.gz: db3766715d0b18b7ebfb4f36753f089c981a099e
5
5
  SHA512:
6
- metadata.gz: 3bf123acebdcab88a882410be484dcf849ecd304807d3263916a23da0bdea43461d23fe1b8842c423bda9db8f8a98bdec012abe534708914ed847460372eb537
7
- data.tar.gz: 6b631a8e6b1fd64d027b6da68e029f31d5d1725325b3440deb3b7ed5700c01d18dc2727f872fdca559b42d6c762913b996b120f0296a3290bda90e8a662f9b94
6
+ metadata.gz: d28f2a33a2c378ec68b302c0391172cda7f2bc12e344abc250f7d42ec952833cdd8e0bf146d6019b965ca0f1ec577e66fcfbdec5d2d44497947a48f284ef4e05
7
+ data.tar.gz: 9f13aea9de25ad5b03968f249fb2052cb9b2eb0ba9eb4d2c43b82eaa21b3977dfa29e3112d82e211947b27a0afc15a4f8b3a52cfd678bf768a1424e52794b338
@@ -11,7 +11,7 @@ module Committee
11
11
  def call
12
12
  # if Content-Type is empty or JSON, and there was a request body, try to
13
13
  # interpret it as JSON
14
- params = if !@request.content_type || @request.content_type =~ %r{application/json}
14
+ params = if !@request.media_type || @request.media_type =~ %r{application/.*json}
15
15
  parse_json
16
16
  elsif @optimistic_json
17
17
  parse_json rescue MultiJson::LoadError nil
@@ -19,7 +19,7 @@ module Committee
19
19
 
20
20
  params = if params
21
21
  params
22
- elsif @allow_form_params && @request.content_type == "application/x-www-form-urlencoded"
22
+ elsif @allow_form_params && @request.media_type == "application/x-www-form-urlencoded"
23
23
  # Actually, POST means anything in the request body, could be from
24
24
  # PUT or PATCH too. Silly Rack.
25
25
  indifferent_params(@request.POST)
@@ -11,7 +11,8 @@ module Committee
11
11
 
12
12
  def call(status, headers, data)
13
13
  unless status == 204 # 204 No Content
14
- check_content_type!(headers)
14
+ response = Rack::Response.new(data, status, headers)
15
+ check_content_type!(response)
15
16
  end
16
17
 
17
18
  if @link.rel == "instances" && !@link.target_schema
@@ -35,13 +36,10 @@ module Committee
35
36
 
36
37
  private
37
38
 
38
- def check_content_type!(headers)
39
- match = [%r{application/json}, %r{application/schema\+json}].any? { |m|
40
- headers["Content-Type"] =~ m
41
- }
42
- unless match
39
+ def check_content_type!(response)
40
+ unless Rack::Mime.match?(response.content_type.to_s, @link.enc_type)
43
41
  raise Committee::InvalidResponse,
44
- %{"Content-Type" response header must be set to "application/json".}
42
+ %{"Content-Type" response header must be set to "#{@link.enc_type}".}
45
43
  end
46
44
  end
47
45
  end
@@ -35,21 +35,24 @@ describe Committee::ResponseValidator do
35
35
  assert_equal message, e.message
36
36
  end
37
37
 
38
- it "detects an invalid response Content-Type" do
38
+ it "detects a blank response Content-Type" do
39
39
  @headers = {}
40
40
  e = assert_raises(Committee::InvalidResponse) { call }
41
41
  message =
42
- %{"Content-Type" response header must be set to "application/json".}
42
+ %{"Content-Type" response header must be set to "#{@link.enc_type}".}
43
43
  assert_equal message, e.message
44
44
  end
45
45
 
46
- it "allows no Content-Type for 204 No Content" do
47
- @status, @headers = 204, {}
48
- call
46
+ it "detects an invalid response Content-Type" do
47
+ @headers = { "Content-Type" => "text/html" }
48
+ e = assert_raises(Committee::InvalidResponse) { call }
49
+ message =
50
+ %{"Content-Type" response header must be set to "#{@link.enc_type}".}
51
+ assert_equal message, e.message
49
52
  end
50
53
 
51
- it "allows application/schema+json in responses as well" do
52
- @headers = { "Content-Type" => "application/schema+json" }
54
+ it "allows no Content-Type for 204 No Content" do
55
+ @status, @headers = 204, {}
53
56
  call
54
57
  end
55
58
 
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.6.4
4
+ version: 1.6.5
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-02-20 00:00:00.000000000 Z
12
+ date: 2015-03-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json_schema