diff --git a/Gemfile b/Gemfile index d09f647a2..b0847db33 100644 --- a/Gemfile +++ b/Gemfile @@ -1,43 +1,43 @@ -source 'https://rubygems.org' +source "https://rubygems.org" ruby File.read(".ruby-version").strip -gem 'asset_bom_removal-rails', '~> 1.0' -gem 'dalli' -gem 'htmlentities', '~> 4.3' -gem 'rack_strip_client_ip', '~> 0.0.2' -gem 'rails', '~> 5.2.3' -gem 'rails-controller-testing', '~> 1.0' -gem 'rails-i18n', '>= 4.0.4' -gem 'rails_translation_manager', '~> 0.1.0' -gem 'sass-rails', '~> 5.0' -gem 'uglifier', '>= 1.3.0' -gem 'gds-api-adapters', '~> 60.0' -gem 'govuk_ab_testing', '~> 2.4' -gem 'govuk_app_config', '~> 2.0' -gem 'govuk_frontend_toolkit', '~> 8.2.0' -gem 'govuk_publishing_components', '~> 21.0.0' -gem 'plek', '~> 3.0' -gem 'slimmer', '~> 13.1' +gem "asset_bom_removal-rails", "~> 1.0" +gem "dalli" +gem "gds-api-adapters", "~> 60.0" +gem "govuk_ab_testing", "~> 2.4" +gem "govuk_app_config", "~> 2.0" +gem "govuk_frontend_toolkit", "~> 8.2.0" +gem "govuk_publishing_components", "~> 21.0.0" +gem "htmlentities", "~> 4.3" +gem "plek", "~> 3.0" +gem "rack_strip_client_ip", "~> 0.0.2" +gem "rails", "~> 5.2.3" +gem "rails-controller-testing", "~> 1.0" +gem "rails-i18n", ">= 4.0.4" +gem "rails_translation_manager", "~> 0.1.0" +gem "sass-rails", "~> 5.0" +gem "slimmer", "~> 13.1" +gem "uglifier", ">= 1.3.0" group :development, :test do - gem 'govuk-lint' - gem 'govuk_schemas', '~> 4.0' - gem 'jasmine-rails' + gem "govuk-lint" + gem "govuk_schemas", "~> 4.0" + gem "jasmine-rails" end group :development do - gem 'pry' - gem 'better_errors' - gem 'binding_of_caller' - gem 'wraith', '~> 4.2' + gem "better_errors" + gem "binding_of_caller" + gem "pry" + gem "wraith", "~> 4.2" end group :test do - gem 'capybara' - gem 'govuk_test' - gem 'faker' - gem 'minitest-reporters' - gem 'mocha' - gem 'webmock', '~> 3.7.4', require: false + gem "capybara" + gem "faker" + gem "govuk_test" + gem "minitest-reporters" + gem "mocha" + gem "webmock", "~> 3.7.4", require: false end diff --git a/Jenkinsfile b/Jenkinsfile index 2024bea5a..c5de6d245 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,5 +6,9 @@ REPOSITORY = 'government-frontend' node { govuk.setEnvar("PUBLISHING_E2E_TESTS_COMMAND", "test-government-frontend") - govuk.buildProject(publishingE2ETests: true, brakeman: true) + govuk.buildProject( + publishingE2ETests: true, + brakeman: true, + rubyLintDiff: false, + ) } diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0f81b56b4..e892e3fdc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -7,7 +7,7 @@ class ApplicationController < ActionController::Base if ENV["BASIC_AUTH_USERNAME"] http_basic_authenticate_with( name: ENV.fetch("BASIC_AUTH_USERNAME"), - password: ENV.fetch("BASIC_AUTH_PASSWORD") + password: ENV.fetch("BASIC_AUTH_PASSWORD"), ) end @@ -17,8 +17,8 @@ def content_item_path path_and_optional_locale = params .values_at(:path, :locale) .compact - .join('.') + .join(".") - '/' + URI.encode(path_and_optional_locale) # rubocop:disable Lint/UriEscapeUnescape + "/" + URI.encode(path_and_optional_locale) # rubocop:disable Lint/UriEscapeUnescape end end diff --git a/app/controllers/content_items_controller.rb b/app/controllers/content_items_controller.rb index 6c81fa4a6..2488ece75 100644 --- a/app/controllers/content_items_controller.rb +++ b/app/controllers/content_items_controller.rb @@ -58,8 +58,8 @@ def set_guide_draft_access_token def load_content_item content_item = Services.content_store.content_item(content_item_path) - if Services.feature_toggler.use_recommended_related_links?(content_item['links'], request.headers) - content_item['links']['ordered_related_items'] = content_item['links'].fetch('suggested_ordered_related_items', []) + if Services.feature_toggler.use_recommended_related_links?(content_item["links"], request.headers) + content_item["links"]["ordered_related_items"] = content_item["links"].fetch("suggested_ordered_related_items", []) end @content_item = PresenterBuilder.new(content_item, content_item_path).presenter @@ -75,9 +75,9 @@ def format_banner_links(links, type) "track-action": "1.#{index} #{type}", "track-label": base_path, "track-options": { - dimension29: title - } - } + dimension29: title, + }, + }, ) end end @@ -114,7 +114,7 @@ def set_access_control_allow_origin_header end def set_use_recommended_related_links_header - response.headers['Vary'] = [response.headers['Vary'], FeatureFlagNames.recommended_related_links].compact.join(', ') + response.headers["Vary"] = [response.headers["Vary"], FeatureFlagNames.recommended_related_links].compact.join(", ") related_links_request_header = RequestHelper.get_header(FeatureFlagNames.recommended_related_links, request.headers) required_header_value = Services.feature_toggler.feature_flags.get_feature_flag(FeatureFlagNames.recommended_related_links) @@ -131,7 +131,7 @@ def service_url(original_url) return original_url if ga_param.nil? url = URI.parse(original_url) - new_query_ar = URI.decode_www_form(url.query || '') << ["_ga", ga_param] + new_query_ar = URI.decode_www_form(url.query || "") << ["_ga", ga_param] url.query = URI.encode_www_form(new_query_ar) url.to_s end @@ -145,15 +145,15 @@ def error_403(exception) end def error_notfound - render plain: 'Not found', status: :not_found + render plain: "Not found", status: :not_found end def error_406 - render plain: 'Not acceptable', status: 406 + render plain: "Not acceptable", status: 406 end def error_410 - render plain: 'Gone', status: 410 + render plain: "Gone", status: 410 end def error_redirect(exception) diff --git a/app/controllers/randomly_generated_content_item_controller.rb b/app/controllers/randomly_generated_content_item_controller.rb index e7c596ee6..c823cbe7e 100644 --- a/app/controllers/randomly_generated_content_item_controller.rb +++ b/app/controllers/randomly_generated_content_item_controller.rb @@ -7,7 +7,7 @@ def load_content_item ) # Use provided schema_name rather than a randomly generated one - random_example['schema_name'] = params[:schema].underscore + random_example["schema_name"] = params[:schema].underscore @content_item = present(random_example) end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 95e4121c5..43859107d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -4,7 +4,7 @@ def page_text_direction end def t_locale_fallback(key, options = {}) - options['locale'] = I18n.locale + options["locale"] = I18n.locale options[:fallback] = nil translation = I18n.t(key, options) @@ -22,7 +22,7 @@ def wrapper_class def active_proposition # Which of the government sections is the page part of? # Derive this from the request path, eg: /government/consultations => consultations - active = request.original_fullpath.split('/')[2] + active = request.original_fullpath.split("/")[2] active_proposition_mapping.fetch(active, active) end @@ -36,8 +36,8 @@ def active_proposition_mapping # Some paths don't map directly to the position nav # eg /government/news sits under 'announcements' { - 'news' => 'announcements', - 'fatalities' => 'announcements' + "news" => "announcements", + "fatalities" => "announcements", } end end diff --git a/app/helpers/machine_readable_metadata_helper.rb b/app/helpers/machine_readable_metadata_helper.rb index 2584030d8..39ee4aaf5 100644 --- a/app/helpers/machine_readable_metadata_helper.rb +++ b/app/helpers/machine_readable_metadata_helper.rb @@ -1,6 +1,6 @@ module MachineReadableMetadataHelper def machine_readable_metadata(args) locals = { content_item: @content_item.content_item }.merge(args) - render('govuk_publishing_components/components/machine_readable_metadata', locals) + render("govuk_publishing_components/components/machine_readable_metadata", locals) end end diff --git a/app/helpers/phase_label_helper.rb b/app/helpers/phase_label_helper.rb index 1d7da5d67..e66107fd6 100644 --- a/app/helpers/phase_label_helper.rb +++ b/app/helpers/phase_label_helper.rb @@ -4,7 +4,7 @@ def render_phase_label(presented_object, message) locals = {} locals[:message] = message if message.present? - render 'govuk_publishing_components/components/phase_banner', locals.merge(phase: presented_object.phase) + render "govuk_publishing_components/components/phase_banner", locals.merge(phase: presented_object.phase) end end end diff --git a/app/helpers/statistics_announcement_helper.rb b/app/helpers/statistics_announcement_helper.rb index 4e29a2b56..d9f6f85e7 100644 --- a/app/helpers/statistics_announcement_helper.rb +++ b/app/helpers/statistics_announcement_helper.rb @@ -3,6 +3,7 @@ def on_in_between_for_release_date(date) return "on #{date}" if date_is_exact_format?(date) return "in #{date}" if date_is_one_month_format?(date) return "between #{replace_on_with_and(date)}" if date_is_two_month_format?(date) + date end diff --git a/app/helpers/typography_helper.rb b/app/helpers/typography_helper.rb index 9cb6434de..31289b310 100644 --- a/app/helpers/typography_helper.rb +++ b/app/helpers/typography_helper.rb @@ -1,11 +1,12 @@ module TypographyHelper def nbsp_between_last_two_words(text) return text if text.nil? + escaped_text = html_escape_once(text.strip) escaped_text.sub(/\s([\w\.\?\!\:]+)$/, ' \1').html_safe end def strip_trailing_colons(text) - text.gsub(/\:$/, '') + text.gsub(/\:$/, "") end end diff --git a/app/lib/services.rb b/app/lib/services.rb index 7315084ce..6ea9c1e22 100644 --- a/app/lib/services.rb +++ b/app/lib/services.rb @@ -1,4 +1,4 @@ -require 'gds_api/content_store' +require "gds_api/content_store" module Services def self.content_store @@ -13,7 +13,7 @@ def self.content_store def self.feature_toggler @feature_toggler ||= FeatureToggler.new( - HttpFeatureFlags.instance + HttpFeatureFlags.instance, ) end end diff --git a/app/models/feature_toggler.rb b/app/models/feature_toggler.rb index 02a1fd093..2c3e2f94f 100644 --- a/app/models/feature_toggler.rb +++ b/app/models/feature_toggler.rb @@ -8,8 +8,8 @@ def initialize(feature_flags) def use_recommended_related_links?(content_item_links, request_headers) return false if content_item_links.nil? - content_item_links.fetch('ordered_related_items', []).empty? && - content_item_links.fetch('ordered_related_items_overrides', []).empty? && + content_item_links.fetch("ordered_related_items", []).empty? && + content_item_links.fetch("ordered_related_items_overrides", []).empty? && @feature_flags.feature_enabled?(FeatureFlagNames.recommended_related_links, request_headers) end end diff --git a/app/presenters/consultation_presenter.rb b/app/presenters/consultation_presenter.rb index 765ab81db..26393817a 100644 --- a/app/presenters/consultation_presenter.rb +++ b/app/presenters/consultation_presenter.rb @@ -55,7 +55,7 @@ def final_outcome_documents? end def final_outcome_documents - final_outcome_documents_list.join('') + final_outcome_documents_list.join("") end def public_feedback_documents? @@ -63,7 +63,7 @@ def public_feedback_documents? end def public_feedback_documents - public_feedback_documents_list.join('') + public_feedback_documents_list.join("") end def public_feedback_detail @@ -83,7 +83,7 @@ def documents? end def documents - documents_list.join('') + documents_list.join("") end def ways_to_respond? @@ -127,7 +127,7 @@ def display_date_and_time(date, rollback_midnight = false) # 12am on 10 January becomes 11:59pm on 9 January time = time - 1.second if time.strftime(time_format) == "12:00am" end - I18n.l(time, format: "#{time_format} on #{date_format}").gsub(':00', '').gsub('12pm', 'midday').gsub('12am on ', '').strip + I18n.l(time, format: "#{time_format} on #{date_format}").gsub(":00", "").gsub("12pm", "midday").gsub("12am on ", "").strip end def ways_to_respond diff --git a/app/presenters/contact_presenter.rb b/app/presenters/contact_presenter.rb index d21f6a13c..d86e11e52 100644 --- a/app/presenters/contact_presenter.rb +++ b/app/presenters/contact_presenter.rb @@ -16,9 +16,9 @@ def online_form_links contact_form_links = content_item["details"]["contact_form_links"] || [] contact_form_links.map do |link| { - url: link['link'], - title: link['title'], - description: link['description'].try(:html_safe) + url: link["link"], + title: link["title"], + description: link["description"].try(:html_safe), } end end @@ -31,10 +31,10 @@ def phone phone_number_groups.map do |group| { numbers: phone_numbers_in_group(group), - title: group['title'], - description: group['description'].try(:strip).try(:html_safe), - opening_times: group['open_hours'].try(:strip).try(:html_safe), - best_time_to_call: group['best_time_to_call'].try(:strip).try(:html_safe) + title: group["title"], + description: group["description"].try(:strip).try(:html_safe), + opening_times: group["open_hours"].try(:strip).try(:html_safe), + best_time_to_call: group["best_time_to_call"].try(:strip).try(:html_safe), } end end @@ -46,15 +46,15 @@ def phone_body def post post_address_groups.map do |group| details = { - description: group['description'].try(:strip).try(:html_safe), + description: group["description"].try(:strip).try(:html_safe), v_card: [ - v_card_part('fn', group['title']), - v_card_part('street-address', group['street_address']), - v_card_part('locality', group['locality']), - v_card_part('region', group['region']), - v_card_part('postal-code', group['postal_code']), - v_card_part('country-name', group['world_location']), - ] + v_card_part("fn", group["title"]), + v_card_part("street-address", group["street_address"]), + v_card_part("locality", group["locality"]), + v_card_part("region", group["region"]), + v_card_part("postal-code", group["postal_code"]), + v_card_part("country-name", group["world_location"]), + ], } details[:v_card].select! { |v| v[:value].present? } @@ -69,9 +69,9 @@ def post_body def email email_address_groups.map do |group| details = { - description: group['description'].try(:strip).try(:html_safe), - email: group['email'].strip, - v_card: [v_card_part('fn', group['title'])], + description: group["description"].try(:strip).try(:html_safe), + email: group["email"].strip, + v_card: [v_card_part("fn", group["title"])], } details[:v_card].select! { |v| v[:value].present? } @@ -100,21 +100,21 @@ def webchat_open_url def phone_numbers_in_group(group) [ { - label: 'Telephone', - number: group['number'] + label: "Telephone", + number: group["number"], }, { - label: 'Textphone', - number: group['textphone'] + label: "Textphone", + number: group["textphone"], }, { - label: 'Outside UK', - number: group['international_phone'] + label: "Outside UK", + number: group["international_phone"], }, { - label: 'Fax', - number: group['fax'] - } + label: "Fax", + number: group["fax"], + }, ].select { |n| n[:number].present? } end @@ -124,23 +124,23 @@ def webchat_id def webchat_ids { - '/government/organisations/hm-revenue-customs/contact/child-benefit' => 1027, - '/government/organisations/hm-revenue-customs/contact/income-tax-enquiries-for-individuals-pensioners-and-employees' => 1030, - '/government/organisations/hm-revenue-customs/contact/vat-online-services-helpdesk' => 1026, - '/government/organisations/hm-revenue-customs/contact/national-insurance-numbers' => 1021, - '/government/organisations/hm-revenue-customs/contact/self-assessment' => 1004, - '/government/organisations/hm-revenue-customs/contact/tax-credits-enquiries' => 1016, - '/government/organisations/hm-revenue-customs/contact/vat-enquiries' => 1028, - '/government/organisations/hm-revenue-customs/contact/customs-international-trade-and-excise-enquiries' => 1034, - '/government/organisations/hm-revenue-customs/contact/employer-enquiries' => 1023, - '/government/organisations/hm-revenue-customs/contact/online-services-helpdesk' => 1003, + "/government/organisations/hm-revenue-customs/contact/child-benefit" => 1027, + "/government/organisations/hm-revenue-customs/contact/income-tax-enquiries-for-individuals-pensioners-and-employees" => 1030, + "/government/organisations/hm-revenue-customs/contact/vat-online-services-helpdesk" => 1026, + "/government/organisations/hm-revenue-customs/contact/national-insurance-numbers" => 1021, + "/government/organisations/hm-revenue-customs/contact/self-assessment" => 1004, + "/government/organisations/hm-revenue-customs/contact/tax-credits-enquiries" => 1016, + "/government/organisations/hm-revenue-customs/contact/vat-enquiries" => 1028, + "/government/organisations/hm-revenue-customs/contact/customs-international-trade-and-excise-enquiries" => 1034, + "/government/organisations/hm-revenue-customs/contact/employer-enquiries" => 1023, + "/government/organisations/hm-revenue-customs/contact/online-services-helpdesk" => 1003, } end def v_card_part(v_card_class, value) { v_card_class: v_card_class, - value: value.try(:strip).try(:html_safe) + value: value.try(:strip).try(:html_safe), } end @@ -161,7 +161,7 @@ def related_contacts_links related.map do |link| { title: link["title"], - url: link["base_path"] + url: link["base_path"], } end end @@ -171,7 +171,7 @@ def quick_links quick.map do |link| { title: link["title"], - url: link["url"] + url: link["url"], } end end diff --git a/app/presenters/content_item/body.rb b/app/presenters/content_item/body.rb index 375fa62ef..b910b6158 100644 --- a/app/presenters/content_item/body.rb +++ b/app/presenters/content_item/body.rb @@ -7,7 +7,7 @@ def body def govspeak_body { content: body.html_safe, - direction: text_direction + direction: text_direction, } end end diff --git a/app/presenters/content_item/contents_list.rb b/app/presenters/content_item/contents_list.rb index 9972f56c6..116683807 100644 --- a/app/presenters/content_item/contents_list.rb +++ b/app/presenters/content_item/contents_list.rb @@ -35,8 +35,8 @@ def show_contents_list? private def extract_headings_with_ids - headings = parsed_body.css('h2').map do |heading| - id = heading.attribute('id') + headings = parsed_body.css("h2").map do |heading| + id = heading.attribute("id") { text: strip_trailing_colons(heading.text), id: id.value } if id end headings.compact @@ -48,10 +48,10 @@ def first_item_has_long_content? def first_item_content element = first_item - first_item_text = '' + first_item_text = "" allowed_elements = %w(p ul ol) - until element.name == 'h2' + until element.name == "h2" first_item_text += element.text if element.name.in?(allowed_elements) element = element.next_element break if element.nil? @@ -70,8 +70,9 @@ def first_item_has_long_table? def find_first_table element = first_item - until element.name == 'h2' do - return element if element.name == 'table' + until element.name == "h2" do + return element if element.name == "table" + element = element.next_element break if element.nil? end @@ -79,14 +80,15 @@ def find_first_table def first_item_table_rows @table ||= find_first_table - @table.present? ? @table.css('tr').count : 0 + @table.present? ? @table.css("tr").count : 0 end def first_item_has_image? element = first_item - until element.name == 'h2' - return true if element.name == 'div' && element['class'] == 'img' + until element.name == "h2" + return true if element.name == "div" && element["class"] == "img" + element = element.next_element return false if element.nil? end @@ -105,7 +107,7 @@ def parsed_body end def first_item - parsed_body.css('h2').first.try(:next_element) + parsed_body.css("h2").first.try(:next_element) end def no_first_item? diff --git a/app/presenters/content_item/corporate_information_groups.rb b/app/presenters/content_item/corporate_information_groups.rb index 4bebc40e1..4576de47d 100644 --- a/app/presenters/content_item/corporate_information_groups.rb +++ b/app/presenters/content_item/corporate_information_groups.rb @@ -10,7 +10,7 @@ def corporate_information corporate_information_groups.map do |group| { heading: content_tag(:h3, group["name"], id: group_title_id(group["name"])), - links: normalised_group_links(group) + links: normalised_group_links(group), } end end @@ -25,8 +25,8 @@ def further_information further_information_about("welsh_language_scheme"), further_information_about("personal_information_charter"), further_information_about("social_media_use"), - further_information_about("about_our_services") - ].join(' ').html_safe + further_information_about("about_our_services"), + ].join(" ").html_safe end private @@ -42,16 +42,16 @@ def further_information_about(type) end def corporate_information_heading - heading_text = I18n.t('corporate_information_page.corporate_information') + heading_text = I18n.t("corporate_information_page.corporate_information") { text: heading_text, - id: group_title_id(heading_text) + id: group_title_id(heading_text), } end def group_title_id(title) - title.tr(' ', '-').downcase + title.tr(" ", "-").downcase end def normalised_group_links(group) @@ -70,7 +70,7 @@ def normalised_group_item_link(group_item) end def corporate_information_page_links - expanded_links_from_content_item('corporate_information_pages') + expanded_links_from_content_item("corporate_information_pages") end def corporate_information_groups diff --git a/app/presenters/content_item/linkable.rb b/app/presenters/content_item/linkable.rb index 45a5f553c..dc07df315 100644 --- a/app/presenters/content_item/linkable.rb +++ b/app/presenters/content_item/linkable.rb @@ -28,6 +28,7 @@ def links(type) def expanded_links_from_content_item(type) return [] unless content_item["links"][type] + content_item["links"][type] end @@ -54,6 +55,7 @@ def emphasised_organisations def link_for_type(type, link) return link_for_world_location(link) if type == "world_locations" + link_to(link["title"], link["base_path"], class: "govuk-link") end diff --git a/app/presenters/content_item/metadata.rb b/app/presenters/content_item/metadata.rb index a9f4a706a..910bece3e 100644 --- a/app/presenters/content_item/metadata.rb +++ b/app/presenters/content_item/metadata.rb @@ -11,7 +11,7 @@ def metadata see_updates_link: true, part_of: part_of, direction: text_direction, - other: {} + other: {}, } end @@ -25,8 +25,8 @@ def publisher_metadata last_updated: updated, link_to_history: !!updated, other: { - from: from - } + from: from, + }, } end end diff --git a/app/presenters/content_item/national_applicability.rb b/app/presenters/content_item/national_applicability.rb index 3b064d2a7..21816f4df 100644 --- a/app/presenters/content_item/national_applicability.rb +++ b/app/presenters/content_item/national_applicability.rb @@ -4,6 +4,7 @@ module NationalApplicability def applies_to return nil if !national_applicability + all_nations = national_applicability.values applicable_nations = all_nations.select { |n| n["applicable"] } inapplicable_nations = all_nations - applicable_nations @@ -14,7 +15,7 @@ def applies_to nations_with_alt_urls = inapplicable_nations.select { |n| n["alternative_url"].present? } if nations_with_alt_urls.any? alternate_links = nations_with_alt_urls - .map { |n| link_to(n['label'], n['alternative_url'], rel: :external, class: "govuk-link app-link") } + .map { |n| link_to(n["label"], n["alternative_url"], rel: :external, class: "govuk-link app-link") } .to_sentence applies_to += " (see #{translated_schema_name(nations_with_alt_urls.count)} for #{alternate_links})" @@ -26,7 +27,7 @@ def applies_to def important_metadata super.tap do |m| - m.merge!('Applies to' => applies_to) + m.merge!("Applies to" => applies_to) end end diff --git a/app/presenters/content_item/national_statistics_logo.rb b/app/presenters/content_item/national_statistics_logo.rb index 070be6817..a1898c345 100644 --- a/app/presenters/content_item/national_statistics_logo.rb +++ b/app/presenters/content_item/national_statistics_logo.rb @@ -2,6 +2,7 @@ module ContentItem module NationalStatisticsLogo def logo return unless national_statistics? + { path: "national-statistics.png", alt_text: "National Statistics" } end end diff --git a/app/presenters/content_item/organisation_branding.rb b/app/presenters/content_item/organisation_branding.rb index 17a8c8a24..9e0735031 100644 --- a/app/presenters/content_item/organisation_branding.rb +++ b/app/presenters/content_item/organisation_branding.rb @@ -10,7 +10,7 @@ def organisation_logo(organisation = default_organisation) url: organisation["base_path"], brand: organisation_brand(organisation), crest: logo["crest"], - } + }, } if logo["image"] @@ -39,6 +39,7 @@ def default_organisation # and updating them with the correct brand in the actual store. def organisation_brand(organisation) return unless organisation + brand = organisation["details"]["brand"] brand = "executive-office" if executive_order_crest?(organisation) brand @@ -46,6 +47,7 @@ def organisation_brand(organisation) def executive_order_crest?(organisation) return unless organisation + organisation["details"]["logo"]["crest"] == "eo" end end diff --git a/app/presenters/content_item/parts.rb b/app/presenters/content_item/parts.rb index 02dfcf40f..da0f12f7c 100644 --- a/app/presenters/content_item/parts.rb +++ b/app/presenters/content_item/parts.rb @@ -5,7 +5,7 @@ module Parts def parts raw_parts.each_with_index.map do |part, i| # Link to base_path for first part - part['full_path'] = i.zero? ? base_path : "#{base_path}/#{part['slug']}" + part["full_path"] = i.zero? ? base_path : "#{base_path}/#{part['slug']}" part end end @@ -42,17 +42,17 @@ def previous_and_next_navigation if previous_part nav[:previous_page] = { - url: previous_part['full_path'], - title: I18n.t('multi_page.previous_page'), - label: previous_part['title'] + url: previous_part["full_path"], + title: I18n.t("multi_page.previous_page"), + label: previous_part["title"], } end if next_part nav[:next_page] = { - url: next_part['full_path'], - title: I18n.t('multi_page.next_page'), - label: next_part['title'] + url: next_part["full_path"], + title: I18n.t("multi_page.next_page"), + label: next_part["title"], } end @@ -61,10 +61,10 @@ def previous_and_next_navigation def part_link_elements parts.map do |part| - if part['slug'] != current_part['slug'] - { href: part['full_path'], text: part['title'] } + if part["slug"] != current_part["slug"] + { href: part["full_path"], text: part["title"] } else - { href: part['full_path'], text: part['title'], active: true } + { href: part["full_path"], text: part["title"], active: true } end end end @@ -85,18 +85,18 @@ def current_part def part_links parts.map.with_index(1) do |part, position| - if part['slug'] != current_part['slug'] - link_to part['title'], part['full_path'], class: "govuk-link", + if part["slug"] != current_part["slug"] + link_to part["title"], part["full_path"], class: "govuk-link", data: { - track_category: 'contentsClicked', + track_category: "contentsClicked", track_action: "content_item #{position}", - track_label: part['full_path'], + track_label: part["full_path"], track_options: { - dimension29: part['title'] - } + dimension29: part["title"], + }, } else - part['title'] + part["title"] end end end diff --git a/app/presenters/content_item/shareable.rb b/app/presenters/content_item/shareable.rb index 5adad5231..627e41a25 100644 --- a/app/presenters/content_item/shareable.rb +++ b/app/presenters/content_item/shareable.rb @@ -7,13 +7,13 @@ def share_links { href: facebook_share_url, text: 'Share on Facebook'.html_safe, - icon: 'facebook' + icon: "facebook", }, { href: twitter_share_url, text: 'Share on Twitter'.html_safe, - icon: 'twitter' - } + icon: "twitter", + }, ] end diff --git a/app/presenters/content_item/title_and_context.rb b/app/presenters/content_item/title_and_context.rb index 5a8348b88..ae5fed83b 100644 --- a/app/presenters/content_item/title_and_context.rb +++ b/app/presenters/content_item/title_and_context.rb @@ -5,7 +5,7 @@ def title_and_context title: title, context: I18n.t("content_item.schema_name.#{document_type}", count: 1), context_locale: t_locale_fallback("content_item.schema_name.#{document_type}", count: 1), - average_title_length: "long" + average_title_length: "long", } end end diff --git a/app/presenters/content_item/updatable.rb b/app/presenters/content_item/updatable.rb index 26277bdbf..d9eb152b4 100644 --- a/app/presenters/content_item/updatable.rb +++ b/app/presenters/content_item/updatable.rb @@ -10,6 +10,7 @@ def updated def history return [] unless any_updates? + reverse_chronological_change_history end @@ -29,7 +30,7 @@ def change_history { display_time: display_date(item["public_timestamp"]), note: item["note"], - timestamp: item["public_timestamp"] + timestamp: item["public_timestamp"], } end end diff --git a/app/presenters/content_item/withdrawable.rb b/app/presenters/content_item/withdrawable.rb index 86a0cda2f..e3e6855ae 100644 --- a/app/presenters/content_item/withdrawable.rb +++ b/app/presenters/content_item/withdrawable.rb @@ -15,7 +15,7 @@ def withdrawal_notice_component { title: withdrawal_notice_title, description_govspeak: withdrawal_notice["explanation"]&.html_safe, - time: withdrawal_notice_time + time: withdrawal_notice_time, } end end diff --git a/app/presenters/content_item_presenter.rb b/app/presenters/content_item_presenter.rb index f1b2faf80..fdd20948e 100644 --- a/app/presenters/content_item_presenter.rb +++ b/app/presenters/content_item_presenter.rb @@ -29,7 +29,7 @@ def initialize(content_item, requested_content_item_path = nil) @document_type = content_item["document_type"] @taxons = content_item["links"]["taxons"] if content_item["links"] @step_by_steps = content_item["links"]["part_of_step_navs"] if content_item["links"] - @part_slug = requesting_a_part? ? requested_content_item_path.split('/').last : nil + @part_slug = requesting_a_part? ? requested_content_item_path.split("/").last : nil end def requesting_a_part? @@ -81,11 +81,11 @@ def cache_control_public? private def display_date(timestamp, format = "%-d %B %Y") - I18n.l(Time.zone.parse(timestamp), format: format, locale: 'en') if timestamp + I18n.l(Time.zone.parse(timestamp), format: format, locale: "en") if timestamp end def sorted_locales(translations) - translations.sort_by { |t| t["locale"] == I18n.default_locale.to_s ? '' : t["locale"] } + translations.sort_by { |t| t["locale"] == I18n.default_locale.to_s ? "" : t["locale"] } end def mapped_locales(translations) @@ -93,7 +93,7 @@ def mapped_locales(translations) { locale: translation["locale"], base_path: translation["base_path"], - text: native_language_name_for(translation["locale"]) + text: native_language_name_for(translation["locale"]), }.tap do |h| h[:active] = true if h[:locale] == I18n.locale.to_s end diff --git a/app/presenters/detailed_guide_presenter.rb b/app/presenters/detailed_guide_presenter.rb index 3addef6d5..cef5831d6 100644 --- a/app/presenters/detailed_guide_presenter.rb +++ b/app/presenters/detailed_guide_presenter.rb @@ -15,6 +15,7 @@ def title_and_context def logo image = content_item.dig("details", "image") return unless image + { path: image["url"], alt_text: "European structural investment funds" } end @@ -27,6 +28,6 @@ def related_links(key) end def related_guides_title - I18n.t('detailed_guide.related_guides') + I18n.t("detailed_guide.related_guides") end end diff --git a/app/presenters/document_collection_presenter.rb b/app/presenters/document_collection_presenter.rb index e34f39eda..87f0bd6f6 100644 --- a/app/presenters/document_collection_presenter.rb +++ b/app/presenters/document_collection_presenter.rb @@ -30,14 +30,14 @@ def group_document_links(group, group_index) text: link["title"], path: link["base_path"], data_attributes: { - track_category: 'navDocumentCollectionLinkClicked', + track_category: "navDocumentCollectionLinkClicked", track_action: "#{group_index + 1}.#{link_index + 1}", track_label: link["base_path"], track_options: { - dimension28: group['documents'].count.to_s, - dimension29: link["title"] - } - } + dimension28: group["documents"].count.to_s, + dimension29: link["title"], + }, + }, }, metadata: { public_updated_at: link["public_updated_at"]&.then { |time| Time.zone.parse(time) }, @@ -62,7 +62,7 @@ def group_documents(group) end def group_title_id(title) - title.tr(' ', '-').downcase + title.tr(" ", "-").downcase end def documents_hash @@ -77,6 +77,6 @@ def reject_withdrawn_documents(group) def first_item @body ||= body.present? ? parsed_body : Nokogiri::HTML(groups.first["body"]) - @body.css('div').first.first_element_child + @body.css("div").first.first_element_child end end diff --git a/app/presenters/fatality_notice_presenter.rb b/app/presenters/fatality_notice_presenter.rb index eb0418269..712ef8a3b 100644 --- a/app/presenters/fatality_notice_presenter.rb +++ b/app/presenters/fatality_notice_presenter.rb @@ -18,7 +18,7 @@ def image def important_metadata super.tap do |m| if field_of_operation - m.merge!('Field of operation' => link_to(field_of_operation.title, field_of_operation.path, class: "govuk-link app-link")) + m.merge!("Field of operation" => link_to(field_of_operation.title, field_of_operation.path, class: "govuk-link app-link")) end end end diff --git a/app/presenters/gone_presenter.rb b/app/presenters/gone_presenter.rb index 1f595acba..1aac28389 100644 --- a/app/presenters/gone_presenter.rb +++ b/app/presenters/gone_presenter.rb @@ -3,8 +3,8 @@ class GonePresenter < ContentItemPresenter def initialize(content_item, requested_content_item_path = nil) super - @explanation = content_item['details']['explanation'] - @alternative_path = content_item['details']['alternative_path'] + @explanation = content_item["details"]["explanation"] + @alternative_path = content_item["details"]["alternative_path"] end def page_title diff --git a/app/presenters/guide_presenter.rb b/app/presenters/guide_presenter.rb index 25d8f776d..3c32d03cc 100644 --- a/app/presenters/guide_presenter.rb +++ b/app/presenters/guide_presenter.rb @@ -15,7 +15,7 @@ def has_parts? unless parts.any? GovukError.notify( "Guide with no parts", - extra: { error_message: "Guide rendered without any parts at #{base_path}" } + extra: { error_message: "Guide rendered without any parts at #{base_path}" }, ) end @@ -34,7 +34,7 @@ def print_link def parts if draft_access_token super.each do |part| - part['full_path'] = "#{part['full_path']}?#{draft_access_token_param}" + part["full_path"] = "#{part['full_path']}?#{draft_access_token_param}" end else super diff --git a/app/presenters/publication_presenter.rb b/app/presenters/publication_presenter.rb index 7a442b334..14cfac43a 100644 --- a/app/presenters/publication_presenter.rb +++ b/app/presenters/publication_presenter.rb @@ -9,7 +9,7 @@ def details end def documents - documents_list.join('') + documents_list.join("") end def documents_count diff --git a/app/presenters/service_sign_in/choose_sign_in_presenter.rb b/app/presenters/service_sign_in/choose_sign_in_presenter.rb index 648b1bd0d..086ac6fac 100644 --- a/app/presenters/service_sign_in/choose_sign_in_presenter.rb +++ b/app/presenters/service_sign_in/choose_sign_in_presenter.rb @@ -49,7 +49,7 @@ def options_id end def back_link - content_item['links']['parent'].first['base_path'] + content_item["links"]["parent"].first["base_path"] end def selected_option(selected_value) @@ -83,7 +83,7 @@ def symbolized_options def options_with_text # Sometimes the dummy store can produce options without text, may be a bug since # the content schemas [specify these as required](https://github.com/alphagov/govuk-content-schemas/blob/master/formats/service_sign_in.jsonnet#L39-L45) - choose_sign_in["options"].select { |option| option['text'].present? } + choose_sign_in["options"].select { |option| option["text"].present? } end end end diff --git a/app/presenters/specialist_document_presenter.rb b/app/presenters/specialist_document_presenter.rb index f2dfcba8b..6dfe91165 100644 --- a/app/presenters/specialist_document_presenter.rb +++ b/app/presenters/specialist_document_presenter.rb @@ -27,7 +27,7 @@ def metadata def important_metadata super.tap do |m| facets_with_friendly_values.each do |facet| - m.merge!(facet['name'] => value_or_array_of_values(facet['values'])) + m.merge!(facet["name"] => value_or_array_of_values(facet["values"])) end end end @@ -48,7 +48,7 @@ def will_continue_on def finder_link if finder && statutory_instrument? - link_to "See all #{finder['title']}", finder['base_path'] + link_to "See all #{finder['title']}", finder["base_path"] end end @@ -84,7 +84,7 @@ def finder if parent_finder.nil? GovukError.notify( "Finder not found", - extra: { error_message: "Finder not found in #{base_path} content item" } + extra: { error_message: "Finder not found in #{base_path} content item" }, ) end @@ -93,7 +93,8 @@ def finder def facets return nil unless finder - finder.dig('details', 'facets') + + finder.dig("details", "facets") end def facet_values @@ -103,14 +104,14 @@ def facet_values def facets_with_friendly_values sorted_facets_with_values.map do |facet| - facet_key = facet['key'] + facet_key = facet["key"] # Cast all values into an array values = [facet_values[facet_key]].flatten - facet['values'] = case facet['type'] - when 'date' + facet["values"] = case facet["type"] + when "date" friendly_facet_date(values) - when 'text' + when "text" friendly_facet_text(facet, values) else values @@ -124,9 +125,9 @@ def sorted_facets_with_values return [] unless facets && facet_values.any? facets - .select { |f| facet_values[f['key']] && facet_values[f['key']].present? } - .reject { |f| f['key'] == first_published_at_facet_key } - .sort_by { |f| f['type'] } + .select { |f| facet_values[f["key"]] && facet_values[f["key"]].present? } + .reject { |f| f["key"] == first_published_at_facet_key } + .sort_by { |f| f["type"] } end def friendly_facet_date(dates) @@ -134,7 +135,7 @@ def friendly_facet_date(dates) end def friendly_facet_text(facet, values) - if facet['allowed_values'] && facet['allowed_values'].any? + if facet["allowed_values"] && facet["allowed_values"].any? facet_blocks(facet, values) else values @@ -152,7 +153,7 @@ def facet_blocks(facet, values) else GovukError.notify( "Facet value not in list of allowed values", - extra: { error_message: "Facet value '#{value}' not an allowed value for facet '#{facet['name']}' on #{base_path} content item" } + extra: { error_message: "Facet value '#{value}' not an allowed value for facet '#{facet['name']}' on #{base_path} content item" }, ) value end @@ -160,19 +161,20 @@ def facet_blocks(facet, values) end def facet_block(facet, allowed_value) - friendly_value = allowed_value['label'] + friendly_value = allowed_value["label"] + + return friendly_value unless facet["filterable"] - return friendly_value unless facet['filterable'] - facet_link(friendly_value, allowed_value['value'], facet['key']) + facet_link(friendly_value, allowed_value["value"], facet["key"]) end def facet_link(label, value, key) - finder_base_path = finder['base_path'] + finder_base_path = finder["base_path"] link_to(label, "#{finder_base_path}?#{key}%5B%5D=#{value}", class: "govuk-link app-link") end def first_published_at_facet_key - 'first_published_at' + "first_published_at" end # first_published_at does not have reliable data diff --git a/app/presenters/speech_presenter.rb b/app/presenters/speech_presenter.rb index 7ab3d98aa..e88d0b6f0 100644 --- a/app/presenters/speech_presenter.rb +++ b/app/presenters/speech_presenter.rb @@ -8,10 +8,10 @@ class SpeechPresenter < ContentItemPresenter include ContentItem::NewsImage def delivery_type - if document_type == 'authored_article' - 'Written on' + if document_type == "authored_article" + "Written on" else - 'Delivered on' + "Delivered on" end end diff --git a/app/presenters/statistics_announcement_presenter.rb b/app/presenters/statistics_announcement_presenter.rb index a2a71135a..36dbe2186 100644 --- a/app/presenters/statistics_announcement_presenter.rb +++ b/app/presenters/statistics_announcement_presenter.rb @@ -12,6 +12,7 @@ def release_date def release_date_and_status return "#{release_date} (#{state})" unless cancelled? + release_date end @@ -28,7 +29,7 @@ def important_metadata if cancelled? m.merge!( "Proposed release" => release_date, - "Cancellation date" => cancellation_date + "Cancellation date" => cancellation_date, ) else m.merge!("Release date" => release_date_and_status) @@ -37,7 +38,7 @@ def important_metadata end def national_statistics? - content_item["details"]["format_sub_type"] == 'national' + content_item["details"]["format_sub_type"] == "national" end def cancellation_date diff --git a/app/presenters/travel_advice_presenter.rb b/app/presenters/travel_advice_presenter.rb index d94e058c9..e76941255 100644 --- a/app/presenters/travel_advice_presenter.rb +++ b/app/presenters/travel_advice_presenter.rb @@ -13,8 +13,8 @@ def page_title end def metadata - reviewed_at = content_item['details']['reviewed_at'] - updated_at = content_item['details']['updated_at'] + reviewed_at = content_item["details"]["reviewed_at"] + updated_at = content_item["details"]["updated_at"] other = { "Still current at" => I18n.l(Time.zone.now, format: "%-d %B %Y"), @@ -24,14 +24,14 @@ def metadata other["Latest update"] = simple_format(latest_update) if latest_update.present? { - other: other + other: other, } end def title_and_context { - context: 'Foreign travel advice', - title: country_name + context: "Foreign travel advice", + title: country_name, } end @@ -81,7 +81,7 @@ def alert_status end end - alert_statuses.join('').html_safe + alert_statuses.join("").html_safe end def atom_change_description @@ -94,6 +94,7 @@ def atom_public_updated_at def cache_control_max_age(format) return ATOM_CACHE_CONTROL_MAX_AGE if format == "atom" + content_item.cache_control.max_age end @@ -108,12 +109,12 @@ def summary_part { "title" => "Summary", "slug" => "", - "body" => content_item["details"]["summary"] + "body" => content_item["details"]["summary"], } end def change_description - content_item['details']['change_description'] + content_item["details"]["change_description"] end # FIXME: Update publishing app UI and remove from content @@ -124,7 +125,7 @@ def change_description # has a latest update label, so we can strip this out. # Avoids: "Latest update: Latest update - …" def latest_update - change_description.sub(/^Latest update:?\s-?\s?/i, '').tap do |latest| + change_description.sub(/^Latest update:?\s-?\s?/i, "").tap do |latest| latest[0] = latest[0].capitalize if latest.present? end end diff --git a/app/presenters/unpublishing_presenter.rb b/app/presenters/unpublishing_presenter.rb index 153cf9b42..2f7591fb4 100644 --- a/app/presenters/unpublishing_presenter.rb +++ b/app/presenters/unpublishing_presenter.rb @@ -3,8 +3,8 @@ class UnpublishingPresenter < ContentItemPresenter def initialize(content_item, requested_content_item_path = nil) super - @explanation = content_item['details']['explanation'] - @alternative_url = content_item['details']['alternative_url'] + @explanation = content_item["details"]["explanation"] + @alternative_url = content_item["details"]["alternative_url"] end def page_title diff --git a/app/presenters/working_group_presenter.rb b/app/presenters/working_group_presenter.rb index b14790a43..65d5073e3 100644 --- a/app/presenters/working_group_presenter.rb +++ b/app/presenters/working_group_presenter.rb @@ -15,6 +15,7 @@ def policies # When we upgrade to Ruby 2.3.0, this could be simplified with `dig`: # http://ruby-doc.org/core-2.3.0/Hash.html#method-i-dig return [] unless content_item["links"] && content_item["links"]["policies"] + content_item["links"]["policies"] end @@ -36,6 +37,7 @@ def extra_headings def first_item return if body.nil? + if parsed_body.css("h2").empty? parsed_body.css("div").first.try(:first_element_child) else diff --git a/config/application.rb b/config/application.rb index 8f90b9040..1eea9403b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,4 +1,4 @@ -require_relative 'boot' +require_relative "boot" # Pick the frameworks you want: require "active_model/railtie" @@ -19,7 +19,7 @@ class Application < Rails::Application # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - config.time_zone = 'London' + config.time_zone = "London" # Custom directories with classes and modules you want to be autoloadable. config.autoload_paths += %W(#{config.root}/lib) @@ -31,11 +31,11 @@ class Application < Rails::Application # Explicitly set available locales config.i18n.available_locales = [ :en, :ar, :az, :be, :bg, :bn, :cs, :cy, :da, :de, :dr, :el, - :es, 'es-419', :et, :fa, :fi, :fr, :gd, :he, :hi, :hr, :hu, + :es, "es-419", :et, :fa, :fi, :fr, :gd, :he, :hi, :hr, :hu, :hy, :id, :is, :it, :ja, :ka, :kk, :ko, :lt, :lv, :ms, :mt, :no, :nl, :pl, :ps, :pt, :ro, :ru, :si, :sk, :sl, :so, :sq, :sr, :sv, :sw, :ta, :th, :tk, :tr, :uk, :ur, :uz, :vi, :zh, - 'zh-hk', 'zh-tw' + "zh-hk", "zh-tw" ] # Enable locale fallbacks for I18n (makes lookups for any locale fall back to @@ -46,7 +46,7 @@ class Application < Rails::Application config.action_dispatch.rack_cache = nil # Path within public/ where assets are compiled to - config.assets.prefix = '/government-frontend' + config.assets.prefix = "/government-frontend" # Do not swallow errors in after_commit/after_rollback callbacks. # config.active_record.raise_in_transactional_callbacks = true diff --git a/config/boot.rb b/config/boot.rb index 30f5120df..282011619 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,3 @@ -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) -require 'bundler/setup' # Set up gems listed in the Gemfile. +require "bundler/setup" # Set up gems listed in the Gemfile. diff --git a/config/environment.rb b/config/environment.rb index 426333bb4..cac531577 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ # Load the Rails application. -require_relative 'application' +require_relative "application" # Initialize the Rails application. Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index 256ba3861..a953f8b63 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -13,12 +13,12 @@ config.consider_all_requests_local = true # Enable/disable caching. By default caching is disabled. - if Rails.root.join('tmp/caching-dev.txt').exist? + if Rails.root.join("tmp/caching-dev.txt").exist? config.action_controller.perform_caching = true config.cache_store = :memory_store config.public_file_server.headers = { - 'Cache-Control' => 'public, max-age=172800' + "Cache-Control" => "public, max-age=172800", } else config.action_controller.perform_caching = false @@ -52,7 +52,7 @@ # routes, locales, etc. This feature depends on the listen gem. # config.file_watcher = ActiveSupport::EventedFileUpdateChecker - if ENV['GOVUK_ASSET_ROOT'].present? - config.asset_host = ENV['GOVUK_ASSET_ROOT'] + if ENV["GOVUK_ASSET_ROOT"].present? + config.asset_host = ENV["GOVUK_ASSET_ROOT"] end end diff --git a/config/environments/production.rb b/config/environments/production.rb index 624ba682f..430105d66 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,8 +1,8 @@ Rails.application.configure do # Set GOVUK_ASSET_ROOT for heroku - for review apps we have the hostname set # at the time of the app being built so can't be set up in the app.json - if !ENV.include?('GOVUK_ASSET_ROOT') && ENV['HEROKU_APP_NAME'] - ENV['GOVUK_ASSET_ROOT'] = "https://#{ENV['HEROKU_APP_NAME']}.herokuapp.com" + if !ENV.include?("GOVUK_ASSET_ROOT") && ENV["HEROKU_APP_NAME"] + ENV["GOVUK_ASSET_ROOT"] = "https://#{ENV['HEROKU_APP_NAME']}.herokuapp.com" end # Settings specified here will take precedence over those in config/application.rb. @@ -22,7 +22,7 @@ # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier @@ -35,7 +35,7 @@ # Enable serving of images, stylesheets, and JavaScripts from an asset server. config.action_controller.asset_host = Plek.current.asset_root - config.slimmer.asset_host = Plek.current.find('static') + config.slimmer.asset_host = Plek.current.find("static") # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache diff --git a/config/environments/test.rb b/config/environments/test.rb index 8fddd1316..93d979cf9 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -15,7 +15,7 @@ # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - 'Cache-Control' => 'public, max-age=3600' + "Cache-Control" => "public, max-age=3600", } # Show full error reports and disable caching. diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index fe56f2619..fe039e753 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,7 +1,7 @@ # Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. -Rails.application.config.assets.version = '1.0' +Rails.application.config.assets.version = "1.0" # Add additional assets to the asset load path # Rails.application.config.assets.paths << Emoji.images_path diff --git a/config/initializers/feature_flags.rb b/config/initializers/feature_flags.rb index 47ce11bec..8c4e30726 100644 --- a/config/initializers/feature_flags.rb +++ b/config/initializers/feature_flags.rb @@ -1,7 +1,7 @@ module FeatureFlagNames def self.recommended_related_links - 'Govuk-Use-Recommended-Related-Links' + "Govuk-Use-Recommended-Related-Links" end end -HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, 'true') +HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, "true") diff --git a/config/routes.rb b/config/routes.rb index b79de125a..0eca6af76 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,25 +2,25 @@ unless Rails.env.production? # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html mount JasmineRails::Engine => "/specs" if defined?(JasmineRails) - get 'random/:schema' => 'randomly_generated_content_item#show' + get "random/:schema" => "randomly_generated_content_item#show" end - root to: 'development#index' + root to: "development#index" mount GovukPublishingComponents::Engine, at: "/component-guide" - get 'healthcheck', to: proc { [200, {}, ['']] } + get "healthcheck", to: proc { [200, {}, [""]] } - get '*path/:variant' => 'content_items#show', + get "*path/:variant" => "content_items#show", constraints: { - variant: /print/ + variant: /print/, } - get '*path(.:locale)(.:format)' => 'content_items#show', + get "*path(.:locale)(.:format)" => "content_items#show", constraints: { format: /atom/, locale: /\w{2}(-[\d\w]{2,3})?/, } - post '*path' => 'content_items#service_sign_in_options' + post "*path" => "content_items#service_sign_in_options" end diff --git a/lib/helpers/document_types_helper.rb b/lib/helpers/document_types_helper.rb index 32a673355..cff7c0924 100644 --- a/lib/helpers/document_types_helper.rb +++ b/lib/helpers/document_types_helper.rb @@ -1,4 +1,4 @@ -require 'rest-client' +require "rest-client" class DocumentTypesHelper ALL_SEARCH_ENDPOINT = "https://www.gov.uk/api/search.json?facet_content_store_document_type=100,example_scope:global,examples:%s&filter_rendering_app=government-frontend&count=0".freeze diff --git a/lib/helpers/wraith_config_helper.rb b/lib/helpers/wraith_config_helper.rb index dab61c377..0578f6b68 100644 --- a/lib/helpers/wraith_config_helper.rb +++ b/lib/helpers/wraith_config_helper.rb @@ -2,7 +2,7 @@ class WraithConfigHelper attr_accessor :name, :paths TEMPLATE_PATH = "test/wraith/config.yaml".freeze - OUTPUT_PATH = 'test/wraith/wip-config-%s.yaml'.freeze + OUTPUT_PATH = "test/wraith/wip-config-%s.yaml".freeze def initialize(name, paths) @name = name @@ -45,7 +45,7 @@ def path_index(prefix, index) def write_config(config) file_name = OUTPUT_PATH % { suffix: @name } - File.open(file_name, 'w') { |f| f.write config.to_yaml } + File.open(file_name, "w") { |f| f.write config.to_yaml } file_name end end diff --git a/lib/tasks/jasmine.rake b/lib/tasks/jasmine.rake index 554e35d54..c9ae8b9f2 100644 --- a/lib/tasks/jasmine.rake +++ b/lib/tasks/jasmine.rake @@ -1 +1 @@ -Rake::Task[:default].enhance ['spec:javascript'] +Rake::Task[:default].enhance ["spec:javascript"] diff --git a/lib/tasks/testing.rake b/lib/tasks/testing.rake index ff1b8e168..a189f134b 100644 --- a/lib/tasks/testing.rake +++ b/lib/tasks/testing.rake @@ -1,4 +1,4 @@ -require 'rake/testtask' +require "rake/testtask" namespace :test do Rake::TestTask.new(presenters: "test:prepare") do |t| diff --git a/lib/tasks/wraith.rake b/lib/tasks/wraith.rake index a72da5195..8b22d0448 100644 --- a/lib/tasks/wraith.rake +++ b/lib/tasks/wraith.rake @@ -1,4 +1,4 @@ -require 'rest-client' +require "rest-client" require "#{Rails.root}/lib/helpers/wraith_config_helper.rb" require "#{Rails.root}/lib/helpers/document_types_helper.rb" diff --git a/test/component_test_helper.rb b/test/component_test_helper.rb index 2ba76858c..9ade067de 100644 --- a/test/component_test_helper.rb +++ b/test/component_test_helper.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class ComponentTestCase < ActionView::TestCase helper Rails.application.helpers diff --git a/test/components/back_to_top_test.rb b/test/components/back_to_top_test.rb index bc216aa04..d4f967b15 100644 --- a/test/components/back_to_top_test.rb +++ b/test/components/back_to_top_test.rb @@ -1,4 +1,4 @@ -require 'component_test_helper' +require "component_test_helper" class BackToTopTest < ComponentTestCase def component_name diff --git a/test/components/banner_test.rb b/test/components/banner_test.rb index d1cd176d6..2633df4c1 100644 --- a/test/components/banner_test.rb +++ b/test/components/banner_test.rb @@ -1,4 +1,4 @@ -require 'component_test_helper' +require "component_test_helper" class BannerTest < ComponentTestCase def component_name @@ -12,33 +12,33 @@ def component_name end test "renders a banner with text correctly" do - render_component(title: 'Summary', text: 'This was published under the 2010 to 2015 Conservative government') + render_component(title: "Summary", text: "This was published under the 2010 to 2015 Conservative government") assert_select ".app-c-banner--aside", false - assert_select ".app-c-banner__desc", text: 'This was published under the 2010 to 2015 Conservative government' + assert_select ".app-c-banner__desc", text: "This was published under the 2010 to 2015 Conservative government" end test "renders a banner with an aria label" do - render_component(title: 'Summary', text: 'Text') + render_component(title: "Summary", text: "Text") assert_select "section[aria-label]" end test "renders a banner with title and text correctly" do - render_component(title: 'Summary', text: 'This was published under the 2010 to 2015 Conservative government') + render_component(title: "Summary", text: "This was published under the 2010 to 2015 Conservative government") assert_select ".app-c-banner--aside", false - assert_select ".app-c-banner__title", text: 'Summary' - assert_select ".app-c-banner__desc", text: 'This was published under the 2010 to 2015 Conservative government' + assert_select ".app-c-banner__title", text: "Summary" + assert_select ".app-c-banner__desc", text: "This was published under the 2010 to 2015 Conservative government" end test "renders a banner with title, text and aside correctly" do - render_component(title: 'Summary', - text: 'This was published under the 2010 to 2015 Conservative government', - aside: 'This consultation ran from 9:30am on 30 January 2017 to 5pm on 28 February 2017') + render_component(title: "Summary", + text: "This was published under the 2010 to 2015 Conservative government", + aside: "This consultation ran from 9:30am on 30 January 2017 to 5pm on 28 February 2017") assert_select ".app-c-banner--aside" - assert_select ".app-c-banner__title", text: 'Summary' - assert_select ".app-c-banner__desc", text: 'This was published under the 2010 to 2015 Conservative government' - assert_select ".app-c-banner__desc", text: 'This consultation ran from 9:30am on 30 January 2017 to 5pm on 28 February 2017' + assert_select ".app-c-banner__title", text: "Summary" + assert_select ".app-c-banner__desc", text: "This was published under the 2010 to 2015 Conservative government" + assert_select ".app-c-banner__desc", text: "This consultation ran from 9:30am on 30 January 2017 to 5pm on 28 February 2017" end end diff --git a/test/components/contents_list_with_body_test.rb b/test/components/contents_list_with_body_test.rb index b66452a23..9d9d39307 100644 --- a/test/components/contents_list_with_body_test.rb +++ b/test/components/contents_list_with_body_test.rb @@ -1,4 +1,4 @@ -require 'component_test_helper' +require "component_test_helper" class ContentsListWithBodyTest < ComponentTestCase def component_path @@ -7,8 +7,8 @@ def component_path def contents_list [ - { href: '/one', text: "1. One" }, - { href: '/two', text: "2. Two" } + { href: "/one", text: "1. One" }, + { href: "/two", text: "2. Two" }, ] end diff --git a/test/components/download_link_test.rb b/test/components/download_link_test.rb index 587f12168..52b4f779b 100644 --- a/test/components/download_link_test.rb +++ b/test/components/download_link_test.rb @@ -1,4 +1,4 @@ -require 'component_test_helper' +require "component_test_helper" class DownloadLinkTest < ComponentTestCase def component_name @@ -12,12 +12,12 @@ def component_name end test "renders a download link correctly" do - render_component(href: '/download-me') + render_component(href: "/download-me") assert_select ".app-c-download-link[href=\"/download-me\"]" end test "renders a download link with custom link text correctly" do - render_component(href: '/download-map', link_text: 'Download this file') + render_component(href: "/download-map", link_text: "Download this file") assert_select ".app-c-download-link[href=\"/download-map\"]", text: "Download this file" end end diff --git a/test/components/error_message_test.rb b/test/components/error_message_test.rb index bcd19e53b..cbb98ffd3 100644 --- a/test/components/error_message_test.rb +++ b/test/components/error_message_test.rb @@ -1,4 +1,4 @@ -require 'component_test_helper' +require "component_test_helper" class ErrorMessageTest < ComponentTestCase def component_name @@ -12,12 +12,12 @@ def component_name end test "renders an error message correctly" do - render_component(text: 'Descriptive error message') - assert_select ".app-c-error-message", text: 'Descriptive error message' + render_component(text: "Descriptive error message") + assert_select ".app-c-error-message", text: "Descriptive error message" end test "renders an error message with an id" do - render_component(text: 'Descriptive error message with id', id: 'unique-error-id') - assert_select ".app-c-error-message[id='unique-error-id']", text: 'Descriptive error message with id' + render_component(text: "Descriptive error message with id", id: "unique-error-id") + assert_select ".app-c-error-message[id='unique-error-id']", text: "Descriptive error message with id" end end diff --git a/test/components/figure_test.rb b/test/components/figure_test.rb index c35313546..efd4d6b7a 100644 --- a/test/components/figure_test.rb +++ b/test/components/figure_test.rb @@ -1,4 +1,4 @@ -require 'component_test_helper' +require "component_test_helper" class FigureTest < ComponentTestCase def component_name @@ -12,30 +12,30 @@ def component_name end test "renders a figure correctly" do - render_component(src: '/image', alt: 'image alt text') + render_component(src: "/image", alt: "image alt text") assert_select ".app-c-figure__image[src=\"/image\"]" assert_select ".app-c-figure__image[alt=\"image alt text\"]" end test "renders a figure with caption correctly" do - render_component(src: '/image', alt: 'image alt text', caption: 'This is a caption') + render_component(src: "/image", alt: "image alt text", caption: "This is a caption") assert_select ".app-c-figure__image[src=\"/image\"]" assert_select ".app-c-figure__image[alt=\"image alt text\"]" - assert_select ".app-c-figure__figcaption .app-c-figure__figcaption-text", text: 'This is a caption' + assert_select ".app-c-figure__figcaption .app-c-figure__figcaption-text", text: "This is a caption" end test "renders a figure with credit correctly" do - render_component(src: '/image', alt: 'image alt text', credit: 'Creative Commons') + render_component(src: "/image", alt: "image alt text", credit: "Creative Commons") assert_select ".app-c-figure__image[src=\"/image\"]" assert_select ".app-c-figure__image[alt=\"image alt text\"]" - assert_select ".app-c-figure__figcaption .app-c-figure__figcaption-credit", text: 'Image credit: Creative Commons' + assert_select ".app-c-figure__figcaption .app-c-figure__figcaption-credit", text: "Image credit: Creative Commons" end test "renders a figure with caption and credit correctly" do - render_component(src: '/image', alt: 'image alt text', caption: 'This is a caption', credit: 'Creative Commons') + render_component(src: "/image", alt: "image alt text", caption: "This is a caption", credit: "Creative Commons") assert_select ".app-c-figure__image[src=\"/image\"]" assert_select ".app-c-figure__image[alt=\"image alt text\"]" - assert_select ".app-c-figure__figcaption .app-c-figure__figcaption-text", text: 'This is a caption' - assert_select ".app-c-figure__figcaption .app-c-figure__figcaption-credit", text: 'Image credit: Creative Commons' + assert_select ".app-c-figure__figcaption .app-c-figure__figcaption-text", text: "This is a caption" + assert_select ".app-c-figure__figcaption .app-c-figure__figcaption-credit", text: "Image credit: Creative Commons" end end diff --git a/test/components/important_metadata_test.rb b/test/components/important_metadata_test.rb index 209b651fd..f15903abc 100644 --- a/test/components/important_metadata_test.rb +++ b/test/components/important_metadata_test.rb @@ -1,4 +1,4 @@ -require 'component_test_helper' +require "component_test_helper" class ImportantMetadataTest < ComponentTestCase def component_name @@ -16,10 +16,10 @@ def component_name test "renders a title when a title is provided" do render_component( - title: 'The release date has been changed', + title: "The release date has been changed", items: { - "Release Date": "14 October 2016" - } + "Release Date": "14 October 2016", + }, ) assert_select ".app-c-important-metadata__title", text: "The release date has been changed" diff --git a/test/components/print_link_test.rb b/test/components/print_link_test.rb index a9f189601..b98138de8 100644 --- a/test/components/print_link_test.rb +++ b/test/components/print_link_test.rb @@ -1,4 +1,4 @@ -require 'component_test_helper' +require "component_test_helper" class PrintLinkTest < ComponentTestCase def component_name @@ -13,17 +13,17 @@ def component_name test "fails to render a print link when no href is given but custom text is" do assert_raise do - render_component(link_text: 'test') + render_component(link_text: "test") end end test "renders a print link correctly" do - render_component(href: '#') + render_component(href: "#") assert_select ".app-c-print-link .app-c-print-link__link[href=\"#\"]" end test "renders a print link with custom link text correctly" do - render_component(href: '#print', link_text: 'Some new link text') + render_component(href: "#print", link_text: "Some new link text") assert_select ".app-c-print-link .app-c-print-link__link[href=\"#print\"]", text: "Some new link text" end end diff --git a/test/components/published_dates_test.rb b/test/components/published_dates_test.rb index 7769d0318..c14110e28 100644 --- a/test/components/published_dates_test.rb +++ b/test/components/published_dates_test.rb @@ -1,4 +1,4 @@ -require 'component_test_helper' +require "component_test_helper" class PublishedDatesTest < ComponentTestCase def component_name @@ -29,7 +29,7 @@ def component_name render_component( published: "1st November 2000", last_updated: "15th July 2015", - history: [display_time: "23 August 2013", note: "Updated with new data"] + history: [display_time: "23 August 2013", note: "Updated with new data"], ) assert_select ".app-c-published-dates__change-history#full-history" assert_select ".app-c-published-dates--history .app-c-published-dates__change-date", text: "23 August 2013" @@ -42,7 +42,7 @@ def component_name render_component( published: "1st November 2000", last_updated: "15th July 2015", - history: [display_time: "23 August 2013", note: "Updated with new data"] + history: [display_time: "23 August 2013", note: "Updated with new data"], ) assert_select "#history" end @@ -51,7 +51,7 @@ def component_name render_component( published: "1st November 2000", last_updated: "15th July 2015", - history: [display_time: "23 August 2013", note: "Updated with new data"] + history: [display_time: "23 August 2013", note: "Updated with new data"], ) assert_select ".app-c-published-dates__change-history.js-hidden" end @@ -60,7 +60,7 @@ def component_name render_component( published: "1st November 2000", last_updated: "15th July 2015", - history: [display_time: "23 August 2013", note: "Updated with new data"] + history: [display_time: "23 August 2013", note: "Updated with new data"], ) assert_select ".app-c-published-dates a[href=\"#full-history\"]" end @@ -69,7 +69,7 @@ def component_name render_component( published: "1st November 2000", last_updated: "15th July 2015", - history: [display_time: "23 August 2013", note: "Updated with new data"] + history: [display_time: "23 August 2013", note: "Updated with new data"], ) assert_select ".app-c-published-dates--history[data-module=\"toggle\"]" assert_select ".app-c-published-dates--history a[href=\"#full-history\"][data-controls=\"full-history\"]" diff --git a/test/components/publisher_metadata_test.rb b/test/components/publisher_metadata_test.rb index 96a6a0c82..70e1e29cc 100644 --- a/test/components/publisher_metadata_test.rb +++ b/test/components/publisher_metadata_test.rb @@ -1,4 +1,4 @@ -require 'component_test_helper' +require "component_test_helper" class PublisherMetadataTest < ComponentTestCase def component_name @@ -16,22 +16,22 @@ def component_name test "renders a from link when from data is given" do render_component(other: { From: ["Ministry of Defence"] }) - assert_select ".app-c-publisher-metadata__other a[href='/government/organisations/ministry-of-defence']", text: 'Ministry of Defence' - assert_select ".app-c-publisher-metadata__other dt", text: 'From:' - assert_select ".app-c-publisher-metadata__other dd", text: 'Ministry of Defence' + assert_select ".app-c-publisher-metadata__other a[href='/government/organisations/ministry-of-defence']", text: "Ministry of Defence" + assert_select ".app-c-publisher-metadata__other dt", text: "From:" + assert_select ".app-c-publisher-metadata__other dd", text: "Ministry of Defence" end test "renders two from links when two publishers are given" do render_component(other: { from: ["Ministry of Defence", "Education Funding Agency"] }) - assert_select ".app-c-publisher-metadata__other a[href='/government/organisations/ministry-of-defence']", text: 'Ministry of Defence' - assert_select ".app-c-publisher-metadata__other a[href='/government/organisations/education-funding-agency']", text: 'Education Funding Agency' + assert_select ".app-c-publisher-metadata__other a[href='/government/organisations/ministry-of-defence']", text: "Ministry of Defence" + assert_select ".app-c-publisher-metadata__other a[href='/government/organisations/education-funding-agency']", text: "Education Funding Agency" end test "renders a sentence when multiple publishers are given" do render_component(other: { from: ["Department for Education", "Education Funding Agency"] }) - assert_select ".app-c-publisher-metadata__other dt", text: 'From:' - assert_select ".app-c-publisher-metadata__other dd", text: 'Department for Education and Education Funding Agency' + assert_select ".app-c-publisher-metadata__other dt", text: "From:" + assert_select ".app-c-publisher-metadata__other dd", text: "Department for Education and Education Funding Agency" end test "renders published dates component when only published date is given" do @@ -47,9 +47,9 @@ def component_name test "renders full metadata component when all parameters are given" do render_component(other: { from: ["Ministry of Defence"] }, published: "31 July 2017", last_updated: "20 September 2017", link_to_history: true) assert_select ".app-c-published-dates" - assert_select ".app-c-publisher-metadata__other a[href='/government/organisations/ministry-of-defence']", text: 'Ministry of Defence' - assert_select ".app-c-publisher-metadata__other dt", text: 'From:' - assert_select ".app-c-publisher-metadata__other dd", text: 'Ministry of Defence' + assert_select ".app-c-publisher-metadata__other a[href='/government/organisations/ministry-of-defence']", text: "Ministry of Defence" + assert_select ".app-c-publisher-metadata__other dt", text: "From:" + assert_select ".app-c-publisher-metadata__other dd", text: "Ministry of Defence" end test "link tracking is enabled" do @@ -59,18 +59,18 @@ def component_name test "renders two collection links when two collections are given" do render_component(other: { collections: ["Tribunals statistics", "Civil justice statistics quarterly"] }) - assert_select ".app-c-publisher-metadata__other dt", text: 'Collections:' - assert_select ".app-c-publisher-metadata__other dd a[href='/government/collections/tribunals-statistics']", text: 'Tribunals statistics' - assert_select ".app-c-publisher-metadata__other dd a[href='/government/collections/civil-justice-statistics-quarterly']", text: 'Civil justice statistics quarterly' + assert_select ".app-c-publisher-metadata__other dt", text: "Collections:" + assert_select ".app-c-publisher-metadata__other dd a[href='/government/collections/tribunals-statistics']", text: "Tribunals statistics" + assert_select ".app-c-publisher-metadata__other dd a[href='/government/collections/civil-justice-statistics-quarterly']", text: "Civil justice statistics quarterly" end test "renders the first collection and a toggle link when more than two collections are given" do render_component(other: { collections: ["Tribunals statistics", "Civil justice statistics quarterly", "Offender management statistics quarterly"] }) - assert_select ".app-c-publisher-metadata__other dt", text: 'Collections:' - assert_select ".app-c-publisher-metadata__other .app-c-publisher-metadata__definition-sentence", text: 'Tribunals statistics, and 2 others' - assert_select ".app-c-publisher-metadata__other a", text: '+ show all' - assert_select ".app-c-publisher-metadata__other a[href='/government/collections/tribunals-statistics']", text: 'Tribunals statistics' - assert_select ".app-c-publisher-metadata__other a[href='/government/collections/civil-justice-statistics-quarterly']", text: 'Civil justice statistics quarterly' - assert_select ".app-c-publisher-metadata__other a[href='/government/collections/offender-management-statistics-quarterly']", text: 'Offender management statistics quarterly' + assert_select ".app-c-publisher-metadata__other dt", text: "Collections:" + assert_select ".app-c-publisher-metadata__other .app-c-publisher-metadata__definition-sentence", text: "Tribunals statistics, and 2 others" + assert_select ".app-c-publisher-metadata__other a", text: "+ show all" + assert_select ".app-c-publisher-metadata__other a[href='/government/collections/tribunals-statistics']", text: "Tribunals statistics" + assert_select ".app-c-publisher-metadata__other a[href='/government/collections/civil-justice-statistics-quarterly']", text: "Civil justice statistics quarterly" + assert_select ".app-c-publisher-metadata__other a[href='/government/collections/offender-management-statistics-quarterly']", text: "Offender management statistics quarterly" end end diff --git a/test/contracts/govuk_content_schemas_test.rb b/test/contracts/govuk_content_schemas_test.rb index 6da680085..9ac9a272f 100644 --- a/test/contracts/govuk_content_schemas_test.rb +++ b/test/contracts/govuk_content_schemas_test.rb @@ -1,13 +1,13 @@ -require 'test_helper' +require "test_helper" class GovukContentSchemasTest < ActionDispatch::IntegrationTest include GovukContentSchemaExamples all_examples_for_supported_schemas.each do |content_item| test "can successfully render #{content_item['base_path']} schema example" do - content_store_has_item(content_item['base_path'], content_item) + content_store_has_item(content_item["base_path"], content_item) - get content_item['base_path'] + get content_item["base_path"] assert_response :success end diff --git a/test/controllers/content_items_controller_test.rb b/test/controllers/content_items_controller_test.rb index 3b31df16b..b06e9dd42 100644 --- a/test/controllers/content_items_controller_test.rb +++ b/test/controllers/content_items_controller_test.rb @@ -1,63 +1,63 @@ -require 'test_helper' +require "test_helper" class ContentItemsControllerTest < ActionController::TestCase include GdsApi::TestHelpers::ContentStore include GovukAbTesting::MinitestHelpers - test 'routing handles paths with no format or locale' do + test "routing handles paths with no format or locale" do assert_routing( - '/government/news/statement-the-status-of-eu-nationals-in-the-uk', - controller: 'content_items', - action: 'show', - path: 'government/news/statement-the-status-of-eu-nationals-in-the-uk', + "/government/news/statement-the-status-of-eu-nationals-in-the-uk", + controller: "content_items", + action: "show", + path: "government/news/statement-the-status-of-eu-nationals-in-the-uk", ) end - test 'routing handles paths for all supported locales' do + test "routing handles paths for all supported locales" do I18n.available_locales.each do |locale| assert_routing( "/government/news/statement-the-status-of-eu-nationals-in-the-uk.#{locale}", - controller: 'content_items', - action: 'show', - path: 'government/news/statement-the-status-of-eu-nationals-in-the-uk', - locale: locale.to_s + controller: "content_items", + action: "show", + path: "government/news/statement-the-status-of-eu-nationals-in-the-uk", + locale: locale.to_s, ) end end - test 'routing handles paths with just format' do + test "routing handles paths with just format" do assert_routing( - '/government/news/statement-the-status-of-eu-nationals-in-the-uk.atom', - controller: 'content_items', - action: 'show', - path: 'government/news/statement-the-status-of-eu-nationals-in-the-uk', - format: 'atom', + "/government/news/statement-the-status-of-eu-nationals-in-the-uk.atom", + controller: "content_items", + action: "show", + path: "government/news/statement-the-status-of-eu-nationals-in-the-uk", + format: "atom", ) end - test 'routing handles paths with format and locale' do + test "routing handles paths with format and locale" do assert_routing( - '/government/news/statement-the-status-of-eu-nationals-in-the-uk.es.atom', - controller: 'content_items', - action: 'show', - path: 'government/news/statement-the-status-of-eu-nationals-in-the-uk', - format: 'atom', - locale: 'es' + "/government/news/statement-the-status-of-eu-nationals-in-the-uk.es.atom", + controller: "content_items", + action: "show", + path: "government/news/statement-the-status-of-eu-nationals-in-the-uk", + format: "atom", + locale: "es", ) end - test 'routing handles paths with print variant' do + test "routing handles paths with print variant" do assert_routing( - '/government/news/statement-the-status-of-eu-nationals-in-the-uk/print', - controller: 'content_items', - action: 'show', - path: 'government/news/statement-the-status-of-eu-nationals-in-the-uk', - variant: 'print' + "/government/news/statement-the-status-of-eu-nationals-in-the-uk/print", + controller: "content_items", + action: "show", + path: "government/news/statement-the-status-of-eu-nationals-in-the-uk", + variant: "print", ) end test "redirects route with invalid parts to base path" do - content_item = content_store_has_schema_example('travel_advice', 'full-country') + content_item = content_store_has_schema_example("travel_advice", "full-country") invalid_part_path = "#{path_for(content_item)}/not-a-valid-part" # The content store performs a 301 to the base path when requesting a content item @@ -69,11 +69,11 @@ class ContentItemsControllerTest < ActionController::TestCase get :show, params: { path: invalid_part_path } assert_response :redirect - assert_redirected_to content_item['base_path'] + assert_redirected_to content_item["base_path"] end test "redirects route for first path to base path" do - content_item = content_store_has_schema_example('guide', 'guide') + content_item = content_store_has_schema_example("guide", "guide") invalid_part_path = "#{path_for(content_item)}/#{content_item['details']['parts'].first['slug']}" stub_request(:get, %r{#{invalid_part_path}}).to_return(status: 200, body: content_item.to_json, headers: {}) @@ -83,28 +83,28 @@ class ContentItemsControllerTest < ActionController::TestCase get :show, params: { path: invalid_part_path } assert_response :redirect - assert_redirected_to content_item['base_path'] + assert_redirected_to content_item["base_path"] end test "returns HTML when an unspecific accepts header is requested (eg by IE8 and below)" do request.headers["Accept"] = "*/*" - content_item = content_store_has_schema_example('travel_advice', 'full-country') + content_item = content_store_has_schema_example("travel_advice", "full-country") get :show, params: { - path: path_for(content_item) + path: path_for(content_item), } - assert_match(/text\/html/, response.headers['Content-Type']) + assert_match(/text\/html/, response.headers["Content-Type"]) assert_response :success - assert_select '#wrapper' + assert_select "#wrapper" end test "returns a 406 for XMLHttpRequests without an Accept header set to a supported format" do request.headers["X-Requested-With"] = "XMLHttpRequest" - content_item = content_store_has_schema_example('case_study', 'case_study') + content_item = content_store_has_schema_example("case_study", "case_study") get :show, params: { - path: path_for(content_item) + path: path_for(content_item), } assert_response :not_acceptable @@ -112,146 +112,146 @@ class ContentItemsControllerTest < ActionController::TestCase test "returns a 406 for unsupported format requests, eg text/javascript" do request.headers["Accept"] = "text/javascript" - content_item = content_store_has_schema_example('case_study', 'case_study') + content_item = content_store_has_schema_example("case_study", "case_study") get :show, params: { - path: path_for(content_item) + path: path_for(content_item), } assert_response :not_acceptable end test "gets item from content store" do - content_item = content_store_has_schema_example('case_study', 'case_study') + content_item = content_store_has_schema_example("case_study", "case_study") get :show, params: { path: path_for(content_item) } assert_response :success - assert_equal content_item['title'], assigns[:content_item].title + assert_equal content_item["title"], assigns[:content_item].title end test "gets item from content store and keeps existing ordered_related_items when feature flag header not specified" do - HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, 'true') - content_item = content_store_has_schema_example('case_study', 'case_study') + HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, "true") + content_item = content_store_has_schema_example("case_study", "case_study") get :show, params: { path: path_for(content_item) } assert_response :success - assert_equal content_item['links']['ordered_related_items'], assigns[:content_item].content_item['links']['ordered_related_items'] + assert_equal content_item["links"]["ordered_related_items"], assigns[:content_item].content_item["links"]["ordered_related_items"] end test "gets item from content store and keep existing ordered_related_items when feature flag header is specified but links already exist" do - HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, 'true') - request.headers["HTTP_GOVUK_USE_RECOMMENDED_RELATED_LINKS"] = 'true' + HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, "true") + request.headers["HTTP_GOVUK_USE_RECOMMENDED_RELATED_LINKS"] = "true" - content_item = content_store_has_schema_example('guide', 'guide') + content_item = content_store_has_schema_example("guide", "guide") get :show, params: { path: path_for(content_item) } assert_response :success - refute_empty content_item['links']['ordered_related_items'], 'Content item should have existing related links' - refute_empty content_item['links']['suggested_ordered_related_items'], 'Content item should have existing suggested related links' - assert_equal content_item['links']['ordered_related_items'], assigns[:content_item].content_item['links']['ordered_related_items'] + refute_empty content_item["links"]["ordered_related_items"], "Content item should have existing related links" + refute_empty content_item["links"]["suggested_ordered_related_items"], "Content item should have existing suggested related links" + assert_equal content_item["links"]["ordered_related_items"], assigns[:content_item].content_item["links"]["ordered_related_items"] end test "gets item from content store and does not change ordered_related_items when feature flag header is specified but link overrides exist" do - HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, 'true') - request.headers["HTTP_GOVUK_USE_RECOMMENDED_RELATED_LINKS"] = 'true' + HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, "true") + request.headers["HTTP_GOVUK_USE_RECOMMENDED_RELATED_LINKS"] = "true" - content_item = content_store_has_schema_example('guide', 'guide-with-related-link-overrides') + content_item = content_store_has_schema_example("guide", "guide-with-related-link-overrides") get :show, params: { path: path_for(content_item) } assert_response :success - assert_nil content_item['links']['ordered_related_items'], 'Content item should not have existing related links' - refute_empty content_item['links']['ordered_related_items_overrides'], 'Content item should have existing related link overrides' - refute_empty content_item['links']['suggested_ordered_related_items'], 'Content item should have existing suggested related links' - assert_nil content_item['links']['ordered_related_items'] + assert_nil content_item["links"]["ordered_related_items"], "Content item should not have existing related links" + refute_empty content_item["links"]["ordered_related_items_overrides"], "Content item should have existing related link overrides" + refute_empty content_item["links"]["suggested_ordered_related_items"], "Content item should have existing suggested related links" + assert_nil content_item["links"]["ordered_related_items"] end test "gets item from content store and keeps ordered_related_items when feature flag header is specified but recommended links turned off" do - HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, 'false') - request.headers["HTTP_GOVUK_USE_RECOMMENDED_RELATED_LINKS"] = 'true' + HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, "false") + request.headers["HTTP_GOVUK_USE_RECOMMENDED_RELATED_LINKS"] = "true" - content_item = content_store_has_schema_example('case_study', 'case_study') + content_item = content_store_has_schema_example("case_study", "case_study") get :show, params: { path: path_for(content_item) } assert_response :success - assert_empty content_item['links']['ordered_related_items'], 'Content item should have existing related links' - refute_empty content_item['links']['suggested_ordered_related_items'], 'Content item should have existing suggested related links' - assert_equal [], assigns[:content_item].content_item['links']['ordered_related_items'] + assert_empty content_item["links"]["ordered_related_items"], "Content item should have existing related links" + refute_empty content_item["links"]["suggested_ordered_related_items"], "Content item should have existing suggested related links" + assert_equal [], assigns[:content_item].content_item["links"]["ordered_related_items"] end test "gets item from content store and replaces ordered_related_items when feature flag header is specified and there are no existing links or overrides" do - HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, 'true') - request.headers["HTTP_GOVUK_USE_RECOMMENDED_RELATED_LINKS"] = 'true' + HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, "true") + request.headers["HTTP_GOVUK_USE_RECOMMENDED_RELATED_LINKS"] = "true" - content_item = content_store_has_schema_example('case_study', 'case_study') + content_item = content_store_has_schema_example("case_study", "case_study") get :show, params: { path: path_for(content_item) } assert_response :success - assert_empty content_item['links']['ordered_related_items'], 'Content item should not have existing related links' - refute_empty content_item['links']['suggested_ordered_related_items'], 'Content item should have existing suggested related links' - assert_equal assigns[:content_item].content_item['links']['ordered_related_items'], content_item['links']['suggested_ordered_related_items'] + assert_empty content_item["links"]["ordered_related_items"], "Content item should not have existing related links" + refute_empty content_item["links"]["suggested_ordered_related_items"], "Content item should have existing suggested related links" + assert_equal assigns[:content_item].content_item["links"]["ordered_related_items"], content_item["links"]["suggested_ordered_related_items"] end test "sets the Govuk-Use-Recommended-Links response header to false when request header is not set" do - HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, 'true') - content_item = content_store_has_schema_example('case_study', 'case_study') + HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, "true") + content_item = content_store_has_schema_example("case_study", "case_study") get :show, params: { path: path_for(content_item) } - assert_includes response.headers['Vary'], FeatureFlagNames.recommended_related_links - assert_equal 'false', response.headers[FeatureFlagNames.recommended_related_links] + assert_includes response.headers["Vary"], FeatureFlagNames.recommended_related_links + assert_equal "false", response.headers[FeatureFlagNames.recommended_related_links] end test "sets the Govuk-Use-Recommended-Links response header to false when request header is set to false" do - HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, 'true') - request.headers["HTTP_GOVUK_USE_RECOMMENDED_RELATED_LINKS"] = 'false' - content_item = content_store_has_schema_example('case_study', 'case_study') + HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, "true") + request.headers["HTTP_GOVUK_USE_RECOMMENDED_RELATED_LINKS"] = "false" + content_item = content_store_has_schema_example("case_study", "case_study") get :show, params: { path: path_for(content_item) } - assert_includes response.headers['Vary'], FeatureFlagNames.recommended_related_links - assert_equal 'false', response.headers[FeatureFlagNames.recommended_related_links] + assert_includes response.headers["Vary"], FeatureFlagNames.recommended_related_links + assert_equal "false", response.headers[FeatureFlagNames.recommended_related_links] end test "sets the Govuk-Use-Recommended-Links response header to true when request header is set to true" do - HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, 'true') - request.headers["HTTP_GOVUK_USE_RECOMMENDED_RELATED_LINKS"] = 'true' - content_item = content_store_has_schema_example('case_study', 'case_study') + HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, "true") + request.headers["HTTP_GOVUK_USE_RECOMMENDED_RELATED_LINKS"] = "true" + content_item = content_store_has_schema_example("case_study", "case_study") get :show, params: { path: path_for(content_item) } - assert_includes response.headers['Vary'], FeatureFlagNames.recommended_related_links - assert_equal 'true', response.headers[FeatureFlagNames.recommended_related_links] + assert_includes response.headers["Vary"], FeatureFlagNames.recommended_related_links + assert_equal "true", response.headers[FeatureFlagNames.recommended_related_links] end test "sets the expiry as sent by content-store" do - content_item = content_store_has_schema_example('coming_soon', 'coming_soon') - content_store_has_item(content_item['base_path'], content_item, max_age: 20) + content_item = content_store_has_schema_example("coming_soon", "coming_soon") + content_store_has_item(content_item["base_path"], content_item, max_age: 20) get :show, params: { path: path_for(content_item) } assert_response :success - assert_equal "max-age=20, public", @response.headers['Cache-Control'] + assert_equal "max-age=20, public", @response.headers["Cache-Control"] end test "sets a longer cache-control header for travel advice atom feeds" do - content_item = content_store_has_schema_example('travel_advice', 'full-country') - get :show, params: { path: path_for(content_item), format: 'atom' } + content_item = content_store_has_schema_example("travel_advice", "full-country") + get :show, params: { path: path_for(content_item), format: "atom" } assert_response :success - assert_equal "max-age=300, public", @response.headers['Cache-Control'] + assert_equal "max-age=300, public", @response.headers["Cache-Control"] end test "honours cache-control private items" do - content_item = content_store_has_schema_example('coming_soon', 'coming_soon') - content_store_has_item(content_item['base_path'], content_item, private: true) + content_item = content_store_has_schema_example("coming_soon", "coming_soon") + content_store_has_item(content_item["base_path"], content_item, private: true) get :show, params: { path: path_for(content_item) } assert_response :success - assert_equal "max-age=900, private", @response.headers['Cache-Control'] + assert_equal "max-age=900, private", @response.headers["Cache-Control"] end test "renders translated content items in their locale" do - content_item = content_store_has_schema_example('case_study', 'translated') - locale = content_item['locale'] + content_item = content_store_has_schema_example("case_study", "translated") + locale = content_item["locale"] translated_schema_name = I18n.t("content_item.schema_name.case_study", count: 1, locale: locale) get :show, params: { path: path_for(content_item, locale), locale: locale } @@ -261,16 +261,16 @@ class ContentItemsControllerTest < ActionController::TestCase end test "renders atom feeds" do - content_item = content_store_has_schema_example('travel_advice', 'full-country') - get :show, params: { path: path_for(content_item), format: 'atom' } + content_item = content_store_has_schema_example("travel_advice", "full-country") + get :show, params: { path: path_for(content_item), format: "atom" } assert_response :success - assert_select "feed title", 'Travel Advice Summary' + assert_select "feed title", "Travel Advice Summary" end test "renders print variants" do - content_item = content_store_has_schema_example('travel_advice', 'full-country') - get :show, params: { path: path_for(content_item), variant: 'print' } + content_item = content_store_has_schema_example("travel_advice", "full-country") + get :show, params: { path: path_for(content_item), variant: "print" } assert_response :success assert_equal request.variant, [:print] @@ -278,39 +278,39 @@ class ContentItemsControllerTest < ActionController::TestCase end test "gets item from content store even when url contains multi-byte UTF8 character" do - content_item = content_store_has_schema_example('case_study', 'case_study') + content_item = content_store_has_schema_example("case_study", "case_study") utf8_path = "government/case-studies/caf\u00e9-culture" - content_item['base_path'] = "/#{utf8_path}" + content_item["base_path"] = "/#{utf8_path}" - content_store_has_item(content_item['base_path'], content_item) + content_store_has_item(content_item["base_path"], content_item) get :show, params: { path: utf8_path } assert_response :success end test "returns 404 for invalid url" do - path = 'foreign-travel-advice/egypt]' + path = "foreign-travel-advice/egypt]" - content_store_does_not_have_item('/' + path) + content_store_does_not_have_item("/" + path) get :show, params: { path: path } assert_response :not_found end test "returns 404 for item not in content store" do - path = 'government/case-studies/boost-chocolate-production' + path = "government/case-studies/boost-chocolate-production" - content_store_does_not_have_item('/' + path) + content_store_does_not_have_item("/" + path) get :show, params: { path: path } assert_response :not_found end test "returns 404 if content store falls through to special route" do - path = 'government/item-not-here' + path = "government/item-not-here" - content_item = content_store_has_schema_example('special_route', 'special_route') - content_item['base_path'] = '/government' + content_item = content_store_has_schema_example("special_route", "special_route") + content_item["base_path"] = "/government" content_store_has_item("/#{path}", content_item) @@ -319,7 +319,7 @@ class ContentItemsControllerTest < ActionController::TestCase end test "returns 403 for access-limited item" do - path = 'government/case-studies/super-sekrit-document' + path = "government/case-studies/super-sekrit-document" url = content_store_endpoint + "/content/" + path stub_request(:get, url).to_return(status: 403, headers: {}) @@ -328,44 +328,44 @@ class ContentItemsControllerTest < ActionController::TestCase end test "returns 406 for schema types which don't support provided format" do - content_item_without_atom = content_store_has_schema_example('case_study', 'case_study') - get :show, params: { path: path_for(content_item_without_atom), format: 'atom' } + content_item_without_atom = content_store_has_schema_example("case_study", "case_study") + get :show, params: { path: path_for(content_item_without_atom), format: "atom" } assert_response :not_acceptable end test "returns 410 for content items that are gone" do - content_store_has_gone_item('/gone-item') - get :show, params: { path: 'gone-item' } + content_store_has_gone_item("/gone-item") + get :show, params: { path: "gone-item" } assert_response :gone end test "returns a redirect when content item is a redirect" do - content_item = content_store_has_schema_example('redirect', 'redirect') - content_store_has_item('/406beacon', content_item) + content_item = content_store_has_schema_example("redirect", "redirect") + content_store_has_item("/406beacon", content_item) - get :show, params: { path: '406beacon' } - assert_redirected_to 'https://www.test.gov.uk/maritime-safety-weather-and-navigation/register-406-mhz-beacons?query=answer#fragment' + get :show, params: { path: "406beacon" } + assert_redirected_to "https://www.test.gov.uk/maritime-safety-weather-and-navigation/register-406-mhz-beacons?query=answer#fragment" end test "returns a prefixed redirect when content item is a prefix redirect" do - content_item = content_store_has_schema_example('redirect', 'redirect') - content_store_has_item('/406beacon/prefix/to-preserve', content_item) + content_item = content_store_has_schema_example("redirect", "redirect") + content_store_has_item("/406beacon/prefix/to-preserve", content_item) - get :show, params: { path: '406beacon/prefix/to-preserve' } - assert_redirected_to 'https://www.test.gov.uk/new-406-beacons-destination/to-preserve' + get :show, params: { path: "406beacon/prefix/to-preserve" } + assert_redirected_to "https://www.test.gov.uk/new-406-beacons-destination/to-preserve" end test "sets the Access-Control-Allow-Origin header for atom pages" do - content_store_has_schema_example('travel_advice', 'full-country') - get :show, params: { path: 'foreign-travel-advice/albania', format: 'atom' } + content_store_has_schema_example("travel_advice", "full-country") + get :show, params: { path: "foreign-travel-advice/albania", format: "atom" } assert_equal response.headers["Access-Control-Allow-Origin"], "*" end def path_for(content_item, locale = nil) - base_path = content_item['base_path'].sub(/^\//, '') - base_path.gsub!(/\.#{locale}$/, '') if locale + base_path = content_item["base_path"].sub(/^\//, "") + base_path.gsub!(/\.#{locale}$/, "") if locale base_path end end diff --git a/test/controllers/service_sign_in_content_item_controller_test.rb b/test/controllers/service_sign_in_content_item_controller_test.rb index 342ea6222..3ba5ea116 100644 --- a/test/controllers/service_sign_in_content_item_controller_test.rb +++ b/test/controllers/service_sign_in_content_item_controller_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class ContentItemsControllerTest < ActionController::TestCase include GdsApi::TestHelpers::ContentStore @@ -62,9 +62,9 @@ class ContentItemsControllerTest < ActionController::TestCase content_item = content_store_has_schema_example("service_sign_in", "service_sign_in") path = "#{path_for(content_item)}/#{content_item['details']['choose_sign_in']['slug']}" - option = content_item['details']['choose_sign_in']['options'][0] - value = option['text'].parameterize - link = option['url'] + option = content_item["details"]["choose_sign_in"]["options"][0] + value = option["text"].parameterize + link = option["url"] stub_request(:get, %r{#{path}}).to_return(status: 200, body: content_item.to_json, headers: {}) @@ -102,14 +102,14 @@ class ContentItemsControllerTest < ActionController::TestCase test "includes _ga as a query param when redirecting if set" do content_item = govuk_content_schema_example("service_sign_in", "service_sign_in") - link = 'https://www.horse.service.gov.uk/account?horse=brown' - content_item['details']['choose_sign_in']['options'][0]['url'] = link - content_store_has_item(content_item['base_path'], content_item) + link = "https://www.horse.service.gov.uk/account?horse=brown" + content_item["details"]["choose_sign_in"]["options"][0]["url"] = link + content_store_has_item(content_item["base_path"], content_item) path = "#{path_for(content_item)}/#{content_item['details']['choose_sign_in']['slug']}" - option = content_item['details']['choose_sign_in']['options'][0] - value = option['text'].parameterize + option = content_item["details"]["choose_sign_in"]["options"][0] + value = option["text"].parameterize stub_request(:get, %r{#{path}}).to_return(status: 200, body: content_item.to_json, headers: {}) @@ -120,8 +120,8 @@ class ContentItemsControllerTest < ActionController::TestCase end def path_for(content_item, locale = nil) - base_path = content_item['base_path'].sub(/^\//, '') - base_path.gsub!(/\.#{locale}$/, '') if locale + base_path = content_item["base_path"].sub(/^\//, "") + base_path.gsub!(/\.#{locale}$/, "") if locale base_path end end diff --git a/test/controllers/step_navigation_controller_test.rb b/test/controllers/step_navigation_controller_test.rb index 295b4fab0..b3329323e 100644 --- a/test/controllers/step_navigation_controller_test.rb +++ b/test/controllers/step_navigation_controller_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class ContentItemsControllerTest < ActionController::TestCase include GdsApi::TestHelpers::ContentStore @@ -6,10 +6,10 @@ class ContentItemsControllerTest < ActionController::TestCase %w(guide answer publication).each do |schema_name| test "#{schema_name} shows step by step navigation where relevant" do content_item = content_store_has_schema_example(schema_name, "#{schema_name}-with-step-navs") - content_item['base_path'] = "/pass-plus" - path = content_item['base_path'][1..-1] + content_item["base_path"] = "/pass-plus" + path = content_item["base_path"][1..-1] - content_store_has_item(content_item['base_path'], content_item) + content_store_has_item(content_item["base_path"], content_item) @controller.stubs(:page_in_scope?).returns(false) @@ -21,10 +21,10 @@ class ContentItemsControllerTest < ActionController::TestCase test "#{schema_name} does not show step by step navigation where relevant" do content_item = content_store_has_schema_example(schema_name, schema_name) - content_item['base_path'] = "/not-part-of-a-step-by-step" - path = content_item['base_path'][1..-1] + content_item["base_path"] = "/not-part-of-a-step-by-step" + path = content_item["base_path"][1..-1] - content_store_has_item(content_item['base_path'], content_item) + content_store_has_item(content_item["base_path"], content_item) @controller.stubs(:page_in_scope?).returns(false) diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index 0a09ec3dc..bef2f6a4f 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -1,16 +1,16 @@ -require 'test_helper' +require "test_helper" class ApplicationHelperTest < ActionView::TestCase tests ApplicationHelper test "#current_path_without_query_string returns the path of the current request" do - self.stubs(:request).returns(ActionDispatch::TestRequest.create("PATH_INFO" => '/foo/bar')) - assert_equal '/foo/bar', current_path_without_query_string + self.stubs(:request).returns(ActionDispatch::TestRequest.create("PATH_INFO" => "/foo/bar")) + assert_equal "/foo/bar", current_path_without_query_string end test "#current_path_without_query_string returns the path of the current request stripping off any query string parameters" do - self.stubs(:request).returns(ActionDispatch::TestRequest.create("PATH_INFO" => '/foo/bar', "QUERY_STRING" => 'ham=jam&spam=gram')) - assert_equal '/foo/bar', current_path_without_query_string + self.stubs(:request).returns(ActionDispatch::TestRequest.create("PATH_INFO" => "/foo/bar", "QUERY_STRING" => "ham=jam&spam=gram")) + assert_equal "/foo/bar", current_path_without_query_string end test "#t_locale_fallback returns nil for a string with a locale translation" do diff --git a/test/helpers/gone_helper_test.rb b/test/helpers/gone_helper_test.rb index 3a4b216a7..bb429fe01 100644 --- a/test/helpers/gone_helper_test.rb +++ b/test/helpers/gone_helper_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class GoneHelperTest < ActionView::TestCase test "it renders a link to the full url" do diff --git a/test/helpers/statistics_announcement_helper_test.rb b/test/helpers/statistics_announcement_helper_test.rb index 214107c90..d2a6eff3f 100644 --- a/test/helpers/statistics_announcement_helper_test.rb +++ b/test/helpers/statistics_announcement_helper_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class StatisticsAnnouncementHelperTest < ActionView::TestCase test "returns 'on' if the date is an exact format" do diff --git a/test/helpers/typography_helper_test.rb b/test/helpers/typography_helper_test.rb index efcac74cc..687d5dfaa 100644 --- a/test/helpers/typography_helper_test.rb +++ b/test/helpers/typography_helper_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class TypographyHelperTest < ActionView::TestCase include ERB::Util diff --git a/test/helpers/webchat_availability_helper_test.rb b/test/helpers/webchat_availability_helper_test.rb index 4003d4d06..ce5213eab 100644 --- a/test/helpers/webchat_availability_helper_test.rb +++ b/test/helpers/webchat_availability_helper_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class WebchatAvailabilityHelperTest < ActionView::TestCase tests WebchatAvailabilityHelper diff --git a/test/integration/answer_test.rb b/test/integration/answer_test.rb index 83028f7ad..b1bb1150a 100644 --- a/test/integration/answer_test.rb +++ b/test/integration/answer_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class AnswerTest < ActionDispatch::IntegrationTest test "random but valid items do not error" do @@ -6,13 +6,13 @@ class AnswerTest < ActionDispatch::IntegrationTest end test "renders title and body" do - setup_and_visit_content_item('answer') + setup_and_visit_content_item("answer") assert page.has_text?(@content_item["title"]) assert page.has_text?("Bydd angen cod cychwyn arnoch i ddechrau defnyddio’r holl wasanaethau hyn, ac eithrio TAW. Anfonir hwn atoch cyn pen saith diwrnod gwaith ar ôl i chi gofrestru. Os ydych chi’n byw dramor, gall gymryd hyd at 21 diwrnod i gyrraedd.") end test "related links are rendered" do - setup_and_visit_content_item('answer') + setup_and_visit_content_item("answer") first_related_link = @content_item["details"]["external_related_links"].first @@ -22,10 +22,10 @@ class AnswerTest < ActionDispatch::IntegrationTest end test "renders FAQ structured data" do - setup_and_visit_content_item('answer') + setup_and_visit_content_item("answer") faq_schema = find_structured_data(page, "FAQPage") - assert_equal faq_schema["headline"], @content_item['title'] + assert_equal faq_schema["headline"], @content_item["title"] assert_not_equal faq_schema["mainEntity"], [] end end diff --git a/test/integration/case_study_test.rb b/test/integration/case_study_test.rb index f929aa5d5..42c5bc342 100644 --- a/test/integration/case_study_test.rb +++ b/test/integration/case_study_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class CaseStudyTest < ActionDispatch::IntegrationTest test "random but valid items do not error" do @@ -6,22 +6,22 @@ class CaseStudyTest < ActionDispatch::IntegrationTest end test "translated case study" do - setup_and_visit_content_item('translated') + setup_and_visit_content_item("translated") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) - assert page.has_css?('.gem-c-translation-nav') + assert page.has_css?(".gem-c-translation-nav") end test "withdrawn case study" do - setup_and_visit_content_item('archived') + setup_and_visit_content_item("archived") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) within ".gem-c-notice" do - assert page.has_text?('This case study was withdrawn'), "is withdrawn" + assert page.has_text?("This case study was withdrawn"), "is withdrawn" assert page.has_text?("We’ve withdrawn this case study and published newer") assert page.has_css?("time[datetime='#{@content_item['withdrawn_notice']['withdrawn_at']}']") end diff --git a/test/integration/component_guide_test.rb b/test/integration/component_guide_test.rb index 072cb1017..088a7e04b 100644 --- a/test/integration/component_guide_test.rb +++ b/test/integration/component_guide_test.rb @@ -1,5 +1,5 @@ -require 'test_helper' -require 'govuk_publishing_components/minitest/component_guide_test' +require "test_helper" +require "govuk_publishing_components/minitest/component_guide_test" class ComponentGuideTest < ActionDispatch::IntegrationTest # temporarily disabling to get around an error to do with an image in one of the component pages diff --git a/test/integration/consultation_test.rb b/test/integration/consultation_test.rb index 84259d4a5..9e9f8b95b 100644 --- a/test/integration/consultation_test.rb +++ b/test/integration/consultation_test.rb @@ -1,8 +1,8 @@ -require 'test_helper' +require "test_helper" class ConsultationTest < ActionDispatch::IntegrationTest test "consultation" do - setup_and_visit_content_item('open_consultation') + setup_and_visit_content_item("open_consultation") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) @@ -11,126 +11,126 @@ class ConsultationTest < ActionDispatch::IntegrationTest published: "Published 4 November 2016", last_updated: "Last updated 7 November 2016", metadata: { - "From": { "Department for Education": "/government/organisations/department-for-education" } - } + "From": { "Department for Education": "/government/organisations/department-for-education" }, + }, ) assert_footer_has_published_dates("Published 4 November 2016", "Last updated 7 November 2016") - within '.consultation-description' do + within ".consultation-description" do assert page.has_text?("We are seeking external views on a postgraduate doctoral loan.") end end test "consultation documents render" do - setup_and_visit_content_item('closed_consultation') + setup_and_visit_content_item("closed_consultation") - within '.consultation-documents' do + within ".consultation-documents" do assert page.has_text?("Museums Review Terms of Reference") end end test "link to external consultations" do - setup_and_visit_content_item('open_consultation') + setup_and_visit_content_item("open_consultation") assert page.has_css?("a[href=\"#{@content_item['details']['held_on_another_website_url']}\"]", text: "another website") end test "open consultation" do - setup_and_visit_content_item('open_consultation') + setup_and_visit_content_item("open_consultation") assert page.has_text?("Open consultation") assert page.has_text?(:all, "closes at 3pm on 16 December 2216") end test "unopened consultation" do - setup_and_visit_content_item('unopened_consultation') + setup_and_visit_content_item("unopened_consultation") assert page.has_text?("Consultation") # There’s no daylight savings after 2037 # http://timezonesjl.readthedocs.io/en/stable/faq/#far-future-zoneddatetime-with-variabletimezone - assert page.has_css?('.gem-c-notice', text: "This consultation opens at 1pm on 5 October 2200") + assert page.has_css?(".gem-c-notice", text: "This consultation opens at 1pm on 5 October 2200") assert page.has_text?(:all, "It closes at 4pm on 31 October 2210") end test "closed consultation pending outcome" do - setup_and_visit_content_item('closed_consultation') + setup_and_visit_content_item("closed_consultation") assert page.has_text?("Closed consultation") - assert page.has_css?('.gem-c-notice', text: "We are analysing your feedback") + assert page.has_css?(".gem-c-notice", text: "We are analysing your feedback") assert page.has_text?("ran from") assert page.has_text?("2pm on 5 September 2016 to 4pm on 31 October 2016") end test "consultation outcome" do - setup_and_visit_content_item('consultation_outcome') + setup_and_visit_content_item("consultation_outcome") assert page.has_text?("Consultation outcome") - assert page.has_css?('.gem-c-notice', text: "This consultation has concluded") - assert page.has_css?('h2', text: "Original consultation") + assert page.has_css?(".gem-c-notice", text: "This consultation has concluded") + assert page.has_css?("h2", text: "Original consultation") assert page.has_text?("ran from") assert page.has_text?("4pm on 20 April 2016 to 10:45pm on 13 July 2016") - within '.consultation-outcome-detail' do + within ".consultation-outcome-detail" do assert page.has_text?(@content_item["details"]["final_outcome_detail"]) end end test "public feedback" do - setup_and_visit_content_item('consultation_outcome_with_feedback') + setup_and_visit_content_item("consultation_outcome_with_feedback") assert page.has_text?("Detail of feedback received") - within '.consultation-feedback' do + within ".consultation-feedback" do assert page.has_text?("The majority of respondents agreed or strongly agreed with our proposals, which were:") end end test "consultation outcome documents render" do - setup_and_visit_content_item('consultation_outcome') + setup_and_visit_content_item("consultation_outcome") - within '.consultation-outcome' do + within ".consultation-outcome" do assert page.has_text?("Employee Share Schemes: NIC elections - consulation response") end end test "public feedback documents render" do - setup_and_visit_content_item('consultation_outcome_with_feedback') + setup_and_visit_content_item("consultation_outcome_with_feedback") assert page.has_text?("Feedback received") - within '.consultation-feedback-documents' do + within ".consultation-feedback-documents" do assert page.has_text?("Analysis of responses to our consultation on setting the grade standards of new GCSEs in England – part 2") end end test "consultation that only applies to a set of nations" do - setup_and_visit_content_item('consultation_outcome_with_feedback') + setup_and_visit_content_item("consultation_outcome_with_feedback") assert_has_important_metadata("Applies to": "England") end test "ways to respond renders" do - setup_and_visit_content_item('open_consultation_with_participation') + setup_and_visit_content_item("open_consultation_with_participation") - within '.consultation-ways-to-respond' do - assert page.has_css?(".call-to-action a[href='https://beisgovuk.citizenspace.com/ukgi/post-office-network-consultation']", text: 'Respond online') - assert page.has_css?("a[href='mailto:po.consultation@ukgi.gov.uk']", text: 'po.consultation@ukgi.gov.uk') - assert page.has_css?(".contact", text: '2016 Post Office Network Consultation') - assert page.has_css?("a[href='https://www.gov.uk/government/uploads/system/uploads/consultation_response_form_data/file/533/beis-16-36rf-post-office-network-consultation-response-form.docx']", text: 'response form') + within ".consultation-ways-to-respond" do + assert page.has_css?(".call-to-action a[href='https://beisgovuk.citizenspace.com/ukgi/post-office-network-consultation']", text: "Respond online") + assert page.has_css?("a[href='mailto:po.consultation@ukgi.gov.uk']", text: "po.consultation@ukgi.gov.uk") + assert page.has_css?(".contact", text: "2016 Post Office Network Consultation") + assert page.has_css?("a[href='https://www.gov.uk/government/uploads/system/uploads/consultation_response_form_data/file/533/beis-16-36rf-post-office-network-consultation-response-form.docx']", text: "response form") end end test "ways to respond postal address is formatted with line breaks" do - setup_and_visit_content_item('open_consultation_with_participation') + setup_and_visit_content_item("open_consultation_with_participation") - within '.consultation-ways-to-respond' do - assert page.has_css?(".contact .content p", text: '2016 Post Office Network Consultation') + within ".consultation-ways-to-respond" do + assert page.has_css?(".contact .content p", text: "2016 Post Office Network Consultation") end end test "share urls" do - setup_and_visit_content_item('open_consultation') + setup_and_visit_content_item("open_consultation") assert page.has_css?("a", text: "Share on Facebook") assert page.has_css?("a", text: "Share on Twitter") end diff --git a/test/integration/contact_test.rb b/test/integration/contact_test.rb index 2dde74439..1f61879fa 100644 --- a/test/integration/contact_test.rb +++ b/test/integration/contact_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class ContactTest < ActionDispatch::IntegrationTest test "random but valid items do not error" do @@ -6,7 +6,7 @@ class ContactTest < ActionDispatch::IntegrationTest end test "online forms are rendered" do - setup_and_visit_content_item('contact') + setup_and_visit_content_item("contact") assert page.has_text?("If HMRC needs to contact you about anything confidential they’ll reply by phone or post.") assert page.has_text?("Contact HMRC to report suspicious activity in relation to smuggling, customs, excise and VAT fraud.") @@ -17,33 +17,33 @@ class ContactTest < ActionDispatch::IntegrationTest end test "emails are rendered" do - setup_and_visit_content_item('contact') + setup_and_visit_content_item("contact") assert page.has_css?("h2#email-title") assert page.has_css?(".email:first-of-type") end test "phones are rendered" do - setup_and_visit_content_item('contact') + setup_and_visit_content_item("contact") first_phone = @content_item["details"]["phone_numbers"].first assert page.has_css?("h2#phone-title") - assert page.has_css?("h3", text: first_phone['title']) - assert page.has_css?("p", text: first_phone['number']) + assert page.has_css?("h3", text: first_phone["title"]) + assert page.has_css?("p", text: first_phone["number"]) assert page.has_css?("p", text: "24 hours a day, 7 days a week") end test "phone number heading is not rendered when only one number" do - setup_and_visit_content_item('contact_with_welsh') + setup_and_visit_content_item("contact_with_welsh") assert_equal 1, @content_item["details"]["phone_numbers"].size first_phone = @content_item["details"]["phone_numbers"].first - refute page.has_css?("h3", text: first_phone['title']) + refute page.has_css?("h3", text: first_phone["title"]) end test "posts are rendered" do - setup_and_visit_content_item('contact') + setup_and_visit_content_item("contact") assert page.has_css?("h2#post-title") assert page.has_css?(".street-address") diff --git a/test/integration/corporate_information_page_test.rb b/test/integration/corporate_information_page_test.rb index e0009f353..e8e301ab6 100644 --- a/test/integration/corporate_information_page_test.rb +++ b/test/integration/corporate_information_page_test.rb @@ -1,8 +1,8 @@ -require 'test_helper' +require "test_helper" class CorporateInformationPageTest < ActionDispatch::IntegrationTest test "renders title, description and body" do - setup_and_visit_content_item('corporate_information_page_translated_custom_logo') + setup_and_visit_content_item("corporate_information_page_translated_custom_logo") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) @@ -10,7 +10,7 @@ class CorporateInformationPageTest < ActionDispatch::IntegrationTest end test "renders with contents list" do - setup_and_visit_content_item('corporate_information_page') + setup_and_visit_content_item("corporate_information_page") assert_has_contents_list([ { text: "Our responsibilities", id: "our-responsibilities" }, { text: "Corporate information", id: "corporate-information" }, @@ -31,7 +31,7 @@ class CorporateInformationPageTest < ActionDispatch::IntegrationTest end test "renders corporate information with body when present" do - setup_and_visit_content_item('corporate_information_page') + setup_and_visit_content_item("corporate_information_page") assert page.has_css?("h2#corporate-information") assert page.has_css?("h3#access-our-information") @@ -43,41 +43,41 @@ class CorporateInformationPageTest < ActionDispatch::IntegrationTest end test "renders further information with body when present" do - setup_and_visit_content_item('corporate_information_page') + setup_and_visit_content_item("corporate_information_page") assert page.has_text?("Read about the types of information we routinely") end test "renders with organisation branding" do - setup_and_visit_content_item('corporate_information_page') - assert page.has_css?('.department-of-health-brand-colour') + setup_and_visit_content_item("corporate_information_page") + assert page.has_css?(".department-of-health-brand-colour") end test "includes organisation in title" do - setup_and_visit_content_item('corporate_information_page') - assert page.has_css?('title', text: 'About us - Department of Health - GOV.UK', visible: false) + setup_and_visit_content_item("corporate_information_page") + assert page.has_css?("title", text: "About us - Department of Health - GOV.UK", visible: false) end test "includes translations" do - setup_and_visit_content_item('corporate_information_page_translated_custom_logo') - assert page.has_css?('.gem-c-translation-nav') + setup_and_visit_content_item("corporate_information_page_translated_custom_logo") + assert page.has_css?(".gem-c-translation-nav") end test "renders an organisation logo" do - setup_and_visit_content_item('corporate_information_page') + setup_and_visit_content_item("corporate_information_page") assert_has_component_organisation_logo end test "renders a custom organisation logo" do - setup_and_visit_content_item('corporate_information_page_translated_custom_logo') + setup_and_visit_content_item("corporate_information_page_translated_custom_logo") assert_has_component_organisation_logo end - test 'renders a withdrawal notice on withdrawn page' do - content_item = GovukSchemas::Example.find('corporate_information_page', example_name: 'corporate_information_page') - content_item['withdrawn_notice'] = { - 'explanation': 'This is out of date', - 'withdrawn_at': '2014-08-09T11:39:05Z' + test "renders a withdrawal notice on withdrawn page" do + content_item = GovukSchemas::Example.find("corporate_information_page", example_name: "corporate_information_page") + content_item["withdrawn_notice"] = { + 'explanation': "This is out of date", + 'withdrawn_at': "2014-08-09T11:39:05Z", } content_store_has_item("/government/organisations/department-of-health/about", content_item.to_json) diff --git a/test/integration/detailed_guide_test.rb b/test/integration/detailed_guide_test.rb index 5ea998988..0c5fadd84 100644 --- a/test/integration/detailed_guide_test.rb +++ b/test/integration/detailed_guide_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class DetailedGuideTest < ActionDispatch::IntegrationTest test "random but valid items do not error" do @@ -6,7 +6,7 @@ class DetailedGuideTest < ActionDispatch::IntegrationTest end test "detailed guide" do - setup_and_visit_content_item('detailed_guide') + setup_and_visit_content_item("detailed_guide") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) @@ -17,57 +17,57 @@ class DetailedGuideTest < ActionDispatch::IntegrationTest history_link: true, metadata: { "From:": { - "HM Revenue & Customs": "/government/organisations/hm-revenue-customs" - } - } + "HM Revenue & Customs": "/government/organisations/hm-revenue-customs", + }, + }, ) end test "renders back to contents elements" do - setup_and_visit_content_item('detailed_guide') + setup_and_visit_content_item("detailed_guide") assert page.has_css?(".app-c-back-to-top[href='#contents']") end test "withdrawn detailed guide" do - setup_and_visit_content_item('withdrawn_detailed_guide') + setup_and_visit_content_item("withdrawn_detailed_guide") - assert page.has_css?('title', text: "[Withdrawn]", visible: false) + assert page.has_css?("title", text: "[Withdrawn]", visible: false) - assert page.has_text?('This guidance was withdrawn'), "is withdrawn" + assert page.has_text?("This guidance was withdrawn"), "is withdrawn" assert page.has_text?("This information has been archived as it is now out of date. For current information please go to") assert page.has_css?("time[datetime='#{@content_item['withdrawn_notice']['withdrawn_at']}']") end test "historically political detailed guide" do - setup_and_visit_content_item('political_detailed_guide') + setup_and_visit_content_item("political_detailed_guide") within ".app-c-banner" do - assert page.has_text?('This was published under the 2010 to 2015 Conservative and Liberal Democrat coalition government') + assert page.has_text?("This was published under the 2010 to 2015 Conservative and Liberal Democrat coalition government") end end - test 'detailed guide that only applies to a set of nations' do - setup_and_visit_content_item('national_applicability_detailed_guide') + test "detailed guide that only applies to a set of nations" do + setup_and_visit_content_item("national_applicability_detailed_guide") assert_has_important_metadata("Applies to:": "England") end - test 'detailed guide that only applies to a set of nations, with alternative urls' do - setup_and_visit_content_item('national_applicability_alternative_url_detailed_guide') + test "detailed guide that only applies to a set of nations, with alternative urls" do + setup_and_visit_content_item("national_applicability_alternative_url_detailed_guide") assert_has_important_metadata( 'Applies to:': - 'England, Scotland, and Wales (see guidance for Northern Ireland)' + "England, Scotland, and Wales (see guidance for Northern Ireland)", ) end test "translated detailed guide" do - setup_and_visit_content_item('translated_detailed_guide') + setup_and_visit_content_item("translated_detailed_guide") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) - assert page.has_css?('.gem-c-translation-nav') + assert page.has_css?(".gem-c-translation-nav") end test "renders a contents list" do diff --git a/test/integration/document_collection_test.rb b/test/integration/document_collection_test.rb index 0f67e1a94..ddb868ee1 100644 --- a/test/integration/document_collection_test.rb +++ b/test/integration/document_collection_test.rb @@ -1,46 +1,46 @@ -require 'test_helper' +require "test_helper" class DocumentCollectionTest < ActionDispatch::IntegrationTest test "document collection with no body" do - setup_and_visit_content_item('document_collection') + setup_and_visit_content_item("document_collection") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) assert page.has_css?(".gem-c-contents-list") end test "document collection with no body and 2 collection groups where 1st group has long body" do - content_item = get_content_example('document_collection') - content_item['details']['collection_groups'][0]['body'] = Faker::Lorem.characters(number: 416) - content_store_has_item(content_item['base_path'], content_item.to_json) - visit(content_item['base_path']) + content_item = get_content_example("document_collection") + content_item["details"]["collection_groups"][0]["body"] = Faker::Lorem.characters(number: 416) + content_store_has_item(content_item["base_path"], content_item.to_json) + visit(content_item["base_path"]) - assert page.has_css?('.gem-c-contents-list') + assert page.has_css?(".gem-c-contents-list") end test "renders metadata and document footer" do - setup_and_visit_content_item('document_collection') + setup_and_visit_content_item("document_collection") assert_has_publisher_metadata( published: "Published 29 February 2016", metadata: { "From:": { - "Driver and Vehicle Standards Agency": "/government/organisations/driver-and-vehicle-standards-agency" - } - } + "Driver and Vehicle Standards Agency": "/government/organisations/driver-and-vehicle-standards-agency", + }, + }, ) assert_footer_has_published_dates("Published 29 February 2016") end test "renders body when provided" do - setup_and_visit_content_item('document_collection_with_body') + setup_and_visit_content_item("document_collection_with_body") assert page.has_text?("Each regime page provides a current list of asset freeze targets designated by the United Nations (UN), European Union and United Kingdom, under legislation relating to current financial sanctions regimes.") end test "renders contents with link to each collection group" do - setup_and_visit_content_item('document_collection') + setup_and_visit_content_item("document_collection") @content_item["details"]["collection_groups"].each do |group| - assert page.has_css?('nav a', text: group["title"]) + assert page.has_css?("nav a", text: group["title"]) end end @@ -50,7 +50,7 @@ class DocumentCollectionTest < ActionDispatch::IntegrationTest { "title" => "Item one", "body" => "

