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
@@ -11,7 +11,8 @@ describe GdsApi::PublishingApiV2 do
11
11
  "content_id" => content_id,
12
12
  "title" => "Instructions for crawler robots",
13
13
  "description" => "robots.txt provides rules for which parts of GOV.UK are permitted to be crawled by different bots.",
14
- "format" => "special_route",
14
+ "schema_name" => "special_route",
15
+ "document_type" => "special_route",
15
16
  "public_updated_at" => "2015-07-30T13:58:11.000Z",
16
17
  "publishing_app" => "static",
17
18
  "rendering_app" => "static",
@@ -83,9 +84,9 @@ describe GdsApi::PublishingApiV2 do
83
84
  body: {
84
85
  "error" => {
85
86
  "code" => 422,
86
- "message" => Pact.term(generate: "Conflict", matcher:/\S+/),
87
+ "message" => Pact.term(generate: "Conflict", matcher: /\S+/),
87
88
  "fields" => {
88
- "base_path" => Pact.each_like("is already in use by the 'publisher' app", :min => 1),
89
+ "base_path" => Pact.each_like("is already in use by the 'publisher' app", min: 1),
89
90
  },
90
91
  },
91
92
  },
@@ -149,7 +150,6 @@ describe GdsApi::PublishingApiV2 do
149
150
  "details" => { "body" => [] },
150
151
  "previous_version" => "3"
151
152
  )
152
- @content_item.delete("format")
153
153
 
154
154
  publishing_api
155
155
  .given("the content item #{@content_id} is at version 3")
@@ -182,7 +182,6 @@ describe GdsApi::PublishingApiV2 do
182
182
  "details" => { "body" => [] },
183
183
  "previous_version" => "2"
184
184
  )
185
- @content_item.delete("format")
186
185
 
187
186
  publishing_api
188
187
  .given("the content item #{@content_id} is at version 3")
@@ -200,9 +199,9 @@ describe GdsApi::PublishingApiV2 do
200
199
  body: {
201
200
  "error" => {
202
201
  "code" => 409,
203
- "message" => Pact.term(generate: "Conflict", matcher:/\S+/),
202
+ "message" => Pact.term(generate: "Conflict", matcher: /\S+/),
204
203
  "fields" => {
205
- "previous_version" => Pact.each_like("does not match", :min => 1),
204
+ "previous_version" => Pact.each_like("does not match", min: 1),
206
205
  },
207
206
  },
208
207
  },
@@ -260,7 +259,7 @@ describe GdsApi::PublishingApiV2 do
260
259
  it "responds with 200 and the content item" do
261
260
  response = @api_client.get_content(@content_id)
262
261
  assert_equal 200, response.code
263
- assert_equal @content_item["format"], response["document_type"]
262
+ assert_equal @content_item["document_type"], response["document_type"]
264
263
  end
265
264
  end
266
265
 
