gds-api-adapters 38.0.0 → 38.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +5 -5
  3. data/lib/gds_api/asset_manager.rb +7 -7
  4. data/lib/gds_api/base.rb +13 -11
  5. data/lib/gds_api/business_support_api.rb +3 -4
  6. data/lib/gds_api/content_api.rb +31 -44
  7. data/lib/gds_api/content_store.rb +2 -3
  8. data/lib/gds_api/email_alert_api.rb +6 -7
  9. data/lib/gds_api/exceptions.rb +4 -1
  10. data/lib/gds_api/gov_uk_delivery.rb +9 -8
  11. data/lib/gds_api/govuk_headers.rb +1 -1
  12. data/lib/gds_api/imminence.rb +9 -10
  13. data/lib/gds_api/json_client.rb +21 -34
  14. data/lib/gds_api/licence_application.rb +2 -2
  15. data/lib/gds_api/list_response.rb +7 -10
  16. data/lib/gds_api/local_links_manager.rb +1 -1
  17. data/lib/gds_api/mapit.rb +5 -6
  18. data/lib/gds_api/middleware/govuk_header_sniffer.rb +1 -1
  19. data/lib/gds_api/need_api.rb +7 -8
  20. data/lib/gds_api/null_cache.rb +2 -2
  21. data/lib/gds_api/organisations.rb +2 -2
  22. data/lib/gds_api/panopticon.rb +11 -11
  23. data/lib/gds_api/performance_platform/data_in.rb +4 -4
  24. data/lib/gds_api/performance_platform/data_out.rb +1 -1
  25. data/lib/gds_api/publishing_api.rb +4 -5
  26. data/lib/gds_api/publishing_api/special_route_publisher.rb +5 -3
  27. data/lib/gds_api/publishing_api_v2.rb +8 -16
  28. data/lib/gds_api/response.rb +2 -5
  29. data/lib/gds_api/router.rb +18 -9
  30. data/lib/gds_api/rummager.rb +6 -7
  31. data/lib/gds_api/support.rb +7 -6
  32. data/lib/gds_api/support_api.rb +14 -14
  33. data/lib/gds_api/test_helpers/asset_manager.rb +3 -6
  34. data/lib/gds_api/test_helpers/business_support_api.rb +4 -4
  35. data/lib/gds_api/test_helpers/business_support_helper.rb +9 -8
  36. data/lib/gds_api/test_helpers/common_responses.rb +10 -12
  37. data/lib/gds_api/test_helpers/content_api.rb +23 -23
  38. data/lib/gds_api/test_helpers/content_api/artefact_stub.rb +13 -12
  39. data/lib/gds_api/test_helpers/content_item_helpers.rb +4 -4
  40. data/lib/gds_api/test_helpers/content_store.rb +3 -3
  41. data/lib/gds_api/test_helpers/email_alert_api.rb +8 -10
  42. data/lib/gds_api/test_helpers/gov_uk_delivery.rb +0 -1
  43. data/lib/gds_api/test_helpers/imminence.rb +4 -4
  44. data/lib/gds_api/test_helpers/intent_helpers.rb +0 -2
  45. data/lib/gds_api/test_helpers/local_links_manager.rb +12 -13
  46. data/lib/gds_api/test_helpers/mapit.rb +14 -15
  47. data/lib/gds_api/test_helpers/need_api.rb +4 -4
  48. data/lib/gds_api/test_helpers/organisations.rb +13 -15
  49. data/lib/gds_api/test_helpers/panopticon.rb +6 -6
  50. data/lib/gds_api/test_helpers/performance_platform/data_in.rb +8 -8
  51. data/lib/gds_api/test_helpers/publishing_api.rb +19 -20
  52. data/lib/gds_api/test_helpers/publishing_api_v2.rb +13 -13
  53. data/lib/gds_api/test_helpers/router.rb +5 -5
  54. data/lib/gds_api/test_helpers/rummager.rb +5 -4
  55. data/lib/gds_api/test_helpers/support.rb +11 -11
  56. data/lib/gds_api/test_helpers/support_api.rb +14 -14
  57. data/lib/gds_api/test_helpers/whitehall_admin_api.rb +1 -1
  58. data/lib/gds_api/test_helpers/worldwide.rb +16 -19
  59. data/lib/gds_api/version.rb +1 -1
  60. data/lib/gds_api/worldwide.rb +4 -4
  61. data/test/asset_manager_test.rb +6 -6
  62. data/test/business_support_api_test.rb +9 -10
  63. data/test/content_api_test.rb +81 -83
  64. data/test/email_alert_api_test.rb +3 -5
  65. data/test/gds_api_base_test.rb +9 -10
  66. data/test/gov_uk_delivery_test.rb +4 -6
  67. data/test/imminence_api_test.rb +7 -9
  68. data/test/json_client_test.rb +71 -64
  69. data/test/licence_application_api_test.rb +5 -7
  70. data/test/list_response_test.rb +27 -32
  71. data/test/mapit_test.rb +7 -9
  72. data/test/middleware/govuk_header_sniffer_test.rb +1 -1
  73. data/test/need_api_test.rb +8 -8
  74. data/test/organisations_api_test.rb +2 -2
  75. data/test/panopticon_registerer_test.rb +10 -10
  76. data/test/panopticon_test.rb +5 -5
  77. data/test/pp_data_in_test.rb +3 -3
  78. data/test/publishing_api_test.rb +2 -6
  79. data/test/publishing_api_v2_test.rb +40 -50
  80. data/test/response_test.rb +21 -22
  81. data/test/router_test.rb +78 -80
  82. data/test/rummager_test.rb +14 -14
  83. data/test/support_api_test.rb +13 -13
  84. data/test/support_test.rb +15 -16
  85. data/test/test_helper.rb +1 -1
  86. data/test/test_helpers/email_alert_api_test.rb +3 -3
  87. data/test/test_helpers/pact_helper.rb +1 -1
  88. data/test/test_helpers/panopticon_test.rb +1 -1
  89. data/test/test_helpers/publishing_api_test.rb +7 -7
  90. data/test/test_helpers/publishing_api_v2_test.rb +5 -9
  91. data/test/worldwide_api_test.rb +3 -3
  92. metadata +2 -3
  93. data/lib/gds_api/core-ext/openstruct.rb +0 -5