Content about item one

", - "documents" => ["a-content-id"] + "documents" => %w[a-content-id], }, ] content_store_has_item(item["base_path"], item.to_json) @@ -60,100 +60,100 @@ class DocumentCollectionTest < ActionDispatch::IntegrationTest end test "renders each collection group" do - setup_and_visit_content_item('document_collection') + setup_and_visit_content_item("document_collection") groups = @content_item["details"]["collection_groups"] group_count = groups.count groups.each do |group| - assert page.has_css?('.group-title', text: group["title"]) + assert page.has_css?(".group-title", text: group["title"]) end within ".app-c-contents-list-with-body" do assert page.has_css?(".gem-c-govspeak", count: group_count) - assert page.has_css?('.gem-c-document-list', count: group_count) + assert page.has_css?(".gem-c-document-list", count: group_count) end end test "renders all collection documents" do - setup_and_visit_content_item('document_collection') + setup_and_visit_content_item("document_collection") documents = @content_item["links"]["documents"] documents.each do |doc| - assert page.has_css?('.gem-c-document-list__item-title', text: doc["title"]) + assert page.has_css?(".gem-c-document-list__item-title", text: doc["title"]) end - assert page.has_css?('.gem-c-document-list .gem-c-document-list__item', count: documents.count) + assert page.has_css?(".gem-c-document-list .gem-c-document-list__item", count: documents.count) - document_lists = page.all('.gem-c-document-list') + document_lists = page.all(".gem-c-document-list") within document_lists[0] do list_items = page.all(".gem-c-document-list__item") within list_items[0] do - assert page.has_text?('16 March 2007'), "has properly formatted date" + assert page.has_text?("16 March 2007"), "has properly formatted date" assert page.has_css?('[datetime="2007-03-16T15:00:02+00:00"]'), "has iso8601 datetime attribute" - assert page.has_text?('Guidance'), "has formatted document_type" + assert page.has_text?("Guidance"), "has formatted document_type" end end end - test 'includes tracking data on all collection documents' do - setup_and_visit_content_item('document_collection') - groups = page.all('.gem-c-document-list') + test "includes tracking data on all collection documents" do + setup_and_visit_content_item("document_collection") + groups = page.all(".gem-c-document-list") assert page.has_css?('[data-module="track-click"]'), count: groups.length - first_section_links = groups.first.all('.gem-c-document-list__item-title') + first_section_links = groups.first.all(".gem-c-document-list__item-title") first_link = first_section_links.first assert_equal( - 'navDocumentCollectionLinkClicked', - first_link['data-track-category'], - 'Expected a tracking category to be set in the data attributes' + "navDocumentCollectionLinkClicked", + first_link["data-track-category"], + "Expected a tracking category to be set in the data attributes", ) assert_equal( - '1.1', - first_link['data-track-action'], - 'Expected the link position to be set in the data attributes' + "1.1", + first_link["data-track-action"], + "Expected the link position to be set in the data attributes", ) assert_match( - first_link['data-track-label'], + first_link["data-track-label"], first_link[:href], - 'Expected the content item base path to be set in the data attributes' + "Expected the content item base path to be set in the data attributes", ) - assert first_link['data-track-options'].present? + assert first_link["data-track-options"].present? - data_options = JSON.parse(first_link['data-track-options']) + data_options = JSON.parse(first_link["data-track-options"]) assert_equal( first_section_links.count.to_s, - data_options['dimension28'], - 'Expected the total number of content items within the section to be present in the tracking options' + data_options["dimension28"], + "Expected the total number of content items within the section to be present in the tracking options", ) assert_equal( first_link.text, - data_options['dimension29'], - 'Expected the subtopic title to be present in the tracking options' + data_options["dimension29"], + "Expected the subtopic title to be present in the tracking options", ) end test "withdrawn collection" do - setup_and_visit_content_item('document_collection_withdrawn') - assert page.has_css?('title', text: "[Withdrawn]", visible: false) + setup_and_visit_content_item("document_collection_withdrawn") + assert page.has_css?("title", text: "[Withdrawn]", visible: false) within ".gem-c-notice" do - assert page.has_text?('This collection was withdrawn'), "is withdrawn" + assert page.has_text?("This collection was withdrawn"), "is withdrawn" assert page.has_text?("This information is now out of date.") assert page.has_css?("time[datetime='#{@content_item['withdrawn_notice']['withdrawn_at']}']") end end test "historically political collection" do - setup_and_visit_content_item('document_collection_political') + setup_and_visit_content_item("document_collection_political") within ".app-c-banner" do - assert page.has_text?('This was published under the 2010 to 2015 Conservative and Liberal Democrat coalition government') + assert page.has_text?("This was published under the 2010 to 2015 Conservative and Liberal Democrat coalition government") end end end diff --git a/test/integration/fatality_notice_test.rb b/test/integration/fatality_notice_test.rb index cc7a30150..1fe9691f2 100644 --- a/test/integration/fatality_notice_test.rb +++ b/test/integration/fatality_notice_test.rb @@ -1,18 +1,18 @@ -require 'test_helper' +require "test_helper" class FatalityNoticeTest < ActionDispatch::IntegrationTest test "typical fatality notice" do - setup_and_visit_content_item('fatality_notice') + setup_and_visit_content_item("fatality_notice") assert_has_component_government_navigation_active("News and communications") assert page.has_title?( - "Sir George Pomeroy Colley killed in Boer War - Fatality notice - GOV.UK" + "Sir George Pomeroy Colley killed in Boer War - Fatality notice - GOV.UK", ) assert page.has_css?( "meta[name='description'][content='It is with great sadness that the Ministry of Defence must confirm that Sir George Pomeroy Colley, died in battle in Zululand on 27 February 1881.']", - visible: false + visible: false, ) assert page.has_content?("Operations in Zululand") @@ -25,19 +25,19 @@ class FatalityNoticeTest < ActionDispatch::IntegrationTest last_updated: "Last updated 14 September 2016", history_link: true, metadata: { - "From": { "Ministry of Defence": "/government/organisations/ministry-of-defence" } - } + "From": { "Ministry of Defence": "/government/organisations/ministry-of-defence" }, + }, ) assert_has_important_metadata( - "Field of operation": { "Zululand": "/government/fields-of-operation/zululand" } + "Field of operation": { "Zululand": "/government/fields-of-operation/zululand" }, ) assert page.has_content?("It is with great sadness that the Ministry of Defence must confirm that Sir George Pomeroy Colley, died in battle") assert( page.has_css?("img[src*=ministry-of-defence-crest][alt='Ministry of Defence crest']"), - 'should have image with ministry-of-defence source with alt text' + "should have image with ministry-of-defence source with alt text", ) assert page.has_text?("Colley served nearly all of his military and administrative career in British South Africa, but he played a significant part in the Second Anglo-Afghan War as military secretary and then private secretary to the governor-general of India, Lord Lytton. The war began in November 1878 and ended in May 1879 with the Treaty of Gandamak.") @@ -59,20 +59,20 @@ class FatalityNoticeTest < ActionDispatch::IntegrationTest end test "fatality notice with minister" do - setup_and_visit_content_item('fatality_notice_with_minister') + setup_and_visit_content_item("fatality_notice_with_minister") assert_has_publisher_metadata_other( "From": { "Ministry of Defence": "/government/organisations/ministry-of-defence", "The Rt Hon Sir Eric Pickles MP": "/government/people/eric-pickles", - } + }, ) end test "fatality notice with withdrawn notice" do - setup_and_visit_content_item('withdrawn_fatality_notice') + setup_and_visit_content_item("withdrawn_fatality_notice") assert page.has_title?( - "[Withdrawn] Sir George Pomeroy Colley killed in Boer War - Fatality notice - GOV.UK" + "[Withdrawn] Sir George Pomeroy Colley killed in Boer War - Fatality notice - GOV.UK", ) within ".gem-c-notice" do diff --git a/test/integration/guide_print_test.rb b/test/integration/guide_print_test.rb index 8edcb4179..4a344c37b 100644 --- a/test/integration/guide_print_test.rb +++ b/test/integration/guide_print_test.rb @@ -1,19 +1,19 @@ -require 'test_helper' +require "test_helper" class GuidePrint < ActionDispatch::IntegrationTest test "it renders the print view" do - setup_and_visit_guide_print('guide') + setup_and_visit_guide_print("guide") assert page.has_css?("#guide-print") end test "it is not indexable by search engines" do - setup_and_visit_guide_print('guide') + setup_and_visit_guide_print("guide") assert page.has_css?("meta[name='robots'][content='noindex, nofollow']", visible: false) end test "it renders all parts in the print view" do - setup_and_visit_guide_print('guide') - parts = @content_item['details']['parts'] + setup_and_visit_guide_print("guide") + parts = @content_item["details"]["parts"] parts.each_with_index do |part, i| assert page.has_css?("h1", text: "#{i + 1}. #{part['title']}") @@ -23,7 +23,7 @@ class GuidePrint < ActionDispatch::IntegrationTest end def setup_and_visit_guide_print(name) - example = get_content_example_by_schema_and_name('guide', name) + example = get_content_example_by_schema_and_name("guide", name) @content_item = example.tap do |item| content_store_has_item(item["base_path"], item.to_json) visit "#{item['base_path']}/print" diff --git a/test/integration/guide_test.rb b/test/integration/guide_test.rb index beefd22c9..dc421b28a 100644 --- a/test/integration/guide_test.rb +++ b/test/integration/guide_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class GuideTest < ActionDispatch::IntegrationTest test "random but valid items do not error" do @@ -6,82 +6,82 @@ class GuideTest < ActionDispatch::IntegrationTest end test "guide header and navigation" do - setup_and_visit_content_item('guide') + setup_and_visit_content_item("guide") - assert page.has_css?("title", visible: false, text: @content_item['title']) - assert_has_component_title(@content_item['title']) + assert page.has_css?("title", visible: false, text: @content_item["title"]) + assert_has_component_title(@content_item["title"]) - assert page.has_css?('h1', text: @content_item['details']['parts'].first['title']) - assert page.has_css?('.gem-c-pagination') + assert page.has_css?("h1", text: @content_item["details"]["parts"].first["title"]) + assert page.has_css?(".gem-c-pagination") assert page.has_css?('.app-c-print-link a[href$="/print"]') end test "draft access tokens are appended to part links within navigation" do - setup_and_visit_content_item('guide', '?token=some_token') + setup_and_visit_content_item("guide", "?token=some_token") assert page.has_css?('.gem-c-contents-list a[href$="?token=some_token"]') end test "does not show part navigation, print link or part title when only one part" do - setup_and_visit_content_item('single-page-guide') + setup_and_visit_content_item("single-page-guide") - refute page.has_css?('h1', text: @content_item['details']['parts'].first['title']) - refute page.has_css?('.app-c-print-link') + refute page.has_css?("h1", text: @content_item["details"]["parts"].first["title"]) + refute page.has_css?(".app-c-print-link") end test "replaces guide title with part title if in a step by step and hide_chapter_navigation is true" do - setup_and_visit_content_item('guide-with-step-navs-and-hide-navigation') - title = @content_item['title'] - part_title = @content_item['details']['parts'][0]['title'] + setup_and_visit_content_item("guide-with-step-navs-and-hide-navigation") + title = @content_item["title"] + part_title = @content_item["details"]["parts"][0]["title"] - refute page.has_css?('h1', text: title) + refute page.has_css?("h1", text: title) assert_has_component_title(part_title) end test "does not replace guide title if not in a step by step and hide_chapter_navigation is true" do - setup_and_visit_content_item('guide-with-hide-navigation') - title = @content_item['title'] - part_title = @content_item['details']['parts'][0]['title'] + setup_and_visit_content_item("guide-with-hide-navigation") + title = @content_item["title"] + part_title = @content_item["details"]["parts"][0]["title"] assert_has_component_title(title) assert_has_component_title(part_title) end test "shows correct title in a single page guide if in a step by step and hide_chapter_navigation is true" do - setup_and_visit_content_item('single-page-guide-with-step-navs-and-hide-navigation') - title = @content_item['title'] - part_title = @content_item['details']['parts'][0]['title'] + setup_and_visit_content_item("single-page-guide-with-step-navs-and-hide-navigation") + title = @content_item["title"] + part_title = @content_item["details"]["parts"][0]["title"] - refute page.has_css?('h1', text: title) + refute page.has_css?("h1", text: title) assert_has_component_title(part_title) end test "does not show guide navigation and print link if in a step by step and hide_chapter_navigation is true" do - setup_and_visit_content_item('guide-with-step-navs-and-hide-navigation') + setup_and_visit_content_item("guide-with-step-navs-and-hide-navigation") - refute page.has_css?('.gem-c-pagination') - refute page.has_css?('.app-c-print-link') + refute page.has_css?(".gem-c-pagination") + refute page.has_css?(".app-c-print-link") end test "shows guide navigation and print link if not in a step by step and hide_chapter_navigation is true" do - setup_and_visit_content_item('guide-with-hide-navigation') + setup_and_visit_content_item("guide-with-hide-navigation") - assert page.has_css?('.gem-c-pagination') - assert page.has_css?('.app-c-print-link') + assert page.has_css?(".gem-c-pagination") + assert page.has_css?(".app-c-print-link") end test "guides with no parts in a step by step with hide_chapter_navigation do not error" do - setup_and_visit_content_item('no-part-guide-with-step-navs-and-hide-navigation') - title = @content_item['title'] + setup_and_visit_content_item("no-part-guide-with-step-navs-and-hide-navigation") + title = @content_item["title"] assert_has_component_title(title) end test "guides show the faq page schema" do - setup_and_visit_content_item('guide') + setup_and_visit_content_item("guide") faq_schema = find_structured_data(page, "FAQPage") - assert_equal faq_schema["headline"], @content_item['title'] + assert_equal faq_schema["headline"], @content_item["title"] assert_not_equal faq_schema["mainEntity"], [] end @@ -89,7 +89,7 @@ class GuideTest < ActionDispatch::IntegrationTest setup_and_visit_part_in_guide faq_schema = find_structured_data(page, "FAQPage") - assert_equal faq_schema["headline"], @content_item['title'] + assert_equal faq_schema["headline"], @content_item["title"] assert_not_equal faq_schema["mainEntity"], [] end diff --git a/test/integration/help_page_test.rb b/test/integration/help_page_test.rb index 88e1adf89..f83b8b7f8 100644 --- a/test/integration/help_page_test.rb +++ b/test/integration/help_page_test.rb @@ -1,8 +1,8 @@ -require 'test_helper' +require "test_helper" class HelpPageTest < ActionDispatch::IntegrationTest test "renders title and body" do - setup_and_visit_content_item('help_page') + setup_and_visit_content_item("help_page") assert page.has_text?(@content_item["title"]) assert page.has_text?("GOV.UK puts small files (known as ‘cookies’) onto your computer to collect information about how you browse the site.") diff --git a/test/integration/html_publication_test.rb b/test/integration/html_publication_test.rb index 3c3ad33e7..061e76575 100644 --- a/test/integration/html_publication_test.rb +++ b/test/integration/html_publication_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class HtmlPublicationTest < ActionDispatch::IntegrationTest test "random but valid items do not error" do @@ -6,7 +6,7 @@ class HtmlPublicationTest < ActionDispatch::IntegrationTest end test "html publications" do - setup_and_visit_content_item('published') + setup_and_visit_content_item("published") within ".gem-c-inverse-header" do assert page.has_text?(@content_item["details"]["format_sub_type"]) @@ -17,7 +17,7 @@ class HtmlPublicationTest < ActionDispatch::IntegrationTest within ".sidebar-with-body" do assert page.has_text?("Contents") - assert page.has_css?('.gem-c-contents-list') + assert page.has_css?(".gem-c-contents-list") end assert page.has_text?("The Environment Agency will normally put any responses it receives on the public register. This includes your name and contact details. Tell us if you don’t want your response to be public.") @@ -31,7 +31,7 @@ class HtmlPublicationTest < ActionDispatch::IntegrationTest assert page.has_no_text?("© Crown copyright #{@content_item['details']['public_timestamp'].to_date.year}") assert page.has_no_text?("Any enquiries regarding this publication should be sent to us at:") - assert page.has_no_text?((@content_item['details']['print_meta_data_contact_address']).to_s) + assert page.has_no_text?((@content_item["details"]["print_meta_data_contact_address"]).to_s) assert page.has_no_text?("Print ISBN: #{@content_item['details']['isbn']}") assert page.has_no_text?("Web ISBN: #{@content_item['details']['web_isbn']}") end @@ -45,13 +45,13 @@ class HtmlPublicationTest < ActionDispatch::IntegrationTest assert page.has_text?("© Crown copyright #{@content_item['details']['public_timestamp'].to_date.year}") assert page.has_text?("Any enquiries regarding this publication should be sent to us at:") - assert page.has_text?(:all, @content_item['details']['print_meta_data_contact_address'].squish) + assert page.has_text?(:all, @content_item["details"]["print_meta_data_contact_address"].squish) assert page.has_text?("Print ISBN: #{@content_item['details']['isbn']}") end end test "renders back to contents elements" do - setup_and_visit_content_item('published') + setup_and_visit_content_item("published") assert page.has_css?(".app-c-back-to-top[href='#contents']") end @@ -80,10 +80,10 @@ def assert_has_component_organisation_logo_with_brand(brand, index = 1) end test "withdrawn html publication" do - content_item = GovukSchemas::Example.find('html_publication', example_name: 'prime_ministers_office') - content_item['withdrawn_notice'] = { - 'explanation': 'This is out of date', - 'withdrawn_at': '2014-08-09T11:39:05Z' + content_item = GovukSchemas::Example.find("html_publication", example_name: "prime_ministers_office") + content_item["withdrawn_notice"] = { + 'explanation': "This is out of date", + 'withdrawn_at': "2014-08-09T11:39:05Z", } content_store_has_item("/government/publications/canada-united-kingdom-joint-declaration/canada-united-kingdom-joint-declaration", content_item.to_json) @@ -94,11 +94,11 @@ def assert_has_component_organisation_logo_with_brand(brand, index = 1) end test "if document has no parent document_type 'publication' is shown" do - content_item = GovukSchemas::Example.find('html_publication', example_name: 'prime_ministers_office') - content_item['links']['parent'][0]['document_type'] = nil - content_item['withdrawn_notice'] = { - 'explanation': 'This is out of date', - 'withdrawn_at': '2014-08-09T11:39:05Z' + content_item = GovukSchemas::Example.find("html_publication", example_name: "prime_ministers_office") + content_item["links"]["parent"][0]["document_type"] = nil + content_item["withdrawn_notice"] = { + 'explanation': "This is out of date", + 'withdrawn_at': "2014-08-09T11:39:05Z", } content_store_has_item("/government/publications/canada-united-kingdom-joint-declaration/canada-united-kingdom-joint-declaration", content_item.to_json) diff --git a/test/integration/meta_tags_test.rb b/test/integration/meta_tags_test.rb index 91d5b9a14..c7ef96db5 100644 --- a/test/integration/meta_tags_test.rb +++ b/test/integration/meta_tags_test.rb @@ -1,8 +1,8 @@ -require 'test_helper' +require "test_helper" class MetaTagsTest < ActionDispatch::IntegrationTest test "correct meta tags are displayed for pages" do - case_study = GovukSchemas::RandomExample.for_schema(frontend_schema: 'news_article') do |random| + case_study = GovukSchemas::RandomExample.for_schema(frontend_schema: "news_article") do |random| random.merge( "title" => "Zhe title", "withdrawn_notice" => {}, @@ -17,7 +17,7 @@ class MetaTagsTest < ActionDispatch::IntegrationTest end test "correct meta tags are displayed for pages without images" do - case_study = GovukSchemas::RandomExample.for_schema(frontend_schema: 'news_article') do |random| + case_study = GovukSchemas::RandomExample.for_schema(frontend_schema: "news_article") do |random| random["details"].delete("image") random end @@ -30,12 +30,12 @@ class MetaTagsTest < ActionDispatch::IntegrationTest end test "correct meta tags are displayed for pages with images" do - case_study = GovukSchemas::RandomExample.for_schema(frontend_schema: 'news_article') do |random| + case_study = GovukSchemas::RandomExample.for_schema(frontend_schema: "news_article") do |random| random["details"] = random["details"].merge( "image" => { "url" => "https://example.org/image.jpg", "alt_text" => "An accessible alt text", - } + }, ) random diff --git a/test/integration/news_article_test.rb b/test/integration/news_article_test.rb index 896778fbe..afbb47b40 100644 --- a/test/integration/news_article_test.rb +++ b/test/integration/news_article_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class NewsArticleTest < ActionDispatch::IntegrationTest test "news article renders title, description and body" do @@ -17,9 +17,9 @@ class NewsArticleTest < ActionDispatch::IntegrationTest metadata: { "From": { "Prime Minister's Office, 10 Downing Street": - "/government/organisations/prime-ministers-office-10-downing-street" - } - } + "/government/organisations/prime-ministers-office-10-downing-street", + }, + }, ) assert_footer_has_published_dates("Published 25 December 2016") diff --git a/test/integration/phase_label_test.rb b/test/integration/phase_label_test.rb index 328f17ce9..5e48e4cec 100644 --- a/test/integration/phase_label_test.rb +++ b/test/integration/phase_label_test.rb @@ -1,8 +1,8 @@ -require 'test_helper' +require "test_helper" class PhaseLabelTest < ActionDispatch::IntegrationTest test "Alpha phase label is displayed for a Case Study in phase 'alpha'" do - case_study = GovukSchemas::Example.find('case_study', example_name: 'case_study') + case_study = GovukSchemas::Example.find("case_study", example_name: "case_study") case_study["phase"] = "alpha" content_store_has_item("/government/case-studies/get-britain-building-carlisle-park", case_study.to_json) @@ -13,7 +13,7 @@ class PhaseLabelTest < ActionDispatch::IntegrationTest end test "No phase label is displayed for a Content item without a phase field" do - content_item = GovukSchemas::Example.find('case_study', example_name: 'case_study') + content_item = GovukSchemas::Example.find("case_study", example_name: "case_study") content_item.delete("phase") content_store_has_item("/government/case-studies/get-britain-building-carlisle-park", content_item.to_json) diff --git a/test/integration/publication_test.rb b/test/integration/publication_test.rb index 36ead4dbe..3c0180158 100644 --- a/test/integration/publication_test.rb +++ b/test/integration/publication_test.rb @@ -1,12 +1,12 @@ -require 'test_helper' +require "test_helper" class PublicationTest < ActionDispatch::IntegrationTest test "random but valid items do not error" do - setup_and_visit_random_content_item(document_type: 'statutory_guidance') + setup_and_visit_random_content_item(document_type: "statutory_guidance") end test "publication" do - setup_and_visit_content_item('publication') + setup_and_visit_content_item("publication") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) @@ -17,7 +17,7 @@ class PublicationTest < ActionDispatch::IntegrationTest end test "renders metadata and document footer" do - setup_and_visit_content_item('publication') + setup_and_visit_content_item("publication") assert_has_publisher_metadata( published: "Published 3 May 2016", @@ -25,46 +25,46 @@ class PublicationTest < ActionDispatch::IntegrationTest "From": { "Environment Agency": "/government/organisations/environment-agency", "The Rt Hon Sir Eric Pickles MP": "/government/people/eric-pickles", - } - } + }, + }, ) assert_footer_has_published_dates("Published 3 May 2016") end test "renders a govspeak block for attachments" do - setup_and_visit_content_item('publication') + setup_and_visit_content_item("publication") within '[aria-labelledby="documents-title"]' do assert page.has_text?("Permit: Veolia ES (UK) Limited") end end test "withdrawn publication" do - setup_and_visit_content_item('withdrawn_publication') - assert page.has_css?('title', text: "[Withdrawn]", visible: false) + setup_and_visit_content_item("withdrawn_publication") + assert page.has_css?("title", text: "[Withdrawn]", visible: false) within ".gem-c-notice" do - assert page.has_text?('This publication was withdrawn'), "is withdrawn" + assert page.has_text?("This publication was withdrawn"), "is withdrawn" assert page.has_text?("guidance for keepers of sheep, goats and pigs") assert page.has_css?("time[datetime='#{@content_item['withdrawn_notice']['withdrawn_at']}']") end end test "historically political publication" do - setup_and_visit_content_item('political_publication') + setup_and_visit_content_item("political_publication") within ".app-c-banner" do - assert page.has_text?('This was published under the 2010 to 2015 Conservative and Liberal Democrat coalition government') + assert page.has_text?("This was published under the 2010 to 2015 Conservative and Liberal Democrat coalition government") end end test "national statistics publication shows a logo" do - setup_and_visit_content_item('statistics_publication') + setup_and_visit_content_item("statistics_publication") assert page.has_css?('img[alt="National Statistics"]') end test "renders 'Applies to' block in important metadata when there are excluded nations" do - setup_and_visit_content_item('statistics_publication') + setup_and_visit_content_item("statistics_publication") assert_has_important_metadata( "Applies to": { @@ -73,7 +73,7 @@ class PublicationTest < ActionDispatch::IntegrationTest "http://www.dsdni.gov.uk/index/stats_and_research/stats-publications/stats-housing-publications/housing_stats.htm", "Scotland": "http://www.scotland.gov.uk/Topics/Statistics/Browse/Housing-Regeneration/HSfS", "Wales": "http://wales.gov.uk/topics/statistics/headlines/housing2012/121025/?lang=en", - } + }, ) end end diff --git a/test/integration/service_sign_in/choose_sign_in_test.rb b/test/integration/service_sign_in/choose_sign_in_test.rb index e19e8f800..1a914ba58 100644 --- a/test/integration/service_sign_in/choose_sign_in_test.rb +++ b/test/integration/service_sign_in/choose_sign_in_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" module ServiceSignIn class ChooseSignInTest < ActionDispatch::IntegrationTest @@ -15,11 +15,11 @@ class ChooseSignInTest < ActionDispatch::IntegrationTest test "page renders correctly" do setup_and_visit_choose_sign_in_page("service_sign_in", "/choose-sign-in") - assert page.has_css?("title", text: 'Prove your identity to continue - GOV.UK', visible: false) + assert page.has_css?("title", text: "Prove your identity to continue - GOV.UK", visible: false) assert page.has_css?('meta[name="robots"][content="noindex, nofollow"]', visible: false) refute page.has_css?("#proposition-menu") - assert page.has_css?('.gem-c-back-link[href="/log-in-file-self-assessment-tax-return"]', text: 'Back') + assert page.has_css?('.gem-c-back-link[href="/log-in-file-self-assessment-tax-return"]', text: "Back") assert page.has_css?('form[data-module="track-radio-group"]') assert page.has_css?("form[data-tracking-code='UA-xxxxxx']") assert page.has_css?("form[data-tracking-domain='tax.service.gov.uk']") @@ -53,15 +53,15 @@ class ChooseSignInTest < ActionDispatch::IntegrationTest test "renders errors correctly" do setup_and_visit_choose_sign_in_page("service_sign_in", "/choose-sign-in") - click_on 'Continue' + click_on "Continue" - assert page.has_text?('You haven’t selected an option') - assert page.has_text?('Please select an option') + assert page.has_text?("You haven’t selected an option") + assert page.has_text?("Please select an option") # Make sure the id is the same as the link href so that they'll link together properly. assert page.has_css?(".gem-c-radio input[id='option-0'][value='use-government-gateway']", visible: false) - assert page.has_css?(".app-c-error-message", text: 'Please select an option') + assert page.has_css?(".app-c-error-message", text: "Please select an option") end test "page less options without an or divider" do @@ -79,8 +79,8 @@ class ChooseSignInTest < ActionDispatch::IntegrationTest test "page renders welsh correctly" do setup_and_visit_choose_sign_in_page("welsh", "/dewiswch-lofnodi") - assert page.has_css?("title", text: 'Profwch pwy ydych chi i fwrw ymlaen - GOV.UK', visible: false) - assert page.has_css?('.gem-c-back-link', text: 'Yn ôl') + assert page.has_css?("title", text: "Profwch pwy ydych chi i fwrw ymlaen - GOV.UK", visible: false) + assert page.has_css?(".gem-c-back-link", text: "Yn ôl") within "#content form" do within ".gem-c-fieldset" do diff --git a/test/integration/service_sign_in/create_new_account_test.rb b/test/integration/service_sign_in/create_new_account_test.rb index b9e3234aa..d2859e903 100644 --- a/test/integration/service_sign_in/create_new_account_test.rb +++ b/test/integration/service_sign_in/create_new_account_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" module ServiceSignIn class CreateNewAccount < ActionDispatch::IntegrationTest @@ -20,7 +20,7 @@ class CreateNewAccount < ActionDispatch::IntegrationTest test "page renders correctly" do setup_and_visit_create_new_account_page - assert page.has_css?("title", text: 'Create an account - GOV.UK', visible: false) + assert page.has_css?("title", text: "Create an account - GOV.UK", visible: false) assert_has_component_title "Create an account" @@ -30,7 +30,7 @@ class CreateNewAccount < ActionDispatch::IntegrationTest assert page.has_css?( '.gem-c-back-link[href="/log-in-file-self-assessment-tax-return/sign-in/choose-sign-in"]', - text: 'Back' + text: "Back", ) end diff --git a/test/integration/specialist_document_test.rb b/test/integration/specialist_document_test.rb index 9b38be92f..c16c7bd52 100644 --- a/test/integration/specialist_document_test.rb +++ b/test/integration/specialist_document_test.rb @@ -1,35 +1,35 @@ -require 'test_helper' +require "test_helper" class SpecialistDocumentTest < ActionDispatch::IntegrationTest test "random but valid specialist documents do not error" do - setup_and_visit_random_content_item(document_type: 'aaib_report') - setup_and_visit_random_content_item(document_type: 'raib_report') - setup_and_visit_random_content_item(document_type: 'tax_tribunal_decision') - setup_and_visit_random_content_item(document_type: 'cma_case') + setup_and_visit_random_content_item(document_type: "aaib_report") + setup_and_visit_random_content_item(document_type: "raib_report") + setup_and_visit_random_content_item(document_type: "tax_tribunal_decision") + setup_and_visit_random_content_item(document_type: "cma_case") end test "specialist document subtypes do not error" do - setup_and_visit_content_item('aaib-reports') - setup_and_visit_content_item('asylum-support-decision') - setup_and_visit_content_item('business-finance-support-scheme') - setup_and_visit_content_item('cma-cases') - setup_and_visit_content_item('countryside-stewardship-grants') - setup_and_visit_content_item('drug-safety-update') - setup_and_visit_content_item('employment-appeal-tribunal-decision') - setup_and_visit_content_item('employment-tribunal-decision') - setup_and_visit_content_item('european-structural-investment-funds') - setup_and_visit_content_item('eu-withdrawal-act-2018-statutory-instruments') - setup_and_visit_content_item('international-development-funding') - setup_and_visit_content_item('maib-reports') - setup_and_visit_content_item('raib-reports') - setup_and_visit_content_item('residential-property-tribunal-decision') - setup_and_visit_content_item('service-standard-report') - setup_and_visit_content_item('tax-tribunal-decision') - setup_and_visit_content_item('utaac-decision') + setup_and_visit_content_item("aaib-reports") + setup_and_visit_content_item("asylum-support-decision") + setup_and_visit_content_item("business-finance-support-scheme") + setup_and_visit_content_item("cma-cases") + setup_and_visit_content_item("countryside-stewardship-grants") + setup_and_visit_content_item("drug-safety-update") + setup_and_visit_content_item("employment-appeal-tribunal-decision") + setup_and_visit_content_item("employment-tribunal-decision") + setup_and_visit_content_item("european-structural-investment-funds") + setup_and_visit_content_item("eu-withdrawal-act-2018-statutory-instruments") + setup_and_visit_content_item("international-development-funding") + setup_and_visit_content_item("maib-reports") + setup_and_visit_content_item("raib-reports") + setup_and_visit_content_item("residential-property-tribunal-decision") + setup_and_visit_content_item("service-standard-report") + setup_and_visit_content_item("tax-tribunal-decision") + setup_and_visit_content_item("utaac-decision") end test "renders title, description and body" do - setup_and_visit_content_item('aaib-reports') + setup_and_visit_content_item("aaib-reports") assert_has_component_title(@content_item["title"].strip) assert page.has_text?(@content_item["description"]) @@ -37,7 +37,7 @@ class SpecialistDocumentTest < ActionDispatch::IntegrationTest end test "returns example for residential tribunal decision" do - setup_and_visit_content_item('residential-property-tribunal-decision') + setup_and_visit_content_item("residential-property-tribunal-decision") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) @@ -45,39 +45,39 @@ class SpecialistDocumentTest < ActionDispatch::IntegrationTest end test "renders from in publisher metadata" do - setup_and_visit_content_item('aaib-reports') + setup_and_visit_content_item("aaib-reports") assert_has_publisher_metadata_other( "From": { "Air Accidents Investigation Branch": - "/government/organisations/air-accidents-investigation-branch" - } + "/government/organisations/air-accidents-investigation-branch", + }, ) end test "renders published and updated in metadata" do - setup_and_visit_content_item('countryside-stewardship-grants') + setup_and_visit_content_item("countryside-stewardship-grants") assert_has_published_dates("Published 2 April 2015", "Last updated 29 March 2016") end test "renders change history in reverse chronological order" do - setup_and_visit_content_item('countryside-stewardship-grants') + setup_and_visit_content_item("countryside-stewardship-grants") within(".app-c-published-dates__change-history") do assert_match @content_item["details"]["change_history"].last["note"], - page.find(".app-c-published-dates__change-item:first-child").text + page.find(".app-c-published-dates__change-item:first-child").text assert_match @content_item["details"]["change_history"].first["note"], - page.find(".app-c-published-dates__change-item:last-child").text + page.find(".app-c-published-dates__change-item:last-child").text assert_equal all(".app-c-published-dates__change-item").size, - @content_item["details"]["change_history"].size + @content_item["details"]["change_history"].size end end test "renders text facets correctly" do - setup_and_visit_content_item('countryside-stewardship-grants') + setup_and_visit_content_item("countryside-stewardship-grants") assert_has_important_metadata( "Grant type": { "Option": "/countryside-stewardship-grants?grant_type%5B%5D=option" }, @@ -90,43 +90,43 @@ class SpecialistDocumentTest < ActionDispatch::IntegrationTest "Mid Tier": "/countryside-stewardship-grants?tiers_or_standalone_items%5B%5D=mid-tier", }, "Funding (per unit per year)": { - "More than £500": "/countryside-stewardship-grants?funding_amount%5B%5D=more-than-500" - } + "More than £500": "/countryside-stewardship-grants?funding_amount%5B%5D=more-than-500", + }, ) end test "renders date facets correctly" do - setup_and_visit_content_item('drug-device-alerts') + setup_and_visit_content_item("drug-device-alerts") assert_has_important_metadata("Issued": "6 July 2015") assert_footer_has_published_dates("Published 6 July 2015") end test "renders when no facet or finder" do - setup_and_visit_content_item('business-finance-support-scheme') + setup_and_visit_content_item("business-finance-support-scheme") assert_has_published_dates("Published 9 July 2015") end test "renders a nested contents list" do - setup_and_visit_content_item('countryside-stewardship-grants') + setup_and_visit_content_item("countryside-stewardship-grants") assert page.has_css?("#contents .gem-c-contents-list") assert page.has_css?(%(#contents .app-c-contents-list-with-body__link-wrapper .app-c-contents-list-with-body__link-container a.app-c-back-to-top)) within ".gem-c-contents-list" do - @content_item['details']['headers'].each do |heading| + @content_item["details"]["headers"].each do |heading| assert_nested_content_item(heading) end end end test "renders a nested contents list with level 2 and 3 headings only" do - setup_and_visit_content_item('drug-device-alerts') + setup_and_visit_content_item("drug-device-alerts") within ".gem-c-contents-list" do - @content_item['details']['headers'].each do |heading| + @content_item["details"]["headers"].each do |heading| assert_nested_content_item(heading) end end @@ -135,7 +135,7 @@ class SpecialistDocumentTest < ActionDispatch::IntegrationTest def assert_nested_content_item(heading) heading_level = heading["level"] selector = "a[href=\"##{heading['id']}\"]" - text = heading["text"].gsub(/\:$/, '') + text = heading["text"].gsub(/\:$/, "") if heading_level < 4 assert page.has_css?(selector), "Failed to find an element matching: #{selector}" @@ -151,29 +151,29 @@ def assert_nested_content_item(heading) end end - test 'renders no start button when not set' do - setup_and_visit_content_item('aaib-reports') + test "renders no start button when not set" do + setup_and_visit_content_item("aaib-reports") - refute page.has_css?('.gem-c-button', text: "Find out more") + refute page.has_css?(".gem-c-button", text: "Find out more") end - test 'renders start button' do - setup_and_visit_content_item('business-finance-support-scheme') + test "renders start button" do + setup_and_visit_content_item("business-finance-support-scheme") assert page.has_css?(".gem-c-button[href='http://www.bigissueinvest.com']", text: "Find out more") assert page.has_content?("on the Big Issue Invest website") end - test 'does not render a contents list if there are fewer than three items in the contents list' do - setup_and_visit_content_item('aaib-reports') + test "does not render a contents list if there are fewer than three items in the contents list" do + setup_and_visit_content_item("aaib-reports") - refute page.has_css?('#contents .gem-c-contents-list') + refute page.has_css?("#contents .gem-c-contents-list") end - test 'renders a link to statutory instruments finder' do - setup_and_visit_content_item('eu-withdrawal-act-2018-statutory-instruments') + test "renders a link to statutory instruments finder" do + setup_and_visit_content_item("eu-withdrawal-act-2018-statutory-instruments") assert page.has_css?("a[href='/eu-withdrawal-act-2018-statutory-instruments']", - text: 'See all EU Withdrawal Act 2018 statutory instruments') + text: "See all EU Withdrawal Act 2018 statutory instruments") end end diff --git a/test/integration/speech_test.rb b/test/integration/speech_test.rb index 0d8e38231..7afea7195 100644 --- a/test/integration/speech_test.rb +++ b/test/integration/speech_test.rb @@ -1,8 +1,8 @@ -require 'test_helper' +require "test_helper" class SpeechTest < ActionDispatch::IntegrationTest test "renders title, description and body" do - setup_and_visit_content_item('speech') + setup_and_visit_content_item("speech") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) @@ -10,15 +10,15 @@ class SpeechTest < ActionDispatch::IntegrationTest end test "translated speech" do - setup_and_visit_content_item('speech-translated') + setup_and_visit_content_item("speech-translated") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) - assert page.has_css?('.gem-c-translation-nav') + assert page.has_css?(".gem-c-translation-nav") end test "renders metadata and document footer, including speaker" do - setup_and_visit_content_item('speech') + setup_and_visit_content_item("speech") assert_has_publisher_metadata( published: "Published 8 March 2016", @@ -27,15 +27,15 @@ class SpeechTest < ActionDispatch::IntegrationTest "Department of Energy & Climate Change and The Rt Hon Andrea Leadsom MP": nil, "Department of Energy": "/government/organisations/department-of-energy-climate-change", "The Rt Hon Andrea Leadsom MP": "/government/people/andrea-leadsom", - } - } + }, + }, ) assert_has_important_metadata( "Delivered on": "2 February 2016 (Original script, may differ from delivered version)", "Location": - "Women in Nuclear UK Conference, Church House Conference Centre, Dean's Yard, Westminster, London" + "Women in Nuclear UK Conference, Church House Conference Centre, Dean's Yard, Westminster, London", ) assert_footer_has_published_dates("Published 8 March 2016") diff --git a/test/integration/statistical_data_set_test.rb b/test/integration/statistical_data_set_test.rb index 7f178531b..7fa3b87b7 100644 --- a/test/integration/statistical_data_set_test.rb +++ b/test/integration/statistical_data_set_test.rb @@ -1,8 +1,8 @@ -require 'test_helper' +require "test_helper" class StatisticalDataSetTest < ActionDispatch::IntegrationTest test "renders title, description and body" do - setup_and_visit_content_item('statistical_data_set') + setup_and_visit_content_item("statistical_data_set") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) @@ -10,12 +10,12 @@ class StatisticalDataSetTest < ActionDispatch::IntegrationTest end test "renders metadata and document footer" do - setup_and_visit_content_item('statistical_data_set') + setup_and_visit_content_item("statistical_data_set") assert_has_publisher_metadata( published: "Published 13 December 2012", metadata: { - "From:": { "Department for Transport": "/government/organisations/department-for-transport" } - } + "From:": { "Department for Transport": "/government/organisations/department-for-transport" }, + }, ) assert_footer_has_published_dates("Published 13 December 2012") end @@ -23,7 +23,7 @@ class StatisticalDataSetTest < ActionDispatch::IntegrationTest test "renders withdrawn notification" do setup_and_visit_content_item("statistical_data_set_withdrawn") - assert page.has_css?('title', text: "[Withdrawn]", visible: false) + assert page.has_css?("title", text: "[Withdrawn]", visible: false) withdrawn_at = @content_item["withdrawn_notice"]["withdrawn_at"] @@ -35,15 +35,15 @@ class StatisticalDataSetTest < ActionDispatch::IntegrationTest end test "historically political statistical data set" do - setup_and_visit_content_item('statistical_data_set_political') + setup_and_visit_content_item("statistical_data_set_political") within ".app-c-banner" do - assert page.has_text?('This was published under the 2010 to 2015 Conservative and Liberal Democrat coalition government') + assert page.has_text?("This was published under the 2010 to 2015 Conservative and Liberal Democrat coalition government") end end test "renders with contents list" do - setup_and_visit_content_item('statistical_data_set') + setup_and_visit_content_item("statistical_data_set") assert_has_contents_list([ { text: "Olympics", id: "olympics" }, diff --git a/test/integration/statistics_announcement_test.rb b/test/integration/statistics_announcement_test.rb index 169c58d0d..6062feb24 100644 --- a/test/integration/statistics_announcement_test.rb +++ b/test/integration/statistics_announcement_test.rb @@ -1,8 +1,8 @@ -require 'test_helper' +require "test_helper" class StatisticsAnnouncementTest < ActionDispatch::IntegrationTest test "official statistics" do - setup_and_visit_content_item('official_statistics') + setup_and_visit_content_item("official_statistics") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) @@ -11,41 +11,41 @@ class StatisticsAnnouncementTest < ActionDispatch::IntegrationTest end test "national statistics" do - setup_and_visit_content_item('national_statistics') + setup_and_visit_content_item("national_statistics") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) assert page.has_css?('img[alt="National Statistics"]') - within '.app-c-important-metadata' do + within ".app-c-important-metadata" do assert page.has_text?(:all, "Release date: January 2016 (provisional)") end end test "cancelled statistics" do - setup_and_visit_content_item('cancelled_official_statistics') + setup_and_visit_content_item("cancelled_official_statistics") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) - within '.gem-c-notice' do - assert page.has_text?('Statistics release cancelled'), "is cancelled" + within ".gem-c-notice" do + assert page.has_text?("Statistics release cancelled"), "is cancelled" assert page.has_text?(@content_item["details"]["cancellation_reason"]), "displays cancelleation reason" end assert_has_important_metadata( "Proposed release": "20 January 2016 9:30am", - "Cancellation date": "17 January 2016 2:19pm" + "Cancellation date": "17 January 2016 2:19pm", ) end test "statistics with a changed release date" do - setup_and_visit_content_item('release_date_changed') + setup_and_visit_content_item("release_date_changed") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) assert page.has_text?(:all, "Release date: 20 January 2016 9:30am (confirmed)") - within '.release-date-changed .app-c-important-metadata' do + within ".release-date-changed .app-c-important-metadata" do assert page.has_text?("The release date has been changed") assert page.has_text?("Previous date") assert page.has_text?("19 January 2016 9:30am") @@ -55,7 +55,7 @@ class StatisticsAnnouncementTest < ActionDispatch::IntegrationTest end test "statistics announcement that are not cancelled display forthcoming notice" do - setup_and_visit_content_item('official_statistics') + setup_and_visit_content_item("official_statistics") within(".gem-c-notice") do assert_text "#{StatisticsAnnouncementPresenter::FORTHCOMING_NOTICE} on #{@content_item['details']['display_date']}" @@ -63,7 +63,7 @@ class StatisticsAnnouncementTest < ActionDispatch::IntegrationTest end test "cancelled statistics announcements do not display the forthcoming notice" do - setup_and_visit_content_item('cancelled_official_statistics') + setup_and_visit_content_item("cancelled_official_statistics") refute page.has_text?(StatisticsAnnouncementPresenter::FORTHCOMING_NOTICE) end diff --git a/test/integration/take_part_test.rb b/test/integration/take_part_test.rb index fb824fcb1..e91053959 100644 --- a/test/integration/take_part_test.rb +++ b/test/integration/take_part_test.rb @@ -1,8 +1,8 @@ -require 'test_helper' +require "test_helper" class TakePartTest < ActionDispatch::IntegrationTest test "take part pages" do - setup_and_visit_content_item('take_part') + setup_and_visit_content_item("take_part") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) diff --git a/test/integration/topical_event_about_page_test.rb b/test/integration/topical_event_about_page_test.rb index 3c3c408e9..3fc3bb8ed 100644 --- a/test/integration/topical_event_about_page_test.rb +++ b/test/integration/topical_event_about_page_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class TopicalEventAboutPageTest < ActionDispatch::IntegrationTest test "random but valid items do not error" do @@ -6,20 +6,20 @@ class TopicalEventAboutPageTest < ActionDispatch::IntegrationTest end test "topical event about pages" do - setup_and_visit_content_item('topical_event_about_page') + setup_and_visit_content_item("topical_event_about_page") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) assert page.has_text?("The risk of Ebola to the UK remains low. The virus is only transmitted by direct contact with the blood or bodily fluids of an infected person.") assert_has_contents_list([ { text: "Response in the UK", id: "response-in-the-uk" }, { text: "Response in Africa", id: "response-in-africa" }, - { text: "Advice for travellers", id: "advice-for-travellers" } + { text: "Advice for travellers", id: "advice-for-travellers" }, ]) end test "slim topical event about pages have no contents" do - setup_and_visit_content_item('slim') - refute page.has_css?('.contents-list.contents-list-dashed') + setup_and_visit_content_item("slim") + refute page.has_css?(".contents-list.contents-list-dashed") end test "contents list not displayed when fewer than three items" do @@ -45,7 +45,7 @@ class TopicalEventAboutPageTest < ActionDispatch::IntegrationTest private def topical_event_end_date - Date.parse(@content_item['links']['parent'][0]['details']['end_date']) + Date.parse(@content_item["links"]["parent"][0]["details"]["end_date"]) end def long_first_item_body diff --git a/test/integration/travel_advice_atom_feed_test.rb b/test/integration/travel_advice_atom_feed_test.rb index 7db2d6917..0fc2578dd 100644 --- a/test/integration/travel_advice_atom_feed_test.rb +++ b/test/integration/travel_advice_atom_feed_test.rb @@ -1,18 +1,18 @@ -require 'test_helper' +require "test_helper" -require 'nokogiri/html' -require 'open-uri' -require 'rss' +require "nokogiri/html" +require "open-uri" +require "rss" class TravelAdviceAtomFeed < ActionDispatch::IntegrationTest setup do - setup_and_parse_travel_advice_atom_feed('full-country') - @base_path = @content_item['base_path'] + setup_and_parse_travel_advice_atom_feed("full-country") + @base_path = @content_item["base_path"] @updated_at = Time.parse(@content_item["public_updated_at"]) end test "it sets the alternative link correctly" do - alternate_link = @feed.links.find { |link| link.rel == 'alternate' } + alternate_link = @feed.links.find { |link| link.rel == "alternate" } assert alternate_link.href.ends_with?(@base_path) end @@ -23,12 +23,12 @@ class TravelAdviceAtomFeed < ActionDispatch::IntegrationTest test "it sets the entry's title correctly" do title = @feed.items.first.title.content - assert_equal title, @content_item['title'] + assert_equal title, @content_item["title"] end test "it sets the entry's summary correctly" do summary = Nokogiri::HTML::fragment(@feed.items.first.summary.content) - assert_equal summary.text.strip, @content_item['details']['change_description'].strip + assert_equal summary.text.strip, @content_item["details"]["change_description"].strip end test "it sets the entry's updated correctly" do @@ -37,12 +37,12 @@ class TravelAdviceAtomFeed < ActionDispatch::IntegrationTest end def setup_and_parse_travel_advice_atom_feed(name) - @content_item = get_content_example_by_schema_and_name('travel_advice', name) + @content_item = get_content_example_by_schema_and_name("travel_advice", name) uri = URI::HTTP.build( host: Capybara.current_session.server.host, port: Capybara.current_session.server.port, - path: "#{@content_item['base_path']}.atom" + path: "#{@content_item['base_path']}.atom", ) content_store_has_item(@content_item["base_path"], @content_item.to_json) diff --git a/test/integration/travel_advice_print_test.rb b/test/integration/travel_advice_print_test.rb index 71c69077f..481fac56c 100644 --- a/test/integration/travel_advice_print_test.rb +++ b/test/integration/travel_advice_print_test.rb @@ -1,37 +1,37 @@ -require 'test_helper' +require "test_helper" class TravelAdvicePrint < ActionDispatch::IntegrationTest test "it renders the print view" do - setup_and_visit_travel_advice_print('full-country') + setup_and_visit_travel_advice_print("full-country") assert page.has_css?("#travel-advice-print") end test "it is not indexable by search engines" do - setup_and_visit_travel_advice_print('full-country') + setup_and_visit_travel_advice_print("full-country") assert page.has_css?("meta[name='robots'][content='noindex, nofollow']", visible: false) end test "it renders the summary and all parts in the print view" do - setup_and_visit_travel_advice_print('full-country') - parts = @content_item['details']['parts'] + setup_and_visit_travel_advice_print("full-country") + parts = @content_item["details"]["parts"] assert_has_component_metadata_pair("Still current at", Date.today.strftime("%-d %B %Y")) assert_has_component_metadata_pair("Updated", Date.parse(@content_item["details"]["reviewed_at"]).strftime("%-d %B %Y")) within ".gem-c-metadata" do - assert page.has_content?(@content_item['details']['change_description'].gsub('Latest update: ', '').strip) + assert page.has_content?(@content_item["details"]["change_description"].gsub("Latest update: ", "").strip) end - assert page.has_css?("h1", text: 'Summary') + assert page.has_css?("h1", text: "Summary") parts.each do |part| - assert page.has_css?("h1", text: part['title']) + assert page.has_css?("h1", text: part["title"]) end assert page.has_content?("Summary – the main opposition party has called for mass protests against the government in Tirana on 18 February 2017") end def setup_and_visit_travel_advice_print(name) - example = get_content_example_by_schema_and_name('travel_advice', name) + example = get_content_example_by_schema_and_name("travel_advice", name) @content_item = example.tap do |item| content_store_has_item(item["base_path"], item.to_json) visit "#{item['base_path']}/print" diff --git a/test/integration/travel_advice_test.rb b/test/integration/travel_advice_test.rb index 24b3427ee..0ce703183 100644 --- a/test/integration/travel_advice_test.rb +++ b/test/integration/travel_advice_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class TravelAdviceTest < ActionDispatch::IntegrationTest test "random but valid items do not error" do @@ -6,29 +6,29 @@ class TravelAdviceTest < ActionDispatch::IntegrationTest end test "travel advice header and navigation" do - setup_and_visit_content_item('full-country') + setup_and_visit_content_item("full-country") - assert page.has_css?("title", visible: false, text: @content_item['title']) + assert page.has_css?("title", visible: false, text: @content_item["title"]) assert_has_component_title(@content_item["details"]["country"]["name"]) assert page.has_css?("a[href=\"#{@content_item['details']['email_signup_link']}\"]", text: "Get email alerts") assert page.has_css?("a[href=\"#{@content_item['base_path']}.atom\"]", text: "Subscribe to feed") - assert page.has_css?('.part-navigation ol', count: 2) - assert page.has_css?('.part-navigation li', count: @content_item['details']['parts'].size + 1) - assert page.has_css?('.part-navigation li', text: 'Summary') - refute page.has_css?('.part-navigation li a', text: 'Summary') + assert page.has_css?(".part-navigation ol", count: 2) + assert page.has_css?(".part-navigation li", count: @content_item["details"]["parts"].size + 1) + assert page.has_css?(".part-navigation li", text: "Summary") + refute page.has_css?(".part-navigation li a", text: "Summary") - @content_item['details']['parts'].each do |part| - assert page.has_css?(".part-navigation li a[href*=\"#{part['slug']}\"]", text: part['title']) + @content_item["details"]["parts"].each do |part| + assert page.has_css?(".part-navigation li a[href*=\"#{part['slug']}\"]", text: part["title"]) end - assert page.has_css?('.gem-c-pagination') + assert page.has_css?(".gem-c-pagination") assert page.has_css?('.app-c-print-link a[href$="/print"]') end test "travel advice summary has latest updates and map" do - setup_and_visit_content_item('full-country') + setup_and_visit_content_item("full-country") assert page.has_css?("h1", text: "Summary") assert page.has_text?("The main opposition party has called for mass protests against the government in Tirana on 18 February 2017. The political atmosphere is likely to become changeable as the country approaches national elections on 18 June 2017.") @@ -37,7 +37,7 @@ class TravelAdviceTest < ActionDispatch::IntegrationTest assert_has_component_metadata_pair("Updated", Date.parse(@content_item["details"]["reviewed_at"]).strftime("%-d %B %Y")) within ".gem-c-metadata" do - assert page.has_content?(@content_item['details']['change_description'].gsub('Latest update: ', '').strip) + assert page.has_content?(@content_item["details"]["change_description"].gsub("Latest update: ", "").strip) end assert page.has_css?(".map img[src=\"#{@content_item['details']['image']['url']}\"]") @@ -45,23 +45,23 @@ class TravelAdviceTest < ActionDispatch::IntegrationTest end test "travel advice part renders just that part" do - example = get_content_example('full-country') - first_part = example['details']['parts'].first - setup_and_visit_travel_advice_part('full-country', first_part['slug']) + example = get_content_example("full-country") + first_part = example["details"]["parts"].first + setup_and_visit_travel_advice_part("full-country", first_part["slug"]) assert page.has_css?("title", visible: false, text: "#{first_part['title']} - #{@content_item['title']}") - assert page.has_css?("h1", text: first_part['title']) + assert page.has_css?("h1", text: first_part["title"]) assert page.has_text?("Public security is generally good, particularly in Tirana, and Albanians are very hospitable to visitors.") refute page.has_css?(".map") refute page.has_css?(".gem-c-metadata") - assert page.has_css?('.part-navigation li', text: first_part['title']) - refute page.has_css?('.part-navigation li a', text: first_part['title']) + assert page.has_css?(".part-navigation li", text: first_part["title"]) + refute page.has_css?(".part-navigation li a", text: first_part["title"]) end test "travel advice includes a discoverable atom feed link" do - setup_and_visit_content_item('full-country') + setup_and_visit_content_item("full-country") assert page.has_css?("link[type*='atom'][href='#{@content_item['base_path']}.atom']", visible: false) end diff --git a/test/integration/working_group_test.rb b/test/integration/working_group_test.rb index be99e07f2..a4ebb65bf 100644 --- a/test/integration/working_group_test.rb +++ b/test/integration/working_group_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class WorkingGroupTest < ActionDispatch::IntegrationTest test "random but valid items do not error" do @@ -6,7 +6,7 @@ class WorkingGroupTest < ActionDispatch::IntegrationTest end test "working groups" do - setup_and_visit_content_item('long') + setup_and_visit_content_item("long") assert_has_component_title(@content_item["title"]) assert page.has_text?(@content_item["description"]) assert page.has_text?("Contact details") @@ -24,7 +24,7 @@ class WorkingGroupTest < ActionDispatch::IntegrationTest end test "with_policies" do - setup_and_visit_content_item('with_policies') + setup_and_visit_content_item("with_policies") policy = @content_item["links"]["policies"][0] assert page.has_text?("Policies") diff --git a/test/integration/world_location_news_article_test.rb b/test/integration/world_location_news_article_test.rb index 11fc9a5e6..269d08e92 100644 --- a/test/integration/world_location_news_article_test.rb +++ b/test/integration/world_location_news_article_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class WorldLocationNewsArticleTest < ActionDispatch::IntegrationTest test "world location news article renders title, description and body" do @@ -6,7 +6,7 @@ class WorldLocationNewsArticleTest < ActionDispatch::IntegrationTest assert page.has_css?( "meta[name='description'][content='Chevening Secretariat announces the Chevening/British Library Fellowship']", - visible: false + visible: false, ) assert_has_component_title(@content_item["title"]) @@ -15,7 +15,7 @@ class WorldLocationNewsArticleTest < ActionDispatch::IntegrationTest end test "renders first published, from and part of in metadata and document footer" do - setup_and_visit_content_item('world_location_news_article') + setup_and_visit_content_item("world_location_news_article") assert_has_published_dates("Published 24 November 2015") assert_footer_has_published_dates("Published 24 November 2015") diff --git a/test/models/feature_toggler_test.rb b/test/models/feature_toggler_test.rb index a8f082e39..bcd633f90 100644 --- a/test/models/feature_toggler_test.rb +++ b/test/models/feature_toggler_test.rb @@ -1,52 +1,52 @@ -require 'test_helper' +require "test_helper" class FeatureTogglerTest < ActiveSupport::TestCase - test 'use_recommended_related_links returns false when content item has no links attribute' do + test "use_recommended_related_links returns false when content item has no links attribute" do content_item = {} instance = setup_feature_toggler_with_feature_enabled(true) - use_recommended_links = instance.use_recommended_related_links?(content_item['links'], @request_headers) + use_recommended_links = instance.use_recommended_related_links?(content_item["links"], @request_headers) assert_equal(false, use_recommended_links) end - test 'use_recommended_related_links returns false when content item has existing ordered_related_items' do + test "use_recommended_related_links returns false when content item has existing ordered_related_items" do content_item = { "links" => { "ordered_related_items" => [{ "content_id" => "1234" }] } } instance = setup_feature_toggler_with_feature_enabled(true) - use_recommended_links = instance.use_recommended_related_links?(content_item['links'], @request_headers) + use_recommended_links = instance.use_recommended_related_links?(content_item["links"], @request_headers) assert_equal(false, use_recommended_links) end - test 'use_recommended_related_links returns false when headers are not correct' do + test "use_recommended_related_links returns false when headers are not correct" do content_item = { "links" => {} } instance = setup_feature_toggler_with_feature_enabled(false) - use_recommended_links = instance.use_recommended_related_links?(content_item['links'], {}) + use_recommended_links = instance.use_recommended_related_links?(content_item["links"], {}) assert_equal(false, use_recommended_links) end - test 'use_recommended_related_links returns true when content item has no ordered_related_items attribute and headers are correct' do + test "use_recommended_related_links returns true when content item has no ordered_related_items attribute and headers are correct" do content_item = { "links" => {} } instance = setup_feature_toggler_with_feature_enabled(true) - use_recommended_links = instance.use_recommended_related_links?(content_item['links'], @request_headers) + use_recommended_links = instance.use_recommended_related_links?(content_item["links"], @request_headers) assert_equal(true, use_recommended_links) end - test 'use_recommended_related_links returns true when content item has no items in ordered_related_items attribute and headers are correct' do + test "use_recommended_related_links returns true when content item has no items in ordered_related_items attribute and headers are correct" do content_item = { "links" => { "ordered_related_items" => [] } } instance = setup_feature_toggler_with_feature_enabled(true) - use_recommended_links = instance.use_recommended_related_links?(content_item['links'], @request_headers) + use_recommended_links = instance.use_recommended_related_links?(content_item["links"], @request_headers) assert_equal(true, use_recommended_links) end - test 'feature_flags attr_reader delegates to instance of feature_flags' do + test "feature_flags attr_reader delegates to instance of feature_flags" do feature_flags = HttpFeatureFlags.new feature_toggler = FeatureToggler.new(feature_flags) @@ -54,7 +54,7 @@ class FeatureTogglerTest < ActiveSupport::TestCase end def setup - @request_headers = { 'HTTP_GOVUK_USE_RECOMMENDED_RELATED_LINKS': 'true' } + @request_headers = { 'HTTP_GOVUK_USE_RECOMMENDED_RELATED_LINKS': "true" } end def setup_feature_toggler_with_feature_enabled(feature_enabled) diff --git a/test/models/http_feature_flags_test.rb b/test/models/http_feature_flags_test.rb index 7e505d63c..3abe9848c 100644 --- a/test/models/http_feature_flags_test.rb +++ b/test/models/http_feature_flags_test.rb @@ -1,72 +1,72 @@ -require 'test_helper' +require "test_helper" class HttpFeatureFlagsTest < ActiveSupport::TestCase - test 'instance should create a singleton instance' do + test "instance should create a singleton instance" do instance = HttpFeatureFlags.instance - instance.add_http_feature_flag('TEST_HEADER', 'show') + instance.add_http_feature_flag("TEST_HEADER", "show") new_instance = HttpFeatureFlags.instance - feature_enabled = new_instance.feature_enabled?('TEST_HEADER', 'HTTP_TEST_HEADER' => 'show') + feature_enabled = new_instance.feature_enabled?("TEST_HEADER", "HTTP_TEST_HEADER" => "show") assert_equal(true, feature_enabled) end - test 'add_http_feature_flag should set a new feature flag' do + test "add_http_feature_flag should set a new feature flag" do instance = HttpFeatureFlags.new - feature_enabled = instance.feature_enabled?('USE_MAGIC', 'HTTP_USE_MAGIC' => 'only_at_weekends') + feature_enabled = instance.feature_enabled?("USE_MAGIC", "HTTP_USE_MAGIC" => "only_at_weekends") assert_equal(false, feature_enabled) - instance.add_http_feature_flag('USE_MAGIC', 'only_at_weekends') - feature_enabled = instance.feature_enabled?('USE_MAGIC', 'HTTP_USE_MAGIC' => 'only_at_weekends') + instance.add_http_feature_flag("USE_MAGIC", "only_at_weekends") + feature_enabled = instance.feature_enabled?("USE_MAGIC", "HTTP_USE_MAGIC" => "only_at_weekends") assert_equal(true, feature_enabled) end - test 'feature_enabled? should return false when feature flag has not been set' do + test "feature_enabled? should return false when feature flag has not been set" do instance = HttpFeatureFlags.new - feature_enabled = instance.feature_enabled?('USE_MAGIC', 'HTTP_USE_MAGIC' => 'only_at_weekends') + feature_enabled = instance.feature_enabled?("USE_MAGIC", "HTTP_USE_MAGIC" => "only_at_weekends") assert_equal(false, feature_enabled) end - test 'feature_enabled? should return false when header has not been set' do + test "feature_enabled? should return false when header has not been set" do instance = HttpFeatureFlags.new - instance.add_http_feature_flag('USE_MAGIC', 'only_at_weekends') - feature_enabled = instance.feature_enabled?('USE_MAGIC', {}) + instance.add_http_feature_flag("USE_MAGIC", "only_at_weekends") + feature_enabled = instance.feature_enabled?("USE_MAGIC", {}) assert_equal(false, feature_enabled) end - test 'feature_enabled? should return false when header has been set but does not match specified value' do + test "feature_enabled? should return false when header has been set but does not match specified value" do instance = HttpFeatureFlags.new - instance.add_http_feature_flag('USE_MAGIC', 'only_at_weekends') - feature_enabled = instance.feature_enabled?('USE_MAGIC', 'HTTP_USE_MAGIC' => 'all_the_time') + instance.add_http_feature_flag("USE_MAGIC", "only_at_weekends") + feature_enabled = instance.feature_enabled?("USE_MAGIC", "HTTP_USE_MAGIC" => "all_the_time") assert_equal(false, feature_enabled) end - test 'feature_enabled? should return true when headers has been set and matches specified value' do + test "feature_enabled? should return true when headers has been set and matches specified value" do instance = HttpFeatureFlags.new - instance.add_http_feature_flag('USE_MAGIC', 'only_at_weekends') - feature_enabled = instance.feature_enabled?('USE_MAGIC', 'HTTP_USE_MAGIC' => 'only_at_weekends') + instance.add_http_feature_flag("USE_MAGIC", "only_at_weekends") + feature_enabled = instance.feature_enabled?("USE_MAGIC", "HTTP_USE_MAGIC" => "only_at_weekends") assert_equal(true, feature_enabled) end - test 'get_feature_flag returns nil when feature flag does not exist' do + test "get_feature_flag returns nil when feature flag does not exist" do instance = HttpFeatureFlags.new - feature_flag_value = instance.get_feature_flag('USE_MAGIC') + feature_flag_value = instance.get_feature_flag("USE_MAGIC") assert_nil feature_flag_value end - test 'get_feature_flag returns feature flag value when feature flag exists' do + test "get_feature_flag returns feature flag value when feature flag exists" do instance = HttpFeatureFlags.new - instance.add_http_feature_flag('USE_MAGIC', 'only_at_weekends') - feature_flag_value = instance.get_feature_flag('USE_MAGIC') + instance.add_http_feature_flag("USE_MAGIC", "only_at_weekends") + feature_flag_value = instance.get_feature_flag("USE_MAGIC") - assert_equal 'only_at_weekends', feature_flag_value + assert_equal "only_at_weekends", feature_flag_value end end diff --git a/test/presenter_test_helper.rb b/test/presenter_test_helper.rb index 1e0740fbb..bb767c957 100644 --- a/test/presenter_test_helper.rb +++ b/test/presenter_test_helper.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class PresenterTestCase < ActiveSupport::TestCase def schema_name diff --git a/test/presenters/answer_presenter_test.rb b/test/presenters/answer_presenter_test.rb index 6d451f5dc..13fab2d13 100644 --- a/test/presenters/answer_presenter_test.rb +++ b/test/presenters/answer_presenter_test.rb @@ -1,15 +1,15 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class AnswerPresenterTest < PresenterTestCase def schema_name "answer" end - test 'presents the title' do - assert_equal schema_item['title'], presented_item.title + test "presents the title" do + assert_equal schema_item["title"], presented_item.title end - test 'presents the body' do - assert_equal schema_item['details']['body'], presented_item.body + test "presents the body" do + assert_equal schema_item["details"]["body"], presented_item.body end end diff --git a/test/presenters/case_study_presenter_test.rb b/test/presenters/case_study_presenter_test.rb index f57d64fda..fb6940659 100644 --- a/test/presenters/case_study_presenter_test.rb +++ b/test/presenters/case_study_presenter_test.rb @@ -1,4 +1,4 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class CaseStudyPresenterTest < PresenterTestCase include ActionView::Helpers::UrlHelper @@ -7,86 +7,86 @@ def schema_name "case_study" end - test 'presents the basic details of a content item' do - assert_equal schema_item['description'], presented_item.description - assert_equal schema_item['schema_name'], presented_item.schema_name - assert_equal schema_item['locale'], presented_item.locale - assert_equal schema_item['title'], presented_item.title - assert_equal schema_item['details']['body'], presented_item.body + test "presents the basic details of a content item" do + assert_equal schema_item["description"], presented_item.description + assert_equal schema_item["schema_name"], presented_item.schema_name + assert_equal schema_item["locale"], presented_item.locale + assert_equal schema_item["title"], presented_item.title + assert_equal schema_item["details"]["body"], presented_item.body end - test '#published returns a formatted date of the day the content item became public' do - assert_equal '17 December 2012', presented_item.published + test "#published returns a formatted date of the day the content item became public" do + assert_equal "17 December 2012", presented_item.published end - test '#updated returns nil if the content item has no updates' do + test "#updated returns nil if the content item has no updates" do assert_nil presented_item.updated end - test '#updated returns a formatted date of the last day the content item was updated' do - assert_equal '21 March 2013', presented_case_study_with_updates.updated + test "#updated returns a formatted date of the last day the content item was updated" do + assert_equal "21 March 2013", presented_case_study_with_updates.updated end - test '#from returns links to lead organisations, supporting organisations and worldwide organisations' do + test "#from returns links to lead organisations, supporting organisations and worldwide organisations" do with_organisations = { "details" => { - "emphasised_organisations" => ["b56753d2-ae3f-480e-88b0-35b1934dfc5a"], + "emphasised_organisations" => %w[b56753d2-ae3f-480e-88b0-35b1934dfc5a], }, "links" => { - "worldwide_organisations" => [{ "title" => 'DFID Pakistan', "base_path" => '/government/world/organisations/dfid-pakistan' }], + "worldwide_organisations" => [{ "title" => "DFID Pakistan", "base_path" => "/government/world/organisations/dfid-pakistan" }], "organisations" => [ - { "title" => 'Supporting org', "base_path" => '/orgs/supporting', 'content_id' => 'dc2beab0-4ee9-41e0-9a6f-9c586d50fa7e' }, - { "title" => 'Lead org', "base_path" => '/orgs/lead', 'content_id' => 'b56753d2-ae3f-480e-88b0-35b1934dfc5a' }, + { "title" => "Supporting org", "base_path" => "/orgs/supporting", "content_id" => "dc2beab0-4ee9-41e0-9a6f-9c586d50fa7e" }, + { "title" => "Lead org", "base_path" => "/orgs/lead", "content_id" => "b56753d2-ae3f-480e-88b0-35b1934dfc5a" }, ], - } + }, } expected_from_links = [ - link_to('Lead org', '/orgs/lead', class: "govuk-link"), - link_to('Supporting org', '/orgs/supporting', class: "govuk-link"), - link_to('DFID Pakistan', '/government/world/organisations/dfid-pakistan', class: "govuk-link"), + link_to("Lead org", "/orgs/lead", class: "govuk-link"), + link_to("Supporting org", "/orgs/supporting", class: "govuk-link"), + link_to("DFID Pakistan", "/government/world/organisations/dfid-pakistan", class: "govuk-link"), ] assert_equal expected_from_links, presented_item(schema_name, with_organisations).from end - test '#part_of returns an array of document_collections, related policies and world locations' do + test "#part_of returns an array of document_collections, related policies and world locations" do with_extras = schema_item - with_extras['links']['document_collections'] = [ - { "title" => "Work Programme real life stories", "base_path" => "/government/collections/work-programme-real-life-stories" } + with_extras["links"]["document_collections"] = [ + { "title" => "Work Programme real life stories", "base_path" => "/government/collections/work-programme-real-life-stories" }, ] - with_extras['links']['related_policies'] = [ - { "title" => "Cheese", "base_path" => "/policy/cheese" } + with_extras["links"]["related_policies"] = [ + { "title" => "Cheese", "base_path" => "/policy/cheese" }, ] expected_part_of_links = [ - link_to('Work Programme real life stories', '/government/collections/work-programme-real-life-stories', class: "govuk-link"), - link_to('Cheese', '/policy/cheese', class: "govuk-link"), - link_to('Pakistan', '/world/pakistan/news', class: "govuk-link"), + link_to("Work Programme real life stories", "/government/collections/work-programme-real-life-stories", class: "govuk-link"), + link_to("Cheese", "/policy/cheese", class: "govuk-link"), + link_to("Pakistan", "/world/pakistan/news", class: "govuk-link"), ] assert_equal expected_part_of_links, presented_item(schema_name, with_extras).part_of end - test '#history returns an empty array if the content item has no updates' do + test "#history returns an empty array if the content item has no updates" do assert_equal [], presented_item.history end - test '#history returns a formatted history if the content item has updates' do + test "#history returns a formatted history if the content item has updates" do expected_history = [ - { display_time: '21 March 2013', note: 'Something changed', timestamp: '2013-03-21 00:00:00 +0000' }, + { display_time: "21 March 2013", note: "Something changed", timestamp: "2013-03-21 00:00:00 +0000" }, ] assert_equal expected_history, presented_case_study_with_updates.history end - test '#history returns an empty array if the content item is not published' do + test "#history returns an empty array if the content item is not published" do never_published = schema_item - never_published['details'].delete('first_public_at') + never_published["details"].delete("first_public_at") presented = CaseStudyPresenter.new(never_published) assert_equal [], presented.history end - test 'presents withdrawn notices' do + test "presents withdrawn notices" do example = schema_item("archived") presented = presented_item("archived") @@ -99,8 +99,8 @@ def schema_name def presented_case_study_with_updates updated_date = Time.new(2013, 3, 21).to_s with_history = schema_item - with_history['details']['change_history'] = [{ 'note' => 'Something changed', 'public_timestamp' => updated_date }] - with_history['public_updated_at'] = updated_date + with_history["details"]["change_history"] = [{ "note" => "Something changed", "public_timestamp" => updated_date }] + with_history["public_updated_at"] = updated_date presented_item(schema_name, with_history) end diff --git a/test/presenters/coming_soon_presenter_test.rb b/test/presenters/coming_soon_presenter_test.rb index 3923e7b1b..7ee950821 100644 --- a/test/presenters/coming_soon_presenter_test.rb +++ b/test/presenters/coming_soon_presenter_test.rb @@ -1,22 +1,22 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class ComingSoonPresenterTest < PresenterTestCase def schema_name "coming_soon" end - test 'presents the basic details required to display a coming soon item' do - assert_equal schema_item['title'], presented_item.title - assert_equal schema_item['schema_name'], presented_item.schema_name - assert_equal schema_item['locale'], presented_item.locale - assert_equal schema_item['details']['publish_time'], presented_item.publish_time + test "presents the basic details required to display a coming soon item" do + assert_equal schema_item["title"], presented_item.title + assert_equal schema_item["schema_name"], presented_item.schema_name + assert_equal schema_item["locale"], presented_item.locale + assert_equal schema_item["details"]["publish_time"], presented_item.publish_time end - test '#formatted_publish_time' do - assert_equal '09:30', presented_item.formatted_publish_time + test "#formatted_publish_time" do + assert_equal "09:30", presented_item.formatted_publish_time end - test '#formatted_publish_date' do - assert_equal '17 December 2014', presented_item.formatted_publish_date + test "#formatted_publish_date" do + assert_equal "17 December 2014", presented_item.formatted_publish_date end end diff --git a/test/presenters/consultation_presenter_test.rb b/test/presenters/consultation_presenter_test.rb index 20c5fe6f2..34051fbfa 100644 --- a/test/presenters/consultation_presenter_test.rb +++ b/test/presenters/consultation_presenter_test.rb @@ -1,4 +1,4 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class ConsultationPresenterTest class PresentedConsultation < PresenterTestCase @@ -6,49 +6,49 @@ def schema_name "consultation" end - test 'presents the schema name' do - assert_equal schema_item("open_consultation")['document_type'], presented_item("open_consultation").document_type - assert_equal schema_item("open_consultation")['details']['body'], presented_item("open_consultation").body + test "presents the schema name" do + assert_equal schema_item("open_consultation")["document_type"], presented_item("open_consultation").document_type + assert_equal schema_item("open_consultation")["details"]["body"], presented_item("open_consultation").body end - test 'presents friendly dates for opening and closing dates, including time' do + test "presents friendly dates for opening and closing dates, including time" do schema = schema_item("open_consultation") - schema['details']['opening_date'] = "2016-11-04T10:00:00+00:00" - schema['details']['closing_date'] = "2216-12-16T16:00:00+00:00" + schema["details"]["opening_date"] = "2016-11-04T10:00:00+00:00" + schema["details"]["closing_date"] = "2216-12-16T16:00:00+00:00" presented = presented_item("open_consultation", schema) assert_equal "10am on 4 November 2016", presented.opening_date assert_equal "4pm on 16 December 2216", presented.closing_date end - test 'presents closing dates at 12am as 11:59pm on the day before' do + test "presents closing dates at 12am as 11:59pm on the day before" do schema = schema_item("open_consultation") - schema['details']['opening_date'] = "2016-11-03T00:01:00+00:00" - schema['details']['closing_date'] = "2016-11-04T00:00:00+00:00" + schema["details"]["opening_date"] = "2016-11-03T00:01:00+00:00" + schema["details"]["closing_date"] = "2016-11-04T00:00:00+00:00" presented = presented_item("open_consultation", schema) assert_equal "12:01am on 3 November 2016", presented.opening_date assert_equal "11:59pm on 3 November 2016", presented.closing_date end - test 'presents opening dates at 12am as the date without a time' do + test "presents opening dates at 12am as the date without a time" do schema = schema_item("open_consultation") - schema['details']['opening_date'] = "2016-11-03T00:00:00+00:00" - schema['details']['closing_date'] = "2016-11-04T00:00:00+00:00" + schema["details"]["opening_date"] = "2016-11-03T00:00:00+00:00" + schema["details"]["closing_date"] = "2016-11-04T00:00:00+00:00" presented = presented_item("open_consultation", schema) assert_equal "3 November 2016", presented.opening_date end - test 'presents 12pm as midday' do + test "presents 12pm as midday" do schema = schema_item("open_consultation") - schema['details']['opening_date'] = "2016-11-04T12:00:00+00:00" + schema["details"]["opening_date"] = "2016-11-04T12:00:00+00:00" presented = presented_item("open_consultation", schema) assert_equal "midday on 4 November 2016", presented.opening_date end - test 'presents open and closed states' do + test "presents open and closed states" do assert presented_item("open_consultation").open? refute presented_item("open_consultation").closed? @@ -62,31 +62,31 @@ def schema_name refute presented_item("unopened_consultation").open? end - test 'presents consultation documents' do + test "presents consultation documents" do presented = presented_item("closed_consultation") schema = schema_item("closed_consultation") assert presented.documents? - assert_equal schema['details']['documents'].join(''), presented.documents + assert_equal schema["details"]["documents"].join(""), presented.documents end - test 'presents final outcome documents' do + test "presents final outcome documents" do presented = presented_item("consultation_outcome") schema = schema_item("consultation_outcome") assert presented.final_outcome_documents? - assert_equal schema['details']['final_outcome_documents'].join(''), presented.final_outcome_documents + assert_equal schema["details"]["final_outcome_documents"].join(""), presented.final_outcome_documents end - test 'presents public feedback documents' do + test "presents public feedback documents" do presented = presented_item("consultation_outcome_with_feedback") schema = schema_item("consultation_outcome_with_feedback") assert presented.public_feedback_documents? - assert_equal schema['details']['public_feedback_documents'].join(''), presented.public_feedback_documents + assert_equal schema["details"]["public_feedback_documents"].join(""), presented.public_feedback_documents end - test 'presents URL for consultations held on another website' do + test "presents URL for consultations held on another website" do assert presented_item("open_consultation").held_on_another_website? refute presented_item("closed_consultation").held_on_another_website? @@ -94,60 +94,60 @@ def schema_name refute presented_item("closed_consultation").held_on_another_website_url end - test 'content can apply only to a set of nations' do - example = schema_item('consultation_outcome_with_feedback') - presented = presented_item('consultation_outcome_with_feedback') + test "content can apply only to a set of nations" do + example = schema_item("consultation_outcome_with_feedback") + presented = presented_item("consultation_outcome_with_feedback") - assert example['details'].include?('national_applicability') - assert_equal presented.applies_to, 'England' + assert example["details"].include?("national_applicability") + assert_equal presented.applies_to, "England" end - test 'presents ways to respond' do - example_ways_to_respond = schema_item('open_consultation_with_participation')['details']['ways_to_respond'] - presented = presented_item('open_consultation_with_participation') + test "presents ways to respond" do + example_ways_to_respond = schema_item("open_consultation_with_participation")["details"]["ways_to_respond"] + presented = presented_item("open_consultation_with_participation") assert presented.ways_to_respond? - assert_equal example_ways_to_respond['email'], presented.email - assert_equal example_ways_to_respond['link_url'], presented.respond_online_url - assert_equal example_ways_to_respond['postal_address'], presented.postal_address + assert_equal example_ways_to_respond["email"], presented.email + assert_equal example_ways_to_respond["link_url"], presented.respond_online_url + assert_equal example_ways_to_respond["postal_address"], presented.postal_address end - test 'presents a response form when included with email or postal address' do - example_ways_to_respond = schema_item('open_consultation_with_participation')['details']['ways_to_respond'] - presented = presented_item('open_consultation_with_participation') + test "presents a response form when included with email or postal address" do + example_ways_to_respond = schema_item("open_consultation_with_participation")["details"]["ways_to_respond"] + presented = presented_item("open_consultation_with_participation") assert presented.response_form? - assert_equal example_ways_to_respond['attachment_url'], presented.attachment_url + assert_equal example_ways_to_respond["attachment_url"], presented.attachment_url example_without_email = schema_item("open_consultation_with_participation") - example_without_email['details']['ways_to_respond'].delete('email') - example_without_email['details']['ways_to_respond'].delete('postal_address') + example_without_email["details"]["ways_to_respond"].delete("email") + example_without_email["details"]["ways_to_respond"].delete("postal_address") presented_without_email = presented_item("open_consultation_with_participation", example_without_email) refute presented_without_email.response_form? end - test 'does not show ways to respond when consultation is closed' do + test "does not show ways to respond when consultation is closed" do example = schema_item("closed_consultation") - example['details']['ways_to_respond'] = { 'email' => 'email@email.com' } + example["details"]["ways_to_respond"] = { "email" => "email@email.com" } presented = presented_item("closed_consultation", example) refute presented.ways_to_respond? end - test 'does not show ways to respond when only an attachment url is provided' do + test "does not show ways to respond when only an attachment url is provided" do example = schema_item("open_consultation_with_participation") - example['details']['ways_to_respond'].delete('email') - example['details']['ways_to_respond'].delete('postal_address') - example['details']['ways_to_respond'].delete('link_url') + example["details"]["ways_to_respond"].delete("email") + example["details"]["ways_to_respond"].delete("postal_address") + example["details"]["ways_to_respond"].delete("link_url") presented = presented_item("open_consultation_with_participation", example) refute presented.ways_to_respond? end - test 'presents share urls with encoded url and title' do - assert_equal 'https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.test.gov.uk%2Fgovernment%2Fconsultations%2Fpostgraduate-doctoral-loans', presented_item("open_consultation").share_links[0][:href] - assert_equal 'https://twitter.com/share?url=https%3A%2F%2Fwww.test.gov.uk%2Fgovernment%2Fconsultations%2Fpostgraduate-doctoral-loans&text=Postgraduate%20doctoral%20loans', presented_item("open_consultation").share_links[1][:href] + test "presents share urls with encoded url and title" do + assert_equal "https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.test.gov.uk%2Fgovernment%2Fconsultations%2Fpostgraduate-doctoral-loans", presented_item("open_consultation").share_links[0][:href] + assert_equal "https://twitter.com/share?url=https%3A%2F%2Fwww.test.gov.uk%2Fgovernment%2Fconsultations%2Fpostgraduate-doctoral-loans&text=Postgraduate%20doctoral%20loans", presented_item("open_consultation").share_links[1][:href] end end end diff --git a/test/presenters/contact_presenter_test.rb b/test/presenters/contact_presenter_test.rb index 0ab622830..53a692709 100644 --- a/test/presenters/contact_presenter_test.rb +++ b/test/presenters/contact_presenter_test.rb @@ -1,4 +1,4 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class ContactPresenterTest class PresentedContact < PresenterTestCase @@ -6,20 +6,20 @@ def schema_name "contact" end - test 'presents the title' do - assert_equal schema_item['title'], presented_item.title + test "presents the title" do + assert_equal schema_item["title"], presented_item.title end - test 'presents online form links' do - assert_equal schema_item['details']['contact_form_links'].first['link'], presented_item.online_form_links.first[:url] + test "presents online form links" do + assert_equal schema_item["details"]["contact_form_links"].first["link"], presented_item.online_form_links.first[:url] end - test 'presents online form body' do - assert_equal schema_item['details']['more_info_contact_form'], presented_item.online_form_body + test "presents online form body" do + assert_equal schema_item["details"]["more_info_contact_form"], presented_item.online_form_body end - test 'phone returns correctly' do - phone_number = schema_item['details']['phone_numbers'][0] + test "phone returns correctly" do + phone_number = schema_item["details"]["phone_numbers"][0] presented_phone_number = presented_item.phone[0] assert_equal phone_number["number"], presented_phone_number[:numbers][0][:number] assert_equal phone_number["textphone"].blank?, presented_phone_number[:numbers][0][:textphone].nil? @@ -29,41 +29,41 @@ def schema_name assert_equal phone_number["best_time_to_call"].strip, presented_phone_number[:best_time_to_call] end - test 'phone_body returns correctly' do - assert_equal schema_item['details']['more_info_phone_number'], presented_item.phone_body + test "phone_body returns correctly" do + assert_equal schema_item["details"]["more_info_phone_number"], presented_item.phone_body end - test 'post' do - post_address = schema_item['details']['post_addresses'][0] + test "post" do + post_address = schema_item["details"]["post_addresses"][0] presented_post_address = presented_item.post[0] - assert_equal post_address['description'].strip, presented_post_address[:description] - rendered_presented_address = presented_post_address[:v_card].reduce('') { |acc, hash| acc << hash[:value].strip } - rendered_input_address = %w(title street_address locality region postal_code world_location).reduce('') do |acc, key| + assert_equal post_address["description"].strip, presented_post_address[:description] + rendered_presented_address = presented_post_address[:v_card].reduce("") { |acc, hash| acc << hash[:value].strip } + rendered_input_address = %w(title street_address locality region postal_code world_location).reduce("") do |acc, key| acc << post_address[key].strip end assert_equal rendered_input_address, rendered_presented_address - assert_equal 'fn', presented_post_address[:v_card][0][:v_card_class] + assert_equal "fn", presented_post_address[:v_card][0][:v_card_class] end - test 'post_body returns correctly' do - assert_equal schema_item['details']['more_info_post_address'], presented_item.post_body + test "post_body returns correctly" do + assert_equal schema_item["details"]["more_info_post_address"], presented_item.post_body end - test 'email' do - assert_equal schema_item['details']['email_addresses'][0]['email'].strip, presented_item.email[0][:email] - assert_equal schema_item['details']['email_addresses'][0]['title'].strip, presented_item.email[0][:v_card][0][:value] + test "email" do + assert_equal schema_item["details"]["email_addresses"][0]["email"].strip, presented_item.email[0][:email] + assert_equal schema_item["details"]["email_addresses"][0]["title"].strip, presented_item.email[0][:v_card][0][:value] end - test 'email_body' do - assert_equal schema_item['details']['more_info_email_address'], presented_item.email_body + test "email_body" do + assert_equal schema_item["details"]["more_info_email_address"], presented_item.email_body end - test 'handles more info when set to nil' do + test "handles more info when set to nil" do example = schema_item - example['details']['more_info_phone_number'] = nil - example['details']['more_info_email_address'] = nil - example['details']['more_info_post_address'] = nil - example['details']['more_info_contact_form'] = nil + example["details"]["more_info_phone_number"] = nil + example["details"]["more_info_email_address"] = nil + example["details"]["more_info_post_address"] = nil + example["details"]["more_info_contact_form"] = nil assert_nil present_example(example).phone_body assert_nil present_example(example).email_body @@ -71,12 +71,12 @@ def schema_name assert_nil present_example(example).online_form_body end - test 'handles more info when not set' do + test "handles more info when not set" do example = schema_item - example['details'].delete('more_info_phone_number') - example['details'].delete('more_info_email_address') - example['details'].delete('more_info_post_address') - example['details'].delete('more_info_contact_form') + example["details"].delete("more_info_phone_number") + example["details"].delete("more_info_email_address") + example["details"].delete("more_info_post_address") + example["details"].delete("more_info_contact_form") assert_nil present_example(example).phone_body assert_nil present_example(example).email_body @@ -84,8 +84,8 @@ def schema_name assert_nil present_example(example).online_form_body end - test 'presents webchat' do - schema = schema_item('contact_with_webchat') + test "presents webchat" do + schema = schema_item("contact_with_webchat") presented = present_example(schema) assert_equal true, presented.show_webchat? assert_equal presented.webchat_availability_url, "https://www.tax.service.gov.uk/csp-partials/availability/1030" diff --git a/test/presenters/content_item/contents_list_test.rb b/test/presenters/content_item/contents_list_test.rb index 7c06e62c9..0438587c3 100644 --- a/test/presenters/content_item/contents_list_test.rb +++ b/test/presenters/content_item/contents_list_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class ContentItemContentsListTest < ActiveSupport::TestCase def setup @@ -13,7 +13,7 @@ def body end end - @contents_list.expects(:contents_items).returns([{ text: "A heading", id: 'custom' }]).once + @contents_list.expects(:contents_items).returns([{ text: "A heading", id: "custom" }]).once @contents_list.contents @contents_list.contents end @@ -25,7 +25,7 @@ def body end end - assert_equal [{ text: "A heading", id: 'custom' }], @contents_list.contents_items + assert_equal [{ text: "A heading", id: "custom" }], @contents_list.contents_items end test "removes trailing colons from headings" do @@ -35,7 +35,7 @@ def body end end - assert_equal [{ text: "List", id: 'custom' }], @contents_list.contents_items + assert_equal [{ text: "List", id: "custom" }], @contents_list.contents_items end test "removes only trailing colons from headings" do @@ -45,13 +45,13 @@ def body end end - assert_equal [{ text: "Part 2: List", id: 'custom' }], @contents_list.contents_items + assert_equal [{ text: "Part 2: List", id: "custom" }], @contents_list.contents_items end test "ignores headings without an id" do class << @contents_list def body - '