@@ -365,7 +364,7 @@ describe GdsApi::PublishingApiV2 do
365
364
  .will_respond_with(
366
365
  status: 200,
367
366
  body: {
368
- "warnings" => Pact.like({"content_item_blocking_publish" => "message"}),
367
+ "warnings" => Pact.like("content_item_blocking_publish" => "message"),
369
368
  "content_id" => @content_id,
370
369
  "document_type" => Pact.like("special_route"),
371
370
  "schema_name" => Pact.like("special_route"),
@@ -388,7 +387,6 @@ describe GdsApi::PublishingApiV2 do
388
387
  assert_equal 200, response.code
389
388
  assert_equal hash_including("content_item_blocking_publish"), response["warnings"]
390
389
  end
391
-
392
390
  end
393
391
 
394
392
  describe "when requesting the published version" do
@@ -492,7 +490,7 @@ describe GdsApi::PublishingApiV2 do
492
490
  body: {
493
491
  "error" => {
494
492
  "code" => 404,
495
- "message" => Pact.term(generate: "not found", matcher:/\S+/)
493
+ "message" => Pact.term(generate: "not found", matcher: /\S+/)
496
494
  },
497
495
  },
498
496
  headers: {
@@ -585,9 +583,9 @@ describe GdsApi::PublishingApiV2 do
585
583
  body: {
586
584
  "error" => {
587
585
  "code" => 422,
588
- "message" => Pact.term(generate: "Unprocessable entity", matcher:/\S+/),
586
+ "message" => Pact.term(generate: "Unprocessable entity", matcher: /\S+/),
589
587
  "fields" => {
590
- "update_type" => Pact.each_like("is required", :min => 1),
588
+ "update_type" => Pact.each_like("is required", min: 1),
591
589
  },
592
590
  },
593
591
  }
@@ -623,7 +621,7 @@ describe GdsApi::PublishingApiV2 do
623
621
  status: 400,
624
622
  body: {
625
623
  "error" => {
626
- "code" => 400, "message" => Pact.term(generate: "Cannot publish an already published content item", matcher:/\S+/),
624
+ "code" => 400, "message" => Pact.term(generate: "Cannot publish an already published content item", matcher: /\S+/),
627
625
  },
628
626
  }
629
627
  )
@@ -715,9 +713,9 @@ describe GdsApi::PublishingApiV2 do
715
713
  body: {
716
714
  "error" => {
717
715
  "code" => 409,
718
- "message" => Pact.term(generate: "Conflict", matcher:/\S+/),
716
+ "message" => Pact.term(generate: "Conflict", matcher: /\S+/),
719
717
  "fields" => {
720
- "previous_version" => Pact.each_like("does not match", :min => 1),
718
+ "previous_version" => Pact.each_like("does not match", min: 1),
721
719
  },
722
720
  },
723
721
  },
@@ -814,7 +812,7 @@ describe GdsApi::PublishingApiV2 do
814
812
  body: {
815
813
  "error" => {
816
814
  "code" => 422,
817
- "message" => Pact.term(generate: "not-a-valid-type is not a valid unpublishing type", matcher:/\S+/),
815
+ "message" => Pact.term(generate: "not-a-valid-type is not a valid unpublishing type", matcher: /\S+/),
818
816
  "fields" => {},
819
817
  },
820
818
  }
@@ -906,9 +904,9 @@ describe GdsApi::PublishingApiV2 do
906
904
  body: {
907
905
  "error" => {
908
906
  "code" => 409,
909
- "message" => Pact.term(generate: "Conflict", matcher:/\S+/),
907
+ "message" => Pact.term(generate: "Conflict", matcher: /\S+/),
910
908
  "fields" => {
911
- "previous_version" => Pact.each_like("does not match", :min => 1),
909
+ "previous_version" => Pact.each_like("does not match", min: 1),
912
910
  },
913
911
  },
914
912
  },
@@ -1149,9 +1147,9 @@ describe GdsApi::PublishingApiV2 do
1149
1147
  body: {
1150
1148
  "error" => {
1151
1149
  "code" => 409,
1152
- "message" => Pact.term(generate: "Conflict", matcher:/\S+/),
1150
+ "message" => Pact.term(generate: "Conflict", matcher: /\S+/),
1153
1151
  "fields" => {
1154
- "previous_version" => Pact.each_like("does not match", :min => 1),
1152
+ "previous_version" => Pact.each_like("does not match", min: 1),
1155
1153
  },
1156
1154
  },
1157
1155
  },
@@ -1200,7 +1198,7 @@ describe GdsApi::PublishingApiV2 do
1200
1198
 
1201
1199
  it "returns the content items of a given document_type" do
1202
1200
  publishing_api
1203
- .given("there is content with format 'topic'")
1201
+ .given("there is content with document_type 'topic'")
1204
1202
  .upon_receiving("a get linkables request")
1205
1203
  .with(
1206
1204
  method: :get,
@@ -1218,18 +1216,13 @@ describe GdsApi::PublishingApiV2 do
1218
1216
  response = @api_client.get_linkables(document_type: "topic")
1219
1217
  assert_equal 200, response.code
1220
1218
  assert_equal linkables, response.to_a
1221
-
1222
- # `format` is supported but deprecated for backwards compatibility
1223
- response = @api_client.get_linkables(format: "topic")
1224
- assert_equal 200, response.code
1225
- assert_equal linkables, response.to_a
1226
1219
  end
1227
1220
  end
1228
1221
 
1229
1222
  describe "#get_content_items" do
1230
- it "returns the content items of a certain format" do
1223
+ it "returns the content items of a certain document_type" do
1231
1224
  publishing_api
1232
- .given("there is content with format 'topic'")
1225
+ .given("there is content with document_type 'topic'")
1233
1226
  .upon_receiving("a get entries request")
1234
1227
  .with(
1235
1228
  method: :get,
@@ -1267,10 +1260,9 @@ describe GdsApi::PublishingApiV2 do
1267
1260
  ["total", 2],
1268
1261
  ["pages", 1],
1269
1262
  ["current_page", 1],
1270
- ["links", [{"href"=>"http://example.org/v2/content?document_type=topic&fields[]=title&fields[]=base_path&page=1", "rel"=>"self"}]],
1271
- ["results", [{"title"=>"Content Item A", "base_path"=>"/a-base-path"}, {"title"=>"Content Item B", "base_path"=>"/another-base-path"}]]
1263
+ ["links", [{ "href" => "http://example.org/v2/content?document_type=topic&fields[]=title&fields[]=base_path&page=1", "rel" => "self" }]],
1264
+ ["results", [{ "title" => "Content Item A", "base_path" => "/a-base-path" }, { "title" => "Content Item B", "base_path" => "/another-base-path" }]]
1272
1265
  ], response.to_a
1273
-
1274
1266
  end
1275
1267
 
1276
1268
  it "returns the content items in english locale by default" do
@@ -1312,8 +1304,8 @@ describe GdsApi::PublishingApiV2 do
1312
1304
  ["total", 1],
1313
1305
  ["pages", 1],
1314
1306
  ["current_page", 1],
1315
- ["links", [{"href"=>"http://example.org/v2/content?document_type=topic&fields[]=content_id&fields[]=locale&page=1", "rel"=>"self"}]],
1316
- ["results", [{"content_id"=>"bed722e6-db68-43e5-9079-063f623335a7", "locale"=>"en"}]]
1307
+ ["links", [{ "href" => "http://example.org/v2/content?document_type=topic&fields[]=content_id&fields[]=locale&page=1", "rel" => "self" }]],
1308
+ ["results", [{ "content_id" => "bed722e6-db68-43e5-9079-063f623335a7", "locale" => "en" }]]
1317
1309
  ], response.to_a
1318
1310
  end
1319
1311
 
@@ -1356,8 +1348,8 @@ describe GdsApi::PublishingApiV2 do
1356
1348
  ["total", 1],
1357
1349
  ["pages", 1],
1358
1350
  ["current_page", 1],
1359
- ["links", [{"href"=>"http://example.org/v2/content?document_type=topic&fields[]=content_id&fields[]=locale&locale=fr&page=1", "rel"=>"self"}]],
1360
- ["results", [{"content_id"=>"bed722e6-db68-43e5-9079-063f623335a7", "locale"=>"fr"}]]
1351
+ ["links", [{ "href" => "http://example.org/v2/content?document_type=topic&fields[]=content_id&fields[]=locale&locale=fr&page=1", "rel" => "self" }]],
1352
+ ["results", [{ "content_id" => "bed722e6-db68-43e5-9079-063f623335a7", "locale" => "fr" }]]
1361
1353
  ], response.to_a
1362
1354
  end
1363
1355
 
@@ -1402,11 +1394,11 @@ describe GdsApi::PublishingApiV2 do
1402
1394
  ["total", 3],
1403
1395
  ["pages", 1], ["current_page", 1],
1404
1396
  ["links",
1405
- [{"href"=>"http://example.org/v2/content?document_type=topic&fields[]=content_id&fields[]=locale&locale=all&page=1", "rel"=>"self"}]],
1397
+ [{ "href" => "http://example.org/v2/content?document_type=topic&fields[]=content_id&fields[]=locale&locale=all&page=1", "rel" => "self" }]],
1406
1398
  ["results",
1407
- [{"content_id"=>"bed722e6-db68-43e5-9079-063f623335a7", "locale"=>"en"},
1408
- {"content_id"=>"bed722e6-db68-43e5-9079-063f623335a7", "locale"=>"fr"},
1409
- {"content_id"=>"bed722e6-db68-43e5-9079-063f623335a7", "locale"=>"ar"}]]
1399
+ [{ "content_id" => "bed722e6-db68-43e5-9079-063f623335a7", "locale" => "en" },
1400
+ { "content_id" => "bed722e6-db68-43e5-9079-063f623335a7", "locale" => "fr" },
1401
+ { "content_id" => "bed722e6-db68-43e5-9079-063f623335a7", "locale" => "ar" }]]
1410
1402
  ], response.to_a
1411
1403
  end
1412
1404
 
@@ -1433,7 +1425,7 @@ describe GdsApi::PublishingApiV2 do
1433
1425
  rel: "self"
1434
1426
  }],
1435
1427
  results: [
1436
- { content_id: @content_id, details: {foo: :bar} }
1428
+ { content_id: @content_id, details: { foo: :bar } }
1437
1429
  ]
1438
1430
  }
1439
1431
  )
@@ -1449,8 +1441,8 @@ describe GdsApi::PublishingApiV2 do
1449
1441
  ["total", 1],
1450
1442
  ["pages", 1],
1451
1443
  ["current_page", 1],
1452
- ["links", [{"href"=>"http://example.org/v2/content?document_type=topic&fields[]=content_id&fields[]=details&page=1", "rel"=>"self"}]],
1453
- ["results", [{"content_id"=>"bed722e6-db68-43e5-9079-063f623335a7", "details"=>{"foo"=>"bar"}}]]
1444
+ ["links", [{ "href" => "http://example.org/v2/content?document_type=topic&fields[]=content_id&fields[]=details&page=1", "rel" => "self" }]],
1445
+ ["results", [{ "content_id" => "bed722e6-db68-43e5-9079-063f623335a7", "details" => { "foo" => "bar" } }]]
1454
1446
  ], response.to_a
1455
1447
  end
1456
1448
  end
@@ -1552,7 +1544,7 @@ describe GdsApi::PublishingApiV2 do
1552
1544
  body: {
1553
1545
  "error" => {
1554
1546
  "code" => 404,
1555
- "message" => Pact.term(generate: "not found", matcher:/\S+/)
1547
+ "message" => Pact.term(generate: "not found", matcher: /\S+/)
1556
1548
  },
1557
1549
  },
