gds-api-adapters 36.4.1 → 37.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06df600e92d5e29ebcc9d2d1011169f25ed806d3
4
- data.tar.gz: 61a8846b1ce2833f1c72124435c154f5246439e5
3
+ metadata.gz: 80e428cbf9fbbf1cc956c99fdab6135b912b0eb7
4
+ data.tar.gz: 2f3522bb16213e2fa76e8fad6786b65f1c4150f7
5
5
  SHA512:
6
- metadata.gz: 66e7c5af97fc0c0f6766be3b134757b96b3e448b231f4898d284d7b53b49bed2521903c7a9621e27bfde9c657bee2febc3b3ab38ad469901cde1f469d5fee6b9
7
- data.tar.gz: 972920cf66478a2134769bcb57958dd70ea58278162d40671940c0c0604552cddc620b33f7293ed295a51cd11fae9896c4a1bb7cb15ff52bca945dac51a0f9fe
6
+ metadata.gz: ba103489e0af11e87a3c3712043a27fd192e96f7242faa40b0e1e85a109337ea26e4ed08ed3ae1e3a474490c975063db7f91251e213d480c09fc14a1d1c959b5
7
+ data.tar.gz: aa8e0fe34d8960d43bb68bd4facb7208459c64545be952414d945f0b35c2eaa20a38fb5376b0725efa422170ed442ccb3eefb8d1e21d745a7970c00c5d392747
data/README.md CHANGED
@@ -18,19 +18,14 @@ Example adapters for frequently used applications:
18
18
 
19
19
  ## Configuration
20
20
 
21
- We're currently deprecating some behaviour of this gem. You can opt-in to the
22
- new behaviour now by adding configuration like this:
21
+ From December 1st, 2016 it won't be possible to use the following configuration
22
+ options:
23
23
 
24
- ```ruby
25
- # config/initializers/gds_api_adapters.rb
26
- GdsApi.configure do |config|
27
- # Never return nil when a server responds with 404 or 410.
28
- config.always_raise_for_not_found = true
29
-
30
- # Return a hash, not an OpenStruct from a request.
31
- config.hash_response_for_requests = true
32
- end
33
- ```
24
+ - `always_raise_for_not_found`
25
+ - `hash_response_for_requests`
26
+
27
+ Please remove these configuration options from your client application and
28
+ migrate to the new behaviour as soon as possible.
34
29
 
35
30
  ## Logging
36
31
 
data/Rakefile CHANGED
@@ -36,6 +36,11 @@ PactBroker::Client::PublicationTask.new("released_version") do | task |
36
36
  configure_pact_broker_location(task)
37
37
  end
38
38
 
39
+ desc "Run the linter against changed files"
40
+ task :lint do
41
+ sh "bundle exec govuk-lint-ruby --diff --cached --format clang"
42
+ end
43
+
39
44
  require "gem_publisher"
40
45
  desc "Publish gem to rubygems.org if necessary"
41
46
  task :publish_gem do |t|
@@ -31,8 +31,8 @@ class GdsApi::AssetManager < GdsApi::Base
31
31
  #
32
32
  # @example Upload a file from disk
33
33
  # response = asset_manager.create_asset(file: File.new('image.jpg', 'r'))
34
- # response.id #=> "http://asset-manager.dev.gov.uk/assets/576bbc52759b74196b000012"
35
- # response.content_type #=> "image/jpeg"
34
+ # response['id'] #=> "http://asset-manager.dev.gov.uk/assets/576bbc52759b74196b000012"
35
+ # response['content_type'] #=> "image/jpeg"
36
36
  # @example Upload a file from a Rails param, (typically a multipart wrapper)
37
37
  # params[:file] #=> #<ActionDispatch::Http::UploadedFile:0x007fc60b43c5c8
38
38
  # # @content_type="application/foofle",
@@ -42,7 +42,7 @@ class GdsApi::AssetManager < GdsApi::Base
42
42
  # # Though we sent a file with a +content_type+ of 'application/foofle',
43
43
  # # this was ignored
44
44
  # response = asset_manager.create_asset(file: params[:file])
45
- # response.content_type #=> "image/jpeg"
45
+ # response['content_type'] #=> "image/jpeg"
46
46
  def create_asset(asset)
47
47
  post_multipart("#{base_url}/assets", { :asset => asset })
48
48
  end
@@ -8,22 +8,69 @@ module GdsApi
8
8
  end
9
9
 
10
10
  class Config
11
- # Always raise a `HTTPNotFound` exception when the server returns 404 or
12
- # 410. This avoids nil-errors in your code and makes debugging easier.
11
+ # Always raise an `HTTPNotFound` exception when the server returns 404 or an
12
+ # `HTTPGone` when the server returns 410. This avoids nil-errors in your
13
+ # code and makes debugging easier.
13
14
  #
14
- # Currently defaults to false.
15
+ # Currently defaults to true.
15
16
  #
16
- # This configuration allows some time to upgrade - you should opt-in to this
17
- # behaviour now. We'll change this to default to true on October 1st, 2016
18
- # and remove the option entirely on December 1st, 2016.
19
- attr_accessor :always_raise_for_not_found
17
+ # This configuration will be removed on December 1st, 2016. Please make sure
18
+ # you upgrade gds-api-adapters to the latest version and avoid configuring
19
+ # it on your client application.
20
+ def always_raise_for_not_found
21
+ return true if @always_raise_for_not_found.nil?
22
+
23
+ @always_raise_for_not_found
24
+ end
25
+
26
+ def always_raise_for_not_found=(value)
27
+ warn <<-doc
28
+
29
+ DEPRECATION NOTICE: Please delete any instances of
30
+ `GdsApi.config.always_raise_for_not_found=` from your codebase to make
31
+ sure all 404 or 410 responses raise an exception.
32
+
33
+ This configuration option will be be removed. Raising exceptions is now
34
+ the default behaviour and it won't be possible to opt-out from December
35
+ 1st, 2016.
36
+
37
+ Called from: #{caller[2]}
38
+
39
+ doc
40
+
41
+ @always_raise_for_not_found = value
42
+ end
20
43
 
21
44
  # Set to true to make `GdsApi::Response` behave like a simple hash, instead
22
45
  # of an OpenStruct. This will prevent nil-errors.
23
46
  #
24
- # This configuration allows some time to upgrade - you should opt-in to this
25
- # behaviour now. We'll change this to default to true on October 1st, 2016
26
- # and remove the option entirely on December 1st, 2016.
27
- attr_accessor :hash_response_for_requests
47
+ # Currently defaults to true.
48
+ #
49
+ # This configuration will be removed on December 1st, 2016. Please make sure
50
+ # you upgrade gds-api-adapters to the latest version and avoid configuring
51
+ # it on your client application.
52
+ def hash_response_for_requests
53
+ return true if @hash_response_for_requests.nil?
54
+
55
+ @hash_response_for_requests
56
+ end
57
+
58
+ def hash_response_for_requests=(value)
59
+ warn <<-doc
60
+
61
+ DEPRECATION NOTICE: Please delete any instances of
62
+ `GdsApi.config.hash_response_for_requests=` from your codebase to make
63
+ sure responses behave like a Hash instead of an OpenStruct.
64
+
65
+ This configuration option will be be removed. Returning responses that
66
+ behave like a Hash is the default behaviour and it won't be possible to
67
+ opt-out from December 1st, 2016.
68
+
69
+ Called from: #{caller[2]}
70
+
71
+ doc
72
+
73
+ @hash_response_for_requests = value
74
+ end
28
75
  end
29
76
  end
@@ -22,7 +22,7 @@ class GdsApi::GovUkDelivery < GdsApi::Base
22
22
 
23
23
  def signup_url(feed_url)
24
24
  if response = get_json("#{base_url}/list-url?feed_url=#{CGI.escape(feed_url)}")
25
- response.list_url
25
+ response['list_url']
26
26
  end
27
27
  end
28
28
 
@@ -78,16 +78,6 @@ module GdsApi
78
78
  if GdsApi.config.always_raise_for_not_found
79
79
  get_raw!(url)
80
80
  else
81
- warn <<-doc
82
- DEPRECATION NOTICE: You are making requests that will potentially
83
- return nil. Please set `GdsApi.config.always_raise_for_not_found = true`
84
- to make sure all responses with 404 or 410 raise an exception.
85
-
86
- Raising exceptions will be the default behaviour from October 1st, 2016.
87
-
88
- Called from: #{caller[2]}
89
- doc
90
-
91
81
  ignoring_missing do
92
82
  get_raw!(url)
93
83
  end
