govuk_navigation_helpers 2.4.0 → 2.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 925f41952a73c6f57ba09696d8b3eb9f3cd4f460
4
- data.tar.gz: c60be579e0918ac56ab9720e07fc7d9957113d0a
3
+ metadata.gz: 96733a7614897c0c7289e94d1b07b01854704614
4
+ data.tar.gz: 7f5b667aa01be69cc1d9324ebabb6db151090c71
5
5
  SHA512:
6
- metadata.gz: 793282df094eb26e965a5ae97215a2279b7f72bf6afec86cbca844c4fc216231ce7c082800ee3526cbeacd9dd12191697f55ff9aa7b04e1e3d0d699bfc5a97fe
7
- data.tar.gz: ba673437955eea0d5ceda36cfe1b53522e278adfa14ca79b9a4228c4d1a89c15d06477befa4ac1f56f6527344edd6081e7ced480d51397a88b249dabf22095de
6
+ metadata.gz: e74bf5f3785e7017722fc3e540626de37c983e2124589a9d595539f3b50bf78f18a80ee17a20c6c52411db26049d1d40fd02b343f5be6530d3708a9c655358a7
7
+ data.tar.gz: 9e55565a8216e3bd4a9f95c52e15aeda80e1ed2d73d82dc1d3e566937c3aa393f02958d574532dd5f7ddfc1412186784c724f668664471e0ca73a77ad984e027
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.4.1
2
+
3
+ * Add related content to the taxonomy sidebar helper
4
+
1
5
  ## 2.4.0
2
6
 
3
7
  * Add helper for rendering sidebar on taxonomy content pages.
data/Jenkinsfile CHANGED
@@ -35,36 +35,7 @@ node {
35
35
 
36
36
  if(env.BRANCH_NAME == "master") {
37
37
  stage('Publish Gem') {
38
- def version = sh(
39
- script: /ruby -e "puts eval(File.read('${REPOSITORY}.gemspec'), TOPLEVEL_BINDING).version.to_s"/,
40
- returnStdout: true
41
- ).trim()
42
-
43
- def taggedReleaseExists = sh(
44
- script: "git tag | grep v${version}",
45
- returnStatus: true
46
- ) == 0
47
-
48
- if (taggedReleaseExists) {
49
- echo "Version ${version} has already been tagged on Github"
50
- } else {
51
- echo('Pushing tag')
52
- govuk.pushTag(REPOSITORY, env.BRANCH_NAME, 'v' + version)
53
- }
54
-
55
- def escapedVersion = version.replaceAll(/\./, /\\\\./)
56
- def versionAlreadyPublished = sh(
57
- script: /gem list ^${REPOSITORY}\$ --remote --all --quiet | grep [^0-9\\.]${escapedVersion}[^0-9\\.]/,
58
- returnStatus: true
59
- ) == 0
60
-
61
- if (versionAlreadyPublished) {
62
- echo "Version ${version} has already been published to rubygems.org"
63
- } else {
64
- echo('Publishing gem')
65
- sh("gem build ${REPOSITORY}.gemspec")
66
- sh("gem push '${REPOSITORY}-${version}.gem'")
67
- }
38
+ govuk.publishGem(REPOSITORY, env.BRANCH_NAME)
68
39
  }
69
40
  }
70
41
 
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_runtime_dependency "gds-api-adapters", "~> 40.1"
22
+
21
23
  spec.add_development_dependency "bundler", "~> 1.6"
22
24
  spec.add_development_dependency "rake", "~> 10.0"
23
25
  spec.add_development_dependency "rspec", "~> 3.5"
@@ -26,6 +28,7 @@ Gem::Specification.new do |spec|
26
28
  spec.add_development_dependency "pry-byebug", "~> 3.4"
27
29
  spec.add_development_dependency "yard", "~> 0.8"
28
30
  spec.add_development_dependency "govuk_schemas", "~> 1.0"
31
+ spec.add_development_dependency "webmock", "~> 2.3"
29
32
 
30
33
  spec.required_ruby_version = ">= 2.3.1"
31
34
  end
@@ -0,0 +1,27 @@
1
+ module GovukNavigationHelpers
2
+ def self.configuration
3
+ @configuration ||= Configuration.new
4
+ end
5
+
6
+ def self.configure
7
+ yield configuration if block_given?
8
+ end
9
+
10
+ class Configuration
11
+ attr_writer :error_handler
12
+
13
+ def initialize
14
+ @configuration = {}
15
+ end
16
+
17
+ def error_handler
18
+ @error_handler ||= NoErrorHandler.new
19
+ end
20
+
21
+ class NoErrorHandler
22
+ def notify(exception, *_args)
23
+ puts exception
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ module GovukNavigationHelpers
2
+ module Guidance
3
+ # DO NOT COPY THIS LIST
4
+ # This hard-coded list is a temporary measure, and will eventually be replaced by a change in Rummager that
5
+ # will allow us to search for "Guidance" content.
6
+ # See: https://trello.com/c/hxGPJ9jw/435-consolidate-guidance-document-types-into-search
7
+ DOCUMENT_TYPES = %w[
8
+ answer
9
+ contact
10
+ detailed_guide
11
+ document_collection
12
+ form
13
+ guidance
14
+ guide
15
+ licence
16
+ local_transaction
17
+ manual
18
+ map
19
+ notice
20
+ place
21
+ programme
22
+ promotional
23
+ regulation
24
+ simple_smart_answer
25
+ smart_answer
26
+ statutory_guidance
27
+ transaction
28
+ travel_advice
29
+ ].freeze
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ require 'gds_api/rummager'
2
+
3
+ module GovukNavigationHelpers
4
+ module Services
5
+ def self.rummager
6
+ @rummager ||= GdsApi::Rummager.new(Plek.find('rummager'))
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,7 @@
1
+ require 'govuk_navigation_helpers/services'
2
+ require 'govuk_navigation_helpers/guidance'
3
+ require 'govuk_navigation_helpers/configuration'
4
+
1
5
  module GovukNavigationHelpers
2
6
  class TaxonomySidebar
3
7
  def initialize(content_item)
@@ -6,7 +10,7 @@ module GovukNavigationHelpers
6
10
 
7
11
  def sidebar
8
12
  {
9
- sections: taxons.any? ? [{ title: "More about", items: taxons }] : []
13
+ sections: taxons.any? ? [{ title: "More about #{@content_item.title}", items: taxons }] : []
10
14
  }
11
15
  end
12
16
 
@@ -19,8 +23,28 @@ module GovukNavigationHelpers
19
23
  title: parent_taxon.title,
20
24
  url: parent_taxon.base_path,
21
25
  description: parent_taxon.description,
26
+ related_content: content_related_to(parent_taxon),
22
27
  }