1558
1550
  headers: {
@@ -1581,12 +1573,12 @@ describe GdsApi::PublishingApiV2 do
1581
1573
  @linking_content_item1 = content_item_for_content_id(content_id3,
1582
1574
  "base_path" => "/item-b",
1583
1575
  "links" => {
1584
- "topic" => [ @linked_content_item['content_id1'] ]
1576
+ "topic" => [@linked_content_item['content_id1']]
1585
1577
  })
1586
1578
  @linking_content_item2 = content_item_for_content_id(content_id2,
1587
1579
  "base_path" => "/item-a",
1588
1580
  "links" => {
1589
- "topic" => [ @linked_content_item['content_id1'] ],
1581
+ "topic" => [@linked_content_item['content_id1']],
1590
1582
  })
1591
1583
 
1592
1584
  publishing_api
@@ -1618,10 +1610,8 @@ describe GdsApi::PublishingApiV2 do
1618
1610
  it "returns the requested fields of linking items" do
1619
1611
  response = @api_client.get_linked_items(
1620
1612
  @linked_content_item["content_id"],
1621
- {
1622
- link_type: "topic",
1623
- fields: ["content_id", "base_path"],
1624
- }
1613
+ link_type: "topic",
1614
+ fields: %w(content_id base_path)
1625
1615
  )
1626
1616
  assert_equal 200, response.code
1627
1617
 
@@ -2,10 +2,9 @@ require_relative 'test_helper'
2
2
  require 'gds_api/response'
3
3
 
4
4
  describe GdsApi::Response do
5
-
6
5
  describe "accessing HTTP response details" do
7
6
  before :each do
8
- @mock_http_response = stub(:body => "A Response body", :code => 200, :headers => {:cache_control => 'public'})
7
+ @mock_http_response = stub(body: "A Response body", code: 200, headers: { cache_control: 'public' })
9
8
  @response = GdsApi::Response.new(@mock_http_response)
10
9
  end
11
10
 
@@ -18,17 +17,17 @@ describe GdsApi::Response do
18
17
  end
19
18
 
20
19
  it "should pass-on the response headers" do
21
- assert_equal({:cache_control => 'public'}, @response.headers)
20
+ assert_equal({ cache_control: 'public' }, @response.headers)
22
21
  end
23
22
  end
24
23
 
25
24
  describe ".expires_at" do
26
25
  it "should be calculated from cache-control max-age" do
27
26
  Timecop.freeze(Time.parse("15:00")) do
28
- cache_control_headers = { :cache_control => 'public, max-age=900' }
27
+ cache_control_headers = { cache_control: 'public, max-age=900' }
29
28
  headers = cache_control_headers.merge(date: Time.now.httpdate)
30
29
 
31
- mock_http_response = stub(:body => "A Response body", :code => 200, :headers => headers)
30
+ mock_http_response = stub(body: "A Response body", code: 200, headers: headers)
32
31
  response = GdsApi::Response.new(mock_http_response)
33
32
 
34
33
  assert_equal Time.parse("15:15"), response.expires_at
@@ -37,10 +36,10 @@ describe GdsApi::Response do
37
36
 
38
37
  it "should be same as the value of Expires header in absence of max-age" do
39
38
  Timecop.freeze(Time.parse("15:00")) do
40
- cache_headers = { :cache_control => 'public', :expires => (Time.now + 900).httpdate }
39
+ cache_headers = { cache_control: 'public', expires: (Time.now + 900).httpdate }
41
40
  headers = cache_headers.merge(date: Time.now.httpdate)
42
41
 
43
- mock_http_response = stub(:body => "A Response body", :code => 200, :headers => headers)
42
+ mock_http_response = stub(body: "A Response body", code: 200, headers: headers)
44
43
  response = GdsApi::Response.new(mock_http_response)
45
44
 
46
45
  assert_equal Time.parse("15:15"), response.expires_at
@@ -48,14 +47,14 @@ describe GdsApi::Response do
48
47
  end
49
48
 
50
49
  it "should be nil in absence of Expires header and max-age" do
51
- mock_http_response = stub(:body => "A Response body", :code => 200, :headers => { :date => Time.now.httpdate })
50
+ mock_http_response = stub(body: "A Response body", code: 200, headers: { date: Time.now.httpdate })
52
51
  response = GdsApi::Response.new(mock_http_response)
53
52
 
54
53
  assert_nil response.expires_at
55
54
  end
56
55
 
57
56
  it "should be nil in absence of Date header and max-age" do
58
- mock_http_response = stub(:body => "A Response body", :code => 200, :headers => {})
57
+ mock_http_response = stub(body: "A Response body", code: 200, headers: {})
59
58
  response = GdsApi::Response.new(mock_http_response)
60
59
 
61
60
  assert_nil response.expires_at
@@ -64,9 +63,9 @@ describe GdsApi::Response do
64
63
 
65
64
  describe ".expires_in" do
66
65
  it "should be seconds remaining from expiration time inferred from max-age" do
67
- cache_control_headers = { :cache_control => 'public, max-age=900' }
66
+ cache_control_headers = { cache_control: 'public, max-age=900' }
68
67
  headers = cache_control_headers.merge(date: Time.now.httpdate)
69
- mock_http_response = stub(:body => "A Response body", :code => 200, :headers => headers)
68
+ mock_http_response = stub(body: "A Response body", code: 200, headers: headers)
70
69
 
71
70
  Timecop.travel(12 * 60) do
72
71
  response = GdsApi::Response.new(mock_http_response)
@@ -75,9 +74,9 @@ describe GdsApi::Response do
75
74
  end
76
75
 
77
76
  it "should be seconds remaining from expiration time inferred from Expires header" do
78
- cache_headers = { :cache_control => 'public', :expires => (Time.now + 900).httpdate }
77
+ cache_headers = { cache_control: 'public', expires: (Time.now + 900).httpdate }
79
78
  headers = cache_headers.merge(date: Time.now.httpdate)
80
- mock_http_response = stub(:body => "A Response body", :code => 200, :headers => headers)
79
+ mock_http_response = stub(body: "A Response body", code: 200, headers: headers)
81
80
 
82
81
  Timecop.travel(12 * 60) do
83
82
  response = GdsApi::Response.new(mock_http_response)
@@ -86,15 +85,15 @@ describe GdsApi::Response do
86
85
  end
87
86
 
88
87
  it "should be nil in absence of Expires header and max-age" do
89
- mock_http_response = stub(:body => "A Response body", :code => 200, :headers => { :date => Time.now.httpdate })
88
+ mock_http_response = stub(body: "A Response body", code: 200, headers: { date: Time.now.httpdate })
90
89
  response = GdsApi::Response.new(mock_http_response)
91
90
 
92
91
  assert_nil response.expires_in
93
92
  end
94
93
 
95
94
  it "should be nil in absence of Date header" do
96
- cache_control_headers = { :cache_control => 'public, max-age=900' }
97
- mock_http_response = stub(:body => "A Response body", :code => 200, :headers => cache_control_headers)
95
+ cache_control_headers = { cache_control: 'public, max-age=900' }
96
+ mock_http_response = stub(body: "A Response body", code: 200, headers: cache_control_headers)
98
97
  response = GdsApi::Response.new(mock_http_response)
99
98
 
100
99
  assert_nil response.expires_in
@@ -103,7 +102,7 @@ describe GdsApi::Response do
103
102
 
104
103
  describe "processing web_urls" do
105
104
  def build_response(body_string, relative_to = "https://www.gov.uk")
106
- GdsApi::Response.new(stub(:body => body_string), :web_urls_relative_to => relative_to)
105
+ GdsApi::Response.new(stub(body: body_string), web_urls_relative_to: relative_to)
107
106
  end
108
107
 
109
108
  it "should map web URLs" do
@@ -149,7 +148,7 @@ describe GdsApi::Response do
149
148
  end
150
149
 
151
150
  it "should handle nil values" do
152
- body = {"web_url" => nil}.to_json
151
+ body = { "web_url" => nil }.to_json
153
152
 
154
153
  response = build_response(body)
155
154
  assert_nil response['web_url']
@@ -210,12 +209,12 @@ describe GdsApi::Response do
210
209
  "language" => "en",
211
210
  },
