From 76320ca5fb641979a4123ad1144128ed60f9394f Mon Sep 17 00:00:00 2001 From: Tijmen Brommet Date: Wed, 18 Apr 2018 08:21:56 +0100 Subject: [PATCH] Don't crash when `host` isn't set Since https://github.com/alphagov/tech-docs-gem/pull/11 the template crashes when `host` isn't specified in config/tech-docs.yml. This makes sure that we don't crash. --- lib/govuk_tech_docs/meta_tags.rb | 2 +- spec/govuk_tech_docs/meta_tags_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/govuk_tech_docs/meta_tags.rb b/lib/govuk_tech_docs/meta_tags.rb index 9c42a217..8d7013cc 100644 --- a/lib/govuk_tech_docs/meta_tags.rb +++ b/lib/govuk_tech_docs/meta_tags.rb @@ -53,7 +53,7 @@ def page_title end def host - config[:tech_docs][:host] + config[:tech_docs][:host].to_s end def locals diff --git a/spec/govuk_tech_docs/meta_tags_spec.rb b/spec/govuk_tech_docs/meta_tags_spec.rb index 1638cd96..bb8bd47b 100644 --- a/spec/govuk_tech_docs/meta_tags_spec.rb +++ b/spec/govuk_tech_docs/meta_tags_spec.rb @@ -80,6 +80,19 @@ def generate_title(site_name:, page_title:) expect(tags["og:title"]).to eql("The local variable title.") end + + it 'works even when no config is set' do + current_page = double("current_page", + data: double("page_frontmatter", description: "The description.", title: "The Title"), + url: "/foo.html", + metadata: { locals: { title: "The local variable title." } }) + + config = { tech_docs: { } } + + tags = GovukTechDocs::MetaTags.new(config, current_page).tags + + expect(tags).to be_a(Hash) + end end def generate_config(config = {})