23
28
  end
24
29
  end
30
+
31
+ # This method will fetch content related to @content_item, and tagged to taxon. This is a
32
+ # temporary method that uses search to achieve this. This behaviour is to be moved into
33
+ # the content store
34
+ def content_related_to(taxon)
35
+ begin
36
+ Services.rummager.search(
37
+ similar_to: @content_item.base_path,
38
+ start: 0,
39
+ count: 5,
40
+ filter_taxons: [taxon.content_id],
41
+ filter_content_store_document_type: Guidance::DOCUMENT_TYPES,
42
+ fields: %w[title link],
43
+ )['results']
44
+ rescue StandardError => e
45
+ GovukNavigationHelpers.configuration.error_handler.notify(e)
46
+ []
47
+ end
48
+ end
25
49
  end
26
50
  end
@@ -1,3 +1,3 @@
1
1
  module GovukNavigationHelpers
2
- VERSION = "2.4.0".freeze
2
+ VERSION = "2.4.1".freeze
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'govuk_navigation_helpers'
2
2
  require 'govuk_schemas'
3
+ require 'webmock/rspec'
3
4
 
4
5
  # This file was generated by the `rspec --init` command. Conventionally, all
5
6
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
@@ -88,3 +89,7 @@ RSpec.configure do |config|
88
89
  # as the one that triggered the failure.
89
90
  Kernel.srand config.seed
90
91
  end
92
+
93
+ # This lets WebMock detect query strings with repeated values (eg ?array=1&array=2)
94
+ # See https://github.com/bblimke/webmock/issues/584#issuecomment-185605565
95
+ WebMock::Config.instance.query_values_notation = :flat_array
@@ -1,7 +1,25 @@
1
1
  require 'spec_helper'
2
+ require 'webmock/rspec'
3
+ require 'gds_api/test_helpers/rummager'
4
+
5
+ include GdsApi::TestHelpers::Rummager
2
6
 
3
7
  RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
4
8
  describe '#sidebar' do
9
+ before(:each) do
10
+ stub_any_rummager_search
11
+ .to_return(
12
+ body: {
13
+ 'results': [
14
+ {
15
+ 'title': 'Result Content',
16
+ 'link': '/result-content',
17
+ },
18
+ ],
19
+ }.to_json
20
+ )
21
+ end
22
+
5
23
  it 'can handle any valid content item' do