212
211
  "tags" => [
213
- {"slug" => "foo"},
214
- {"slug" => "bar"},
215
- {"slug" => "baz"},
212
+ { "slug" => "foo" },
213
+ { "slug" => "bar" },
214
+ { "slug" => "baz" },
216
215
  ],
217
216
  }
218
- @response = GdsApi::Response.new(stub(:body => @response_data.to_json))
217
+ @response = GdsApi::Response.new(stub(body: @response_data.to_json))
219
218
  end
220
219
 
221
220
  describe "behaving like a read-only hash" do
data/test/router_test.rb CHANGED
@@ -2,7 +2,6 @@ require 'test_helper'
2
2
  require 'gds_api/router'
3
3
 
4
4
  describe GdsApi::Router do
5
-
6
5
  before do
7
6
  @base_api_url = "http://router-api.example.com"
8
7
  @api = GdsApi::Router.new(@base_api_url)
@@ -12,8 +11,8 @@ describe GdsApi::Router do
12
11
  describe "fetching details about a backend" do
13
12
  it "should return backend details" do
14
13
  req = WebMock.stub_request(:get, "#{@base_api_url}/backends/foo").
15
- to_return(:body => {"backend_id" => "foo", "backend_url" => "http://foo.example.com/"}.to_json,
16
- :headers => {"Content-type" => "application/json"})
14
+ to_return(body: { "backend_id" => "foo", "backend_url" => "http://foo.example.com/" }.to_json,
15
+ headers: { "Content-type" => "application/json" })
17
16
 
18
17
  response = @api.get_backend("foo")
19
18
  assert_equal 200, response.code
@@ -24,7 +23,7 @@ describe GdsApi::Router do
24
23
 
25
24
  it "raises for a non-existend backend" do
26
25
  req = WebMock.stub_request(:get, "#{@base_api_url}/backends/foo").
27
- to_return(:status => 404)
26
+ to_return(status: 404)
28
27
 
29
28
  assert_raises(GdsApi::HTTPNotFound) do
30
29
  @api.get_backend("foo")
@@ -35,7 +34,7 @@ describe GdsApi::Router do
35
34
 
36
35
  it "should URI escape the given ID" do
37
36
  req = WebMock.stub_request(:get, "#{@base_api_url}/backends/foo+bar").
38
- to_return(:status => 404)
37
+ to_return(status: 404)
39
38
 
40
39
  assert_raises(GdsApi::HTTPNotFound) do
41
40
  @api.get_backend("foo bar")
@@ -48,9 +47,9 @@ describe GdsApi::Router do
48
47
  describe "creating/updating a backend" do
49
48
  it "should allow creating/updating a backend" do
50
49
  req = WebMock.stub_request(:put, "#{@base_api_url}/backends/foo").
51
- with(:body => {"backend" => {"backend_url" => "http://foo.example.com/"}}.to_json).
52
- to_return(:status => 201, :body => {"backend_id" => "foo", "backend_url" => "http://foo.example.com/"}.to_json,
53
- :headers => {"Content-type" => "application/json"})
50
+ with(body: { "backend" => { "backend_url" => "http://foo.example.com/" } }.to_json).
51
+ to_return(status: 201, body: { "backend_id" => "foo", "backend_url" => "http://foo.example.com/" }.to_json,
52
+ headers: { "Content-type" => "application/json" })
54
53
 
55
54
  response = @api.add_backend("foo", "http://foo.example.com/")
56
55
  assert_equal 201, response.code
@@ -60,10 +59,10 @@ describe GdsApi::Router do
60
59
  end
61
60
 
62
61
  it "should raise an error if creating/updating a backend fails" do
63
- response_data = {"backend_id" => "foo", "backend_url" => "ftp://foo.example.com/", "errors" => {"backend_url" => "is not an HTTP URL"}}
62
+ response_data = { "backend_id" => "foo", "backend_url" => "ftp://foo.example.com/", "errors" => { "backend_url" => "is not an HTTP URL" } }
64
63
  req = WebMock.stub_request(:put, "#{@base_api_url}/backends/foo").
65
- with(:body => {"backend" => {"backend_url" => "http://foo.example.com/"}}.to_json).
66
- to_return(:status => 400, :body => response_data.to_json, :headers => {"Content-type" => "application/json"})
64
+ with(body: { "backend" => { "backend_url" => "http://foo.example.com/" } }.to_json).
65
+ to_return(status: 400, body: response_data.to_json, headers: { "Content-type" => "application/json" })
67
66
 
68
67
  e = nil
69
68
  begin
@@ -81,13 +80,14 @@ describe GdsApi::Router do
81
80
 
82
81
  it "should URI escape the passed id" do
83
82
  req = WebMock.stub_request(:put, "#{@base_api_url}/backends/foo+bar").
84
- with(:body => {"backend" => {"backend_url" => "http://foo.example.com/"}}.to_json).
85
- to_return(:status => 404, :body => "Not found")
83
+ with(body: { "backend" => { "backend_url" => "http://foo.example.com/" } }.to_json).
84
+ to_return(status: 404, body: "Not found")
86
85
 
87
86
  # We expect a GdsApi::HTTPErrorResponse, but we want to ensure nothing else is raised
88
87
  begin
89
88
  @api.add_backend("foo bar", "http://foo.example.com/")
90
89
  rescue GdsApi::HTTPErrorResponse
90
+ nil
91
91
  end
92
92
 
93
93
  assert_requested(req)
@@ -97,8 +97,8 @@ describe GdsApi::Router do
97
97
  describe "deleting a backend" do
98
98
  it "allow deleting a backend" do
99
99
  req = WebMock.stub_request(:delete, "#{@base_api_url}/backends/foo").