@@ -105,16 +95,6 @@ module GdsApi
105
95
  if GdsApi.config.always_raise_for_not_found
106
96
  send (method_name + "!"), url, *args, &block
107
97
  else
108
- warn <<-doc
109
- DEPRECATION NOTICE: You are making requests that will potentially
110
- return nil. Please set `GdsApi.config.always_raise_for_not_found = true`
111
- to make sure all responses with 404 or 410 raise an exception.
112
-
113
- Raising exceptions will be the default behaviour from October 1st, 2016.
114
-
115
- Called from: #{caller[2]}
116
- doc
117
-
118
98
  ignoring_missing do
119
99
  send (method_name + "!"), url, *args, &block
120
100
  end
@@ -1,12 +1,12 @@
1
1
  module GdsApi::PartMethods
2
2
 
3
3
  def part_index(slug)
4
- parts.index { |p| p.slug == slug }
4
+ parsed_content['parts'].index { |p| p['slug'] == slug }
5
5
  end
6
6
 
7
7
  def find_part(slug)
8
8
  return nil unless index = part_index(slug)
9
- parts[index]
9
+ parsed_content['parts'][index]
10
10
  end
11
11
 
12
12
  def has_parts?(part)
@@ -14,13 +14,13 @@ module GdsApi::PartMethods
14
14
  end
15
15
 
16
16
  def has_previous_part?(part)
17
- index = part_index(part.slug)
17
+ index = part_index(part['slug'])
18
18
  !! (index && index > 0)
19
19
  end
20
20
 
21
21
  def has_next_part?(part)
22
- index = part_index(part.slug)
23
- !! (index && (index + 1) < parts.length)
22
+ index = part_index(part['slug'])
23
+ !! (index && (index + 1) < parsed_content['parts'].length)
24
24
  end
25
25
 
26
26
  def part_after(part)
@@ -33,9 +33,12 @@ module GdsApi::PartMethods
33
33
 
34
34
  private
35
35
  def part_at(part, relative_offset)
36
- return nil unless current_index = part_index(part.slug)
36
+ current_index = part_index(part['slug'])
37
+ return nil unless current_index
38
+
37
39
  other_index = current_index + relative_offset
38
- return nil unless (0 ... parts.length).include?(other_index)
39
- parts[other_index]
40
+ return nil unless (0...parsed_content['parts'].length).cover?(other_index)
41
+
42
+ parsed_content['parts'][other_index]
40
43
  end
41
44
  end
@@ -7,8 +7,8 @@ class GdsApi::Publisher < GdsApi::Base
7
7
 
8
8
  response = get_json(url_for_slug(slug, options))
9
9
  if response
10
- container = response.to_ostruct
11
- container.extend(GdsApi::PartMethods) if container.parts
10
+ container = response.dup
11
+ container.extend(GdsApi::PartMethods) if container['parts']
12
12
  convert_updated_date(container)
13
13
  container
14
14
  else
@@ -39,8 +39,9 @@ class GdsApi::Publisher < GdsApi::Base
39
39
 
40
40
  private
41
41
  def convert_updated_date(container)
42
- if container.updated_at && container.updated_at.class == String
43
- container.updated_at = Time.parse(container.updated_at)
42
+ if container['updated_at'] && container['updated_at'].is_a?(String)
43
+ container.parsed_content['updated_at'] =
44
+ Time.parse(container['updated_at'])
44
45
  end
45
46
  end
46
47
 
@@ -241,7 +241,24 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
241
241
  patch_json!(links_url(content_id), payload)
242
242
  end
243
243
 
244
- # FIXME: Add documentation
244
+ # Get a list of content items from the Publishing API.
245
+ #
246
+ # The only required key in the params hash is `document_type`. These will be used to filter down the content items being returned by the API. Other allowed options can be seen from the link below.
247
+ #
248
+ # @param params [Hash] At minimum, this hash has to include the `document_type` of the content items we wish to see. All other optional keys are documented above.
249
+ #
250
+ # @example
251
+ #
252
+ # publishing_api.get_content_items(
253
+ # document_type: 'taxon',
254
+ # q: 'Driving',
255
+ # page: 1,
256
+ # per_page: 50,
257
+ # publishing_app: 'content-tagger',
258
+ # fields: ['title', 'description', 'public_updated_at'],
259
+ # locale: 'en',
260
+ # order: '-public_updated_at'
261
+ # )
245
262
  #
246
263
  # @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#get-v2content
247
264
  def get_content_items(params)
@@ -19,7 +19,7 @@ module GdsApi
19
19
  # Example:
20
20
  #
21
21
  # r = Response.new(response, web_urls_relative_to: "https://www.gov.uk")
22
- # r.results[0].web_url
22
+ # r['results'][0]['web_url']
23
23
  # => "/bank-holidays"
24
24
  class Response
25
25
  extend Forwardable
@@ -71,12 +71,16 @@ module GdsApi
71
71
  end
72
72
 
73
73
  def to_hash
74
- @parsed ||= transform_parsed(JSON.parse(@http_response.body))
74
+ parsed_content
75
+ end
76
+
77
+ def parsed_content
78
+ @parsed_content ||= transform_parsed(JSON.parse(@http_response.body))
75
79
  end
76
80
 
77
81
  def to_ostruct
78
82
  raise NoMethodError if GdsApi.config.hash_response_for_requests
79
- @ostruct ||= self.class.build_ostruct_recursively(to_hash)
83
+ @ostruct ||= self.class.build_ostruct_recursively(parsed_content)
80
84
  end
81
85
 
82
86
  def method_missing(method_sym, *arguments, &block)
@@ -38,6 +38,18 @@ module GdsApi
38
38
  end
39
39
  end
40
40
 
41
+ def stub_any_rummager_search
42
+ stub_request(:get, %r{#{RUMMAGER_ENDPOINT}/search.json})
43
+ end
44
+
45
+ def stub_any_rummager_search_to_return_no_results
46
+ stub_any_rummager_search.to_return(body: { results: [] }.to_json)
47
+ end
48
+
49
+ def assert_rummager_search(options)
50
+ assert_requested :get, "#{RUMMAGER_ENDPOINT}/search.json", **options
51
+ end
52
+
41
53
  def stub_any_rummager_delete(index: nil)
42
54
  if index
43
55
  stub_request(:delete, %r{#{RUMMAGER_ENDPOINT}/#{index}/documents/.*})
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '36.4.1'
2
+ VERSION = '37.0.0'.freeze
3
3
  end
@@ -22,14 +22,6 @@ describe GdsApi::AssetManager do
22
22
  }
23
23
  }
24
24
 
25
- before do
26
- GdsApi.config.always_raise_for_not_found = true
27
- end
28
-
29
- after do
30
- GdsApi.config.always_raise_for_not_found = false
31
- end
32
-
33
25
  it "creates an asset with a file" do
34
26
  req = stub_request(:post, "#{base_api_url}/assets").
35
27
  with(:body => %r{Content\-Disposition: form\-data; name="asset\[file\]"; filename="hello\.txt"\r\nContent\-Type: text/plain}).
@@ -37,7 +29,7 @@ describe GdsApi::AssetManager do
37
29
 
38
30
  response = api.create_asset(:file => file_fixture)
39
31
 
40
- assert_equal asset_url, response.asset.id
32
+ assert_equal asset_url, response['asset']['id']
41
33
  assert_requested(req)
42
34
  end
43
35
 
@@ -67,16 +59,16 @@ describe GdsApi::AssetManager do
67
59
 
68
60
  response = api.update_asset(asset_id, :file => file_fixture)
69
61
 
70
- assert_equal "#{base_api_url}/assets/#{asset_id}", response.asset.id
62
+ assert_equal "#{base_api_url}/assets/#{asset_id}", response['asset']['id']
71
63
  assert_requested(req)
72
64
  end
73
65
 
74
66
  it "retrieves an asset" do
75
67
  asset = api.asset(asset_id)
76
68
 
77
- assert_equal "photo.jpg", asset.name
78
- assert_equal "image/jpeg", asset.content_type
79
- assert_equal "http://fooey.gov.uk/media/photo.jpg", asset.file_url
69
+ assert_equal "photo.jpg", asset['name']
70
+ assert_equal "image/jpeg", asset['content_type']
71
+ assert_equal "http://fooey.gov.uk/media/photo.jpg", asset['file_url']
80
72
  end
81
73
  end
82
74
 
@@ -86,7 +78,7 @@ describe GdsApi::AssetManager do
86
78
 
87
79
  response = api.delete_asset(asset_id)
88
80
 
89
- assert_equal "#{base_api_url}/assets/#{asset_id}", response.asset.id
81
+ assert_equal "#{base_api_url}/assets/#{asset_id}", response['asset']['id']
90
82
  assert_requested(req)
91
83
  end
92
84
  end
@@ -32,10 +32,13 @@ describe GdsApi::ContentApi do
32
32
  content_api_has_an_artefact("bank-holidays", artefact_response)
33
33
  artefact = @api.artefact("bank-holidays")
34
34
 
35
- assert_equal "Bank holidays", artefact.title
36
- assert_equal "/bank-holidays", artefact.web_url
35
+ assert_equal "Bank holidays", artefact['title']
36
+ assert_equal "/bank-holidays", artefact['web_url']
37
37
 
38
- assert_equal "/browse/cheese", artefact.tags[0].content_with_tag.web_url
38
+ assert_equal(
39
+ "/browse/cheese",
40
+ artefact['tags'][0]['content_with_tag']['web_url']
41
+ )
39
42
  end
40
43
 
41
44
  it "should use relative URLs for tag listings" do
@@ -44,7 +47,7 @@ describe GdsApi::ContentApi do
44
47
 
45
48
  assert_equal 3, tags.count
46
49
  tags.each do |tag|
47
- web_url = tag.content_with_tag.web_url
50
+ web_url = tag['content_with_tag']['web_url']
48
51
  assert web_url.start_with?("/browse/"), web_url
49
52
  end
50
53
  end
@@ -60,12 +63,15 @@ describe GdsApi::ContentApi do
60
63
  artefact_response["web_url"] = "http://www.test.gov.uk/bank-holidays"
61
64
  content_api_has_an_artefact("bank-holidays", artefact_response)
62
65
 
63
- assert_equal "/bank-holidays", @api.artefact("bank-holidays").web_url
66
+ assert_equal "/bank-holidays", @api.artefact("bank-holidays")['web_url']
64
67
 
65
68
  clean_api = GdsApi::ContentApi.new(@base_api_url)
66
69
  clean_artefact = clean_api.artefact("bank-holidays")
67
70
 
68
- assert_equal "http://www.test.gov.uk/bank-holidays", clean_artefact.web_url
71
+ assert_equal(
72
+ "http://www.test.gov.uk/bank-holidays",
73
+ clean_artefact['web_url']
74
+ )
69
75
  end
70
76
 
71
77
  after do
@@ -85,7 +91,10 @@ describe GdsApi::ContentApi do
85
91
 
86
92
  # Also check attribute access
87
93
  first_section = response.first
88
- assert_equal "#{@base_api_url}/tags/sections/crime.json", first_section.id
94
+ assert_equal(
95
+ "#{@base_api_url}/tags/sections/crime.json",
96
+ first_section['id']
97
+ )
89
98
  end
90
99
 
91
100
  def section_page_url(page_parameter)
@@ -134,7 +143,10 @@ describe GdsApi::ContentApi do
134
143
 
135
144
  sections = @api.sections
136
145
  assert_equal 20, sections.with_subsequent_pages.count
137
- assert_equal "Section 20", sections.with_subsequent_pages.to_a.last.title
146
+ assert_equal(
147
+ "Section 20",
148
+ sections.with_subsequent_pages.to_a.last['title']
149
+ )
138
150
  end
139
151
 
140
152
  it "should iterate across three or more pages" do
@@ -144,7 +156,10 @@ describe GdsApi::ContentApi do
144
156
 
145
157
  sections = @api.sections
146
158
  assert_equal 30, sections.with_subsequent_pages.count
147
- assert_equal "Section 30", sections.with_subsequent_pages.to_a.last.title
159
+ assert_equal(
160
+ "Section 30",
161
+ sections.with_subsequent_pages.to_a.last['title']
162
+ )
148
163
  end
149
164
 
150
165
  it "should not load a page multiple times" do
@@ -225,7 +240,10 @@ describe GdsApi::ContentApi do
225
240
 
226
241
  response = @api.artefacts
227
242
  assert_equal 4, response.count
228
- assert_equal %w(answer local_transaction place guide), response.map(&:format)
243
+ assert_equal(
244
+ %w(answer local_transaction place guide),
245
+ response.map { |item| item['format'] }
246
+ )
229
247
  end
230
248
 
231
249
  it "should work with a paginated response" do
@@ -257,7 +275,10 @@ describe GdsApi::ContentApi do
257
275
  )
258
276
  response = @api.artefacts
259
277
  assert_equal 7, response.with_subsequent_pages.count
260
- assert_equal "http://www.test.gov.uk/vat2", response.with_subsequent_pages.to_a.last.web_url
278
+ assert_equal(
279
+ "http://www.test.gov.uk/vat2",
280
+ response.with_subsequent_pages.to_a.last['web_url']
281
+ )
261
282
  end
262
283
  end
263
284
 
@@ -272,8 +293,18 @@ describe GdsApi::ContentApi do
272
293
  response = @api.for_need(100123)
273
294
 
274
295
  assert_equal 3, response.count
275
- assert_equal ["http://www.gov.uk/burrito", "http://www.gov.uk/burrito-standard", "http://www.gov.uk/local-burrito-place" ], response.map(&:web_url)
276
- assert_equal ["answer", "guide", "transaction" ], response.map(&:format)
296
+ assert_equal(
297
+ [
298
+ "http://www.gov.uk/burrito",
299
+ "http://www.gov.uk/burrito-standard",
300
+ "http://www.gov.uk/local-burrito-place"
301
+ ],
302
+ response.map { |item| item['web_url'] }
303
+ )
304
+ assert_equal(
305
+ %w(answer guide transaction),
306
+ response.map { |item| item['format'] }
307
+ )
277
308
  end
278
309
  end
279
310
 
@@ -288,7 +319,10 @@ describe GdsApi::ContentApi do
288
319
 
289
320
  # Also check attribute access
290
321
  first_section = response.first
291
- assert_equal "#{@base_api_url}/tags/authors/justin-thyme.json", first_section.id
322
+ assert_equal(
323
+ "#{@base_api_url}/tags/authors/justin-thyme.json",
324
+ first_section['id']
325
+ )
292
326
  end
293
327
 
294
328
  it "returns a sorted list of tags of a given type" do
@@ -296,17 +330,29 @@ describe GdsApi::ContentApi do
296
330
  response = @api.tags("author", sort: "alphabetical")
297
331
 
298
332
  first_section = response.first
299
- assert_equal "#{@base_api_url}/tags/authors/justin-thyme.json", first_section.id
333
+ assert_equal(
334
+ "#{@base_api_url}/tags/authors/justin-thyme.json",
335
+ first_section['id']
336
+ )
300
337
  end
301
338
 
302
339
  it "returns draft tags if requested" do
303
340
  content_api_has_draft_and_live_tags(type: "specialist", draft: ["draft-tag-1"], live: ["live-tag-1"])
304
341
 
305
342
  all_tags = @api.tags("specialist", draft: true)
306
- assert_equal [["draft-tag-1", "draft"], ["live-tag-1", "live"]].to_set, all_tags.map {|t| [t.slug, t.state] }.to_set
343
+ assert_equal(
344
+ [
345
+ ["draft-tag-1", "draft"],
346
+ ["live-tag-1", "live"]
347
+ ].to_set,
348
+ all_tags.map { |t| [t['slug'], t['state']] }.to_set
349
+ )
307
350
 
308
351
  live_tags = @api.tags("specialist")
309
- assert_equal [["live-tag-1", "live"]], live_tags.map {|t| [t.slug, t.state] }
352
+ assert_equal(
353
+ [["live-tag-1", "live"]],
354
+ live_tags.map { |t| [t['slug'], t['state']] }
355
+ )
310
356
  end
311
357
 
312
358
  it "returns a list of root tags of a given type" do
@@ -319,7 +365,10 @@ describe GdsApi::ContentApi do
319
365
 
320
366
  # Also check attribute access
321
367
  first_section = response.first
322
- assert_equal "#{@base_api_url}/tags/authors/oliver-sudden.json", first_section.id
368
+ assert_equal(
369
+ "#{@base_api_url}/tags/authors/oliver-sudden.json",
370
+ first_section['id']
371
+ )
323
372
  end
324
373
 
325
374
  it "returns a list of child tags of a given type" do
@@ -332,7 +381,10 @@ describe GdsApi::ContentApi do
332
381
 
333
382
  # Also check attribute access
334
383
  first_section = response.first
335
- assert_equal "#{@base_api_url}/tags/genres/indie%2Findie-rock.json", first_section.id
384
+ assert_equal(
385
+ "#{@base_api_url}/tags/genres/indie%2Findie-rock.json",
386
+ first_section['id']
387
+ )
336
388
  end
337
389
 
338
390
  it "returns a sorted list of child tags of a given type" do
@@ -340,7 +392,10 @@ describe GdsApi::ContentApi do
340
392
  response = @api.child_tags("genre", "indie", sort: "alphabetical")
341
393
 
342
394
  first_section = response.first
343
- assert_equal "#{@base_api_url}/tags/genres/indie%2Findie-rock.json", first_section.id
395
+ assert_equal(
396
+ "#{@base_api_url}/tags/genres/indie%2Findie-rock.json",
397
+ first_section['id']
398
+ )
344
399
  end
345
400
 
346
401
  it "returns tag information for a section" do
@@ -411,14 +466,16 @@ describe GdsApi::ContentApi do
411
466
  end
412
467
 
413
468
  describe "local authorities" do
414
- it "should return nil if no local authority found" do
469
+ it "should raise if no local authority found" do
415
470
  stub_request(:get, "#{@base_api_url}/local_authorities/does-not-exist.json").
416
471
  with(:headers => GdsApi::JsonClient.default_request_headers).
417
472
  to_return(:status => 404,
418
473
  :body => {"_response_info" => {"status" => "ok"}}.to_json,
419
474
  :headers => {})
420
475
 
421
- assert_nil @api.local_authority("does-not-exist")
476
+ assert_raises(GdsApi::HTTPNotFound) do
477
+ @api.local_authority("does-not-exist")
478
+ end
422
479
  end
423
480
 
424
481
  it "should produce a LocalAuthority hash for an existing snac code" do
@@ -602,19 +659,37 @@ describe GdsApi::ContentApi do
602
659
  content_api_has_licence :licence_identifier => "AB1234", :title => 'Test Licence 3', :slug => 'test-licence-3',
603
660
  :licence_short_description => 'A short description'
604
661
 
605
- results = @api.licences_for_ids([1234, 'AB1234', 'something']).to_ostruct.results
662
+ results = @api.licences_for_ids([1234, 'AB1234', 'something'])['results']
606
663
  assert_equal 2, results.size
607
- assert_equal ['1234', 'AB1234'], results.map { |r| r.details.licence_identifier }
608
- assert_equal ['Test Licence 1', 'Test Licence 3'], results.map(&:title).sort
609
- assert_equal ['http://www.test.gov.uk/test-licence-1', 'http://www.test.gov.uk/test-licence-3'], results.map(&:web_url).sort
610
- assert_equal 'A short description', results[0].details.licence_short_description
611
- assert_equal 'A short description', results[1].details.licence_short_description
664
+ assert_equal(
665
+ %w(1234 AB1234),
666
+ results.map { |r| r['details']['licence_identifier'] }
667
+ )
668
+ assert_equal(
669
+ ['Test Licence 1', 'Test Licence 3'],
670
+ results.map { |item| item['title'] }.sort
671
+ )
672
+ assert_equal(
673
+ [
674
+ 'http://www.test.gov.uk/test-licence-1',
675
+ 'http://www.test.gov.uk/test-licence-3'
676
+ ],
677
+ results.map { |item| item['web_url'] }.sort
678
+ )
679
+ assert_equal(
680
+ 'A short description',
681
+ results[0]['details']['licence_short_description']
682
+ )
683
+ assert_equal(
684
+ 'A short description',
685
+ results[1]['details']['licence_short_description']
686
+ )
612
687
  end
613
688
 
614
689
  it "should return empty array with no licences" do
615
690
  setup_content_api_licences_stubs
616
691
 
617
- assert_equal [], @api.licences_for_ids([123,124]).to_ostruct.results
692
+ assert_equal [], @api.licences_for_ids([123, 124])['results']
618
693
  end
619
694
 
620
695
  it "should raise an error if publisher returns an error" do
@@ -622,7 +697,7 @@ describe GdsApi::ContentApi do
622
697
  to_return(:status => [503, "Service temporarily unabailable"])
623
698
 
624
699
  assert_raises GdsApi::HTTPServerError do
625
- @api.licences_for_ids([123,124])
700
+ @api.licences_for_ids([123, 124])
626
701
  end
627
702
  end
628
703
  end