6
24
  generator = GovukSchemas::RandomExample.for_schema(
7
25
  'placeholder',
@@ -22,22 +40,70 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
22
40
  end
23
41
 
24
42
  context 'given a content item tagged to taxons' do
25
- it 'returns a sidebar hash containing a list of parent taxons' do
43
+ it 'returns a sidebar hash containing a list of parent taxons and related content' do
26
44
  content_item = content_item_tagged_to_taxon
27
45
 
28
46
  expect(sidebar_for(content_item)).to eq(
29
47
  sections: [
30
48
  {
31
- title: "More about",
49
+ title: "More about A piece of content",
32
50
  items: [
33
- { title: "Taxon 1", url: "/taxon-1", description: "The 1st taxon." },
34
- { title: "Taxon 2", url: "/taxon-2", description: "The 2nd taxon." },
51
+ {
52
+ title: "Taxon 1",
53
+ url: "/taxon-1",
54
+ description: "The 1st taxon.",
55
+ related_content: [
56
+ {
57
+ "title" => 'Result Content',
58
+ "link" => '/result-content',
59
+ },
60
+ ],
61
+ },
62
+ {
63
+ title: "Taxon 2",
64
+ url: "/taxon-2",
65
+ description: "The 2nd taxon.",
66
+ related_content: [
67
+ {
68
+ "title" => 'Result Content',
69
+ "link" => '/result-content',
70
+ },
71
+ ],
72
+ },
35
73
  ],
36
74
  }
37
75
  ]
38
76
  )
39
77
  end
40
78
  end
79
+
80
+ context 'when Rummager raises an exception' do
81
+ error_handler = nil
82
+
83
+ before(:each) do
84
+ stub_any_rummager_search
85
+ .to_return(status: 500)
86
+
87
+ error_handler = spy('error_handler')
88
+
89
+ GovukNavigationHelpers.configure do |config|
90
+ config.error_handler = error_handler
91
+ end
92
+ end
93
+
94
+ it 'does not re-raise' do
95
+ content_item = content_item_tagged_to_taxon
96
+
97
+ expect { sidebar_for(content_item) }.to_not raise_error
98
+ end
99
+
100
+ it 'logs an error' do
101
+ content_item = content_item_tagged_to_taxon
102
+ sidebar_for(content_item)
103
+
104
+ expect(error_handler).to have_received(:notify).at_least(1).times
105
+ end
106
+ end
41
107
  end
42
108
 
43
109
  def sidebar_for(content_item)
@@ -47,16 +113,19 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
47
113
  def content_item_tagged_to_taxon
48
114
  {
49
115
  "title" => "A piece of content",
116
+ "base_path" => "/a-piece-of-content",
50
117
  "links" => {
51
118
  "taxons" => [
52
119
  {
53
120
  "title" => "Taxon 1",
54
121
  "base_path" => "/taxon-1",
122
+ "content_id" => "taxon1",
55
123
  "description" => "The 1st taxon.",
56
124
  },
57
125
  {
58
126
  "title" => "Taxon 2",
59
127
  "base_path" => "/taxon-2",
128
+ "content_id" => "taxon2",
60
129
  "description" => "The 2nd taxon.",
61
130
  },
62
131
  ],
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_navigation_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-22 00:00:00.000000000 Z
11
+ date: 2017-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gds-api-adapters
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '40.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '40.1'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +136,20 @@ dependencies:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
138
  version: '1.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.3'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.3'
125
153
  description: Gem to transform items from the content-store into payloads for GOV.UK
126
154
  components
127
155
  email:
@@ -143,9 +171,12 @@ files:
143
171
  - govuk_navigation_helpers.gemspec
144
172
  - lib/govuk_navigation_helpers.rb
145
173
  - lib/govuk_navigation_helpers/breadcrumbs.rb
174
+ - lib/govuk_navigation_helpers/configuration.rb
146
175
  - lib/govuk_navigation_helpers/content_item.rb
147
176
  - lib/govuk_navigation_helpers/grouped_related_links.rb
177
+ - lib/govuk_navigation_helpers/guidance.rb
148
178
  - lib/govuk_navigation_helpers/related_items.rb
179
+ - lib/govuk_navigation_helpers/services.rb
149
180
  - lib/govuk_navigation_helpers/taxon_breadcrumbs.rb
150
181
  - lib/govuk_navigation_helpers/taxonomy_sidebar.rb
151
182
  - lib/govuk_navigation_helpers/version.rb