govuk_taxonomy_helpers 0.0.1 → 0.1.0

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: 4a9bcf516b96e7dcec97d7c83fc3915100922700
4
- data.tar.gz: ded38f9b3e0d1602a22b4d3d1e498995a65048a9
3
+ metadata.gz: e5c3007adf0ce60349335ca892e7e1dc794272fe
4
+ data.tar.gz: b33cdedec387f8fdbd42ede8a5d35c6a6cff0bcb
5
5
  SHA512:
6
- metadata.gz: 2a7bbbb176477e4d4c7611c900f4df8830579cc9b2289b93cb18b3a39bf397c2cfca51e57b3ef3c274cc1140fb4548a83e5912a9e85a22f34312593e4c3b6bdd
7
- data.tar.gz: 2730337dfffb046d85fb25c84c728285bdd111245e3758ff7e0188dd87d2545936cfab48e3e7c4a7f4af3363e897e84cd673e14f43ce72c80b3b785c34f52642
6
+ metadata.gz: 2b3604308af84d0f683812197af5a2ccb72db718a59a797dec168756c82bf90fef5ab232432674ff66f98a33be64364f848814f75f2e1d40a2e5b583fc8402e2
7
+ data.tar.gz: f7a29142e29897c8950d2f634d1786e9a2254b272a893f31373404fbc89741a52a2888e933bcb67fb7d7ae13982da0fc3d195f7da76d9750e30a5ecfbe7eaeff
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.0
2
+
3
+ * When parsing publishing api responses, allow both links and details hashes to
4
+ be omitted.
5
+
1
6
  ## 0.0.1
2
7
 
3
8
  * Gem created
@@ -23,9 +23,11 @@ module GovukTaxonomyHelpers
23
23
  # @param content_item [Hash] Publishing API `get_content` response hash
24
24
  # @param expanded_links [Hash] Publishing API `get_expanded_links` response hash
25
25
  def initialize(content_item:, expanded_links:)
26
+ details = content_item["details"] || {}
27
+
26
28
  @linked_content_item = LinkedContentItem.new(
27
29
  title: content_item["title"],
28
- internal_name: content_item["details"]["internal_name"],
30
+ internal_name: details["internal_name"],
29
31
  content_id: content_item["content_id"],
30
32
  base_path: content_item["base_path"]
31
33
  )
@@ -62,14 +64,17 @@ module GovukTaxonomyHelpers
62
64
  end
63
65
 
64
66
  def parse_nested_child(nested_item)
67
+ details = nested_item["details"] || {}
68
+ links = nested_item["links"] || {}
69
+
65
70
  nested_linked_content_item = LinkedContentItem.new(
66
71
  title: nested_item["title"],
67
- internal_name: nested_item["details"]["internal_name"],
72
+ internal_name: details["internal_name"],
68
73
  content_id: nested_item["content_id"],
69
74
  base_path: nested_item["base_path"]
70
75
  )
71
76
 
72
- child_taxons = nested_item["links"]["child_taxons"]
77
+ child_taxons = links["child_taxons"]
73
78
 
74
79
  if !child_taxons.nil?
75
80
  child_taxons.each do |child|
@@ -81,14 +86,17 @@ module GovukTaxonomyHelpers
81
86
  end
82
87
 
83
88
  def parse_nested_parent(nested_item)
89
+ details = nested_item["details"] || {}
90
+ links = nested_item["links"] || {}
91
+
84
92
  nested_linked_content_item = LinkedContentItem.new(
85
93
  title: nested_item["title"],
86
- internal_name: nested_item["details"]["internal_name"],
94
+ internal_name: details["internal_name"],
87
95
  content_id: nested_item["content_id"],
88
96
  base_path: nested_item["base_path"]
89
97
  )
90
98
 
91
- parent_taxons = nested_item["links"]["parent_taxons"]
99
+ parent_taxons = links["parent_taxons"]
92
100
 
93
101
  if !parent_taxons.nil?
94
102
  single_parent = parent_taxons.first
@@ -1,3 +1,3 @@
1
1
  module GovukTaxonomyHelpers
2
- VERSION = "0.0.1".freeze
2
+ VERSION = "0.1.0".freeze
3
3
  end
@@ -340,4 +340,66 @@ RSpec.describe GovukTaxonomyHelpers::PublishingApiResponse do
340
340
  )
341
341
  end
342
342
  end
343
+
344
+ context "minimal responses with missing links and details hashes" do
345
+ let(:minimal_taxon) do
346
+ grandchild_1 = {
347
+ "content_id" => "84aadc14-9bca-40d9-abb4-4f21f9792a05",
348
+ "base_path" => "/grandchild-1",
349
+ "title" => "Grandchild 1",
350
+ }
351
+
352
+ grandchild_2 = {
353
+ "content_id" => "94aadc14-9bca-40d9-abb4-4f21f9792a05",
354
+ "base_path" => "/grandchild-2",
355
+ "title" => "Grandchild 2",
356
+ }
357
+
358
+ child_1 = {
359
+ "content_id" => "74aadc14-9bca-40d9-abb4-4f21f9792a05",
360
+ "base_path" => "/child-1",
361
+ "title" => "Child 1",
362
+ "links" => {
363
+ "child_taxons" => [
364
+ grandchild_1,
365
+ grandchild_2
366
+ ]
367
+ }
368
+ }
369
+
370
+ content_item = {
371
+ "content_id" => "aaaaaa14-9bca-40d9-abb4-4f21f9792a05",
372
+ "base_path" => "/minimal-taxon",
373
+ "title" => "Minimal Taxon",
374
+ }
375
+
376
+ expanded_links = {
377
+ "content_id" => "64aadc14-9bca-40d9-abb4-4f21f9792a05",
378
+ "expanded_links" => {
379
+ "child_taxons" => [child_1],
380
+ "parent_taxons" => [
381
+ {
382
+ "content_id" => "ffaadc14-9bca-40d9-abb4-4f21f9792aff",
383
+ "title" => "Parent Taxon",
384
+ "base_path" => "/parent"
385
+ }
386
+ ]
387
+ }
388
+ }
389
+
390
+ GovukTaxonomyHelpers::LinkedContentItem.from_publishing_api(
391
+ content_item: content_item,
392
+ expanded_links: expanded_links
393
+ )
394
+ end
395
+
396
+ it "parses taxons with nil internal names" do
397
+ expect(minimal_taxon.title).to eq("Minimal Taxon")
398
+ expect(minimal_taxon.internal_name).to be_nil
399
+ expect(minimal_taxon.parent.title).to eq("Parent Taxon")
400
+ expect(minimal_taxon.parent.internal_name).to be_nil
401
+ expect(minimal_taxon.descendants.map(&:title)).to eq(["Child 1", "Grandchild 1", "Grandchild 2"])
402
+ expect(minimal_taxon.descendants.map(&:internal_name)).to all(be_nil)
403
+ end
404
+ end
343
405
  end
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.0.1
4
+ version: 0.1.0
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-06 00:00:00.000000000 Z
11
+ date: 2017-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler