ridley 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,8 @@ module Ridley
2
2
  module Middleware
3
3
  # @author Jamie Winsor <jamie@vialstudios.com>
4
4
  class ParseJson < Faraday::Response::Middleware
5
+ include Ridley::Logging
6
+
5
7
  JSON_TYPE = 'application/json'.freeze
6
8
 
7
9
  BRACKETS = [
@@ -17,6 +19,8 @@ module Ridley
17
19
  ].freeze
18
20
 
19
21
  class << self
22
+ include Ridley::Logging
23
+
20
24
  # Takes a string containing JSON and converts it to a Ruby hash
21
25
  # symbols for keys
22
26
  #
@@ -47,7 +51,7 @@ module Ridley
47
51
  # @return [String]
48
52
  def response_type(env)
49
53
  if env[:response_headers][CONTENT_TYPE].nil?
50
- Ridley.log.debug "Response did not specify a content type."
54
+ log.debug "Response did not specify a content type."
51
55
  return "text/html"
52
56
  end
53
57
 
@@ -62,7 +66,7 @@ module Ridley
62
66
  #
63
67
  # @return [Boolean]
64
68
  def json_response?(env)
65
- response_type(env) == JSON_TYPE || looks_like_json?(env)
69
+ response_type(env) == JSON_TYPE && looks_like_json?(env)
66
70
  end
67
71
 
68
72
  # Examines the body of a request env and returns true if it appears
@@ -91,14 +95,13 @@ module Ridley
91
95
  end
92
96
 
93
97
  def on_complete(env)
94
- if self.class.json_response?(env)
95
- Ridley.log.debug("Parsing JSON Chef Response")
96
- Ridley.log.debug(env)
98
+ log.debug(env)
97
99
 
100
+ if self.class.json_response?(env)
101
+ log.debug("Parsing Chef Response body as JSON")
98
102
  env[:body] = self.class.parse(env[:body])
99
103
  else
100
- Ridley.log.debug("Chef Response was not JSON")
101
- Ridley.log.debug(env)
104
+ log.debug("Chef Response did not contain a JSON body")
102
105
  end
103
106
  end
104
107
  end
@@ -1,3 +1,3 @@
1
1
  module Ridley
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
@@ -18,31 +18,31 @@ describe Ridley::Middleware::ParseJson do
18
18
  end
19
19
 
20
20
  describe "::json_response?" do
21
- it "returns true if the value of content-type includes 'application/json'" do
21
+ it "returns true if the value of content-type includes 'application/json' and the body looks like JSON" do
22
22
  env = double('env')
23
23
  env.stub(:[]).with(:response_headers).and_return(
24
24
  'content-type' => 'application/json; charset=utf8'
25
25
  )
26
+ subject.should_receive(:looks_like_json?).with(env).and_return(true)
26
27
 
27
28
  subject.json_response?(env).should be_true
28
29
  end
29
30
 
30
- it "returns true if the value of content-type does not include 'application/json' and the body contains JSON" do
31
+ it "returns false if the value of content-type includes 'application/json' but the body does not look like JSON" do
31
32
  env = double('env')
32
33
  env.stub(:[]).with(:response_headers).and_return(
33
- 'content-type' => 'text/plain'
34
+ 'content-type' => 'application/json; charset=utf8'
34
35
  )
35
- subject.should_receive(:looks_like_json?).with(env).and_return(true)
36
+ subject.should_receive(:looks_like_json?).with(env).and_return(false)
36
37
 
37
- subject.json_response?(env).should be_true
38
+ subject.json_response?(env).should be_false
38
39
  end
39
40
 
40
- it "returns false if the value of content-type does not include 'application/json' and the body does not contain JSON" do
41
+ it "returns false if the value of content-type does not include 'application/json'" do
41
42
  env = double('env')
42
43
  env.stub(:[]).with(:response_headers).and_return(
43
44
  'content-type' => 'text/plain'
44
45
  )
45
- subject.should_receive(:looks_like_json?).with(env).and_return(false)
46
46
 
47
47
  subject.json_response?(env).should be_false
48
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridley
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-31 00:00:00.000000000 Z
12
+ date: 2013-01-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -325,7 +325,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
325
325
  version: '0'
326
326
  segments:
327
327
  - 0
328
- hash: 2477295223740290227
328
+ hash: -3636346058198245509
329
329
  requirements: []
330
330
  rubyforge_project:
331
331
  rubygems_version: 1.8.23