@@ -3,7 +3,6 @@ require 'gds_api/gov_uk_delivery'
3
3
  require 'gds_api/test_helpers/gov_uk_delivery'
4
4
 
5
5
  describe GdsApi::GovUkDelivery do
6
-
7
6
  include GdsApi::TestHelpers::GovUkDelivery
8
7
 
9
8
  before do
@@ -28,7 +27,7 @@ describe GdsApi::GovUkDelivery do
28
27
  end
29
28
 
30
29
  it "can post a notification" do
31
- expected_payload = { feed_urls: ['http://example.com/feed'], subject: 'Test', body: '<p>Something</p>'}
30
+ expected_payload = { feed_urls: ['http://example.com/feed'], subject: 'Test', body: '<p>Something</p>' }
32
31
  stub = stub_gov_uk_delivery_post_request('notifications', expected_payload).to_return(created_response_hash)
33
32
 
34
33
  assert @api.notify(['http://example.com/feed'], 'Test', '<p>Something</p>')
@@ -37,15 +36,15 @@ describe GdsApi::GovUkDelivery do
37
36
 
38
37
  it "can get a subscription URL" do
39
38
  expected_payload = { feed_url: 'http://example.com/feed' }
40
- stub = stub_gov_uk_delivery_get_request('list-url', expected_payload).to_return(created_response_json_hash({list_url: 'thing'}))
39
+ stub = stub_gov_uk_delivery_get_request('list-url', expected_payload).to_return(created_response_json_hash(list_url: 'thing'))
41
40
 
42
41
  assert @api.signup_url('http://example.com/feed')
43
42
  assert_requested stub
44
43
  end
45
44
 
46
45
  it "raises if the API 404s" do
47
- expected_payload = { feed_url: 'http://example.com/feed'}
48
- stub = stub_gov_uk_delivery_get_request('list-url', expected_payload).to_return(not_found_hash)
46
+ expected_payload = { feed_url: 'http://example.com/feed' }
47
+ stub_gov_uk_delivery_get_request('list-url', expected_payload).to_return(not_found_hash)
49
48
 
50
49
  assert_raises(GdsApi::HTTPNotFound) do
51
50
  @api.signup_url('http://example.com/feed')
@@ -65,5 +64,4 @@ describe GdsApi::GovUkDelivery do
65
64
  def created_response_json_hash(data)
66
65
  { body: data.to_json, status: 201 }
67
66
  end
68
-
69
67
  end
@@ -2,8 +2,7 @@ require "test_helper"
2
2
  require "gds_api/imminence"
3
3
 
4
4
  class ImminenceApiTest < Minitest::Test
5
-
6
- ROOT = "https://imminence.test.alphagov.co.uk"
5
+ ROOT = "https://imminence.test.alphagov.co.uk".freeze
7
6
  LATITUDE = 52.1327584352089
8
7
  LONGITUDE = -0.4702813074674147
9
8
 
@@ -87,7 +86,7 @@ class ImminenceApiTest < Minitest::Test
87
86
  c = api_client
88
87
  url = "#{ROOT}/places/wibble.json?limit=5&lat=52&lng=0"
89
88
  place_info = dummy_place.merge(
90
- "location" => {"longitude" => LONGITUDE, "latitude" => LATITUDE}
89
+ "location" => { "longitude" => LONGITUDE, "latitude" => LATITUDE }
91
90
  )
92
91
  c.expects(:get_json).with(url).returns([place_info])
93
92
  places = c.places("wibble", 52, 0)
@@ -139,7 +138,7 @@ EOS
139
138
 
140
139
  stub_request(:get, "#{ROOT}/places/test.kml").
141
140
  with(headers: GdsApi::JsonClient.default_request_headers).
