govuk_taxonomy_helpers 0.1.0 → 0.1.1
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 +4 -4
 - data/CHANGELOG.md +4 -0
 - data/lib/govuk_taxonomy_helpers/linked_content_item.rb +2 -0
 - data/lib/govuk_taxonomy_helpers/publishing_api_response.rb +12 -2
 - data/lib/govuk_taxonomy_helpers/version.rb +1 -1
 - data/lib/govuk_taxonomy_helpers.rb +5 -3
 - data/spec/publishing_api_response_spec.rb +31 -0
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 145e8e7f48e099c7854d619770ef6d05183c44ed
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 71505d56dc561f034407a03eea998e8d2f7b375b
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: d8200cd1c85991d6f978183c593ff2812c5c3db909c29228993047eb7235759e0ee4d182779fe0d8040794ec9fab6289d3f225b562fb0590d9781d85b88515f6
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: ecbd204b86e4a97f47d5580c98a17b721ca7a262d37e2521153a59bb26c502086157c0f8e44ecbfa3740da9a9cc69434fc13056ac7ee3e1a6b83e771392b6500
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
| 
         @@ -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,5 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            require  
     | 
| 
      
 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. 
     | 
| 
      
 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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-07-31 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     |