govuk_taxonomy_helpers 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5c3007adf0ce60349335ca892e7e1dc794272fe
4
- data.tar.gz: b33cdedec387f8fdbd42ede8a5d35c6a6cff0bcb
3
+ metadata.gz: 145e8e7f48e099c7854d619770ef6d05183c44ed
4
+ data.tar.gz: 71505d56dc561f034407a03eea998e8d2f7b375b
5
5
  SHA512:
6
- metadata.gz: 2b3604308af84d0f683812197af5a2ccb72db718a59a797dec168756c82bf90fef5ab232432674ff66f98a33be64364f848814f75f2e1d40a2e5b583fc8402e2
7
- data.tar.gz: f7a29142e29897c8950d2f634d1786e9a2254b272a893f31373404fbc89741a52a2888e933bcb67fb7d7ae13982da0fc3d195f7da76d9750e30a5ecfbe7eaeff
6
+ metadata.gz: d8200cd1c85991d6f978183c593ff2812c5c3db909c29228993047eb7235759e0ee4d182779fe0d8040794ec9fab6289d3f225b562fb0590d9781d85b88515f6
7
+ data.tar.gz: ecbd204b86e4a97f47d5580c98a17b721ca7a262d37e2521153a59bb26c502086157c0f8e44ecbfa3740da9a9cc69434fc13056ac7ee3e1a6b83e771392b6500
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.1
2
+
3
+ * Adds the from_content_id builder method to LinkedContentItem
4
+
1
5
  ## 0.1.0
2
6
 
3
7
  * When parsing publishing api responses, allow both links and details hashes to
@@ -1,3 +1,5 @@
1
+ require 'forwardable'
2
+
1
3
  module GovukTaxonomyHelpers
2
4
  # A LinkedContentItem can be anything that has a content store representation
3
5
  # on GOV.UK.
@@ -1,5 +1,3 @@
1
- require 'govuk_taxonomy_helpers/linked_content_item'
2
-
3
1
  module GovukTaxonomyHelpers
4
2
  class LinkedContentItem
5
3
  # Extract a LinkedContentItem from publishing api response data.
@@ -15,6 +13,18 @@ module GovukTaxonomyHelpers
15
13
  expanded_links: expanded_links,
16
14
  ).linked_content_item
17
15
  end
16
+
17
+ # Use the publishing API service to fetch and extract a LinkedContentItem
18
+ #
19
+ # @param content_id [String] id of the content
20
+ # @param publishing_api [PublishingApiV2] Publishing API service
21
+ # @return [LinkedContentItem]
22
+ def self.from_content_id(content_id:, publishing_api:)
23
+ GovukTaxonomyHelpers::LinkedContentItem.from_publishing_api(
24
+ content_item: publishing_api.get_content(content_id).to_h,
25
+ expanded_links: publishing_api.get_expanded_links(content_id).to_h
26
+ )
27
+ end
18
28
  end
19
29
 
20
30
  class PublishingApiResponse
@@ -1,3 +1,3 @@
1
1
  module GovukTaxonomyHelpers
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.1.1".freeze
3
3
  end
@@ -1,3 +1,5 @@
1
- require "govuk_taxonomy_helpers/version"
2
- require "govuk_taxonomy_helpers/publishing_api_response"
3
- require "govuk_taxonomy_helpers/linked_content_item"
1
+ module GovukTaxonomyHelpers
2
+ Dir[File.dirname(__FILE__) + '/govuk_taxonomy_helpers/*.rb'].each do |file|
3
+ require file
4
+ end
5
+ end
@@ -13,6 +13,37 @@ RSpec.describe GovukTaxonomyHelpers::PublishingApiResponse do
13
13
  }
14
14
  end
15
15
 
16
+ describe '#from_content_id - simple one child case' do
17
+ let(:expanded_links) do
18
+ child = {
19
+ "content_id" => "74aadc14-9bca-40d9-abb4-4f21f9792a05",
20
+ "base_path" => "/child",
21
+ "title" => "Child",
22
+ "details" => {
23
+ "internal_name" => "C",
24
+ },
25
+ "links" => {}
26
+ }
27
+
28
+ {
29
+ "content_id" => "64aadc14-9bca-40d9-abb4-4f21f9792a05",
30
+ "expanded_links" => {
31
+ "child_taxons" => [child]
32
+ }
33
+ }
34
+ end
35
+ before :each do
36
+ @publishing_api = double('publishing_api')
37
+ allow(@publishing_api).to receive(:get_content).with('64aadc14-9bca-40d9-abb4-4f21f9792a05').and_return(content_item)
38
+ allow(@publishing_api).to receive(:get_expanded_links).with('64aadc14-9bca-40d9-abb4-4f21f9792a05').and_return(expanded_links)
39
+ end
40
+ it 'loads the taxon' do
41
+ expect(linked_content_item.title).to eq("Taxon")
42
+ expect(linked_content_item.children.map(&:title)).to eq(["Child"])
43
+ expect(linked_content_item.children.map(&:children)).to all(be_empty)
44
+ end
45
+ end
46
+
16
47
  let(:linked_content_item) do
17
48
  GovukTaxonomyHelpers::LinkedContentItem.from_publishing_api(
18
49
  content_item: content_item,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_taxonomy_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-15 00:00:00.000000000 Z
11
+ date: 2017-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler