gds-api-adapters 12.2.0 → 12.3.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.
@@ -31,6 +31,7 @@ class GdsApi::ContentApi < GdsApi::Base
31
31
  "type=#{CGI.escape(tag_type)}"
32
32
  ]
33
33
  params << "sort=#{options[:sort]}" if options.has_key?(:sort)
34
+ params << "draft=true" if options[:draft]
34
35
 
35
36
  get_list!("#{base_url}/tags.json?#{params.join('&')}")
36
37
  end
@@ -71,6 +71,20 @@ module GdsApi
71
71
  end
72
72
  end
73
73
 
74
+ def content_api_has_draft_and_live_tags(options = {})
75
+ type = options.fetch(:type)
76
+ live_tags = options.fetch(:live).map { |tag| tag_result(tag, type, state: 'live') }
77
+ draft_tags = options.fetch(:draft).map { |tag| tag_result(tag, type, state: 'draft') }
78
+
79
+ body = plural_response_base.merge("results" => (live_tags + draft_tags))
80
+ url = "#{CONTENT_API_ENDPOINT}/tags.json?type=#{type}&draft=true"
81
+ stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
82
+
83
+ body = plural_response_base.merge("results" => live_tags)
84
+ url = "#{CONTENT_API_ENDPOINT}/tags.json?type=#{type}"
85
+ stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
86
+ end
87
+
74
88
  def content_api_has_tags(tag_type, slugs_or_tags)
75
89
  body = plural_response_base.merge(
76
90
  "results" => slugs_or_tags.map { |tag| tag_result(tag, tag_type) }
@@ -336,7 +350,7 @@ module GdsApi
336
350
  end
337
351
  end
338
352
 
339
- def tag_result(slug_or_hash, tag_type = nil)
353
+ def tag_result(slug_or_hash, tag_type = nil, options = {})
340
354
  tag = tag_hash(slug_or_hash, tag_type)
341
355
 
342
356
  parent = tag_result(tag[:parent]) if tag[:parent]
@@ -356,7 +370,8 @@ module GdsApi
356
370
  "content_with_tag" => {
357
371
  "id" => "#{CONTENT_API_ENDPOINT}/with_tag.json?tag=#{CGI.escape(tag[:slug])}",
358
372
  "web_url" => "http://www.test.gov.uk/browse/#{tag[:slug]}"
359
- }
373
+ },
374
+ "state" => options[:state]
360
375
  }
361
376
  end
362
377
 
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '12.2.0'
2
+ VERSION = '12.3.0'
3
3
  end
@@ -299,6 +299,16 @@ describe GdsApi::ContentApi do
299
299
  assert_equal "#{@base_api_url}/tags/authors/justin-thyme.json", first_section.id
300
300
  end
301
301
 
302
+ it "returns draft tags if requested" do
303
+ content_api_has_draft_and_live_tags(type: "specialist", draft: ["draft-tag-1"], live: ["live-tag-1"])
304
+
305
+ 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
307
+
308
+ live_tags = @api.tags("specialist")
309
+ assert_equal [["live-tag-1", "live"]], live_tags.map {|t| [t.slug, t.state] }
310
+ end
311
+
302
312
  it "returns a list of root tags of a given type" do
303
313
  content_api_has_root_tags("author", ["oliver-sudden", "percy-vere"])
304
314
  response = @api.root_tags("author")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.2.0
4
+ version: 12.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-18 00:00:00.000000000 Z
12
+ date: 2014-07-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: plek
@@ -404,7 +404,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
404
404
  version: '0'
405
405
  segments:
406
406
  - 0
407
- hash: -2448133198351219130
407
+ hash: 2677929826004224176
408
408
  required_rubygems_version: !ruby/object:Gem::Requirement
409
409
  none: false
410
410
  requirements:
@@ -413,7 +413,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
413
413
  version: '0'
414
414
  segments:
415
415
  - 0
416
- hash: -2448133198351219130
416
+ hash: 2677929826004224176
417
417
  requirements: []
418
418
  rubyforge_project:
419
419
  rubygems_version: 1.8.23