John Doe

' + "

John Doe

" end end @@ -75,7 +75,7 @@ def body { text: "One", id: "one" }, { text: "Two", id: "two" }, { text: "Three", id: "three" }, - { text: "Four", id: "four" } + { text: "Four", id: "four" }, ], @contents_list.contents_items end diff --git a/test/presenters/content_item/linkable_test.rb b/test/presenters/content_item/linkable_test.rb index 4eba604d6..7381ae8fa 100644 --- a/test/presenters/content_item/linkable_test.rb +++ b/test/presenters/content_item/linkable_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class ContentItemLinkableTest < ActiveSupport::TestCase class DummyContentItem @@ -20,11 +20,11 @@ def initialize { "title" => "Winston Churchill", "base_path" => "/government/people/winston-churchill", - } + }, ] expected_from_links = [ - %{Winston Churchill} + %{Winston Churchill}, ] assert_equal expected_from_links, item.from end @@ -35,7 +35,7 @@ def initialize { "title" => "Winston Churchill", "base_path" => nil, - } + }, ] expected_from_links = [] @@ -51,11 +51,11 @@ def initialize { "title" => "Germany", "base_path" => nil, - } + }, ] expected_from_links = [ - %{Germany} + %{Germany}, ] assert_equal expected_from_links, item.part_of end diff --git a/test/presenters/content_item/news_image_test.rb b/test/presenters/content_item/news_image_test.rb index 98efa8e99..a76f81b28 100644 --- a/test/presenters/content_item/news_image_test.rb +++ b/test/presenters/content_item/news_image_test.rb @@ -26,7 +26,7 @@ def initialize item = DummyContentItem.new default_news_image = { "url" => "http://www.test.dev.gov.uk/default_news_image.jpg" } item.content_item["links"]["primary_publishing_organisation"] = [ - "details" => { "default_news_image" => default_news_image } + "details" => { "default_news_image" => default_news_image }, ] assert_equal default_news_image, item.image diff --git a/test/presenters/content_item/organisation_branding_test.rb b/test/presenters/content_item/organisation_branding_test.rb index 165d1eb5c..df6505670 100644 --- a/test/presenters/content_item/organisation_branding_test.rb +++ b/test/presenters/content_item/organisation_branding_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class ContentItemOrganisationBrandingTest < ActiveSupport::TestCase include ContentItem::OrganisationBranding @@ -10,9 +10,9 @@ def test_organisation "brand" => "department-of-health", "logo" => { "formatted_title" => "Department
of Health", - "crest" => "single-identity" - } - } + "crest" => "single-identity", + }, + }, } end @@ -49,7 +49,7 @@ def test_organisation organisation = test_organisation organisation["details"]["logo"]["image"] = { "url" => "url", - "alt_text" => "alt_text" + "alt_text" => "alt_text", } logo = organisation_logo(organisation) diff --git a/test/presenters/content_item/parts_test.rb b/test/presenters/content_item/parts_test.rb index 487cff474..aad75113e 100644 --- a/test/presenters/content_item/parts_test.rb +++ b/test/presenters/content_item/parts_test.rb @@ -1,26 +1,26 @@ -require 'test_helper' +require "test_helper" module ContentItemPartsStubs def base_path - '/base-path' + "/base-path" end def content_item { - 'details' => { - 'parts' => [ + "details" => { + "parts" => [ { - 'title' => 'first-title', - 'slug' => 'first-slug', - 'body' => 'first-body', + "title" => "first-title", + "slug" => "first-slug", + "body" => "first-body", }, { - 'title' => 'second-title', - 'slug' => 'second-slug', - 'body' => 'second-body', - } - ] - } + "title" => "second-title", + "slug" => "second-slug", + "body" => "second-body", + }, + ], + }, } end end @@ -37,7 +37,7 @@ def requested_content_item_path module PresentingSecondPartInContentItem def part_slug - 'second-slug' + "second-slug" end def requested_content_item_path @@ -60,17 +60,17 @@ def presenting_second_part_in_content_item @parts.extend(PresentingSecondPartInContentItem) end - test 'is not requesting a part when no parts exist' do + test "is not requesting a part when no parts exist" do class << @parts def content_item - { 'details' => {} } + { "details" => {} } end end refute @parts.requesting_a_part? end - test 'is not requesting a part when parts exist and base_path matches requested_content_item_path' do + test "is not requesting a part when parts exist and base_path matches requested_content_item_path" do class << @parts def requested_content_item_path base_path @@ -80,44 +80,44 @@ def requested_content_item_path refute @parts.requesting_a_part? end - test 'is requesting a part when part exists and base_path is different to requested_content_item_path' do + test "is requesting a part when part exists and base_path is different to requested_content_item_path" do class << @parts def part_slug - 'second-slug' + "second-slug" end def requested_content_item_path - base_path + '/second-slug' + base_path + "/second-slug" end end assert @parts.requesting_a_part? end - test 'is requesting a valid part when part exists' do + test "is requesting a valid part when part exists" do class << @parts def part_slug - 'second-slug' + "second-slug" end def requested_content_item_path - base_path + '/' + part_slug + base_path + "/" + part_slug end end assert @parts.has_valid_part? - assert_equal @parts.current_part_body, 'second-body' - assert_equal @parts.current_part_title, 'second-title' + assert_equal @parts.current_part_body, "second-body" + assert_equal @parts.current_part_title, "second-title" end - test 'is requesting an invalid part when no part with corresponding slug exists' do + test "is requesting an invalid part when no part with corresponding slug exists" do class << @parts def part_slug - 'not-a-valid-slug' + "not-a-valid-slug" end def requested_content_item_path - base_path + '/' + part_slug + base_path + "/" + part_slug end end @@ -125,14 +125,14 @@ def requested_content_item_path refute @parts.has_valid_part? end - test 'invalid when slug for first part is present in URL' do + test "invalid when slug for first part is present in URL" do class << @parts def part_slug - 'first-slug' + "first-slug" end def requested_content_item_path - base_path + '/' + part_slug + base_path + "/" + part_slug end end @@ -140,51 +140,51 @@ def requested_content_item_path refute @parts.has_valid_part? end - test 'defaults to first part as current part when parts exist but no part requested' do + test "defaults to first part as current part when parts exist but no part requested" do presenting_first_part_in_content_item refute @parts.requesting_a_part? - assert_equal @parts.current_part_body, 'first-body' - assert_equal @parts.current_part_title, 'first-title' + assert_equal @parts.current_part_body, "first-body" + assert_equal @parts.current_part_title, "first-title" end - test 'navigation items are presented as trackable links unless they are the current part' do + test "navigation items are presented as trackable links unless they are the current part" do presenting_first_part_in_content_item - assert_equal @parts.current_part_title, 'first-title' + assert_equal @parts.current_part_title, "first-title" assert_equal @parts.parts_navigation, - [[ - "first-title", - "second-title" - ]] + [[ + "first-title", + "second-title", + ]] end - test 'links to the first part ignore the part\'s slug and use the base path' do + test "links to the first part ignore the part's slug and use the base path" do presenting_second_part_in_content_item - assert_equal @parts.current_part_title, 'second-title' + assert_equal @parts.current_part_title, "second-title" assert @parts.parts_navigation[0][0].include? "href=\"/base-path\"" end - test 'navigation items link to all parts' do + test "navigation items link to all parts" do presenting_first_part_in_content_item assert_equal @parts.parts.size, @parts.parts_navigation.flatten.size end - test 'part navigation is in one group when 3 or fewer navigation items (2 parts + summary)' do + test "part navigation is in one group when 3 or fewer navigation items (2 parts + summary)" do presenting_first_part_in_content_item class << @parts def content_item { - 'details' => { - 'parts' => [ - { 'title' => 'title', 'slug' => 'slug', 'body' => 'body' }, - { 'title' => 'title', 'slug' => 'slug', 'body' => 'body' }, - { 'title' => 'title', 'slug' => 'slug', 'body' => 'body' } - ] - } + "details" => { + "parts" => [ + { "title" => "title", "slug" => "slug", "body" => "body" }, + { "title" => "title", "slug" => "slug", "body" => "body" }, + { "title" => "title", "slug" => "slug", "body" => "body" }, + ], + }, } end end @@ -198,14 +198,14 @@ def content_item class << @parts def content_item { - 'details' => { - 'parts' => [ - { 'title' => 'first-title', 'slug' => 'first-slug', 'body' => 'first-body' }, - { 'title' => 'second-title', 'slug' => 'second-slug', 'body' => 'second-body' }, - { 'title' => 'third-title', 'slug' => 'third-slug', 'body' => 'third-body' }, - { 'title' => 'fourth-title', 'slug' => 'fourth-slug', 'body' => 'fourth-body' } - ] - } + "details" => { + "parts" => [ + { "title" => "first-title", "slug" => "first-slug", "body" => "first-body" }, + { "title" => "second-title", "slug" => "second-slug", "body" => "second-body" }, + { "title" => "third-title", "slug" => "third-slug", "body" => "third-body" }, + { "title" => "fourth-title", "slug" => "fourth-slug", "body" => "fourth-body" }, + ], + }, } end end @@ -225,8 +225,8 @@ def content_item "fourth-title" - ] + "href=\"/base-path/fourth-slug\">fourth-title", + ], ] end end diff --git a/test/presenters/content_item/shareable_test.rb b/test/presenters/content_item/shareable_test.rb index 6ebcfd07b..e5ff02bab 100644 --- a/test/presenters/content_item/shareable_test.rb +++ b/test/presenters/content_item/shareable_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class ContentItemShareableTest < ActiveSupport::TestCase include ERB::Util @@ -18,13 +18,13 @@ def expected_path url_encode(Plek.current.website_root + "/a/base/path") end - test 'presents the twitter share url' do + test "presents the twitter share url" do expected_twitter_url = "https://twitter.com/share?url=#{expected_path}&text=A%20Title" actual = DummyContentItem.new.share_links[1][:href] assert_equal expected_twitter_url, actual end - test 'presents the facebook share url' do + test "presents the facebook share url" do expected_facebook_url = "https://www.facebook.com/sharer/sharer.php?u=#{expected_path}" actual = DummyContentItem.new.share_links[0][:href] assert_equal expected_facebook_url, actual diff --git a/test/presenters/content_item/updatable_test.rb b/test/presenters/content_item/updatable_test.rb index a2d3ce76e..15b73248a 100644 --- a/test/presenters/content_item/updatable_test.rb +++ b/test/presenters/content_item/updatable_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" module ContentItemUpdatableStubs def display_date(date) @@ -19,53 +19,53 @@ def setup @updatable.extend(ContentItemUpdatableStubs) end - test '#history returns an empty array when there is no change history' do + test "#history returns an empty array when there is no change history" do @updatable.extend(ContentItemUpdatableWithUpdates) class << @updatable def content_item - { 'details' => {} } + { "details" => {} } end end assert_empty @updatable.history end - test '#history returns updates when first_public_at does not match public_updated_at' do + test "#history returns updates when first_public_at does not match public_updated_at" do class << @updatable def content_item { - 'public_updated_at' => '2002-02-02', - 'first_published_at' => '2001-01-01', - 'details' => { - 'change_history' => [ + "public_updated_at" => "2002-02-02", + "first_published_at" => "2001-01-01", + "details" => { + "change_history" => [ { - 'note' => 'note', - 'public_timestamp' => '2002-02-02' - } - ] - } + "note" => "note", + "public_timestamp" => "2002-02-02", + }, + ], + }, } end end assert @updatable.history.any? - assert_equal @updatable.updated, '2002-02-02' + assert_equal @updatable.updated, "2002-02-02" end - test '#history returns no updates when first_public_at matches public_updated_at' do + test "#history returns no updates when first_public_at matches public_updated_at" do class << @updatable def content_item { - 'public_updated_at' => '2002-02-02', - 'details' => { - 'first_public_at' => '2002-02-02', - 'change_history' => [ + "public_updated_at" => "2002-02-02", + "details" => { + "first_public_at" => "2002-02-02", + "change_history" => [ { - 'note' => 'note', - 'public_timestamp' => '2002-02-02' - } - ] - } + "note" => "note", + "public_timestamp" => "2002-02-02", + }, + ], + }, } end end @@ -74,19 +74,19 @@ def content_item refute @updatable.updated end - test '#history returns no updates when first_public_at is not present' do + test "#history returns no updates when first_public_at is not present" do class << @updatable def content_item { - 'public_updated_at' => '2002-02-02', - 'details' => { - 'change_history' => [ + "public_updated_at" => "2002-02-02", + "details" => { + "change_history" => [ { - 'note' => 'note', - 'public_timestap' => '2002-02-02' - } - ] - } + "note" => "note", + "public_timestap" => "2002-02-02", + }, + ], + }, } end end @@ -95,19 +95,19 @@ def content_item refute @updatable.updated end - test '#history returns no updates when public_updated_at not present' do + test "#history returns no updates when public_updated_at not present" do class << @updatable def content_item { - 'details' => { - 'first_public_at' => '2001-01-01', - 'change_history' => [ + "details" => { + "first_public_at" => "2001-01-01", + "change_history" => [ { - 'note' => 'note', - 'public_timestamp' => '2002-02-02' - } - ] - } + "note" => "note", + "public_timestamp" => "2002-02-02", + }, + ], + }, } end end @@ -116,19 +116,19 @@ def content_item refute @updatable.updated end - test '#history returns an array of hashes when there is change history' do + test "#history returns an array of hashes when there is change history" do @updatable.extend(ContentItemUpdatableWithUpdates) class << @updatable def content_item { - 'details' => { - 'change_history' => [ + "details" => { + "change_history" => [ { - 'note' => 'notes', - 'public_timestamp' => '2016-02-29T09:24:10.000+00:00', - } - ] - } + "note" => "notes", + "public_timestamp" => "2016-02-29T09:24:10.000+00:00", + }, + ], + }, } end end @@ -136,38 +136,38 @@ def content_item assert_equal @updatable.history, [ { - display_time: '2016-02-29T09:24:10.000+00:00', - note: 'notes', - timestamp: '2016-02-29T09:24:10.000+00:00' - } + display_time: "2016-02-29T09:24:10.000+00:00", + note: "notes", + timestamp: "2016-02-29T09:24:10.000+00:00", + }, ] end - test '#history returns a reverse chronologically sorted array of hashes when there is change history' do + test "#history returns a reverse chronologically sorted array of hashes when there is change history" do @updatable.extend(ContentItemUpdatableWithUpdates) class << @updatable def content_item { - 'details' => { - 'change_history' => [ + "details" => { + "change_history" => [ { - 'note' => 'first', - 'public_timestamp' => '2001-01-01', + "note" => "first", + "public_timestamp" => "2001-01-01", }, { - 'note' => 'third', - 'public_timestamp' => '2003-03-03', + "note" => "third", + "public_timestamp" => "2003-03-03", }, { - 'note' => 'second', - 'public_timestamp' => '2002-02-02', - } - ] - } + "note" => "second", + "public_timestamp" => "2002-02-02", + }, + ], + }, } end end - assert_equal @updatable.history.map { |i| i[:timestamp] }, ['2003-03-03', '2002-02-02', '2001-01-01'] + assert_equal @updatable.history.map { |i| i[:timestamp] }, %w[2003-03-03 2002-02-02 2001-01-01] end end diff --git a/test/presenters/content_item/withdrawable_test.rb b/test/presenters/content_item/withdrawable_test.rb index 5862f60e5..5477c8188 100644 --- a/test/presenters/content_item/withdrawable_test.rb +++ b/test/presenters/content_item/withdrawable_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class ContentItemWithdrawableTest < ActiveSupport::TestCase def setup @@ -11,13 +11,13 @@ def teardown I18n.locale = I18n.default_locale end - test 'content item is withdrawn' do + test "content item is withdrawn" do class << @withdrawable def content_item { - 'withdrawn_notice' => { - 'withdrawn_at' => '2016-07-12T09:47:15Z' - } + "withdrawn_notice" => { + "withdrawn_at" => "2016-07-12T09:47:15Z", + }, } end end @@ -25,7 +25,7 @@ def content_item assert @withdrawable.withdrawn? end - test 'page title has withdrawn appended if content withdrawn' do + test "page title has withdrawn appended if content withdrawn" do class << @withdrawable def title content_item["title"] @@ -33,10 +33,10 @@ def title def content_item { - 'title' => 'Proportion of residents who do any walking or cycling (at local authority level) (CW010)', - 'withdrawn_notice' => { - 'withdrawn_at' => '2016-07-12T09:47:15Z' - } + "title" => "Proportion of residents who do any walking or cycling (at local authority level) (CW010)", + "withdrawn_notice" => { + "withdrawn_at" => "2016-07-12T09:47:15Z", + }, } end end @@ -44,10 +44,10 @@ def content_item assert_equal @withdrawable.page_title, "[Withdrawn] Proportion of residents who do any walking or cycling (at local authority level) (CW010)" end - test 'notice title and description are generated correctly' do + test "notice title and description are generated correctly" do class << @withdrawable def schema_name - 'news_article' + "news_article" end def display_date(date) @@ -56,11 +56,11 @@ def display_date(date) def content_item { - 'title' => 'Proportion of residents who do any walking or cycling (at local authority level) (CW010)', - 'withdrawn_notice' => { - 'explanation' => '', - 'withdrawn_at' => '2016-07-12T09:47:15Z' - } + "title" => "Proportion of residents who do any walking or cycling (at local authority level) (CW010)", + "withdrawn_notice" => { + "explanation" => '', + "withdrawn_at" => "2016-07-12T09:47:15Z", + }, } end end @@ -69,22 +69,22 @@ def content_item assert_equal @withdrawable.withdrawal_notice_component[:description_govspeak], "" end - test 'notice title presents only in English, even if locale is set to another language' do + test "notice title presents only in English, even if locale is set to another language" do # This is to prevent the withdrawal notices on translated editions # displaying a combination of languages in their titles. class << @withdrawable def schema_name - 'publication' + "publication" end def content_item { - 'title' => 'Proportion of residents who do any walking or cycling (at local authority level) (CW010)', - 'withdrawn_notice' => { - 'explanation' => '', - 'withdrawn_at' => '2016-07-12T09:47:15Z' + "title" => "Proportion of residents who do any walking or cycling (at local authority level) (CW010)", + "withdrawn_notice" => { + "explanation" => '', + "withdrawn_at" => "2016-07-12T09:47:15Z", }, - 'locale': 'cy' + 'locale': "cy", } end end diff --git a/test/presenters/content_item_presenter_test.rb b/test/presenters/content_item_presenter_test.rb index b5ed60b20..6365780b0 100644 --- a/test/presenters/content_item_presenter_test.rb +++ b/test/presenters/content_item_presenter_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class ContentItemPresenterTest < ActiveSupport::TestCase test "#title" do @@ -26,29 +26,29 @@ class ContentItemPresenterTest < ActiveSupport::TestCase end test "#canonical_url with a part" do - example_with_parts = govuk_content_schema_example('travel_advice', 'full-country') - request_path = example_with_parts['base_path'] + '/safety-and-security' + example_with_parts = govuk_content_schema_example("travel_advice", "full-country") + request_path = example_with_parts["base_path"] + "/safety-and-security" presented_example = TravelAdvicePresenter.new(example_with_parts, request_path) assert_equal "https://www.test.gov.uk/foreign-travel-advice/albania/safety-and-security", presented_example.canonical_url end test "available_translations sorts languages by locale with English first" do - translated = govuk_content_schema_example('case_study', 'translated') + translated = govuk_content_schema_example("case_study", "translated") locales = ContentItemPresenter.new(translated).available_translations assert_equal %w(en ar es), (locales.map { |t| t[:locale] }) end test "available_translations returns native locale names using native_language_name_for" do - translated = govuk_content_schema_example('case_study', 'translated') + translated = govuk_content_schema_example("case_study", "translated") locales = ContentItemPresenter.new(translated).available_translations assert_equal %w(English العربية Español), (locales.map { |t| t[:text] }) end test "part slug is nil when requesting a content item without parts" do - example_without_parts = govuk_content_schema_example('case_study', 'translated') - presented_example = ContentItemPresenter.new(example_without_parts, example_without_parts['base_path']) + example_without_parts = govuk_content_schema_example("case_study", "translated") + presented_example = ContentItemPresenter.new(example_without_parts, example_without_parts["base_path"]) refute presented_example.requesting_a_part? assert presented_example.part_slug.nil? diff --git a/test/presenters/corporate_information_page_presenter_test.rb b/test/presenters/corporate_information_page_presenter_test.rb index cf96be6a1..33c25766e 100644 --- a/test/presenters/corporate_information_page_presenter_test.rb +++ b/test/presenters/corporate_information_page_presenter_test.rb @@ -1,4 +1,4 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class CorporateInformationPagePresenterTest class PresentedCorporateInformationPage < PresenterTestCase @@ -6,76 +6,76 @@ def schema_name "corporate_information_page" end - test 'presents the body' do - assert_equal schema_item['details']['body'], presented_item.body + test "presents the body" do + assert_equal schema_item["details"]["body"], presented_item.body end - test 'presents the organisation in the title' do + test "presents the organisation in the title" do assert_equal "About us - Department of Health", presented_item.page_title end - test 'does not present an organisation in the title when it is not present in links' do + test "does not present an organisation in the title when it is not present in links" do presented_item = presented_item(schema_name, "links" => {}) assert_equal "About us", presented_item.page_title end - test 'presents withdrawn in the title for withdrawn content' do + test "presents withdrawn in the title for withdrawn content" do presented_item = presented_item(schema_name, "withdrawn_notice" => { "explanation": "Withdrawn", "withdrawn_at": "2014-08-22T10:29:02+01:00" }) assert_equal "[Withdrawn] About us - Department of Health", presented_item.page_title end - test 'has contents list' do + test "has contents list" do assert presented_item.is_a?(ContentItem::ContentsList) end - test 'has title without context' do + test "has title without context" do assert presented_item.is_a?(ContentItem::TitleAndContext) title_component_params = { title: "About us", context_locale: :en } assert_equal title_component_params, presented_item.title_and_context end - test 'has organisation branding' do + test "has organisation branding" do assert presented_item.is_a?(ContentItem::OrganisationBranding) end - test 'presents corporate information groups on about pages' do + test "presents corporate information groups on about pages" do assert presented_item.is_a?(ContentItem::CorporateInformationGroups) - expected_contents_list = { text: 'Corporate information', id: 'corporate-information', href: '#corporate-information' } + expected_contents_list = { text: "Corporate information", id: "corporate-information", href: "#corporate-information" } assert_equal expected_contents_list, presented_item.contents.last assert presented_item.corporate_information? end - test 'presents group links that are guids' do + test "presents group links that are guids" do presented_groups = presented_item.corporate_information assert_equal 'Complaints procedure', presented_groups.first[:links].first end - test 'presents group links that are internal links with paths and no GUID' do + test "presents group links that are internal links with paths and no GUID" do presented_groups = presented_item.corporate_information assert_equal 'Corporate reports', presented_groups.first[:links].last end - test 'presents group links that are external' do + test "presents group links that are external" do presented_groups = presented_item.corporate_information assert_equal 'Jobs', presented_groups.last[:links].last end - test 'presents group headings' do + test "presents group headings" do presented_groups = presented_item.corporate_information assert_equal '