100
- to_return(:status => 200, :body => {"backend_id" => "foo", "backend_url" => "http://foo.example.com/"}.to_json,
101
- :headers => {"Content-type" => "application/json"})
100
+ to_return(status: 200, body: { "backend_id" => "foo", "backend_url" => "http://foo.example.com/" }.to_json,
101
+ headers: { "Content-type" => "application/json" })
102
102
 
103
103
  response = @api.delete_backend("foo")
104
104
  assert_equal 200, response.code
@@ -108,9 +108,9 @@ describe GdsApi::Router do
108
108
  end
109
109
 
110
110
  it "should raise an error if deleting the backend fails" do
111
- response_data = {"backend_id" => "foo", "backend_url" => "ftp://foo.example.com/", "errors" => {"base" => "Backend has routes - can't delete"}}
111
+ response_data = { "backend_id" => "foo", "backend_url" => "ftp://foo.example.com/", "errors" => { "base" => "Backend has routes - can't delete" } }
112
112
  req = WebMock.stub_request(:delete, "#{@base_api_url}/backends/foo").
113
- to_return(:status => 400, :body => response_data.to_json, :headers => {"Content-type" => "application/json"})
113
+ to_return(status: 400, body: response_data.to_json, headers: { "Content-type" => "application/json" })
114
114
 
115
115
  e = nil
116
116
  begin
@@ -128,12 +128,11 @@ describe GdsApi::Router do
128
128
 
129
129
  it "should URI escape the passed id" do
130
130
  req = WebMock.stub_request(:delete, "#{@base_api_url}/backends/foo+bar").
131
- to_return(:status => 404, :body => "Not found")
131
+ to_return(status: 404, body: "Not found")
132
132
 
133
133
  # We expect a GdsApi::HTTPErrorResponse, but we want to ensure nothing else is raised
134
- begin
134
+ assert_raises GdsApi::HTTPErrorResponse do
135
135
  @api.delete_backend("foo bar")
136
- rescue GdsApi::HTTPErrorResponse
137
136
  end
138
137
 
139
138
  assert_requested(req)
@@ -144,15 +143,15 @@ describe GdsApi::Router do
144
143
  describe "managing routes" do
145
144
  before :each do
146
145
  @commit_req = WebMock.stub_request(:post, "#{@base_api_url}/routes/commit").
147
- to_return(:status => 200, :body => "Routers updated")
146
+ to_return(status: 200, body: "Routers updated")
148
147
  end
149
148
 
150
149
  describe "fetching a route" do
151
150
  it "should return the route details" do
152
- route_data = {"incoming_path" => "/foo", "route_type" => "exact", "handler" => "backend", "backend_id" => "foo"}
151
+ route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "backend", "backend_id" => "foo" }
153
152
  req = WebMock.stub_request(:get, "#{@base_api_url}/routes").
154
- with(:query => {"incoming_path" => "/foo"}).
155
- to_return(:status => 200, :body => route_data.to_json, :headers => {"Content-type" => "application/json"})
153
+ with(query: { "incoming_path" => "/foo" }).
154
+ to_return(status: 200, body: route_data.to_json, headers: { "Content-type" => "application/json" })
156
155
 
157
156
  response = @api.get_route("/foo")
158
157
  assert_equal 200, response.code
@@ -164,8 +163,8 @@ describe GdsApi::Router do
164
163
 
165
164
  it "should raise if nothing found" do
166
165
  req = WebMock.stub_request(:get, "#{@base_api_url}/routes").
167
- with(:query => {"incoming_path" => "/foo"}).
168
- to_return(:status => 404)
166
+ with(query: { "incoming_path" => "/foo" }).
167
+ to_return(status: 404)
169
168
 
170
169
  assert_raises(GdsApi::HTTPNotFound) do
171
170
  @api.get_route("/foo")
@@ -179,8 +178,8 @@ describe GdsApi::Router do
179
178
  # The WebMock query matcher matches unescaped params. The call blows up if they're not escaped
180
179
 
181
180
  req = WebMock.stub_request(:get, "#{@base_api_url}/routes").
182
- with(:query => {"incoming_path" => "/foo bar"}).
183
- to_return(:status => 404)
181
+ with(query: { "incoming_path" => "/foo bar" }).
182
+ to_return(status: 404)
184
183
 
185
184
  assert_raises(GdsApi::HTTPNotFound) do
186
185
  @api.get_route("/foo bar")
@@ -193,10 +192,10 @@ describe GdsApi::Router do
193
192
 
194
193
  describe "creating/updating a route" do
195
194
  it "should allow creating/updating a route" do
196
- route_data = {"incoming_path" => "/foo", "route_type" => "exact", "handler" => "backend", "backend_id" => "foo"}
195
+ route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "backend", "backend_id" => "foo" }
197
196
  req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
198
- with(:body => {"route" => route_data}.to_json).
199
- to_return(:status => 201, :body => route_data.to_json, :headers => {"Content-type" => "application/json"})
197
+ with(body: { "route" => route_data }.to_json).
198
+ to_return(status: 201, body: route_data.to_json, headers: { "Content-type" => "application/json" })
200
199
 
201
200
  response = @api.add_route("/foo", "exact", "foo")
202
201
  assert_equal 201, response.code
@@ -208,21 +207,21 @@ describe GdsApi::Router do
208
207
 
209
208
  it "should commit the routes when asked to" do
210
209
  req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
211
- to_return(:status => 201, :body => {}.to_json, :headers => {"Content-type" => "application/json"})
210
+ to_return(status: 201, body: {}.to_json, headers: { "Content-type" => "application/json" })
212
211
 
213
- @api.add_route("/foo", "exact", "foo", :commit => true)
212
+ @api.add_route("/foo", "exact", "foo", commit: true)
214
213
 
215
214
  assert_requested(req)
216
215
  assert_requested(@commit_req)
217
216
  end
218
217
 
219
218
  it "should raise an error if creating/updating the route fails" do
