hal-client 3.0 → 3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  class HalClient
2
- VERSION = "3.0"
2
+ VERSION = "3.1"
3
3
  end
data/lib/hal_client.rb CHANGED
@@ -89,7 +89,11 @@ class HalClient
89
89
  begin
90
90
  Representation.new hal_client: self, parsed_json: MultiJson.load(resp.to_s)
91
91
  rescue MultiJson::ParseError, InvalidRepresentationError => e
92
- resp
92
+ if resp.headers["Location"]
93
+ Representation.new hal_client: self, href: resp.headers["Location"]
94
+ else
95
+ resp
96
+ end
93
97
  end
94
98
 
95
99
  when 400...500
@@ -131,13 +131,32 @@ describe HalClient do
131
131
 
132
132
  describe "#post(<url>)" do
133
133
  subject(:client) { HalClient.new }
134
- let!(:return_val) { client.post "http://example.com/foo", post_data }
134
+ let(:url) { "http://example.com/foo" }
135
+ let(:return_val) { client.post url, post_data }
135
136
 
136
137
  it "returns a HalClient::Representation" do
137
138
  expect(return_val).to be_kind_of HalClient::Representation
138
139
  end
139
140
 
141
+ context "201 response w/ location header and w/o body" do
142
+ let(:url) { "http://example.com/lhnb" }
143
+ let!(:req) { stub_request(:post, url).
144
+ to_return(status: 201,
145
+ body: nil,
146
+ headers: {"Location" => "http://example.com/new"})
147
+ }
148
+
149
+ it "returns a HalClient::Representation" do
150
+ expect(return_val).to be_kind_of HalClient::Representation
151
+ end
152
+
153
+ it "returns representation of new resource" do
154
+ expect(return_val.href).to eq "http://example.com/new"
155
+ end
156
+ end
157
+
140
158
  describe "request" do
159
+ before do return_val end
141
160
  subject { post_request }
142
161
  it("should have been made") { should have_been_made }
143
162
 
@@ -148,6 +167,7 @@ describe HalClient do
148
167
  end
149
168
 
150
169
  context "explicit content type" do
170
+ before do return_val end
151
171
  subject(:client) { HalClient.new content_type: 'app/test' }
152
172
  it "sends specified content-type header" do
153
173
  expect(post_request.with(headers: {'Content-Type' => 'app/test'})).
@@ -156,6 +176,7 @@ describe HalClient do
156
176
  end
157
177
 
158
178
  context "other headers" do
179
+ before do return_val end
159
180
  let(:headers) { {"Authorization" => "Bearer f73c04b0970f1deb6005fab53edd1708"} }
160
181
  subject(:client) { HalClient.new headers: headers }
161
182
  it "sends the supplied header" do
@@ -163,7 +184,7 @@ describe HalClient do
163
184
  end
164
185
  end
165
186
 
166
- context "with no response body" do
187
+ context "with no response body and no location header" do
167
188
  subject { empty_post_request }
168
189
  let!(:return_val) { client.post "http://example.com/foo", nil }
169
190
 
@@ -191,6 +212,7 @@ describe HalClient do
191
212
  end
192
213
  end
193
214
 
215
+
194
216
  let(:post_data) { "ABC" }
195
217
 
196
218
  let!(:empty_post_request) { stub_request(:post, "http://example.com/foo").
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hal-client
3
3
  version: !ruby/object:Gem::Version
4
- version: '3.0'
4
+ version: '3.1'
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: 2014-05-13 00:00:00.000000000 Z
12
+ date: 2014-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: http
@@ -190,7 +190,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
190
  version: '0'
191
191
  segments:
192
192
  - 0
193
- hash: -442637899348440832
193
+ hash: -1711145322493868301
194
194
  required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  none: false
196
196
  requirements:
@@ -199,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
199
  version: '0'
200
200
  segments:
201
201
  - 0
202
- hash: -442637899348440832
202
+ hash: -1711145322493868301
203
203
  requirements: []
204
204
  rubyforge_project:
205
205
  rubygems_version: 1.8.23