142
- to_return(status: 200, body: kml_body )
141
+ to_return(status: 200, body: kml_body)
143
142
 
144
143
  response_body = api_client.places_kml("test")
145
144
  assert_equal kml_body, response_body
@@ -151,14 +150,14 @@ EOS
151
150
  { "id" => 66, "type" => "EUR", "name" => "London", "country_name" => "England" }
152
151
  ]
153
152
  results = {
154
- "_response_info" => {"status" => "ok"},
153
+ "_response_info" => { "status" => "ok" },
155
154
  "total" => areas.size, "startIndex" => 1, "pageSize" => areas.size,
156
155
  "currentPage" => 1, "pages" => 1, "results" => areas
157
156
  }
158
157
 
159
158
  stub_request(:get, "#{ROOT}/areas/WC2B%206SE.json").
160
159
  with(headers: GdsApi::JsonClient.default_request_headers).
161
- to_return(status: 200, body: results.to_json )
160
+ to_return(status: 200, body: results.to_json)
162
161
 
163
162
  response = api_client.areas_for_postcode("WC2B 6SE")
164
163
 
@@ -175,14 +174,14 @@ EOS
175
174
  { "id" => 665, "type" => "EUR", "name" => "London", "country_name" => "England" }
176
175
  ]
177
176
  results = {
178
- "_response_info" => {"status" => "ok"},
177
+ "_response_info" => { "status" => "ok" },
179
178
  "total" => areas.size, "startIndex" => 1, "pageSize" => areas.size,
180
179
  "currentPage" => 1, "pages" => 1, "results" => areas
181
180
  }
182
181
 
183
182
  stub_request(:get, "#{ROOT}/areas/EUR.json").
184
183
  with(headers: GdsApi::JsonClient.default_request_headers).
185
- to_return(status: 200, body: results.to_json )
184
+ to_return(status: 200, body: results.to_json)
186
185
 
187
186
  response = api_client.areas_for_type("EUR")
188
187
 
@@ -194,5 +193,4 @@ EOS
194
193
  assert_equal 122, areas_from_response.first["id"]
195
194
  assert_equal 665, areas_from_response.last["id"]
196
195
  end
197
-
198
196
  end
@@ -45,6 +45,13 @@ class JsonClientTest < MiniTest::Spec
45
45
  end
46
46
  end
47
47
 
48
+ def test_request_an_invalid_url
49
+ url = "http://www.example.com/there-is-a-space-in-this-slug /"
50
+ assert_raises GdsApi::InvalidUrl do
51
+ @client.get_json(url)
52
+ end
53
+ end
54
+
48
55
  def test_get_should_raise_endpoint_not_found_if_connection_refused
49
56
  url = "http://some.endpoint/some.json"
50
57
  stub_request(:get, url).to_raise(Errno::ECONNREFUSED)
@@ -85,7 +92,7 @@ class JsonClientTest < MiniTest::Spec
85
92
 
86
93
  def test_should_cache_multiple_requests_to_same_url_across_instances
87
94
  url = "http://some.endpoint/some.json"
88
- result = {"foo" => "bar"}
95
+ result = { "foo" => "bar" }
89
96
  stub_request(:get, url).to_return(body: JSON.dump(result), status: 200)
90
97
  response_a = GdsApi::JsonClient.new.get_json(url)
91
98
  response_b = GdsApi::JsonClient.new.get_json(url)
@@ -99,12 +106,12 @@ class JsonClientTest < MiniTest::Spec
99
106
  GdsApi::JsonClient.cache = nil
100
107
 
101
108
  url = "http://some.endpoint/"