Access our information

', presented_groups.first[:heading] end - test 'presents further information based on corporate information page links' do - publication_scheme = schema_item['links']['corporate_information_pages'].find { |l| l['document_type'] == 'publication_scheme' } - information_charter = schema_item['links']['corporate_information_pages'].find { |l| l['document_type'] == 'personal_information_charter' } + test "presents further information based on corporate information page links" do + publication_scheme = schema_item["links"]["corporate_information_pages"].find { |l| l["document_type"] == "publication_scheme" } + information_charter = schema_item["links"]["corporate_information_pages"].find { |l| l["document_type"] == "personal_information_charter" } - assert presented_item.further_information.include?(publication_scheme['base_path']) - assert presented_item.further_information.include?(publication_scheme['title']) - assert presented_item.further_information.include?(information_charter['base_path']) - assert presented_item.further_information.include?(information_charter['title']) + assert presented_item.further_information.include?(publication_scheme["base_path"]) + assert presented_item.further_information.include?(publication_scheme["title"]) + assert presented_item.further_information.include?(information_charter["base_path"]) + assert presented_item.further_information.include?(information_charter["title"]) end end end diff --git a/test/presenters/detailed_guide_presenter_test.rb b/test/presenters/detailed_guide_presenter_test.rb index d99cb4256..2ec436a01 100644 --- a/test/presenters/detailed_guide_presenter_test.rb +++ b/test/presenters/detailed_guide_presenter_test.rb @@ -1,27 +1,27 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class DetailedGuidePresenterTest < PresenterTestCase def schema_name "detailed_guide" end - test 'presents the basic details of a content item' do - assert_equal schema_item['description'], presented_item.description - assert_equal schema_item['schema_name'], presented_item.schema_name - assert_equal schema_item['title'], presented_item.title - assert_equal schema_item['details']['body'], presented_item.body + test "presents the basic details of a content item" do + assert_equal schema_item["description"], presented_item.description + assert_equal schema_item["schema_name"], presented_item.schema_name + assert_equal schema_item["title"], presented_item.title + assert_equal schema_item["details"]["body"], presented_item.body end - test 'presents a list of contents extracted from headings in the body' do + test "presents a list of contents extracted from headings in the body" do expected_contents_list_item = { text: "The basics", id: "the-basics", href: "#the-basics" } assert_equal expected_contents_list_item, presented_item.contents[0] end - test '#published returns a formatted date of the day the content item became public' do - assert_equal '12 June 2014', presented_item.published + test "#published returns a formatted date of the day the content item became public" do + assert_equal "12 June 2014", presented_item.published end - test 'presents withdrawn notices' do + test "presents withdrawn notices" do example = schema_item("withdrawn_detailed_guide") presented = presented_item("withdrawn_detailed_guide") @@ -31,11 +31,11 @@ def schema_name assert_equal '', presented.withdrawal_notice_component[:time] end - test 'presents the title of the publishing government' do + test "presents the title of the publishing government" do assert_equal schema_item["details"]["government"]["title"], presented_item.publishing_government end - test 'content can be historically political' do + test "content can be historically political" do example = schema_item("political_detailed_guide") presented = presented_item("political_detailed_guide") @@ -45,34 +45,34 @@ def schema_name assert presented.historically_political? end - test 'content can apply only to a set of nations' do - example = schema_item('national_applicability_detailed_guide') - presented = presented_item('national_applicability_detailed_guide') + test "content can apply only to a set of nations" do + example = schema_item("national_applicability_detailed_guide") + presented = presented_item("national_applicability_detailed_guide") - assert example['details'].include?('national_applicability') - assert_equal presented.applies_to, 'England' + assert example["details"].include?("national_applicability") + assert_equal presented.applies_to, "England" end - test 'content can apply only to a set of nations with alternative urls' do - example = schema_item('national_applicability_alternative_url_detailed_guide') - presented = presented_item('national_applicability_alternative_url_detailed_guide') + test "content can apply only to a set of nations with alternative urls" do + example = schema_item("national_applicability_alternative_url_detailed_guide") + presented = presented_item("national_applicability_alternative_url_detailed_guide") - assert example['details'].include?('national_applicability') + assert example["details"].include?("national_applicability") assert_equal presented.applies_to, 'England, Scotland, and Wales (see guidance for Northern Ireland)' end - test 'context in title is overridden to display as guidance' do + test "context in title is overridden to display as guidance" do I18n.with_locale("fr") do assert_equal I18n.t("content_item.schema_name.guidance", count: 1), presented_item.title_and_context[:context] end end - test 'eu structural fund logo is presented where applicable' do - presented = presented_item('england-2014-to-2020-european-structural-and-investment-funds') + test "eu structural fund logo is presented where applicable" do + presented = presented_item("england-2014-to-2020-european-structural-and-investment-funds") expected = { - alt_text: 'European structural investment funds', - path: 'https://assets.publishing.service.gov.uk/media/5540ab8aed915d15d8000030/european-structural-investment-funds.png' + alt_text: "European structural investment funds", + path: "https://assets.publishing.service.gov.uk/media/5540ab8aed915d15d8000030/european-structural-investment-funds.png", } assert_equal presented.logo, expected end diff --git a/test/presenters/document_collection_presenter_test.rb b/test/presenters/document_collection_presenter_test.rb index 49286829c..109e75d24 100644 --- a/test/presenters/document_collection_presenter_test.rb +++ b/test/presenters/document_collection_presenter_test.rb @@ -1,4 +1,4 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class DocumentCollectionPresenterTest class TestCase < PresenterTestCase @@ -8,27 +8,27 @@ def schema_name end class PresentedDocumentCollection < TestCase - test 'presents the title' do - assert_equal schema_item['title'], presented_item.title + test "presents the title" do + assert_equal schema_item["title"], presented_item.title end - test 'presents the description' do - assert_equal schema_item['description'], presented_item.description + test "presents the description" do + assert_equal schema_item["description"], presented_item.description end - test 'presents the schema name' do - assert_equal schema_item['schema_name'], presented_item.schema_name + test "presents the schema name" do + assert_equal schema_item["schema_name"], presented_item.schema_name end - test 'presents the body' do - example = 'document_collection_with_body' - expected_body = schema_item(example)['details']['body'] + test "presents the body" do + example = "document_collection_with_body" + expected_body = schema_item(example)["details"]["body"] presented_body = presented_item(example).body assert_equal expected_body, presented_body end - test 'presents a contents list based on collection groups' do + test "presents a contents list based on collection groups" do contents = [ { text: "Car and light van", id: "car-and-light-van", href: "#car-and-light-van" }, { text: "Moped and motorcycle", id: "moped-and-motorcycle", href: "#moped-and-motorcycle" }, @@ -41,13 +41,13 @@ class PresentedDocumentCollection < TestCase assert_equal contents, presented_item.contents end - test 'presents a group heading with generated ID' do + test "presents a group heading with generated ID" do heading = '