220
- route_data = {"incoming_path" => "/foo", "route_type" => "exact", "handler" => "backend", "backend_id" => "foo"}
221
- response_data = route_data.merge("errors" => {"backend_id" => "does not exist"})
219
+ route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "backend", "backend_id" => "foo" }
220
+ response_data = route_data.merge("errors" => { "backend_id" => "does not exist" })
222
221
 
223
222
  req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
224
- with(:body => {"route" => route_data}.to_json).
225
- to_return(:status => 400, :body => response_data.to_json, :headers => {"Content-type" => "application/json"})
223
+ with(body: { "route" => route_data }.to_json).
224
+ to_return(status: 400, body: response_data.to_json, headers: { "Content-type" => "application/json" })
226
225
 
227
226
  e = nil
228
227
  begin
@@ -242,11 +241,11 @@ describe GdsApi::Router do
242
241
 
243
242
  describe "creating/updating a redirect route" do
244
243
  it "should allow creating/updating a redirect route" do
245
- route_data = {"incoming_path" => "/foo", "route_type" => "exact", "handler" => "redirect",
246
- "redirect_to" => "/bar", "redirect_type" => "permanent", "segments_mode" => nil}
244
+ route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "redirect",
245
+ "redirect_to" => "/bar", "redirect_type" => "permanent", "segments_mode" => nil }
247
246
  req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
248
- with(:body => {"route" => route_data}.to_json).
249
- to_return(:status => 201, :body => route_data.to_json, :headers => {"Content-type" => "application/json"})
247
+ with(body: { "route" => route_data }.to_json).
248
+ to_return(status: 201, body: route_data.to_json, headers: { "Content-type" => "application/json" })
250
249
 
251
250
  response = @api.add_redirect_route("/foo", "exact", "/bar")
252
251
  assert_equal 201, response.code
@@ -257,11 +256,11 @@ describe GdsApi::Router do
257
256
  end
258
257
 
259
258
  it "should allow creating/updating a temporary redirect route" do
260
- route_data = {"incoming_path" => "/foo", "route_type" => "exact", "handler" => "redirect",
261
- "redirect_to" => "/bar", "redirect_type" => "temporary", "segments_mode" => nil}
259
+ route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "redirect",
260
+ "redirect_to" => "/bar", "redirect_type" => "temporary", "segments_mode" => nil }
262
261
  req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
263
- with(:body => {"route" => route_data}.to_json).
264
- to_return(:status => 201, :body => route_data.to_json, :headers => {"Content-type" => "application/json"})
262
+ with(body: { "route" => route_data }.to_json).
263
+ to_return(status: 201, body: route_data.to_json, headers: { "Content-type" => "application/json" })
265
264
 
266
265
  response = @api.add_redirect_route("/foo", "exact", "/bar", "temporary")
267
266
  assert_equal 201, response.code
@@ -272,13 +271,13 @@ describe GdsApi::Router do
272
271
  end
273
272
 
274
273
  it "should allow creating/updating a redirect route which preserves segments" do
275
- route_data = {"incoming_path" => "/foo", "route_type" => "exact", "handler" => "redirect",
276
- "redirect_to" => "/bar", "redirect_type" => "temporary", "segments_mode" => "preserve"}
274
+ route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "redirect",
275
+ "redirect_to" => "/bar", "redirect_type" => "temporary", "segments_mode" => "preserve" }
277
276
  req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
278
- with(:body => {"route" => route_data}.to_json).
279
- to_return(:status => 201, :body => route_data.to_json, :headers => {"Content-type" => "application/json"})
277
+ with(body: { "route" => route_data }.to_json).
278
+ to_return(status: 201, body: route_data.to_json, headers: { "Content-type" => "application/json" })
280
279
 
281
- response = @api.add_redirect_route("/foo", "exact", "/bar", "temporary", :segments_mode => "preserve")
280
+ response = @api.add_redirect_route("/foo", "exact", "/bar", "temporary", segments_mode: "preserve")
282
281
  assert_equal 201, response.code
283
282
  assert_equal "/bar", response['redirect_to']
284
283
 
@@ -288,22 +287,22 @@ describe GdsApi::Router do
288
287
 
289
288
  it "should commit the routes when asked to" do
290
289
  req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
291
- to_return(:status => 201, :body =>{}.to_json, :headers => {"Content-type" => "application/json"})
290
+ to_return(status: 201, body: {}.to_json, headers: { "Content-type" => "application/json" })
292
291
 
293
- @api.add_redirect_route("/foo", "exact", "/bar", "temporary", :commit => true)
292
+ @api.add_redirect_route("/foo", "exact", "/bar", "temporary", commit: true)
294
293
 
295
294
  assert_requested(req)
296
295
  assert_requested(@commit_req)
297
296
  end
298
297
 
299
298
  it "should raise an error if creating/updating the redirect route fails" do
300
- route_data = {"incoming_path" => "/foo", "route_type" => "exact", "handler" => "redirect",
301
- "redirect_to" => "bar", "redirect_type" => "permanent", "segments_mode" => nil}
302
- response_data = route_data.merge("errors" => {"redirect_to" => "is not a valid URL path"})
299
+ route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "redirect",
300
+ "redirect_to" => "bar", "redirect_type" => "permanent", "segments_mode" => nil }
301
+ response_data = route_data.merge("errors" => { "redirect_to" => "is not a valid URL path" })
303
302
 
304
303
  req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
305
- with(:body => {"route" => route_data}.to_json).
306
- to_return(:status => 400, :body => response_data.to_json, :headers => {"Content-type" => "application/json"})
304
+ with(body: { "route" => route_data }.to_json).
305
+ to_return(status: 400, body: response_data.to_json, headers: { "Content-type" => "application/json" })
307
306
 
308
307
  e = nil