102
- result = {"foo" => "bar"}
109
+
103
110
  stub_request(:get, %r{\A#{url}}).to_return do |request|
104
111
  { body: { "url" => request.uri }.to_json, status: 200 }
105
112
  end
106
113
 
107
- response_a = GdsApi::JsonClient.new(:cache_size => 5).get_json("#{url}/first.json")
114
+ response_a = GdsApi::JsonClient.new(cache_size: 5).get_json("#{url}/first.json")
108
115
  response_b = GdsApi::JsonClient.new.get_json("#{url}/second.json")
109
116
  4.times { |n| GdsApi::JsonClient.new.get_json("#{url}/#{n}.json") }
110
117
 
@@ -119,7 +126,7 @@ class JsonClientTest < MiniTest::Spec
119
126
 
120
127
  def test_should_cache_requests_for_15_mins_by_default
121
128
  url = "http://some.endpoint/some.json"
122
- result = {"foo" => "bar"}
129
+ result = { "foo" => "bar" }
123
130
  stub_request(:get, url).to_return(body: JSON.dump(result), status: 200)
124
131
  response_a = GdsApi::JsonClient.new.get_json(url)
125
132
  response_b = GdsApi::JsonClient.new.get_json(url)
@@ -127,14 +134,14 @@ class JsonClientTest < MiniTest::Spec
127
134
  assert_requested :get, url, times: 1
128
135
  assert_equal response_a.to_hash, response_b.to_hash
129
136
 
130
- Timecop.travel( 15 * 60 - 30) do # now + 14 mins 30 secs
137
+ Timecop.travel(15 * 60 - 30) do # now + 14 mins 30 secs
131
138
  response_c = GdsApi::JsonClient.new.get_json(url)
132
139
 
133
140
  assert_requested :get, url, times: 1
134
141
  assert_equal response_a.to_hash, response_c.to_hash
135
142
  end
136
143
 
137
- Timecop.travel( 15 * 60 + 30) do # now + 15 mins 30 secs
144
+ Timecop.travel(15 * 60 + 30) do # now + 15 mins 30 secs
138
145
  response_d = GdsApi::JsonClient.new.get_json(url)
139
146
 
140
147
  assert_requested :get, url, times: 2
@@ -148,22 +155,22 @@ class JsonClientTest < MiniTest::Spec
148
155
  GdsApi::JsonClient.cache = nil
149
156
 
150
157
  url = "http://some.endpoint/some.json"
151
- result = {"foo" => "bar"}
158
+ result = { "foo" => "bar" }
152
159
  stub_request(:get, url).to_return(body: JSON.dump(result), status: 200)
153
- response_a = GdsApi::JsonClient.new(:cache_ttl => 5 * 60).get_json(url)
160
+ response_a = GdsApi::JsonClient.new(cache_ttl: 5 * 60).get_json(url)
154
161
  response_b = GdsApi::JsonClient.new.get_json(url)
155
162
 
156
163
  assert_requested :get, url, times: 1
157
164
  assert_equal response_a.to_hash, response_b.to_hash
158
165
 
159
- Timecop.travel( 5 * 60 - 30) do # now + 4 mins 30 secs
166
+ Timecop.travel(5 * 60 - 30) do # now + 4 mins 30 secs
160
167
  response_c = GdsApi::JsonClient.new.get_json(url)
161
168
 
162
169
  assert_requested :get, url, times: 1
163
170
  assert_equal response_a.to_hash, response_c.to_hash
164
171
  end
165
172
 
166
- Timecop.travel( 5 * 60 + 30) do # now + 5 mins 30 secs
173
+ Timecop.travel(5 * 60 + 30) do # now + 5 mins 30 secs
167
174
  response_d = GdsApi::JsonClient.new.get_json(url)
168
175
 
169
176
  assert_requested :get, url, times: 2
@@ -173,7 +180,7 @@ class JsonClientTest < MiniTest::Spec
173
180
 
174
181
  def test_should_allow_disabling_caching
175
182
  url = "http://some.endpoint/some.json"
176
- result = {"foo" => "bar"}
183
+ result = { "foo" => "bar" }
177
184
  stub_request(:get, url).to_return(body: JSON.dump(result), status: 200)
178
185
 
179
186
  client = GdsApi::JsonClient.new(disable_cache: true)
@@ -190,7 +197,7 @@ class JsonClientTest < MiniTest::Spec
190
197
 
191
198
  def test_should_respect_expiry_headers
192
199
  url = "http://some.endpoint/some.json"
193
- result = {"foo" => "bar"}
200
+ result = { "foo" => "bar" }
194
201
  stub_request(:get, url).to_return(
195
202
  body: JSON.dump(result),
196
203
  status: 200,
@@ -199,14 +206,14 @@ class JsonClientTest < MiniTest::Spec
199
206
 
200
207
  response_a = GdsApi::JsonClient.new.get_json(url)
201
208
 
202
- Timecop.travel( 7 * 60 - 30) do # now + 6 mins 30 secs
209
+ Timecop.travel(7 * 60 - 30) do # now + 6 mins 30 secs
203
210
  response_b = GdsApi::JsonClient.new.get_json(url)
204
211
 
205
212
  assert_requested :get, url, times: 1
206
213
  assert_equal response_a.to_hash, response_b.to_hash
207
214
  end
208
215
 
209
- Timecop.travel( 7 * 60 + 30) do # now + 7 mins 30 secs
216
+ Timecop.travel(7 * 60 + 30) do # now + 7 mins 30 secs
210
217
  response_c = GdsApi::JsonClient.new.get_json(url)
211
218
 
212
219
  assert_requested :get, url, times: 2
@@ -216,7 +223,7 @@ class JsonClientTest < MiniTest::Spec
216
223
 
217
224
  def test_should_respect_cache_control_headers_with_max_age
218
225
  url = "http://some.endpoint/max_age.json"
219
- result = {"foo" => "bar"}
226
+ result = { "foo" => "bar" }
220
227
  stub_request(:get, url).to_return(
221
228
  body: JSON.dump(result),
222
229
  status: 200,
@@ -225,14 +232,14 @@ class JsonClientTest < MiniTest::Spec
225
232
 
226
233
  response_a = GdsApi::JsonClient.new.get_json(url)
227
234
 
228
- Timecop.travel( 7 * 60 - 30) do # now + 6 mins 30 secs
235
+ Timecop.travel(7 * 60 - 30) do # now + 6 mins 30 secs
229
236
  response_b = GdsApi::JsonClient.new.get_json(url)
230
237
 
231
238
  assert_requested :get, url, times: 1
232
239
  assert_equal response_a.to_hash, response_b.to_hash
233
240
  end
234
241
 
235
- Timecop.travel( 7 * 60 + 30) do # now + 7 mins 30 secs
242
+ Timecop.travel(7 * 60 + 30) do # now + 7 mins 30 secs
236
243
  response_c = GdsApi::JsonClient.new.get_json(url)
237
244
 
238
245
  assert_requested :get, url, times: 2
@@ -242,7 +249,7 @@ class JsonClientTest < MiniTest::Spec
242
249
 
243
250
  def test_should_respect_cache_control_headers_with_no_cache
244
251
  url = "http://some.endpoint/no_cache.json"
245
- result = {"foo" => "bar"}
252
+ result = { "foo" => "bar" }
246
253
  stub_request(:get, url).to_return(
247
254
  body: JSON.dump(result),
248
255
  status: 200,
@@ -251,7 +258,7 @@ class JsonClientTest < MiniTest::Spec
251
258
 
252
259
  response_a = GdsApi::JsonClient.new.get_json(url)
253
260
 
254
- Timecop.travel( 7 * 60 - 30) do # now + 6 mins 30 secs
261
+ Timecop.travel(7 * 60 - 30) do # now + 6 mins 30 secs
255
262
  response_b = GdsApi::JsonClient.new.get_json(url)
256
263
 
257
264
  assert_requested :get, url, times: 2
@@ -261,7 +268,7 @@ class JsonClientTest < MiniTest::Spec
261
268
 
262
269
  def test_does_not_cache_responses_with_cache_control_private
263
270
  url = "http://some.endpoint/private.json"
264
- result = {"foo" => "bar"}
271
+ result = { "foo" => "bar" }
265
272
  stub_request(:get, url).to_return(
266
273
  body: JSON.dump(result),
267
274
  status: 200,
@@ -270,7 +277,7 @@ class JsonClientTest < MiniTest::Spec
270
277
 
271
278
  response_a = GdsApi::JsonClient.new.get_json(url)
272
279
 
273
- Timecop.travel( 7 * 60 - 30) do # now + 6 mins 30 secs
280
+ Timecop.travel(7 * 60 - 30) do # now + 6 mins 30 secs
274
281
  response_b = GdsApi::JsonClient.new.get_json(url)
275
282
 
276
283
  assert_requested :get, url, times: 2
@@ -280,7 +287,7 @@ class JsonClientTest < MiniTest::Spec
280
287
 
281
288
  def test_does_not_cache_responses_with_cache_control_no_store
282
289
  url = "http://some.endpoint/private.json"
283
- result = {"foo" => "bar"}
290
+ result = { "foo" => "bar" }
284
291
  stub_request(:get, url).to_return(
285
292
  body: JSON.dump(result),
286
293
  status: 200,
@@ -289,7 +296,7 @@ class JsonClientTest < MiniTest::Spec
289
296
 
290
297
  response_a = GdsApi::JsonClient.new.get_json(url)
291
298
 
292
- Timecop.travel( 7 * 60 - 30) do # now + 6 mins 30 secs
299
+ Timecop.travel(7 * 60 - 30) do # now + 6 mins 30 secs
293
300
  response_b = GdsApi::JsonClient.new.get_json(url)
294
301
 
295
302
  assert_requested :get, url, times: 2
@@ -299,7 +306,7 @@ class JsonClientTest < MiniTest::Spec
299
306
 
300
307
  def test_should_respect_cache_control_headers_with_no_cache_and_max_age
301
308
  url = "http://some.endpoint/no_cache_and_max_age.json"
302
- result = {"foo" => "bar"}
309
+ result = { "foo" => "bar" }
303
310
  stub_request(:get, url).to_return(
304
311
  body: JSON.dump(result),
305
312
  status: 200,
@@ -308,7 +315,7 @@ class JsonClientTest < MiniTest::Spec
308
315
 
309
316
  response_a = GdsApi::JsonClient.new.get_json(url)
310
317
 
311
- Timecop.travel( 7 * 60 - 30) do # now + 6 mins 30 secs
318
+ Timecop.travel(7 * 60 - 30) do # now + 6 mins 30 secs
312
319
  response_b = GdsApi::JsonClient.new.get_json(url)
313
320
 
314
321
  assert_requested :get, url, times: 2
@@ -318,7 +325,7 @@ class JsonClientTest < MiniTest::Spec
318
325
 
319
326
  def test_should_use_cache_control_headers_over_expires_headers
320
327
  url = "http://some.endpoint/url.json"
321
- result = {"foo" => "bar"}
328
+ result = { "foo" => "bar" }
322
329
  stub_request(:get, url).to_return(
323
330
  body: JSON.dump(result),
324
331
  status: 200,
@@ -330,7 +337,7 @@ class JsonClientTest < MiniTest::Spec
330
337
 
331
338
  response_a = GdsApi::JsonClient.new.get_json(url)
332
339
 
333
- Timecop.travel( 7 * 60 - 30) do # now + 6 mins 30 secs
340
+ Timecop.travel(7 * 60 - 30) do # now + 6 mins 30 secs
334
341
  response_b = GdsApi::JsonClient.new.get_json(url)
335
342
 
336
343
  assert_requested :get, url, times: 2
@@ -340,7 +347,7 @@ class JsonClientTest < MiniTest::Spec
340
347
 
341
348
  def test_should_fallback_to_expires_headers_if_cache_control_is_malformed
342
349
  url = "http://some.endpoint/url.json"
343
- result = {"foo" => "bar"}
350
+ result = { "foo" => "bar" }
344
351
  stub_request(:get, url).to_return(
345
352
  body: JSON.dump(result),
346
353
  status: 200,
@@ -352,7 +359,7 @@ class JsonClientTest < MiniTest::Spec
352
359
 
353
360
  response_a = GdsApi::JsonClient.new.get_json(url)
354
361
 
355
- Timecop.travel( 7 * 60 - 30) do # now + 6 mins 30 secs
362
+ Timecop.travel(7 * 60 - 30) do # now + 6 mins 30 secs
356
363
  response_b = GdsApi::JsonClient.new.get_json(url)
357
364
 
358
365
  assert_requested :get, url, times: 1
@@ -364,7 +371,7 @@ class JsonClientTest < MiniTest::Spec
364
371
  url = "http://some.endpoint/some.json"
365
372
  stub_request(:get, url).to_return(body: "{}", status: 404)
366
373
  assert_raises GdsApi::HTTPNotFound do
367
- @client.get_json!(url)
374
+ @client.get_json(url)
368
375
  end
369
376
  end
370
377
 
@@ -372,7 +379,7 @@ class JsonClientTest < MiniTest::Spec
372
379
  url = "http://some.endpoint/some.json"
373
380
  stub_request(:get, url).to_return(body: "{}", status: 410)
374
381
  assert_raises GdsApi::HTTPGone do
375
- @client.get_json!(url)
382
+ @client.get_json(url)
376
383
  end
377
384
  end
378
385
 
@@ -380,7 +387,7 @@ class JsonClientTest < MiniTest::Spec
380
387
  url = "http://some.endpoint/some.json"
381
388
  stub_request(:get, url).to_return(body: "{}", status: 403)
382
389
  assert_raises GdsApi::HTTPForbidden do
383
- @client.get_json!(url)
390
+ @client.get_json(url)
384
391
  end
385
392
  end
386
393
 
@@ -428,7 +435,7 @@ class JsonClientTest < MiniTest::Spec
428
435
  url = "http://some.endpoint/some.json"
429
436
  stub_request(:delete, url).to_return(body: "{}", status: 409)
430
437
  assert_raises GdsApi::HTTPConflict do
431
- @client.delete_json!(url)
438
+ @client.delete_json(url)
432
439
  end
433
440
  end
434
441
 
@@ -496,7 +503,7 @@ class JsonClientTest < MiniTest::Spec
496
503
  # with a redirect to the same URL, but we'd risk getting the test code into
497
504
  # an infinite loop if the code didn't do what it was supposed to. The
498
505
  # failure response block aborts the test if we have too many requests.
499
- failure = lambda { |request| flunk("Request called too many times") }
506
+ failure = lambda { |_request| flunk("Request called too many times") }
500
507
  stub_request(:get, url).to_return(redirect).times(11).then.to_return(failure)
501
508
 
502
509
  assert_raises GdsApi::HTTPErrorResponse do
@@ -520,7 +527,7 @@ class JsonClientTest < MiniTest::Spec
520
527
  }
521
528
 
522
529
  # See the comment in the above test for an explanation of this
523
- failure = lambda { |request| flunk("Request called too many times") }
530
+ failure = lambda { |_request| flunk("Request called too many times") }
524
531
  stub_request(:get, first_url).to_return(first_redirect).times(6).then.to_return(failure)
525
532
  stub_request(:get, second_url).to_return(second_redirect).times(6).then.to_return(failure)
526
533
 
@@ -582,7 +589,7 @@ class JsonClientTest < MiniTest::Spec
582
589
 
583
590
  def test_put_json_does_put_with_json_encoded_packet
584
591
  url = "http://some.endpoint/some.json"
585
- payload = {a: 1}
592
+ payload = { a: 1 }
586
593
  stub_request(:put, url).with(body: payload.to_json).to_return(body: "{}", status: 200)
587
594
  assert_equal({}, @client.put_json(url, payload).to_hash)
588
595
  end
@@ -597,7 +604,7 @@ class JsonClientTest < MiniTest::Spec
597
604
  url = "http://some.endpoint/some.json"
598
605
  stub_request(:get, url).to_return(body: "Hello there!")
599
606
 
600
- response = @client.get_json(url) { |http_response| http_response.body }
607
+ response = @client.get_json(url, &:body)
601
608
  assert response.is_a? String
602
609
  assert_equal "Hello there!", response
603
610
  end
@@ -615,7 +622,7 @@ class JsonClientTest < MiniTest::Spec
615
622
  url = "http://some.endpoint/some.json"
616
623
  stub_request(:get, url).to_return(body: "Hello there!")
617
624
 
618
- response = @client.get_json!(url) { |http_response| http_response.body }
625
+ response = @client.get_json(url, &:body)
619
626
  assert response.is_a? String
620
627
  assert_equal "Hello there!", response
621
628
  end
@@ -637,7 +644,7 @@ class JsonClientTest < MiniTest::Spec
637
644
  end
638
645
 
639
646
  def test_client_can_use_basic_auth
640
- client = GdsApi::JsonClient.new(basic_auth: {user: 'user', password: 'password'})
647
+ client = GdsApi::JsonClient.new(basic_auth: { user: 'user', password: 'password' })
641
648
 
642
649
  stub_request(:put, "http://user:password@some.endpoint/some.json").
643
650
  to_return(body: '{"a":1}', status: 200)
@@ -662,11 +669,11 @@ class JsonClientTest < MiniTest::Spec
662
669
  def test_client_can_set_custom_headers_on_gets
663
670
  stub_request(:get, "http://some.other.endpoint/some.json").to_return(status: 200)
664
671
 
665
- response = GdsApi::JsonClient.new.get_json("http://some.other.endpoint/some.json",
666
- { "HEADER-A" => "B", "HEADER-C" => "D" })
672
+ GdsApi::JsonClient.new.get_json("http://some.other.endpoint/some.json",
673
+ "HEADER-A" => "B", "HEADER-C" => "D")
667
674
 
668
675
  assert_requested(:get, %r{/some.json}) do |request|
669
- headers_with_uppercase_names = Hash[request.headers.collect {|key, value| [key.upcase, value] }]
676
+ headers_with_uppercase_names = Hash[request.headers.collect { |key, value| [key.upcase, value] }]
670
677
  headers_with_uppercase_names["HEADER-A"] == "B" && headers_with_uppercase_names["HEADER-C"] == "D"
671
678
  end
672
679
  end
@@ -674,11 +681,11 @@ class JsonClientTest < MiniTest::Spec
674
681
  def test_client_can_set_custom_headers_on_posts
675
682
  stub_request(:post, "http://some.other.endpoint/some.json").to_return(status: 200)
676
683
 
677
- response = GdsApi::JsonClient.new.post_json("http://some.other.endpoint/some.json", {},
678
- { "HEADER-A" => "B", "HEADER-C" => "D" })
684
+ GdsApi::JsonClient.new.post_json("http://some.other.endpoint/some.json", {},
685
+ "HEADER-A" => "B", "HEADER-C" => "D")
679
686
 
680
687
  assert_requested(:post, %r{/some.json}) do |request|
681
- headers_with_uppercase_names = Hash[request.headers.collect {|key, value| [key.upcase, value] }]
688
+ headers_with_uppercase_names = Hash[request.headers.collect { |key, value| [key.upcase, value] }]
682
689
  headers_with_uppercase_names["HEADER-A"] == "B" && headers_with_uppercase_names["HEADER-C"] == "D"
683
690
  end
684
691
  end
@@ -686,11 +693,11 @@ class JsonClientTest < MiniTest::Spec
686
693
  def test_client_can_set_custom_headers_on_puts
687
694
  stub_request(:put, "http://some.other.endpoint/some.json").to_return(status: 200)
688
695
 
689
- response = GdsApi::JsonClient.new.put_json("http://some.other.endpoint/some.json", {},
690
- { "HEADER-A" => "B", "HEADER-C" => "D" })
696
+ GdsApi::JsonClient.new.put_json("http://some.other.endpoint/some.json", {},
697
+ "HEADER-A" => "B", "HEADER-C" => "D")
691
698
 
692
699
  assert_requested(:put, %r{/some.json}) do |request|
693
- headers_with_uppercase_names = Hash[request.headers.collect {|key, value| [key.upcase, value] }]
700
+ headers_with_uppercase_names = Hash[request.headers.collect { |key, value| [key.upcase, value] }]
694
701
  headers_with_uppercase_names["HEADER-A"] == "B" && headers_with_uppercase_names["HEADER-C"] == "D"
695
702
  end
696
703
  end
@@ -698,11 +705,11 @@ class JsonClientTest < MiniTest::Spec
698
705
  def test_client_can_set_custom_headers_on_deletes
699
706
  stub_request(:delete, "http://some.other.endpoint/some.json").to_return(status: 200)
700
707
 
701
- response = GdsApi::JsonClient.new.delete_json("http://some.other.endpoint/some.json",
702
- { "HEADER-A" => "B", "HEADER-C" => "D" })
708
+ GdsApi::JsonClient.new.delete_json("http://some.other.endpoint/some.json",
709
+ "HEADER-A" => "B", "HEADER-C" => "D")
703
710
 
704
711
  assert_requested(:delete, %r{/some.json}) do |request|
705
- headers_with_uppercase_names = Hash[request.headers.collect {|key, value| [key.upcase, value] }]
712
+ headers_with_uppercase_names = Hash[request.headers.collect { |key, value| [key.upcase, value] }]
706
713
  headers_with_uppercase_names["HEADER-A"] == "B" && headers_with_uppercase_names["HEADER-C"] == "D"
707
714
  end
708
715
  end
@@ -718,7 +725,7 @@ class JsonClientTest < MiniTest::Spec
718
725
 
719
726
  assert_requested(:get, %r{/some.json}) do |request|
720
727
  request.headers['Govuk-Request-Id'] == '12345' &&
721
- request.headers['Govuk-Original-Url'] == 'http://example.com'
728
+ request.headers['Govuk-Original-Url'] == 'http://example.com'
722
729
  end
723
730
  end
724
731
 
@@ -764,7 +771,7 @@ class JsonClientTest < MiniTest::Spec
764
771
  }).
765
772
  to_return(body: '{"b": "1"}', status: 200)
766
773
 
767
- response = @client.post_multipart("http://some.endpoint/some.json", {"a" => "123"})
774
+ response = @client.post_multipart("http://some.endpoint/some.json", "a" => "123")
768
775
  assert_equal "1", response["b"]
769
776
  end
770
777
 
@@ -773,7 +780,7 @@ class JsonClientTest < MiniTest::Spec
773
780
  stub_request(:post, url).to_return(body: '', status: 404)
774
781
 
775
782
  assert_raises GdsApi::HTTPNotFound do
776
- @client.post_multipart("http://some.endpoint/some.json", {"a" => "123"})
783
+ @client.post_multipart("http://some.endpoint/some.json", "a" => "123")
777
784
  end
778
785
  end
779
786
 
@@ -782,7 +789,7 @@ class JsonClientTest < MiniTest::Spec
782
789
  stub_request(:post, url).to_return(body: '', status: 500)
783
790
 
784
791
  assert_raises GdsApi::HTTPServerError do
785
- @client.post_multipart("http://some.endpoint/some.json", {"a" => "123"})
792
+ @client.post_multipart("http://some.endpoint/some.json", "a" => "123")
786
793
  end
787
794
  end
788
795
 
@@ -796,7 +803,7 @@ class JsonClientTest < MiniTest::Spec
796
803
  }).
797
804
  to_return(body: '{"b": "1"}', status: 200)
798
805
 
799
- response = @client.put_multipart("http://some.endpoint/some.json", {"a" => "123"})
806
+ response = @client.put_multipart("http://some.endpoint/some.json", "a" => "123")
800
807
  assert_equal "1", response["b"]
801
808
  end
802
809
 
@@ -805,7 +812,7 @@ class JsonClientTest < MiniTest::Spec
805
812
  stub_request(:put, url).to_return(body: '', status: 404)
806
813
 
807
814
  assert_raises GdsApi::HTTPNotFound do
808
- @client.put_multipart("http://some.endpoint/some.json", {"a" => "123"})
815
+ @client.put_multipart("http://some.endpoint/some.json", "a" => "123")
809
816
  end
810
817
  end
811
818
 
@@ -814,16 +821,16 @@ class JsonClientTest < MiniTest::Spec
814
821
  stub_request(:put, url).to_return(body: '', status: 500)
815
822
 
816
823
  assert_raises GdsApi::HTTPServerError do
817
- @client.put_multipart("http://some.endpoint/some.json", {"a" => "123"})
824
+ @client.put_multipart("http://some.endpoint/some.json", "a" => "123")
818
825
  end
819
826
  end
820
827
 
821
828
  def test_should_raise_error_if_attempting_to_disable_timeout
822
829
  assert_raises RuntimeError do
823
- GdsApi::JsonClient.new(:disable_timeout => true)
830
+ GdsApi::JsonClient.new(disable_timeout: true)
824
831
  end
825
832
  assert_raises RuntimeError do
826
- GdsApi::JsonClient.new(:timeout => -1)
833
+ GdsApi::JsonClient.new(timeout: -1)
827
834
  end
828
835
  end
829
836
 
@@ -857,16 +864,16 @@ class JsonClientTest < MiniTest::Spec
857
864
  url = "http://some.endpoint/some.json"
858
865
  stub_request(:any, url)
859
866
 
860
- @client.get_json!(url)
867
+ @client.get_json(url)
861
868
  assert_requested(:get, url, headers: GdsApi::JsonClient.default_request_headers)
862
869
 
863
- @client.delete_json!(url)
870
+ @client.delete_json(url)
864
871
  assert_requested(:delete, url, headers: GdsApi::JsonClient.default_request_headers)
865
872
 
866
- @client.post_json!(url, test: "123")
873
+ @client.post_json(url, test: "123")
867
874
  assert_requested(:post, url, headers: GdsApi::JsonClient.default_request_with_json_body_headers)
868
875
 
869
- @client.put_json!(url, test: "123")
876
+ @client.put_json(url, test: "123")
870
877
  assert_requested(:put, url, headers: GdsApi::JsonClient.default_request_with_json_body_headers)
871
878
  end
872
879
  end