gds-api-adapters 36.4.1 → 37.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -110,7 +110,7 @@ describe GdsApi::Response do
110
110
  body = {
111
111
  "web_url" => "https://www.gov.uk/test"
112
112
  }.to_json
113
- assert_equal "/test", build_response(body).web_url
113
+ assert_equal "/test", build_response(body)['web_url']
114
114
  end
115
115
 
116
116
  it "should leave other properties alone" do
@@ -119,8 +119,8 @@ describe GdsApi::Response do
119
119
  "description" => "Description"
120
120
  }.to_json
121
121
  response = build_response(body)
122
- assert_equal "Title", response.title
123
- assert_equal "Description", response.description
122
+ assert_equal "Title", response['title']
123
+ assert_equal "Description", response['description']
124
124
  end
125
125
 
126
126
  it "should traverse into hashes" do
@@ -132,7 +132,7 @@ describe GdsApi::Response do
132
132
  }.to_json
133
133
 
134
134
  response = build_response(body)
135
- assert_equal "/left", response.details.web_url
135
+ assert_equal "/left", response['details']['web_url']
136
136
  end
137
137
 
138
138
  it "should traverse into arrays" do
@@ -144,15 +144,15 @@ describe GdsApi::Response do
144
144
  }.to_json
145
145
 
146
146
  response = build_response(body)
147
- assert_equal "/pies", response.other_urls[0].web_url
148
- assert_equal "/cheese", response.other_urls[1].web_url
147
+ assert_equal "/pies", response['other_urls'][0]['web_url']
148
+ assert_equal "/cheese", response['other_urls'][1]['web_url']
149
149
  end
150
150
 
151
151
  it "should handle nil values" do
152
152
  body = {"web_url" => nil}.to_json
153
153
 
154
154
  response = build_response(body)
155
- assert_nil response.web_url
155
+ assert_nil response['web_url']
156
156
  end
157
157
 
158
158
  it "should handle query parameters" do
@@ -161,7 +161,7 @@ describe GdsApi::Response do
161
161
  }.to_json
162
162
 
163
163
  response = build_response(body)
164
- assert_equal "/thing?does=stuff", response.web_url
164
+ assert_equal "/thing?does=stuff", response['web_url']
165
165
  end
166
166
 
167
167
  it "should handle fragments" do
@@ -170,7 +170,7 @@ describe GdsApi::Response do
170
170
  }.to_json
171
171
 
172
172
  response = build_response(body)
173
- assert_equal "/thing#part-2", response.web_url
173
+ assert_equal "/thing#part-2", response['web_url']
174
174
  end
175
175
 
176
176
  it "should keep URLs from other domains absolute" do
@@ -179,7 +179,7 @@ describe GdsApi::Response do
179
179
  }.to_json
180
180
 
181
181
  response = build_response(body)
182
- assert_equal "https://www.example.com/example", response.web_url
182
+ assert_equal "https://www.example.com/example", response['web_url']
183
183
  end
184
184
 
185
185
  it "should keep URLs with other schemes absolute" do
@@ -188,7 +188,7 @@ describe GdsApi::Response do
188
188
  }.to_json
189
189
 
190
190
  response = build_response(body)
191
- assert_equal "http://www.example.com/example", response.web_url
191
+ assert_equal "http://www.example.com/example", response['web_url']
192
192
  end
193
193
  end
194
194
 
@@ -238,36 +238,65 @@ describe GdsApi::Response do
238
238
  end
239
239
  end
240
240
 
241
+ # TODO: When we remove `GdsApi.config.hash_response_for_requests`, this
242
+ # describe block no longer makes sense and it should be removed.
241
243
  describe "behaving like a read-only openstruct" do
244
+ def with_hash_response_for_requests_disabled
245
+ @old_hash_response_for_requests = GdsApi.config.hash_response_for_requests
246
+ GdsApi.configure do |config|
247
+ config.hash_response_for_requests = false
248
+ end
249
+
250
+ yield
251
+
252
+ GdsApi.configure do |config|
253
+ config.hash_response_for_requests = @old_hash_response_for_requests
254
+ end
255
+ end
256
+
242
257
  it "should allow accessing members using methods" do