309
308
  begin
@@ -323,10 +322,10 @@ describe GdsApi::Router do
323
322
 
324
323
  describe "#add_gone_route" do
325
324
  it "should allow creating/updating a gone route" do
326
- route_data = {"incoming_path" => "/foo", "route_type" => "exact", "handler" => "gone"}
325
+ route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "gone" }
327
326
  req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
328
- with(:body => {"route" => route_data}.to_json).
329
- to_return(:status => 201, :body => route_data.to_json, :headers => {"Content-type" => "application/json"})
327
+ with(body: { "route" => route_data }.to_json).
328
+ to_return(status: 201, body: route_data.to_json, headers: { "Content-type" => "application/json" })
330
329
 
331
330
  response = @api.add_gone_route("/foo", "exact")
332
331
  assert_equal 201, response.code
@@ -338,21 +337,21 @@ describe GdsApi::Router do
338
337
 
339
338
  it "should commit the routes when asked to" do
340
339
  req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
341
- to_return(:status => 201, :body =>{}.to_json, :headers => {"Content-type" => "application/json"})
340
+ to_return(status: 201, body: {}.to_json, headers: { "Content-type" => "application/json" })
342
341
 
343
- @api.add_gone_route("/foo", "exact", :commit => true)
342
+ @api.add_gone_route("/foo", "exact", commit: true)
344
343
 
345
344
  assert_requested(req)
346
345
  assert_requested(@commit_req)
347
346
  end
348
347
 
349
348
  it "should raise an error if creating/updating the gone route fails" do
350
- route_data = {"incoming_path" => "foo", "route_type" => "exact", "handler" => "gone"}
351
- response_data = route_data.merge("errors" => {"incoming_path" => "is not a valid URL path"})
349
+ route_data = { "incoming_path" => "foo", "route_type" => "exact", "handler" => "gone" }
350
+ response_data = route_data.merge("errors" => { "incoming_path" => "is not a valid URL path" })
352
351
 
353
352
  req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
354
- with(:body => {"route" => route_data}.to_json).
355
- to_return(:status => 400, :body => response_data.to_json, :headers => {"Content-type" => "application/json"})
353
+ with(body: { "route" => route_data }.to_json).
354
+ to_return(status: 400, body: response_data.to_json, headers: { "Content-type" => "application/json" })
356
355
 
357
356
  e = nil
358
357
  begin
@@ -372,10 +371,10 @@ describe GdsApi::Router do
372
371
 
373
372
  describe "deleting a route" do
374
373
  it "should allow deleting a route" do
375
- route_data = {"incoming_path" => "/foo", "route_type" => "exact", "handler" => "backend", "backend_id" => "foo"}
374
+ route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "backend", "backend_id" => "foo" }
376
375
  req = WebMock.stub_request(:delete, "#{@base_api_url}/routes").
377
- with(:query => {"incoming_path" => "/foo"}).
378
- to_return(:status => 200, :body => route_data.to_json, :headers => {"Content-type" => "application/json"})
376
+ with(query: { "incoming_path" => "/foo" }).
377
+ to_return(status: 200, body: route_data.to_json, headers: { "Content-type" => "application/json" })
379
378
 
380
379
  response = @api.delete_route("/foo")
381
380
  assert_equal 200, response.code
@@ -387,10 +386,10 @@ describe GdsApi::Router do
387
386
 
388
387
  it "should commit the routes when asked to" do
389
388
  req = WebMock.stub_request(:delete, "#{@base_api_url}/routes").
390
- with(:query => {"incoming_path" => "/foo"}).
391
- to_return(:status => 200, :body => {}.to_json, :headers => {"Content-type" => "application/json"})
389
+ with(query: { "incoming_path" => "/foo" }).
390
+ to_return(status: 200, body: {}.to_json, headers: { "Content-type" => "application/json" })
392
391
 
393
- @api.delete_route("/foo", :commit => true)
392
+ @api.delete_route("/foo", commit: true)
394
393
 
395
394
  assert_requested(req)
396
395
  assert_requested(@commit_req)
@@ -398,8 +397,8 @@ describe GdsApi::Router do
398
397
 
399
398
  it "should raise HTTPNotFound if nothing found" do
400
399
  req = WebMock.stub_request(:delete, "#{@base_api_url}/routes").
401
- with(:query => {"incoming_path" => "/foo"}).
402
- to_return(:status => 404)
400
+ with(query: { "incoming_path" => "/foo" }).
401
+ to_return(status: 404)
403
402
 
404
403
  e = nil
405
404
  begin
@@ -419,12 +418,11 @@ describe GdsApi::Router do
419
418
  # The WebMock query matcher matches unescaped params. The call blows up if they're not escaped
420
419
 
421
420
  req = WebMock.stub_request(:delete, "#{@base_api_url}/routes").
422
- with(:query => {"incoming_path" => "/foo bar"}).
423
- to_return(:status => 404)
421
+ with(query: { "incoming_path" => "/foo bar" }).
422
+ to_return(status: 404)
424
423
 
425
- begin
424
+ assert_raises GdsApi::HTTPNotFound do
426
425
  @api.delete_route("/foo bar")
427
- rescue GdsApi::HTTPNotFound
428
426
  end
429
427
 
430
428
  assert_requested(req)
@@ -439,8 +437,8 @@ describe GdsApi::Router do
439
437
  end
440
438
 
441
439
  it "should raise an error if committing the routes fails" do
442
- req = WebMock.stub_request(:post, "#{@base_api_url}/routes/commit").
443
- to_return(:status => 500, :body => "Failed to update all routers")
440
+ WebMock.stub_request(:post, "#{@base_api_url}/routes/commit").
441
+ to_return(status: 500, body: "Failed to update all routers")
444
442
 
445
443
  e = nil
446
444
  begin