Heading with Spaces

' assert_equal heading, presented_item.group_heading("title" => "Heading with Spaces") end - test 'presents an ordered list of group documents' do + test "presents an ordered list of group documents" do documents = [ { link: { @@ -59,22 +59,22 @@ class PresentedDocumentCollection < TestCase track_label: "/government/publications/national-standard-for-driving-cars-and-light-vans", track_options: { dimension28: "1", - dimension29: "National standard for driving cars and light vans" - } - } + dimension29: "National standard for driving cars and light vans", + }, + }, }, metadata: { public_updated_at: Time.zone.parse("2007-03-16 15:00:02 +0000"), - document_type: "Guidance" - } - } + document_type: "Guidance", + }, + }, ] document_ids = schema_item["details"]["collection_groups"].first["documents"] assert_equal documents, presented_item.group_document_links({ "documents" => [document_ids.first] }, 0) end - test 'it handles the document type lacking a translation' do + test "it handles the document type lacking a translation" do schema_data = schema_item document = schema_data["links"]["documents"].first.tap do |link| @@ -89,7 +89,7 @@ class PresentedDocumentCollection < TestCase assert_nil grouped.first[:metadata][:document_type] end - test 'it handles public_updated_at not being specified' do + test "it handles public_updated_at not being specified" do schema_data = schema_item document = schema_data["links"]["documents"].first.tap do |link| @@ -120,7 +120,7 @@ class GroupWithMissingDocument < TestCase assert_equal( ["/government/publications/national-standard-for-developed-driving-competence"], - presented_links_base_paths + presented_links_base_paths, ) end end @@ -141,7 +141,7 @@ class GroupWithNoDocuments < TestCase class GroupWithOnlyMissingDocuments < TestCase test "does not present the group" do presenter = presented_item( - "document_collection_with_missing_links_documents" + "document_collection_with_missing_links_documents", ) group_with_missing_documents = @@ -156,7 +156,7 @@ class GroupWithOnlyMissingDocuments < TestCase class GroupWithDocumentsWhenThereIsNoLinksDocuments < TestCase test "does not present the group" do presenter = presented_item( - "document_collection_with_group_but_no_documents" + "document_collection_with_group_but_no_documents", ) group_with_missing_documents = @@ -171,7 +171,7 @@ class GroupWithDocumentsWhenThereIsNoLinksDocuments < TestCase class GroupWithDocumentsWhenThereAreWithdrawnDocuments < TestCase test "does not present withdrawn documents" do presenter = presented_item( - "document_collection_with_withdrawn_links_documents" + "document_collection_with_withdrawn_links_documents", ) presented_documents = presenter.groups.first["documents"] @@ -180,7 +180,7 @@ class GroupWithDocumentsWhenThereAreWithdrawnDocuments < TestCase assert_equal( presented_documents.size, - expected_number_of_presented_documents + expected_number_of_presented_documents, ) end end diff --git a/test/presenters/fatality_notice_presenter_test.rb b/test/presenters/fatality_notice_presenter_test.rb index f40d85c10..d549e18b3 100644 --- a/test/presenters/fatality_notice_presenter_test.rb +++ b/test/presenters/fatality_notice_presenter_test.rb @@ -1,35 +1,35 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class FatalityNoticePresenterTest < PresenterTestCase def schema_name "fatality_notice" end - test 'presents the basic details of a content item' do - assert_equal schema_item['title'], presented_item.title - assert_equal schema_item['description'], presented_item.description + test "presents the basic details of a content item" do + assert_equal schema_item["title"], presented_item.title + assert_equal schema_item["description"], presented_item.description end - test 'presents the field of operation' do + test "presents the field of operation" do assert_equal( - schema_item['links']['field_of_operation'].first['title'], - presented_item.field_of_operation.title + schema_item["links"]["field_of_operation"].first["title"], + presented_item.field_of_operation.title, ) assert_equal( - schema_item['links']['field_of_operation'].first['base_path'], - presented_item.field_of_operation.path + schema_item["links"]["field_of_operation"].first["base_path"], + presented_item.field_of_operation.path, ) end - test 'is linkable' do + test "is linkable" do assert presented_item.is_a?(ContentItem::Linkable) end - test 'is updatable' do + test "is updatable" do assert presented_item.is_a?(ContentItem::Updatable) end - test 'it presents the body' do - assert_equal schema_item['details']['body'], presented_item.body + test "it presents the body" do + assert_equal schema_item["details"]["body"], presented_item.body end end diff --git a/test/presenters/gone_presenter_test.rb b/test/presenters/gone_presenter_test.rb index af325d087..bc69509bd 100644 --- a/test/presenters/gone_presenter_test.rb +++ b/test/presenters/gone_presenter_test.rb @@ -1,13 +1,13 @@ -require 'test_helper' +require "test_helper" class GonePresenterTest < ActiveSupport::TestCase - test 'presents the basic details required to display an gone' do - assert_equal gone['details']['explanation'], presented_gone.explanation - assert_equal gone['details']['alternative_path'], presented_gone.alternative_path + test "presents the basic details required to display an gone" do + assert_equal gone["details"]["explanation"], presented_gone.explanation + assert_equal gone["details"]["alternative_path"], presented_gone.alternative_path end def gone - govuk_content_schema_example('gone', 'gone') + govuk_content_schema_example("gone", "gone") end def presented_gone diff --git a/test/presenters/guide_presenter_test.rb b/test/presenters/guide_presenter_test.rb index ce1c1107a..37c24494a 100644 --- a/test/presenters/guide_presenter_test.rb +++ b/test/presenters/guide_presenter_test.rb @@ -1,4 +1,4 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class GuidePresenterTest class PresentedGuide < PresenterTestCase @@ -6,18 +6,18 @@ def schema_name "guide" end - test 'has parts' do + test "has parts" do assert presented_item.is_a?(ContentItem::Parts) end test "presents unique page titles for each part" do - assert_equal presented_item.page_title, schema_item['title'] - schema_item['details']['parts'].each do |part| - assert_equal presented_item('guide', part['slug']).page_title, "#{schema_item['title']}: #{part['title']}" + assert_equal presented_item.page_title, schema_item["title"] + schema_item["details"]["parts"].each do |part| + assert_equal presented_item("guide", part["slug"]).page_title, "#{schema_item['title']}: #{part['title']}" end end - test 'presents withdrawn in the title for withdrawn content' do + test "presents withdrawn in the title for withdrawn content" do presented_item = presented_item(schema_name, nil, "withdrawn_notice" => { "explanation": "Withdrawn", "withdrawn_at": "2014-08-22T10:29:02+01:00" }) assert_equal "[Withdrawn] The national curriculum", presented_item.page_title end @@ -27,73 +27,73 @@ def schema_name end test "presents only next navigation when first part" do - parts = schema_item['details']['parts'] + parts = schema_item["details"]["parts"] nav = presented_item.previous_and_next_navigation expected_nav = { next_page: { url: "#{schema_item['base_path']}/#{parts[1]['slug']}", title: "Next", - label: parts[1]['title'] - } + label: parts[1]["title"], + }, } assert_equal nav, expected_nav end test "presents previous and next navigation" do - parts = schema_item['details']['parts'] - nav = presented_item('guide', parts[1]['slug']).previous_and_next_navigation + parts = schema_item["details"]["parts"] + nav = presented_item("guide", parts[1]["slug"]).previous_and_next_navigation expected_nav = { next_page: { url: "#{schema_item['base_path']}/#{parts[2]['slug']}", title: "Next", - label: parts[2]['title'] + label: parts[2]["title"], }, previous_page: { - url: schema_item['base_path'], + url: schema_item["base_path"], title: "Previous", - label: parts[0]['title'] - } + label: parts[0]["title"], + }, } assert_equal nav, expected_nav end test "presents only previous navigation when last part" do - parts = schema_item['details']['parts'] - nav = presented_item('guide', parts.last['slug']).previous_and_next_navigation + parts = schema_item["details"]["parts"] + nav = presented_item("guide", parts.last["slug"]).previous_and_next_navigation expected_nav = { previous_page: { url: "#{schema_item['base_path']}/#{parts[-2]['slug']}", title: "Previous", - label: parts[-2]['title'] - } + label: parts[-2]["title"], + }, } assert_equal nav, expected_nav end test "presents no navigation when no other parts" do - nav = presented_item('single-page-guide').previous_and_next_navigation + nav = presented_item("single-page-guide").previous_and_next_navigation assert_equal nav, {} end test "sends an error notification for guide with no parts" do GovukError.expects(:notify).with( - 'Guide with no parts', - extra: { error_message: 'Guide rendered without any parts at /correct-marriage-registration' } + "Guide with no parts", + extra: { error_message: "Guide rendered without any parts at /correct-marriage-registration" }, ) - presented_item('no-part-guide').has_parts? + presented_item("no-part-guide").has_parts? end test "presents access tokens in part links when provided" do - presented = presented_item('guide') - presented.draft_access_token = 'some_token' - expected_param = '?token=some_token' + presented = presented_item("guide") + presented.draft_access_token = "some_token" + expected_param = "?token=some_token" presented.parts.each do |part| - assert part['full_path'].ends_with?(expected_param) + assert part["full_path"].ends_with?(expected_param) end presented.parts_navigation.flatten.each_with_index do |link, i| @@ -114,7 +114,7 @@ def presented_item(type = schema_name, part_slug = nil, overrides = {}) GuidePresenter.new( schema_example_content_item.merge(overrides), - "#{schema_example_content_item['base_path']}#{part_slug}" + "#{schema_example_content_item['base_path']}#{part_slug}", ) end end diff --git a/test/presenters/help_page_presenter_test.rb b/test/presenters/help_page_presenter_test.rb index e87fb3a19..af71a73ec 100644 --- a/test/presenters/help_page_presenter_test.rb +++ b/test/presenters/help_page_presenter_test.rb @@ -1,15 +1,15 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class HelpPagePresenterTest < PresenterTestCase def schema_name "help_page" end - test 'presents the title' do - assert_equal schema_item['title'], presented_item.title + test "presents the title" do + assert_equal schema_item["title"], presented_item.title end - test 'presents the body' do - assert_equal schema_item['details']['body'], presented_item.body + test "presents the body" do + assert_equal schema_item["details"]["body"], presented_item.body end end diff --git a/test/presenters/html_publication_presenter_test.rb b/test/presenters/html_publication_presenter_test.rb index c6dbc4870..10dd34ee6 100644 --- a/test/presenters/html_publication_presenter_test.rb +++ b/test/presenters/html_publication_presenter_test.rb @@ -1,29 +1,29 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class HtmlPublicationPresenterTest < PresenterTestCase def schema_name "html_publication" end - test 'presents the basic details of a content item' do - assert_equal schema_item("published")['schema_name'], presented_item("published").schema_name - assert_equal schema_item("published")['links']['parent'][0]['document_type'], presented_item("published").format_sub_type - assert_equal schema_item("published")['title'], presented_item("published").title - assert_equal schema_item("published")['details']['body'], presented_item("published").body + test "presents the basic details of a content item" do + assert_equal schema_item("published")["schema_name"], presented_item("published").schema_name + assert_equal schema_item("published")["links"]["parent"][0]["document_type"], presented_item("published").format_sub_type + assert_equal schema_item("published")["title"], presented_item("published").title + assert_equal schema_item("published")["details"]["body"], presented_item("published").body end - test 'presents a list of contents extracted from headings in the body' do + test "presents a list of contents extracted from headings in the body" do expected_contents_list_item = { text: "Details of the application", id: "details-of-the-application", href: "#details-of-the-application" } assert_equal expected_contents_list_item, presented_item("published").contents[0] end - test 'presents the meta data info of a content item' do - assert_equal schema_item("print_with_meta_data")['details']['isbn'], presented_item("print_with_meta_data").isbn - assert_equal schema_item("print_with_meta_data")['details']['web_isbn'], presented_item("print_with_meta_data").web_isbn - assert_equal schema_item("print_with_meta_data")['details']['print_meta_data_contact_address'], presented_item("print_with_meta_data").print_meta_data_contact_address + test "presents the meta data info of a content item" do + assert_equal schema_item("print_with_meta_data")["details"]["isbn"], presented_item("print_with_meta_data").isbn + assert_equal schema_item("print_with_meta_data")["details"]["web_isbn"], presented_item("print_with_meta_data").web_isbn + assert_equal schema_item("print_with_meta_data")["details"]["print_meta_data_contact_address"], presented_item("print_with_meta_data").print_meta_data_contact_address end - test 'presents the last change date' do + test "presents the last change date" do published = presented_item("published") assert_equal "Published 17 January 2016", published.last_changed @@ -31,8 +31,8 @@ def schema_name assert_equal "Updated 2 February 2016", updated.last_changed end - test 'presents the list of organisations' do - multiple_organisations_html_publication = schema_item('multiple_organisations') + test "presents the list of organisations" do + multiple_organisations_html_publication = schema_item("multiple_organisations") organisation_titles = multiple_organisations_html_publication["links"]["organisations"].map { |o| o["title"] } presented_unordered_html_publication = HtmlPublicationPresenter.new(multiple_organisations_html_publication) @@ -41,11 +41,11 @@ def schema_name assert_equal organisation_titles, presented_organisations end - test 'has organisation branding' do + test "has organisation branding" do assert presented_item("published").is_a?(ContentItem::OrganisationBranding) end - test 'includes custom organisation logos when a single organisation is listed' do + test "includes custom organisation logos when a single organisation is listed" do presented = presented_item("updated") organisation = presented.organisations.first example_logo = schema_item("updated")["links"]["organisations"][0]["details"]["logo"]["image"].symbolize_keys @@ -55,11 +55,11 @@ def schema_name assert_equal example_logo, presented_logo end - test 'hides custom organisation logos when multiple organisations listed together' do + test "hides custom organisation logos when multiple organisations listed together" do presented = presented_item("multiple_organisations") organisation = presented.organisations.first organisation["details"]["logo"]["image"] = { - "url" => "url" + "url" => "url", } assert presented.organisations.count > 1 diff --git a/test/presenters/news_article_presenter_test.rb b/test/presenters/news_article_presenter_test.rb index 7dd09d040..dab8c9443 100644 --- a/test/presenters/news_article_presenter_test.rb +++ b/test/presenters/news_article_presenter_test.rb @@ -1,4 +1,4 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class NewsArticlePresenterTest class NewsArticlePresenterTestCase < PresenterTestCase @@ -10,40 +10,40 @@ def schema_name end class PresentedNewsArticleTest < NewsArticlePresenterTestCase - test 'is linkable' do + test "is linkable" do assert presented_item.is_a?(ContentItem::Linkable) end - test 'is updatable' do + test "is updatable" do assert presented_item.is_a?(ContentItem::Updatable) end - test 'is withdrawable' do + test "is withdrawable" do assert presented_item.is_a?(ContentItem::Withdrawable) end - test 'is shareable' do + test "is shareable" do assert presented_item.is_a?(ContentItem::Shareable) end - test 'includes political' do + test "includes political" do assert presented_item.is_a?(ContentItem::Political) end - test 'presents a description' do - assert_equal schema_item['description'], presented_item.description + test "presents a description" do + assert_equal schema_item["description"], presented_item.description end - test 'presents a body' do - assert_equal schema_item['details']['body'], presented_item.body + test "presents a body" do + assert_equal schema_item["details"]["body"], presented_item.body end - test 'presents a readable first published date' do - assert_equal '25 December 2016', presented_item.published + test "presents a readable first published date" do + assert_equal "25 December 2016", presented_item.published end - test 'presents the locale' do - assert_equal schema_item['locale'], presented_item.locale + test "presents the locale" do + assert_equal schema_item["locale"], presented_item.locale end end @@ -52,7 +52,7 @@ def example_schema_name "news_article_history_mode" end - test 'presents historically political' do + test "presents historically political" do assert presented_item(example_schema_name).historically_political? end end @@ -62,8 +62,8 @@ def example_schema_name "news_article_news_story_translated_arabic" end - test 'presents the locale as the translated item locale' do - assert_equal 'ur', presented_item(example_schema_name).locale + test "presents the locale as the translated item locale" do + assert_equal "ur", presented_item(example_schema_name).locale end end end diff --git a/test/presenters/publication_presenter_test.rb b/test/presenters/publication_presenter_test.rb index b0f17de18..58f0283ee 100644 --- a/test/presenters/publication_presenter_test.rb +++ b/test/presenters/publication_presenter_test.rb @@ -1,31 +1,31 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class PublicationPresenterTest < PresenterTestCase def schema_name "publication" end - test 'presents the basic details of a content item' do - assert_equal schema_item['description'], presented_item.description - assert_equal schema_item['schema_name'], presented_item.schema_name - assert_equal schema_item['title'], presented_item.title - assert_equal schema_item['details']['body'], presented_item.details - assert_equal schema_item['details']['documents'].join(''), presented_item.documents + test "presents the basic details of a content item" do + assert_equal schema_item["description"], presented_item.description + assert_equal schema_item["schema_name"], presented_item.schema_name + assert_equal schema_item["title"], presented_item.title + assert_equal schema_item["details"]["body"], presented_item.details + assert_equal schema_item["details"]["documents"].join(""), presented_item.documents end - test '#published returns a formatted date of the day the content item became public' do - assert_equal '3 May 2016', presented_item.published + test "#published returns a formatted date of the day the content item became public" do + assert_equal "3 May 2016", presented_item.published end - test 'counts documents attached to publication' do + test "counts documents attached to publication" do assert_equal 2, presented_item.documents_count end - test 'presents the title of the publishing government' do + test "presents the title of the publishing government" do assert_equal schema_item["details"]["government"]["title"], presented_item.publishing_government end - test 'content can be historically political' do + test "content can be historically political" do example = schema_item("political_publication") presented = presented_item("political_publication") @@ -35,27 +35,27 @@ def schema_name assert presented.historically_political? end - test '#from presents people' do + test "#from presents people" do minister = schema_item["links"]["people"][0] assert presented_item.from.include?("#{minister['title']}") end - test '#part_of presents topical events' do + test "#part_of presents topical events" do event = schema_item["links"]["topical_events"][0] assert presented_item.part_of.include?("#{event['title']}") end - test '#part_of presents related statistical data sets' do + test "#part_of presents related statistical data sets" do data_set = schema_item("statistics_publication")["links"]["related_statistical_data_sets"][0] assert presented_item("statistics_publication").part_of.include?("#{data_set['title']}") end - test '#national_statistics? matches national statistics documents' do + test "#national_statistics? matches national statistics documents" do refute presented_item.national_statistics? assert presented_item("statistics_publication").national_statistics? end - test 'presents withdrawn notices' do + test "presents withdrawn notices" do example = schema_item("withdrawn_publication") presented = presented_item("withdrawn_publication") @@ -65,14 +65,14 @@ def schema_name assert_equal '', presented.withdrawal_notice_component[:time] end - test 'content can apply only to a set of nations (with alternative urls when provided)' do - example = schema_item('statistics_publication') - presented = presented_item('statistics_publication') + test "content can apply only to a set of nations (with alternative urls when provided)" do + example = schema_item("statistics_publication") + presented = presented_item("statistics_publication") - assert example['details'].include?('national_applicability') + assert example["details"].include?("national_applicability") assert_equal( presented.applies_to, - 'England (see publications for Northern Ireland, Scotland, and Wales)' + 'England (see publications for Northern Ireland, Scotland, and Wales)', ) end end diff --git a/test/presenters/service_sign_in/choose_sign_in_presenter_test.rb b/test/presenters/service_sign_in/choose_sign_in_presenter_test.rb index 77253249d..dda641b7b 100644 --- a/test/presenters/service_sign_in/choose_sign_in_presenter_test.rb +++ b/test/presenters/service_sign_in/choose_sign_in_presenter_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class ServiceSignInPresenterTest class ChooseSignIn < ActiveSupport::TestCase @@ -19,8 +19,8 @@ def schema_item @schema_item ||= govuk_content_schema_example(schema_name, schema_name) end - test 'presents the schema_name' do - assert_equal schema_item['schema_name'], @presented_item.schema_name + test "presents the schema_name" do + assert_equal schema_item["schema_name"], @presented_item.schema_name end test "presents the title" do @@ -48,18 +48,18 @@ def schema_item assert_equal "option", @presented_item.options_id end - test 'presents :or before last radio button option' do + test "presents :or before last radio button option" do assert_equal @presented_item.options[2], :or end - test 'presents the back_link' do - assert_equal schema_item['links']['parent'].first['base_path'], @presented_item.back_link + test "presents the back_link" do + assert_equal schema_item["links"]["parent"].first["base_path"], @presented_item.back_link end - test 'presents the tracking values' do - assert_equal @choose_sign_in['tracking_code'], @presented_item.tracking_code - assert_equal @choose_sign_in['tracking_domain'], @presented_item.tracking_domain - assert_equal @choose_sign_in['tracking_name'], @presented_item.tracking_name + test "presents the tracking values" do + assert_equal @choose_sign_in["tracking_code"], @presented_item.tracking_code + assert_equal @choose_sign_in["tracking_domain"], @presented_item.tracking_domain + assert_equal @choose_sign_in["tracking_name"], @presented_item.tracking_name end end end diff --git a/test/presenters/service_sign_in/create_new_account_presenter_test.rb b/test/presenters/service_sign_in/create_new_account_presenter_test.rb index 69cff66d9..91d71f832 100644 --- a/test/presenters/service_sign_in/create_new_account_presenter_test.rb +++ b/test/presenters/service_sign_in/create_new_account_presenter_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class ServiceSignInPresenterTest class CreateNewAccount < ActiveSupport::TestCase @@ -20,11 +20,11 @@ def schema_item end def parent_slug - schema_item['details']['choose_sign_in']['slug'] + schema_item["details"]["choose_sign_in"]["slug"] end - test 'presents the schema_name' do - assert_equal schema_item['schema_name'], @presented_item.schema_name + test "presents the schema_name" do + assert_equal schema_item["schema_name"], @presented_item.schema_name end test "presents the title" do @@ -35,7 +35,7 @@ def parent_slug assert_equal @create_new_account["body"], @presented_item.body end - test 'presents the back_link' do + test "presents the back_link" do assert_equal "#{schema_item['base_path']}/#{parent_slug}", @presented_item.back_link end end diff --git a/test/presenters/specialist_document_presenter_test.rb b/test/presenters/specialist_document_presenter_test.rb index 5cbc28e27..a3e096cda 100644 --- a/test/presenters/specialist_document_presenter_test.rb +++ b/test/presenters/specialist_document_presenter_test.rb @@ -1,4 +1,4 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class SpecialistDocumentPresenterTest class SpecialistDocumentTestCase < PresenterTestCase @@ -8,37 +8,37 @@ def schema_name end class PresentedSpecialistDocument < SpecialistDocumentTestCase - test 'presents the schema name' do - assert_equal schema_item('aaib-reports')['schema_name'], presented_item('aaib-reports').schema_name + test "presents the schema name" do + assert_equal schema_item("aaib-reports")["schema_name"], presented_item("aaib-reports").schema_name end - test 'presents the body' do - expected_body = schema_item('aaib-reports')['details']['body'] + test "presents the body" do + expected_body = schema_item("aaib-reports")["details"]["body"] - assert_equal expected_body, presented_item('aaib-reports').body + assert_equal expected_body, presented_item("aaib-reports").body end - test 'has metadata' do - assert presented_item('aaib-reports').is_a?(ContentItem::Metadata) + test "has metadata" do + assert presented_item("aaib-reports").is_a?(ContentItem::Metadata) end - test 'presents headers as nested contents (with trailing colons removed)' do + test "presents headers as nested contents (with trailing colons removed)" do expected_headers = [ { text: "Reports of diabetic acidosis", id: "reports-of-diabetic-acidosis", href: "#reports-of-diabetic-acidosis" }, { text: "SGLT2 inhibitors – medicines in this class", id: "sglt2-inhibitors--medicines-in-this-class", href: "#sglt2-inhibitors--medicines-in-this-class" }, - { text: "Further information", id: "further-information", href: "#further-information" } + { text: "Further information", id: "further-information", href: "#further-information" }, ] - assert_equal expected_headers, presented_item('drug-safety-update').contents + assert_equal expected_headers, presented_item("drug-safety-update").contents end - test 'presents updates based on change history' do - example = schema_item('aaib-reports') + test "presents updates based on change history" do + example = schema_item("aaib-reports") example["details"]["change_history"] = [ { "note" => "First published", - "public_timestamp" => "2003-03-03" - } + "public_timestamp" => "2003-03-03", + }, ] refute present_example(example).updated @@ -46,32 +46,32 @@ class PresentedSpecialistDocument < SpecialistDocumentTestCase example["details"]["change_history"] = [ { "note" => "First published", - "public_timestamp" => "2003-03-03" + "public_timestamp" => "2003-03-03", }, { "note" => "Modified since first published", - "public_timestamp" => "2013-04-05" - } + "public_timestamp" => "2013-04-05", + }, ] assert present_example(example).updated end - test 'presents the published date using the oldest date in the change history (when no first published facet)' do - example = schema_item('aaib-reports') + test "presents the published date using the oldest date in the change history (when no first published facet)" do + example = schema_item("aaib-reports") example["first_published_at"] = "2001-01-01" example["details"]["change_history"] = [ { "note" => "Newer", - "public_timestamp" => "2003-03-03" + "public_timestamp" => "2003-03-03", }, { "note" => "Oldest", - "public_timestamp" => "2002-02-02" + "public_timestamp" => "2002-02-02", }, { "note" => "More recent", - "public_timestamp" => "2013-03-03" + "public_timestamp" => "2013-03-03", }, ] @@ -79,42 +79,42 @@ class PresentedSpecialistDocument < SpecialistDocumentTestCase assert Time.parse(presented.published) == Time.parse("2002-02-02") end - test 'has title without context' do - assert presented_item('aaib-reports').is_a?(ContentItem::TitleAndContext) + test "has title without context" do + assert presented_item("aaib-reports").is_a?(ContentItem::TitleAndContext) title_component_params = { - title: schema_item('aaib-reports')['title'], + title: schema_item("aaib-reports")["title"], context_locale: nil, - average_title_length: 'long', + average_title_length: "long", } - assert_equal title_component_params, presented_item('aaib-reports').title_and_context + assert_equal title_component_params, presented_item("aaib-reports").title_and_context end - test 'should not present continuation_link' do - assert_nil presented_item('aaib-reports').continuation_link + test "should not present continuation_link" do + assert_nil presented_item("aaib-reports").continuation_link end - test 'should not present will_continue_on' do - assert_nil presented_item('aaib-reports').will_continue_on + test "should not present will_continue_on" do + assert_nil presented_item("aaib-reports").will_continue_on end - test 'should present continuation_link' do + test "should present continuation_link" do assert_equal( - presented_item('business-finance-support-scheme').continuation_link, - 'http://www.bigissueinvest.com' + presented_item("business-finance-support-scheme").continuation_link, + "http://www.bigissueinvest.com", ) end - test 'should present will_continue_on' do + test "should present will_continue_on" do assert_equal( - presented_item('business-finance-support-scheme').will_continue_on, - 'on the Big Issue Invest website' + presented_item("business-finance-support-scheme").will_continue_on, + "on the Big Issue Invest website", ) end - test 'removes first published dates for bulk published documents' do - example = schema_item('aaib-reports') + test "removes first published dates for bulk published documents" do + example = schema_item("aaib-reports") example["details"]["metadata"]["bulk_published"] = true refute present_example(example).metadata[:first_published] @@ -129,7 +129,7 @@ class PresentedSpecialistDocument < SpecialistDocumentTestCase class PresentedSpecialistDocumentWithFinderFacets < SpecialistDocumentTestCase def example_with_finder_facets(facets = [], values = {}) - example = schema_item('aaib-reports') + example = schema_item("aaib-reports") example_finder = { "class" => "govuk-link", "base_path" => "/finder-base-path", @@ -137,15 +137,15 @@ def example_with_finder_facets(facets = [], values = {}) "details" => { "document_noun" => "case", "filter" => { - "document_type" => "cma_case" + "document_type" => "cma_case", }, "format_name" => "Competition and Markets Authority case", "facets" => facets, }, } - example['details']['metadata'] = values - example['links']['finder'] = [example_finder] + example["details"]["metadata"] = values + example["links"]["finder"] = [example_finder] example end @@ -154,11 +154,11 @@ def example_facet(overrides = {}) "name" => "Facet name", "key" => "facet-key", "type" => "text", - "filterable" => false + "filterable" => false, }.merge(overrides) end - test 'includes non-filterable facet as text in metadata' do + test "includes non-filterable facet as text in metadata" do values = { "facet-key" => "document-value" } example = example_with_finder_facets([example_facet], values) @@ -166,14 +166,14 @@ def example_facet(overrides = {}) assert_equal "document-value", presented.important_metadata["Facet name"] end - test 'includes friendly label for facet value in metadata' do + test "includes friendly label for facet value in metadata" do overrides = { "allowed_values" => [ { "label" => "Document value from label", - "value" => "document-value" - } - ] + "value" => "document-value", + }, + ], } values = { "facet-key" => "document-value" } @@ -183,29 +183,29 @@ def example_facet(overrides = {}) assert_equal "Document value from label", presented.important_metadata["Facet name"] end - test 'falls back to provided value if value not found in allowed list' do + test "falls back to provided value if value not found in allowed list" do overrides = { "allowed_values" => [ { "label" => "Document value from label", - "value" => "document-value" - } - ] + "value" => "document-value", + }, + ], } values = { "facet-key" => "not-an-allowed-value" } example = example_with_finder_facets([example_facet(overrides)], values) GovukError.expects(:notify).once.with( - 'Facet value not in list of allowed values', - extra: { error_message: "Facet value 'not-an-allowed-value' not an allowed value for facet 'Facet name' on /aaib-reports/aaib-investigation-to-rotorsport-uk-calidus-g-pcpc content item" } + "Facet value not in list of allowed values", + extra: { error_message: "Facet value 'not-an-allowed-value' not an allowed value for facet 'Facet name' on /aaib-reports/aaib-investigation-to-rotorsport-uk-calidus-g-pcpc content item" }, ) presented = present_example(example) assert_equal "not-an-allowed-value", presented.important_metadata["Facet name"] end - test 'ignores facets in metadata if not a valid finder facet' do + test "ignores facets in metadata if not a valid finder facet" do values = { "random-invalid-facet" => "something-odd" } example = example_with_finder_facets([example_facet], values) @@ -213,7 +213,7 @@ def example_facet(overrides = {}) assert_empty presented.metadata[:other] end - test 'ignores facets if valid key but set to an empty string' do + test "ignores facets if valid key but set to an empty string" do example = example_with_finder_facets([ { "name" => "Facet name", @@ -224,26 +224,26 @@ def example_facet(overrides = {}) "name" => "Date facet", "key" => "date-facet", "type" => "date", - } + }, ], - "facet-key" => "", - "date-facet" => "") + "facet-key" => "", + "date-facet" => "") assert_empty present_example(example).metadata[:other] end - test 'passes array of multiple values to metadata' do + test "passes array of multiple values to metadata" do overrides = { "allowed_values" => [ { "label" => "One", - "value" => "one" + "value" => "one", }, { "label" => "Two", - "value" => "two" - } - ] + "value" => "two", + }, + ], } values = { "facet-key" => %w{one two} } @@ -253,15 +253,15 @@ def example_facet(overrides = {}) assert_equal %w{One Two}, presented.important_metadata["Facet name"] end - test 'creates links for filterable friendly values' do + test "creates links for filterable friendly values" do overrides = { "filterable" => true, "allowed_values" => [ { "label" => "Something", - "value" => "something" - } - ] + "value" => "something", + }, + ], } values = { "facet-key" => "something" } @@ -272,7 +272,7 @@ def example_facet(overrides = {}) assert_equal expected_link, presented.important_metadata["Facet name"] end - test 'includes friendly dates for date facets in metadata' do + test "includes friendly dates for date facets in metadata" do overrides = { "type" => "date" } values = { "facet-key" => "2010-01-01" } example = example_with_finder_facets([example_facet(overrides)], values) @@ -281,7 +281,7 @@ def example_facet(overrides = {}) assert_equal "1 January 2010", presented_metadata["Facet name"] end - test 'puts date facets together and before text facets' do + test "puts date facets together and before text facets" do example = example_with_finder_facets([ { "name" => "Facet name", @@ -302,57 +302,57 @@ def example_facet(overrides = {}) "name" => "More text", "key" => "more-text", "type" => "text", - } + }, ], - "facet-key" => "Text", - "first-date-facet" => "2010-01-01", - "second-date-facet" => "2010-02-03", - "more-text" => "More text") + "facet-key" => "Text", + "first-date-facet" => "2010-01-01", + "second-date-facet" => "2010-02-03", + "more-text" => "More text") expected_order = ["First date facet", "Second date facet", "Facet name", "More text"] assert_equal expected_order, present_example(example).important_metadata.keys end - test 'sends an error notification when there is no finder' do - example = schema_item('aaib-reports') - example['links']['finder'] = [] + test "sends an error notification when there is no finder" do + example = schema_item("aaib-reports") + example["links"]["finder"] = [] GovukError.expects(:notify).with( - 'Finder not found', - extra: { error_message: 'Finder not found in /aaib-reports/aaib-investigation-to-rotorsport-uk-calidus-g-pcpc content item' } + "Finder not found", + extra: { error_message: "Finder not found in /aaib-reports/aaib-investigation-to-rotorsport-uk-calidus-g-pcpc content item" }, ) present_example(example).important_metadata end - test 'omits first_published_at facet values from `other` section of component parameters to avoid duplicates' do + test "omits first_published_at facet values from `other` section of component parameters to avoid duplicates" do facets = [ { "name" => "Published", "key" => "first_published_at", "type" => "date", - } + }, ] example = example_with_finder_facets(facets, "first_published_at" => "2010-01-01") presented = present_example(example) - refute presented.metadata[:other]['Published'] + refute presented.metadata[:other]["Published"] end - test 'uses first published date in facets as canonical publish date if provided' do + test "uses first published date in facets as canonical publish date if provided" do facets = [ { "name" => "Published", "key" => "first_published_at", "type" => "date", - } + }, ] example = example_with_finder_facets(facets, "first_published_at" => "2010-01-01") example["details"]["change_history"] = [ { "note" => "A date in the change history", - "public_timestamp" => "2002-02-02" + "public_timestamp" => "2002-02-02", }, ] diff --git a/test/presenters/speech_presenter_test.rb b/test/presenters/speech_presenter_test.rb index d94ef1604..00adbb8ed 100644 --- a/test/presenters/speech_presenter_test.rb +++ b/test/presenters/speech_presenter_test.rb @@ -1,4 +1,4 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class SpeechPresenterTest class SpeechTestCase < PresenterTestCase @@ -8,89 +8,89 @@ def schema_name end class PresentedSpeech < SpeechTestCase - test 'presents the schema name' do - assert_equal schema_item['schema_name'], presented_item.schema_name + test "presents the schema name" do + assert_equal schema_item["schema_name"], presented_item.schema_name end - test '#published returns a formatted date of the day the content item became public' do + test "#published returns a formatted date of the day the content item became public" do assert_equal "8 March 2016", presented_item.published end - test 'presents a description' do - assert_equal schema_item['description'], presented_item.description + test "presents a description" do + assert_equal schema_item["description"], presented_item.description end - test 'presents a speech location' do - assert_equal schema_item['details']['location'], presented_item.important_metadata["Location"] + test "presents a speech location" do + assert_equal schema_item["details"]["location"], presented_item.important_metadata["Location"] end - test 'presents how speech was delivered' do - assert_equal 'Delivered on', presented_item.delivery_type + test "presents how speech was delivered" do + assert_equal "Delivered on", presented_item.delivery_type end - test 'presents a delivered on date with speech type explanation for the metadata component' do + test "presents a delivered on date with speech type explanation for the metadata component" do assert_equal ' (Original script, may differ from delivered version)', presented_item.delivered_on_metadata end - test 'presents the body' do - expected_body = schema_item['details']['body'] + test "presents the body" do + expected_body = schema_item["details"]["body"] assert_equal expected_body, presented_item.body end - test 'from includes speaker' do + test "from includes speaker" do assert presented_item.from.include?("The Rt Hon Andrea Leadsom MP") end end class TranscriptPresentedSpeech < SpeechTestCase def example_schema_name - 'speech-transcript' + "speech-transcript" end - test 'presents a delivered on date with speech type explanation for the metadata component' do + test "presents a delivered on date with speech type explanation for the metadata component" do assert_equal ' (Original script, may differ from delivered version)', presented_item.delivered_on_metadata end end class WrittenStatementParliamentPresentedSpeech < SpeechTestCase def example_schema_name - 'speech-written-statement-parliament' + "speech-written-statement-parliament" end - test 'presents the speech as being delivered' do - assert_equal 'Delivered on', presented_item(example_schema_name).delivery_type + test "presents the speech as being delivered" do + assert_equal "Delivered on", presented_item(example_schema_name).delivery_type end - test 'presents a delivered on date without an explanation' do + test "presents a delivered on date without an explanation" do assert_equal '', presented_item(example_schema_name).delivered_on_metadata end end class AuthoredArticlePresentedSpeech < SpeechTestCase def example_schema_name - 'speech-authored-article' + "speech-authored-article" end - test 'presents the speech as being written' do - assert_equal 'Written on', presented_item(example_schema_name).delivery_type + test "presents the speech as being written" do + assert_equal "Written on", presented_item(example_schema_name).delivery_type end - test 'presents a delivered on date without an explanation' do + test "presents a delivered on date without an explanation" do assert_equal '', presented_item(example_schema_name).delivered_on_metadata end end class SpeakerWithoutProfilePresentedSpeech < SpeechTestCase def example_schema_name - 'speech-speaker-without-profile' + "speech-speaker-without-profile" end - test 'includes speaker without profile in from_with_speaker' do + test "includes speaker without profile in from_with_speaker" do assert_equal [ "Prime Minister's Office, 10 Downing Street", "Cabinet Office", - "Her Majesty the Queen" + "Her Majesty the Queen", ], presented_item(example_schema_name).from end end diff --git a/test/presenters/statistical_data_set_presenter_test.rb b/test/presenters/statistical_data_set_presenter_test.rb index 4da422002..ef30a7cf3 100644 --- a/test/presenters/statistical_data_set_presenter_test.rb +++ b/test/presenters/statistical_data_set_presenter_test.rb @@ -1,4 +1,4 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class StatisticalDataSetPresenterTest class StatisticalDataSetTestCase < PresenterTestCase @@ -8,25 +8,25 @@ def schema_name end class PresentedStatisticalDataSet < StatisticalDataSetTestCase - test 'presents the schema name' do - assert_equal schema_item['schema_name'], presented_item.schema_name + test "presents the schema name" do + assert_equal schema_item["schema_name"], presented_item.schema_name end - test 'presents a list of contents extracted from headings in the body' do + test "presents a list of contents extracted from headings in the body" do expected_contents_item = { text: "Olympics", id: "olympics", href: "#olympics" } assert_equal expected_contents_item, presented_item.contents[0] end - test '#published returns a formatted date of the day the content item became public' do + test "#published returns a formatted date of the day the content item became public" do assert_equal "13 December 2012", presented_item.published end - test 'presents a description' do + test "presents a description" do assert_equal schema_item["description"], presented_item.description end - test 'presents the body' do - expected_body = schema_item['details']['body'] + test "presents the body" do + expected_body = schema_item["details"]["body"] assert_equal expected_body, presented_item.body end @@ -45,15 +45,15 @@ def presented presented_item(example_schema_name) end - test 'presents the withdrawn notice explanation' do + test "presents the withdrawn notice explanation" do assert_equal expected["withdrawn_notice"]["explanation"], presented.withdrawal_notice_component[:description_govspeak] end - test 'presents the withdrawn notification time' do + test "presents the withdrawn notification time" do expected_time = expected["withdrawn_notice"]["withdrawn_at"] expected_date_as_string = I18n.l( Date.parse(expected_time), - format: "%-d %B %Y" + format: "%-d %B %Y", ) expected_withdrawn_time_html = "" @@ -74,7 +74,7 @@ def presented presented_item(example_schema_name) end - test 'presents the political fields' do + test "presents the political fields" do assert_equal expected["details"]["political"], presented.historically_political? assert_equal expected["details"]["government"]["title"], presented.publishing_government end diff --git a/test/presenters/statistics_announcement_presenter_test.rb b/test/presenters/statistics_announcement_presenter_test.rb index 9a66496c3..3c326f704 100644 --- a/test/presenters/statistics_announcement_presenter_test.rb +++ b/test/presenters/statistics_announcement_presenter_test.rb @@ -1,4 +1,4 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class StatisticsAnnouncementPresenterTest < PresenterTestCase include ActionView::Helpers::UrlHelper @@ -7,36 +7,36 @@ def schema_name "statistics_announcement" end - test 'presents from as links to organisations' do + test "presents from as links to organisations" do links = [ - link_to('NHS England', '/government/organisations/nhs-commissioning-board', class: "govuk-link") + link_to("NHS England", "/government/organisations/nhs-commissioning-board", class: "govuk-link"), ] assert_equal links, statistics_announcement.from end - test 'presents release_date' do - assert_equal '20 January 2016 9:30am', statistics_announcement.release_date + test "presents release_date" do + assert_equal "20 January 2016 9:30am", statistics_announcement.release_date end - test 'presents previous_release_date' do - assert_equal '19 January 2016 9:30am', statistics_announcement_date_changed.previous_release_date + test "presents previous_release_date" do + assert_equal "19 January 2016 9:30am", statistics_announcement_date_changed.previous_release_date end - test 'presents release_date_and_status when confirmed' do - assert_equal '20 January 2016 9:30am (confirmed)', statistics_announcement.release_date_and_status + test "presents release_date_and_status when confirmed" do + assert_equal "20 January 2016 9:30am (confirmed)", statistics_announcement.release_date_and_status end - test 'presents release_date_and_status when provisional' do - assert_equal 'January 2016 (provisional)', statistics_announcement_provisional.release_date_and_status + test "presents release_date_and_status when provisional" do + assert_equal "January 2016 (provisional)", statistics_announcement_provisional.release_date_and_status end - test 'presents release_date_and_status when cancelled' do - assert_equal '20 January 2016 9:30am', statistics_announcement_cancelled.release_date_and_status + test "presents release_date_and_status when cancelled" do + assert_equal "20 January 2016 9:30am", statistics_announcement_cancelled.release_date_and_status end test "present important metadata when confirmed" do metadata = { - "Release date" => "20 January 2016 9:30am (confirmed)" + "Release date" => "20 January 2016 9:30am (confirmed)", } assert_equal metadata, statistics_announcement.important_metadata end @@ -44,7 +44,7 @@ def schema_name test "present important metadata when cancelled" do metadata = { "Proposed release" => "20 January 2016 9:30am", - "Cancellation date" => "17 January 2016 2:19pm" + "Cancellation date" => "17 January 2016 2:19pm", } assert_equal metadata, statistics_announcement_cancelled.important_metadata end @@ -54,41 +54,41 @@ def schema_name assert_equal "Official Statistics", item.cancellation_reason end - test 'knows if an item is a national statistic' do + test "knows if an item is a national statistic" do refute statistics_announcement.national_statistics? assert statistics_announcement_national.national_statistics? end - test 'knows if the release date has changed' do + test "knows if the release date has changed" do assert statistics_announcement_date_changed.release_date_changed? refute statistics_announcement_national.release_date_changed? end - test 'an announcement is forthcoming if it is not cancelled' do + test "an announcement is forthcoming if it is not cancelled" do assert statistics_announcement.forthcoming_publication? end - test 'a cancelled announcement takes precedence over a forthcoming announcement' do + test "a cancelled announcement takes precedence over a forthcoming announcement" do refute statistics_announcement_cancelled.forthcoming_publication? end def statistics_announcement_cancelled - presented_item('cancelled_official_statistics') + presented_item("cancelled_official_statistics") end def statistics_announcement_provisional - presented_item('national_statistics') + presented_item("national_statistics") end def statistics_announcement_national - presented_item('national_statistics') + presented_item("national_statistics") end def statistics_announcement_date_changed - presented_item('release_date_changed') + presented_item("release_date_changed") end def statistics_announcement - presented_item('official_statistics') + presented_item("official_statistics") end end diff --git a/test/presenters/take_part_presenter_test.rb b/test/presenters/take_part_presenter_test.rb index 856515b74..61204af38 100644 --- a/test/presenters/take_part_presenter_test.rb +++ b/test/presenters/take_part_presenter_test.rb @@ -1,15 +1,15 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class TakePartPresenterTest < PresenterTestCase def schema_name "take_part" end - test 'presents the basic details of a content item' do - assert_equal schema_item['description'], presented_item.description - assert_equal schema_item['schema_name'], presented_item.schema_name - assert_equal schema_item['locale'], presented_item.locale - assert_equal schema_item['title'], presented_item.title - assert_equal schema_item['details']['body'], presented_item.body + test "presents the basic details of a content item" do + assert_equal schema_item["description"], presented_item.description + assert_equal schema_item["schema_name"], presented_item.schema_name + assert_equal schema_item["locale"], presented_item.locale + assert_equal schema_item["title"], presented_item.title + assert_equal schema_item["details"]["body"], presented_item.body end end diff --git a/test/presenters/topical_event_about_page_presenter_test.rb b/test/presenters/topical_event_about_page_presenter_test.rb index 575d79ae9..ff5d9cade 100644 --- a/test/presenters/topical_event_about_page_presenter_test.rb +++ b/test/presenters/topical_event_about_page_presenter_test.rb @@ -1,18 +1,18 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class TopicalEventAboutPagePresenterTest < PresenterTestCase def schema_name "topical_event_about_page" end - test 'presents the basic details of a content item' do - assert_equal schema_item['description'], presented_item.description - assert_equal schema_item['schema_name'], presented_item.schema_name - assert_equal schema_item['title'], presented_item.title - assert_equal schema_item['details']['body'], presented_item.body + test "presents the basic details of a content item" do + assert_equal schema_item["description"], presented_item.description + assert_equal schema_item["schema_name"], presented_item.schema_name + assert_equal schema_item["title"], presented_item.title + assert_equal schema_item["details"]["body"], presented_item.body end - test 'presents a list of contents extracted from headings in the body' do + test "presents a list of contents extracted from headings in the body" do assert_equal [ { text: "Response in the UK", id: "response-in-the-uk", href: "#response-in-the-uk" }, { text: "Response in Africa", id: "response-in-africa", href: "#response-in-africa" }, @@ -23,7 +23,7 @@ def schema_name ], presented_item.contents end - test 'presents no contents when no headings in the body' do - assert_equal [], presented_item('slim').contents + test "presents no contents when no headings in the body" do + assert_equal [], presented_item("slim").contents end end diff --git a/test/presenters/travel_advice_presenter_test.rb b/test/presenters/travel_advice_presenter_test.rb index ea69c51ed..ef5aa2559 100644 --- a/test/presenters/travel_advice_presenter_test.rb +++ b/test/presenters/travel_advice_presenter_test.rb @@ -1,4 +1,4 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class TravelAdvicePresenterTest class PresentedTravelAdvice < PresenterTestCase @@ -6,7 +6,7 @@ def schema_name "travel_advice" end - test 'has parts' do + test "has parts" do assert presented_item("full-country").is_a?(ContentItem::Parts) end @@ -17,33 +17,33 @@ def schema_name test "part slug set to last segment of requested content item path when content item has parts" do example = schema_item("full-country") - first_part = example['details']['parts'].first - presented = presented_item("full-country", first_part['slug']) + first_part = example["details"]["parts"].first + presented = presented_item("full-country", first_part["slug"]) assert presented.requesting_a_part? - assert_equal presented.part_slug, first_part['slug'] + assert_equal presented.part_slug, first_part["slug"] assert presented.has_valid_part? end test "knows when an invalid part has been requested" do - presented = presented_item("full-country", 'not-a-valid-part') + presented = presented_item("full-country", "not-a-valid-part") assert presented.requesting_a_part? - assert_equal presented.part_slug, 'not-a-valid-part' + assert_equal presented.part_slug, "not-a-valid-part" refute presented.has_valid_part? end test "presents unique titles for each part" do example = schema_item("full-country") presented = presented_item("full-country") - assert_equal example['title'], presented.page_title + assert_equal example["title"], presented.page_title - first_part = example['details']['parts'].first - presented_part = presented_item("full-country", first_part['slug']) + first_part = example["details"]["parts"].first + presented_part = presented_item("full-country", first_part["slug"]) assert_equal "#{first_part['title']} - #{example['title']}", presented_part.page_title end - test 'presents withdrawn in the title for withdrawn content' do + test "presents withdrawn in the title for withdrawn content" do presented_item = presented_item("full-country", nil, "withdrawn_notice" => { "explanation": "Withdrawn", "withdrawn_at": "2014-08-22T10:29:02+01:00" }) assert_equal "[Withdrawn] Albania travel advice", presented_item.page_title end @@ -53,8 +53,8 @@ def schema_name presented = presented_item("full-country") assert presented.is_summary? - assert_equal 'Summary', presented.current_part_title - assert_equal example['details']['summary'], presented.current_part_body + assert_equal "Summary", presented.current_part_title + assert_equal example["details"]["summary"], presented.current_part_body end test "presents the current part when a part slug is provided" do @@ -64,12 +64,12 @@ def schema_name refute presented.is_summary? assert presented.has_valid_part? - assert_equal first_part['title'], presented.current_part_title - assert_equal first_part['body'], presented.current_part_body + assert_equal first_part["title"], presented.current_part_title + assert_equal first_part["body"], presented.current_part_body end test "marks parts not in the content item as invalid" do - example_part_slugs = schema_item("full-country")["details"]["parts"].map { |part| part['slug'] } + example_part_slugs = schema_item("full-country")["details"]["parts"].map { |part| part["slug"] } presented = presented_item("full-country", "not-a-valid-part") refute example_part_slugs.include?("not-a-valid-part") @@ -78,7 +78,7 @@ def schema_name test "the summary is included as the first navigation item" do first_nav_item = presented_item("full-country").parts_navigation.first.first - assert_equal 'Summary', first_nav_item + assert_equal "Summary", first_nav_item end test "navigation items are presented as trackable links unless they are the current part" do @@ -97,7 +97,7 @@ def schema_name "data-track-label=\"/foreign-travel-advice/albania\" "\ "data-track-options=\"{"dimension29":"Summary"}\" "\ "href=\"/foreign-travel-advice/albania\">Summary" - assert_equal current_part_nav_item, current_part['title'] + assert_equal current_part_nav_item, current_part["title"] assert_equal another_part_nav_item, "Test<br>XML

", present_example(example).atom_change_description end @@ -276,8 +276,8 @@ def schema_name summary = parts.shift parts.each_with_index do |part, i| - assert_equal example_parts[i]['body'], part['body'] - assert_equal example_parts[i]['slug'], part['slug'] + assert_equal example_parts[i]["body"], part["body"] + assert_equal example_parts[i]["slug"], part["slug"] end assert_equal "Summary", summary["title"] assert_equal schema_item("full-country")["details"]["summary"], summary["body"] @@ -289,7 +289,7 @@ def present_latest(latest) with_custom_change_description = { "details" => { "change_description" => latest, - } + }, } presented = presented_item("full-country", nil, with_custom_change_description) presented.metadata[:other]["Latest update"] @@ -301,7 +301,7 @@ def presented_item(type = schema_name, part_slug = nil, overrides = {}) TravelAdvicePresenter.new( schema_example_content_item.merge(overrides), - "#{schema_example_content_item['base_path']}#{part_slug}" + "#{schema_example_content_item['base_path']}#{part_slug}", ) end end diff --git a/test/presenters/unpublishing_presenter_test.rb b/test/presenters/unpublishing_presenter_test.rb index 7777e231a..85ba1a612 100644 --- a/test/presenters/unpublishing_presenter_test.rb +++ b/test/presenters/unpublishing_presenter_test.rb @@ -1,17 +1,17 @@ -require 'test_helper' +require "test_helper" class UnpublishingPresenterTest < ActiveSupport::TestCase - test 'presents the basic details required to display an unpublishing' do - assert_equal unpublishing['schema_name'], presented_unpublishing.schema_name - assert_equal unpublishing['locale'], presented_unpublishing.locale - assert_equal unpublishing['details']['explanation'], presented_unpublishing.explanation + test "presents the basic details required to display an unpublishing" do + assert_equal unpublishing["schema_name"], presented_unpublishing.schema_name + assert_equal unpublishing["locale"], presented_unpublishing.locale + assert_equal unpublishing["details"]["explanation"], presented_unpublishing.explanation - assert_nil unpublishing['details']['alternative_url'] + assert_nil unpublishing["details"]["alternative_url"] assert_nil presented_unpublishing.alternative_url end def unpublishing - govuk_content_schema_example('unpublishing', 'unpublishing') + govuk_content_schema_example("unpublishing", "unpublishing") end def presented_unpublishing diff --git a/test/presenters/world_location_news_article_presenter_test.rb b/test/presenters/world_location_news_article_presenter_test.rb index bd96a6971..d190df35e 100644 --- a/test/presenters/world_location_news_article_presenter_test.rb +++ b/test/presenters/world_location_news_article_presenter_test.rb @@ -1,4 +1,4 @@ -require 'presenter_test_helper' +require "presenter_test_helper" class WorldLocationNewsArticlePresenterTest class WorldLocationNewsArticlePresenterTestCase < PresenterTestCase @@ -10,52 +10,52 @@ def schema_name end class PresentedWorldLocationNewsArticleTest < WorldLocationNewsArticlePresenterTestCase - test 'is linkable' do + test "is linkable" do assert presented_item.is_a?(ContentItem::Linkable) end - test 'is updatable' do + test "is updatable" do assert presented_item.is_a?(ContentItem::Updatable) end - test 'is withdrawable' do + test "is withdrawable" do assert presented_item.is_a?(ContentItem::Withdrawable) end - test 'is shareable' do + test "is shareable" do assert presented_item.is_a?(ContentItem::Shareable) end - test 'includes political' do + test "includes political" do assert presented_item.is_a?(ContentItem::Political) end - test 'presents the schema name' do - assert_equal schema_item['schema_name'], presented_item.schema_name + test "presents the schema name" do + assert_equal schema_item["schema_name"], presented_item.schema_name end - test 'presents a description' do - assert_equal schema_item['description'], presented_item.description + test "presents a description" do + assert_equal schema_item["description"], presented_item.description end - test 'presents a body' do - assert_equal schema_item['details']['body'], presented_item.body + test "presents a body" do + assert_equal schema_item["details"]["body"], presented_item.body end - test 'presents a readable first published date' do - assert_equal '24 November 2015', presented_item.published + test "presents a readable first published date" do + assert_equal "24 November 2015", presented_item.published end - test 'presents the locale' do - assert_equal schema_item['locale'], presented_item.locale + test "presents the locale" do + assert_equal schema_item["locale"], presented_item.locale end - test 'presents worldwide organisations as from' do - assert_includes presented_item.from[0], schema_item['links']['worldwide_organisations'][0]['title'] + test "presents worldwide organisations as from" do + assert_includes presented_item.from[0], schema_item["links"]["worldwide_organisations"][0]["title"] end - test 'presents world locations as part_of' do - assert_includes presented_item.part_of[0], schema_item['links']['world_locations'][0]['title'] + test "presents world locations as part_of" do + assert_includes presented_item.part_of[0], schema_item["links"]["world_locations"][0]["title"] end end @@ -64,7 +64,7 @@ def example_schema_name "world_location_news_article_history_mode" end - test 'presents historically political' do + test "presents historically political" do assert presented_item(example_schema_name).historically_political? end end @@ -74,8 +74,8 @@ def example_schema_name "world_location_news_article_translated" end - test 'presents the locale as the translated item locale' do - assert_equal 'pt', presented_item(example_schema_name).locale + test "presents the locale as the translated item locale" do + assert_equal "pt", presented_item(example_schema_name).locale end end @@ -90,9 +90,9 @@ def example_schema_name @presented_translations = presented_item(example_schema_name).available_translations.sort_by { |hash| hash["locale"] } end - test 'presents the translations' do - assert_equal @expected_translations.first['locale'], @presented_translations.first[:locale] - assert_equal @expected_translations.first['base_path'], @presented_translations.first[:base_path] + test "presents the translations" do + assert_equal @expected_translations.first["locale"], @presented_translations.first[:locale] + assert_equal @expected_translations.first["base_path"], @presented_translations.first[:base_path] end end end diff --git a/test/services/request_helper_test.rb b/test/services/request_helper_test.rb index 1e7c5c948..a2e9c7056 100644 --- a/test/services/request_helper_test.rb +++ b/test/services/request_helper_test.rb @@ -1,23 +1,23 @@ -require 'test_helper' +require "test_helper" class RequestHelperTest < ActiveSupport::TestCase - test 'get_header returns nil when header does not exist' do - header_val = RequestHelper.get_header('Govuk-Example-Header', {}) + test "get_header returns nil when header does not exist" do + header_val = RequestHelper.get_header("Govuk-Example-Header", {}) assert_nil header_val end - test 'get_header returns header when header exists' do - header_val = RequestHelper.get_header('Govuk-Example-Header', 'HTTP_GOVUK_EXAMPLE_HEADER' => 'this_is_a_test') + test "get_header returns header when header exists" do + header_val = RequestHelper.get_header("Govuk-Example-Header", "HTTP_GOVUK_EXAMPLE_HEADER" => "this_is_a_test") - assert_equal 'this_is_a_test', header_val + assert_equal "this_is_a_test", header_val end - test 'headerise returns header with HTTP prefix, no dashes and all uppercase' do - header_name = 'Govuk-Example-Header' + test "headerise returns header with HTTP prefix, no dashes and all uppercase" do + header_name = "Govuk-Example-Header" transformed_header_name = RequestHelper.headerise(header_name) - assert_equal 'HTTP_GOVUK_EXAMPLE_HEADER', transformed_header_name + assert_equal "HTTP_GOVUK_EXAMPLE_HEADER", transformed_header_name end end diff --git a/test/services/world_location_base_path_test.rb b/test/services/world_location_base_path_test.rb index c987a6e33..c4de49621 100644 --- a/test/services/world_location_base_path_test.rb +++ b/test/services/world_location_base_path_test.rb @@ -4,7 +4,7 @@ class WorldLocationBasePathWhenPathExists < ActiveSupport::TestCase test "returns the base_path" do link = { "base_path" => "/government/world/usa", - "government" => "USA" + "government" => "USA", } assert_equal "/government/world/usa", WorldLocationBasePath.for(link) end @@ -13,7 +13,7 @@ class WorldLocationBasePathWhenPathExists < ActiveSupport::TestCase class WorldLocationBasePathWithoutBasePath < ActiveSupport::TestCase test "returns /world/usa/news" do link = { - "title" => "USA" + "title" => "USA", } assert_equal "/world/usa/news", WorldLocationBasePath.for(link) end @@ -23,11 +23,11 @@ class WorldLocationBasePathForExceptionalCase < ActiveSupport::TestCase { "Democratic Republic of Congo" => "democratic-republic-of-congo", "South Georgia and the South Sandwich Islands" => "south-georgia-and-the-south-sandwich-islands", - "St Pierre & Miquelon" => "st-pierre-miquelon" + "St Pierre & Miquelon" => "st-pierre-miquelon", }.each do |title, expected_slug| test "returns /world/#{expected_slug}/news" do link = { - "title" => title + "title" => title, } assert_equal "/world/#{expected_slug}/news", WorldLocationBasePath.for(link) end diff --git a/test/support/custom_assertions.rb b/test/support/custom_assertions.rb index 8d1621f25..1beed41c4 100644 --- a/test/support/custom_assertions.rb +++ b/test/support/custom_assertions.rb @@ -8,7 +8,7 @@ def assert_includes_subhash(expected_sub_hash, hash) assert_equal( value, hash[key], - "Expected #{hash} to include #{key}=#{value}" + "Expected #{hash} to include #{key}=#{value}", ) end end diff --git a/test/support/govuk_content_schema_examples.rb b/test/support/govuk_content_schema_examples.rb index f27ffb209..616d7e196 100644 --- a/test/support/govuk_content_schema_examples.rb +++ b/test/support/govuk_content_schema_examples.rb @@ -1,4 +1,4 @@ -require 'gds_api/test_helpers/content_store' +require "gds_api/test_helpers/content_store" # Include this module to get access to the GOVUK Content Schema examples in the # tests. @@ -21,7 +21,7 @@ module GovukContentSchemaExamples def content_store_has_schema_example(schema_name, example_name) document = govuk_content_schema_example(schema_name, example_name) - content_store_has_item(document['base_path'], document) + content_store_has_item(document["base_path"], document) document end diff --git a/test/support/webmock.rb b/test/support/webmock.rb index 3374e54b8..7751bfcd3 100644 --- a/test/support/webmock.rb +++ b/test/support/webmock.rb @@ -1,2 +1,2 @@ -require 'webmock/minitest' +require "webmock/minitest" WebMock.disable_net_connect!(allow_localhost: true) diff --git a/test/test_helper.rb b/test/test_helper.rb index b8060339e..58e65e36a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,16 +1,16 @@ -ENV['RAILS_ENV'] ||= 'test' -ENV['GOVUK_APP_DOMAIN'] = 'test.gov.uk' -ENV['GOVUK_ASSET_ROOT'] = 'http://static.test.gov.uk' - -require File.expand_path('../config/environment', __dir__) -require 'rails/test_help' -require 'capybara/rails' -require 'mocha/minitest' -require 'capybara/minitest' -require 'faker' +ENV["RAILS_ENV"] ||= "test" +ENV["GOVUK_APP_DOMAIN"] = "test.gov.uk" +ENV["GOVUK_ASSET_ROOT"] = "http://static.test.gov.uk" + +require File.expand_path("../config/environment", __dir__) +require "rails/test_help" +require "capybara/rails" +require "mocha/minitest" +require "capybara/minitest" +require "faker" require "minitest/reporters" -Dir[Rails.root.join('test/support/*.rb')].each { |f| require f } +Dir[Rails.root.join("test/support/*.rb")].each { |f| require f } Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new @@ -51,7 +51,7 @@ def assert_has_component_metadata_pair(label, value) end def assert_has_component_title(title) - assert page.has_css?('h1', text: title) + assert page.has_css?("h1", text: title) end def assert_has_component_organisation_logo @@ -59,7 +59,7 @@ def assert_has_component_organisation_logo end def assert_has_component_government_navigation_active(active) - assert page.has_css?("a", class: 'active', text: active) + assert page.has_css?("a", class: "active", text: active) end def assert_has_contents_list(contents) @@ -97,7 +97,7 @@ def assert_has_publisher_metadata_other(metadata) def assert_has_metadata(metadata, term_selector, definition_selector) metadata.each do |key, value| assert page.has_css?(term_selector, text: key), - "Metadata term '#{key}' not found" + "Metadata term '#{key}' not found" value = { value => nil } if value.is_a?(String) @@ -132,7 +132,7 @@ def assert_footer_has_published_dates(published = nil, last_updated = nil, histo assert_has_published_dates(published, last_updated, history_link, 1) end - def setup_and_visit_content_item(name, parameter_string = '') + def setup_and_visit_content_item(name, parameter_string = "") @content_item = get_content_example(name).tap do |item| content_store_has_item(item["base_path"], item.to_json) visit_with_cachebust("#{item['base_path']}#{parameter_string}") @@ -143,13 +143,13 @@ def setup_and_visit_content_item_with_taxons(name, taxons) @content_item = get_content_example(name).tap do |item| item["links"]["taxons"] = taxons content_store_has_item(item["base_path"], item.to_json) - visit_with_cachebust(item['base_path']) + visit_with_cachebust(item["base_path"]) end end def setup_and_visit_random_content_item(document_type: nil) content_item = GovukSchemas::RandomExample.for_schema(frontend_schema: schema_type) do |payload| - payload.merge('document_type' => document_type) unless document_type.nil? + payload.merge("document_type" => document_type) unless document_type.nil? payload end @@ -173,7 +173,7 @@ def get_content_example_by_schema_and_name(schema_type, name) # Override this method if your test file doesn't match the convention def schema_type - self.class.to_s.gsub('Test', '').underscore + self.class.to_s.gsub("Test", "").underscore end def visit_with_cachebust(visit_uri)