243
- assert_equal "VAT rates", @response.title
258
+ with_hash_response_for_requests_disabled do
259
+ assert_equal "VAT rates", @response.title
260
+ end
244
261
  end
245
262
 
246
263
  it "should allow accessing nested values" do
247
- assert_equal "1870", @response.details.need_id
264
+ with_hash_response_for_requests_disabled do
265
+ assert_equal "1870", @response.details.need_id
266
+ end
248
267
  end
249
268
 
250
269
  it "should allow accessing values nested within arrays" do
251
- assert_equal "bar", @response.tags[1].slug
270
+ with_hash_response_for_requests_disabled do
271
+ assert_equal "bar", @response.tags[1].slug
272
+ end
252
273
  end
253
274
 
254
275
  it "should return nil for a non-existent key" do
255
- assert_equal nil, @response.foo
276
+ with_hash_response_for_requests_disabled do
277
+ assert_equal nil, @response.foo
278
+ end
256
279
  end
257
280
 
258
281
  it "should memoize the generated openstruct" do
259
- @response.id
260
- GdsApi::Response.expects(:build_ostruct_recursively).never
261
- assert_equal "VAT rates", @response.title
282
+ with_hash_response_for_requests_disabled do
283
+ @response.id
284
+ GdsApi::Response.expects(:build_ostruct_recursively).never
285
+ assert_equal "VAT rates", @response.title
286
+ end
262
287
  end
263
288
 
264
289
  describe "handling respond_to?" do
265
290
  it "should respond_to methods for keys that exist" do
266
- assert @response.respond_to?(:title)
291
+ with_hash_response_for_requests_disabled do
292
+ assert @response.respond_to?(:title)
293
+ end
267
294
  end
268
295
 
269
296
  it "should not respond_to keys that don't exist" do
270
- assert ! @response.respond_to?(:foo)
297
+ with_hash_response_for_requests_disabled do
298
+ assert ! @response.respond_to?(:foo)
299
+ end
271
300
  end
272
301
  end
273
302
  end
data/test/router_test.rb CHANGED
@@ -17,17 +17,18 @@ describe GdsApi::Router do
17
17
 
18
18
  response = @api.get_backend("foo")
19
19
  assert_equal 200, response.code
20
- assert_equal "http://foo.example.com/", response.backend_url
20
+ assert_equal "http://foo.example.com/", response['backend_url']
21
21
 
22
22
  assert_requested(req)
23
23
  end
24
24
 
25
- it "should return nil for a non-existend backend" do
25
+ it "raises for a non-existend backend" do
26
26
  req = WebMock.stub_request(:get, "#{@base_api_url}/backends/foo").
27
27
  to_return(:status => 404)
28
28
 
29
- response = @api.get_backend("foo")
30
- assert_nil response
29
+ assert_raises(GdsApi::HTTPNotFound) do
30
+ @api.get_backend("foo")
31
+ end
31
32
 
32
33
  assert_requested(req)
33
34
  end
@@ -36,8 +37,9 @@ describe GdsApi::Router do
36
37
  req = WebMock.stub_request(:get, "#{@base_api_url}/backends/foo+bar").
37
38
  to_return(:status => 404)
38
39
 
39
- response = @api.get_backend("foo bar")
40
- assert_nil response
40
+ assert_raises(GdsApi::HTTPNotFound) do
41
+ @api.get_backend("foo bar")
42
+ end
41
43
 
42
44
  assert_requested(req)
43
45
  end
@@ -52,7 +54,7 @@ describe GdsApi::Router do
52
54
 
53
55
  response = @api.add_backend("foo", "http://foo.example.com/")
54
56
  assert_equal 201, response.code
55
- assert_equal "http://foo.example.com/", response.backend_url
57
+ assert_equal "http://foo.example.com/", response['backend_url']
56
58
 
57
59
  assert_requested(req)
58
60
  end
@@ -100,7 +102,7 @@ describe GdsApi::Router do
100
102
 
101
103
  response = @api.delete_backend("foo")
102
104
  assert_equal 200, response.code
103
- assert_equal "http://foo.example.com/", response.backend_url
105
+ assert_equal "http://foo.example.com/", response['backend_url']
104
106
 
105
107
  assert_requested(req)
106
108
  end
@@ -154,19 +156,20 @@ describe GdsApi::Router do
154
156
 
155
157
  response = @api.get_route("/foo")
156
158
  assert_equal 200, response.code
157
- assert_equal "foo", response.backend_id
159
+ assert_equal "foo", response['backend_id']
158
160
 
159
161
  assert_requested(req)
160
162
  assert_not_requested(@commit_req)
161
163
  end
162
164
 
163
- it "should return nil if nothing found" do
165
+ it "should raise if nothing found" do
164
166
  req = WebMock.stub_request(:get, "#{@base_api_url}/routes").
165
167
  with(:query => {"incoming_path" => "/foo"}).
166
168
  to_return(:status => 404)
167
169
 
168
- response = @api.get_route("/foo")
169
- assert_nil response
170
+ assert_raises(GdsApi::HTTPNotFound) do
171
+ @api.get_route("/foo")
172
+ end
170
173
 
171
174
  assert_requested(req)
172
175
  assert_not_requested(@commit_req)
@@ -179,8 +182,9 @@ describe GdsApi::Router do
179
182
  with(:query => {"incoming_path" => "/foo bar"}).
180
183
  to_return(:status => 404)
181
184
 
182
- response = @api.get_route("/foo bar")
183
- assert_nil response
185
+ assert_raises(GdsApi::HTTPNotFound) do
186
+ @api.get_route("/foo bar")
187
+ end
184
188
 
185
189
  assert_requested(req)
186
190
  assert_not_requested(@commit_req)
@@ -196,7 +200,7 @@ describe GdsApi::Router do
196
200
 
197
201
  response = @api.add_route("/foo", "exact", "foo")
198
202
  assert_equal 201, response.code
199
- assert_equal "foo", response.backend_id
203
+ assert_equal "foo", response['backend_id']
200
204
 
201
205
  assert_requested(req)
202
206
  assert_not_requested(@commit_req)
@@ -246,7 +250,7 @@ describe GdsApi::Router do
246
250
 
247
251
  response = @api.add_redirect_route("/foo", "exact", "/bar")
248
252
  assert_equal 201, response.code
249
- assert_equal "/bar", response.redirect_to
253
+ assert_equal "/bar", response['redirect_to']
250
254
 
251
255
  assert_requested(req)
252
256
  assert_not_requested(@commit_req)
@@ -261,7 +265,7 @@ describe GdsApi::Router do
261
265
 
262
266
  response = @api.add_redirect_route("/foo", "exact", "/bar", "temporary")
263
267
  assert_equal 201, response.code
264
- assert_equal "/bar", response.redirect_to
268
+ assert_equal "/bar", response['redirect_to']
265
269
 
266
270
  assert_requested(req)
267
271
  assert_not_requested(@commit_req)
@@ -276,7 +280,7 @@ describe GdsApi::Router do
276
280
 
277
281
  response = @api.add_redirect_route("/foo", "exact", "/bar", "temporary", :segments_mode => "preserve")
278
282
  assert_equal 201, response.code
279
- assert_equal "/bar", response.redirect_to
283
+ assert_equal "/bar", response['redirect_to']
280
284
 
281
285
  assert_requested(req)
282
286
  assert_not_requested(@commit_req)
@@ -326,7 +330,7 @@ describe GdsApi::Router do
326
330
 
327
331
  response = @api.add_gone_route("/foo", "exact")
328
332
  assert_equal 201, response.code
329
- assert_equal "/foo", response.incoming_path
333
+ assert_equal "/foo", response['incoming_path']
330
334
 
331
335
  assert_requested(req)
332
336
  assert_not_requested(@commit_req)
@@ -375,7 +379,7 @@ describe GdsApi::Router do
375
379
 
376
380
  response = @api.delete_route("/foo")
377
381
  assert_equal 200, response.code
378
- assert_equal "foo", response.backend_id
382
+ assert_equal "foo", response['backend_id']
379
383
 
380
384
  assert_requested(req)
381
385
  assert_not_requested(@commit_req)
@@ -15,6 +15,6 @@ class RummagerHelpersTest < Minitest::Test
15
15
  response = rummager_has_no_services_and_info_data_for_organisation
16
16
 
17
17
  assert_instance_of GdsApi::Response, response
18
- assert_equal 0, response.facets.specialist_sectors.total_options
18
+ assert_equal 0, response['facets']['specialist_sectors']['total_options']
19
19
  end
20
20
  end
@@ -16,8 +16,8 @@ describe GdsApi::Worldwide do
16
16
  worldwide_api_has_locations(country_slugs)
17
17
 
18
18
  response = @api.world_locations
19
- assert_equal country_slugs, response.map {|r| r.details.slug }
20
- assert_equal "Rohan", response.results[2].title
19
+ assert_equal country_slugs, response.map { |r| r['details']['slug'] }
20
+ assert_equal "Rohan", response['results'][2]['title']
21
21
  end
22
22
 
23
23
  it "should handle the pagination" do
@@ -25,7 +25,10 @@ describe GdsApi::Worldwide do
25
25
  worldwide_api_has_locations(country_slugs)
26
26
 
27
27
  response = @api.world_locations
28
- assert_equal country_slugs, response.with_subsequent_pages.map {|r| r.details.slug }
28
+ assert_equal(
29
+ country_slugs,
30
+ response.with_subsequent_pages.map { |r| r['details']['slug'] }
31
+ )
29
32
  end
30
33
 
31
34
  it "should raise error if endpoint 404s" do
@@ -41,13 +44,15 @@ describe GdsApi::Worldwide do
41
44
  worldwide_api_has_location('rohan')
42
45
 
43
46
  response = @api.world_location('rohan')
44
- assert_equal 'Rohan', response.title
47
+ assert_equal 'Rohan', response['title']
45
48
  end
46
49
 
47
- it "should return nil for a non-existent location" do
50
+ it "raises for a non-existent location" do
48
51
  worldwide_api_does_not_have_location('non-existent')
49
52
 
50
- assert_nil @api.world_location('non-existent')
53
+ assert_raises(GdsApi::HTTPNotFound) do
54
+ @api.world_location('non-existent')
55
+ end
51
56
  end
52
57
  end
53
58
 
@@ -58,7 +63,13 @@ describe GdsApi::Worldwide do
58
63
 
59
64
  response = @api.organisations_for_world_location('australia')
60
65
  assert response.is_a?(GdsApi::ListResponse)
61
- assert_equal ["UK Trade & Investment Australia", "British High Commission Canberra"], response.map(&:title)
66
+ assert_equal(
67
+ [
68
+ "UK Trade & Investment Australia",
69
+ "British High Commission Canberra"
70
+ ],
71
+ response.map { |item| item['title'] }
72
+ )
62
73
  end
63
74
 
64
75
  it "should raise error on 404" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 36.4.1
4
+ version: 37.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Stewart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-30 00:00:00.000000000 Z
11
+ date: 2016-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plek
@@ -318,6 +318,20 @@ dependencies:
318
318
  - - '='
319
319
  - !ruby/object:Gem::Version
320
320
  version: 1.0.0
321
+ - !ruby/object:Gem::Dependency
322
+ name: govuk-lint
323
+ requirement: !ruby/object:Gem::Requirement
324
+ requirements:
325
+ - - '='
326
+ - !ruby/object:Gem::Version
327
+ version: 1.2.1
328
+ type: :development
329
+ prerelease: false
330
+ version_requirements: !ruby/object:Gem::Requirement
331
+ requirements:
332
+ - - '='
333
+ - !ruby/object:Gem::Version
334
+ version: 1.2.1
321
335
  description: A set of adapters providing easy access to the GDS GOV.UK APIs
322
336
  email:
323
337
  - jystewart@gmail.com
@@ -468,7 +482,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
468
482
  version: '0'
469
483
  requirements: []
470
484
  rubyforge_project:
471
- rubygems_version: 2.2.5
485
+ rubygems_version: 2.5.1
472
486
  signing_key:
473
487
  specification_version: 4
474
488
  summary: Adapters to work with GDS APIs