From 4548d2d7bdcafc04b650e8b34b3719f449118c68 Mon Sep 17 00:00:00 2001 From: Benjamin Eskola Date: Fri, 29 Nov 2019 14:03:06 +0000 Subject: [PATCH] Enable rails-specific rules for rubocop-govuk Mostly just running rubocop --auto-correct; however, a few special cases: - Some checks have been disabled. This is intended to be temporary; making them pass will require some kind of refactoring (`OutputSafety` and `HelperInstanceVariable`) or decisions about the behaviour of the code (`HasManyOrHasOneDependent` and `InverseOf`) that I felt were out of scope for this PR. I'll be raising them as future tasks. --- .rubocop.yml | 6 ++++++ app/controllers/content_items_controller.rb | 6 +++--- app/helpers/webchat_availability_helper.rb | 4 ++-- app/presenters/coming_soon_presenter.rb | 2 +- app/presenters/content_item/updatable.rb | 2 +- app/presenters/travel_advice_presenter.rb | 2 +- lib/tasks/wraith.rake | 10 +++++----- .../content_items_controller_test.rb | 12 +++++------ .../step_navigation_controller_test.rb | 2 +- .../webchat_availability_helper_test.rb | 8 ++++---- test/integration/contact_test.rb | 2 +- .../corporate_information_page_test.rb | 2 +- test/integration/detailed_guide_test.rb | 2 +- test/integration/document_collection_test.rb | 2 +- test/integration/fatality_notice_test.rb | 2 +- test/integration/guide_test.rb | 12 +++++------ test/integration/html_publication_test.rb | 2 +- test/integration/phase_label_test.rb | 2 +- .../service_sign_in/choose_sign_in_test.rb | 4 ++-- .../create_new_account_test.rb | 2 +- test/integration/specialist_document_test.rb | 6 +++--- test/integration/statistical_data_set_test.rb | 2 +- .../statistics_announcement_test.rb | 2 +- .../topical_event_about_page_test.rb | 4 ++-- .../travel_advice_atom_feed_test.rb | 2 +- test/integration/travel_advice_print_test.rb | 2 +- test/integration/travel_advice_test.rb | 10 +++++----- test/integration/working_group_test.rb | 2 +- .../world_location_news_article_test.rb | 2 +- test/presenters/case_study_presenter_test.rb | 2 +- .../presenters/consultation_presenter_test.rb | 20 +++++++++---------- .../content_item/contents_list_test.rb | 4 ++-- .../organisation_branding_test.rb | 2 +- test/presenters/content_item/parts_test.rb | 10 +++++----- .../presenters/content_item/updatable_test.rb | 6 +++--- .../presenters/content_item_presenter_test.rb | 2 +- .../detailed_guide_presenter_test.rb | 2 +- .../html_publication_presenter_test.rb | 2 +- test/presenters/publication_presenter_test.rb | 4 ++-- .../specialist_document_presenter_test.rb | 10 +++++----- .../statistics_announcement_presenter_test.rb | 6 +++--- .../travel_advice_presenter_test.rb | 10 +++++----- 42 files changed, 102 insertions(+), 96 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index aee37a5b3..29db37a33 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,13 @@ inherit_gem: rubocop-govuk: - "config/default.yml" + - "config/rails.yml" Metrics/BlockLength: Exclude: - "test/**/*_test.rb" + +Rails/OutputSafety: + Enabled: false +Rails/HelperInstanceVariable: + Enabled: false diff --git a/app/controllers/content_items_controller.rb b/app/controllers/content_items_controller.rb index cb6c1fbd9..7acaff8e9 100644 --- a/app/controllers/content_items_controller.rb +++ b/app/controllers/content_items_controller.rb @@ -144,7 +144,7 @@ def with_locale end def error_403(exception) - render plain: exception.message, status: 403 + render plain: exception.message, status: :forbidden end def error_notfound @@ -152,11 +152,11 @@ def error_notfound end def error_406 - render plain: "Not acceptable", status: 406 + render plain: "Not acceptable", status: :not_acceptable end def error_410 - render plain: "Gone", status: 410 + render plain: "Gone", status: :gone end def error_redirect(exception) diff --git a/app/helpers/webchat_availability_helper.rb b/app/helpers/webchat_availability_helper.rb index fce3978f2..bfb4fc4f3 100644 --- a/app/helpers/webchat_availability_helper.rb +++ b/app/helpers/webchat_availability_helper.rb @@ -6,8 +6,8 @@ module WebchatAvailabilityHelper /government/organisations/hm-revenue-customs/contact/self-assessment /government/organisations/hm-revenue-customs/contact/tax-credits-enquiries ).freeze - UNAVAILABILITY_START = Time.parse("2018-05-12 16:00 BST").freeze - UNAVAILABILITY_END = Time.parse("2018-05-14 09:00 BST").freeze + UNAVAILABILITY_START = Time.zone.parse("2018-05-12 16:00 BST").freeze + UNAVAILABILITY_END = Time.zone.parse("2018-05-14 09:00 BST").freeze def webchat_unavailable?(now = Time.zone.now) show_unavailability = now >= UNAVAILABILITY_START && now < UNAVAILABILITY_END diff --git a/app/presenters/coming_soon_presenter.rb b/app/presenters/coming_soon_presenter.rb index 1511975d9..8e68554ce 100644 --- a/app/presenters/coming_soon_presenter.rb +++ b/app/presenters/coming_soon_presenter.rb @@ -15,7 +15,7 @@ def formatted_publish_date end def formatted_publish_time - display_time(Time.parse(@publish_time)) + display_time(Time.zone.parse(@publish_time)) end def page_title diff --git a/app/presenters/content_item/updatable.rb b/app/presenters/content_item/updatable.rb index d9eb152b4..e9a0ec9d4 100644 --- a/app/presenters/content_item/updatable.rb +++ b/app/presenters/content_item/updatable.rb @@ -38,7 +38,7 @@ def change_history # The direction of change history isn’t guaranteed # https://github.com/alphagov/govuk-content-schemas/issues/545 def reverse_chronological_change_history - change_history.sort_by { |item| Time.parse(item[:timestamp]) }.reverse + change_history.sort_by { |item| Time.zone.parse(item[:timestamp]) }.reverse end def any_updates? diff --git a/app/presenters/travel_advice_presenter.rb b/app/presenters/travel_advice_presenter.rb index e76941255..3db1992bd 100644 --- a/app/presenters/travel_advice_presenter.rb +++ b/app/presenters/travel_advice_presenter.rb @@ -89,7 +89,7 @@ def atom_change_description end def atom_public_updated_at - Time.parse(content_item["public_updated_at"]) + Time.zone.parse(content_item["public_updated_at"]) end def cache_control_max_age(format) diff --git a/lib/tasks/wraith.rake b/lib/tasks/wraith.rake index 8b22d0448..2b756e8ca 100644 --- a/lib/tasks/wraith.rake +++ b/lib/tasks/wraith.rake @@ -1,10 +1,10 @@ require "rest-client" -require "#{Rails.root}/lib/helpers/wraith_config_helper.rb" -require "#{Rails.root}/lib/helpers/document_types_helper.rb" +require Rails.root.join("lib/helpers/wraith_config_helper.rb") +require Rails.root.join("lib/helpers/document_types_helper.rb") namespace :wraith do desc "check top 10 content items for document_type using wraith" - task :document_type, [:document_type] do |_t, args| + task :document_type, [:document_type] => :environment do |_t, args| document_type = args[:document_type] document_type_paths = DocumentTypesHelper.new.type_paths(document_type) wraith_config_file = WraithConfigHelper.new(document_type, document_type_paths).create_config @@ -13,7 +13,7 @@ namespace :wraith do end desc "check top 10 content items for all known document types" - task :all_document_types, [:sample_size] do |_t, args| + task :all_document_types, [:sample_size] => :environment do |_t, args| args.with_defaults(sample_size: 10) # Make sure an up to date document_types file exists Rake::Task["wraith:update_document_types"].invoke args[:sample_size] @@ -23,7 +23,7 @@ namespace :wraith do end desc "creates a wraith config of document type examples from the search api" - task :update_document_types, [:sample_size] do |_t, args| + task :update_document_types, [:sample_size] => :environment do |_t, args| args.with_defaults(sample_size: 10) document_type_paths = DocumentTypesHelper.new(args[:sample_size]).all_type_paths document_types = { "document_types" => document_type_paths.keys } diff --git a/test/controllers/content_items_controller_test.rb b/test/controllers/content_items_controller_test.rb index b06e9dd42..8add145fc 100644 --- a/test/controllers/content_items_controller_test.rb +++ b/test/controllers/content_items_controller_test.rb @@ -146,8 +146,8 @@ class ContentItemsControllerTest < ActionController::TestCase 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_not_empty content_item["links"]["ordered_related_items"], "Content item should have existing related links" + assert_not_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 @@ -160,8 +160,8 @@ class ContentItemsControllerTest < ActionController::TestCase 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_not_empty content_item["links"]["ordered_related_items_overrides"], "Content item should have existing related link overrides" + assert_not_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 @@ -174,7 +174,7 @@ class ContentItemsControllerTest < ActionController::TestCase 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_not_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 @@ -187,7 +187,7 @@ class ContentItemsControllerTest < ActionController::TestCase 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_not_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 diff --git a/test/controllers/step_navigation_controller_test.rb b/test/controllers/step_navigation_controller_test.rb index b3329323e..7b312b1f2 100644 --- a/test/controllers/step_navigation_controller_test.rb +++ b/test/controllers/step_navigation_controller_test.rb @@ -31,7 +31,7 @@ class ContentItemsControllerTest < ActionController::TestCase get :show, params: { path: path } assert_response 200 - refute response.body.include?("Learn to drive a car: step by step") + assert_not response.body.include?("Learn to drive a car: step by step") end end end diff --git a/test/helpers/webchat_availability_helper_test.rb b/test/helpers/webchat_availability_helper_test.rb index ce5213eab..d660595f8 100644 --- a/test/helpers/webchat_availability_helper_test.rb +++ b/test/helpers/webchat_availability_helper_test.rb @@ -9,9 +9,9 @@ class WebchatAvailabilityHelperTest < ActionView::TestCase end test "webchat_unavailable? indicates unavailability" do - refute webchat_unavailable?(Time.parse("2018-05-12 15:59 BST")) - assert webchat_unavailable?(Time.parse("2018-05-12 16:00 BST")) - assert webchat_unavailable?(Time.parse("2018-05-14 08:59 BST")) - refute webchat_unavailable?(Time.parse("2018-05-14 09:00 BST")) + assert_not webchat_unavailable?(Time.zone.parse("2018-05-12 15:59 BST")) + assert webchat_unavailable?(Time.zone.parse("2018-05-12 16:00 BST")) + assert webchat_unavailable?(Time.zone.parse("2018-05-14 08:59 BST")) + assert_not webchat_unavailable?(Time.zone.parse("2018-05-14 09:00 BST")) end end diff --git a/test/integration/contact_test.rb b/test/integration/contact_test.rb index 1f61879fa..644ea6ff6 100644 --- a/test/integration/contact_test.rb +++ b/test/integration/contact_test.rb @@ -39,7 +39,7 @@ class ContactTest < ActionDispatch::IntegrationTest 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"]) + assert_not page.has_css?("h3", text: first_phone["title"]) end test "posts are rendered" do diff --git a/test/integration/corporate_information_page_test.rb b/test/integration/corporate_information_page_test.rb index e8e301ab6..3e54183e4 100644 --- a/test/integration/corporate_information_page_test.rb +++ b/test/integration/corporate_information_page_test.rb @@ -27,7 +27,7 @@ class CorporateInformationPageTest < ActionDispatch::IntegrationTest content_store_has_item(item["base_path"], item.to_json) visit_with_cachebust(item["base_path"]) - refute page.has_css?(".gem-c-contents-list") + assert_not page.has_css?(".gem-c-contents-list") end test "renders corporate information with body when present" do diff --git a/test/integration/detailed_guide_test.rb b/test/integration/detailed_guide_test.rb index 0c5fadd84..b4867e15f 100644 --- a/test/integration/detailed_guide_test.rb +++ b/test/integration/detailed_guide_test.rb @@ -77,7 +77,7 @@ class DetailedGuideTest < ActionDispatch::IntegrationTest test "renders without contents list if it has fewer than 3 items" do setup_and_visit_content_item("national_applicability_alternative_url_detailed_guide") - refute page.has_css?(".gem-c-contents-list") + assert_not page.has_css?(".gem-c-contents-list") end test "conditionally renders a logo" do diff --git a/test/integration/document_collection_test.rb b/test/integration/document_collection_test.rb index ddb868ee1..ad1d3711c 100644 --- a/test/integration/document_collection_test.rb +++ b/test/integration/document_collection_test.rb @@ -56,7 +56,7 @@ class DocumentCollectionTest < ActionDispatch::IntegrationTest content_store_has_item(item["base_path"], item.to_json) visit_with_cachebust(item["base_path"]) - refute page.has_css?(".gem-c-contents-list") + assert_not page.has_css?(".gem-c-contents-list") end test "renders each collection group" do diff --git a/test/integration/fatality_notice_test.rb b/test/integration/fatality_notice_test.rb index 1fe9691f2..be7369fc7 100644 --- a/test/integration/fatality_notice_test.rb +++ b/test/integration/fatality_notice_test.rb @@ -18,7 +18,7 @@ class FatalityNoticeTest < ActionDispatch::IntegrationTest assert page.has_content?("Operations in Zululand") assert_has_component_title("Sir George Pomeroy Colley killed in Boer War") - refute page.has_css?(".gem-c-notice") + assert_not page.has_css?(".gem-c-notice") assert_has_publisher_metadata( published: "Published 27 February 1881", diff --git a/test/integration/guide_test.rb b/test/integration/guide_test.rb index be8a754a1..14a62bb4b 100644 --- a/test/integration/guide_test.rb +++ b/test/integration/guide_test.rb @@ -25,8 +25,8 @@ class GuideTest < ActionDispatch::IntegrationTest test "does not show part navigation, print link or part title when only one part" do 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") + assert_not page.has_css?("h1", text: @content_item["details"]["parts"].first["title"]) + assert_not 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 @@ -34,7 +34,7 @@ class GuideTest < ActionDispatch::IntegrationTest title = @content_item["title"] part_title = @content_item["details"]["parts"][0]["title"] - refute page.has_css?("h1", text: title) + assert_not page.has_css?("h1", text: title) assert_has_component_title(part_title) end @@ -52,15 +52,15 @@ class GuideTest < ActionDispatch::IntegrationTest title = @content_item["title"] part_title = @content_item["details"]["parts"][0]["title"] - refute page.has_css?("h1", text: title) + assert_not 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") - refute page.has_css?(".gem-c-pagination") - refute page.has_css?(".app-c-print-link") + assert_not page.has_css?(".gem-c-pagination") + assert_not 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 diff --git a/test/integration/html_publication_test.rb b/test/integration/html_publication_test.rb index b611d2a87..b86524b2e 100644 --- a/test/integration/html_publication_test.rb +++ b/test/integration/html_publication_test.rb @@ -64,7 +64,7 @@ class HtmlPublicationTest < ActionDispatch::IntegrationTest setup_and_visit_content_item("prime_ministers_office") within ".gem-c-inverse-header" do - refute page.has_text?("Contents") + assert_not page.has_text?("Contents") end end diff --git a/test/integration/phase_label_test.rb b/test/integration/phase_label_test.rb index 5e48e4cec..7d2ebf567 100644 --- a/test/integration/phase_label_test.rb +++ b/test/integration/phase_label_test.rb @@ -19,6 +19,6 @@ class PhaseLabelTest < ActionDispatch::IntegrationTest visit_with_cachebust "/government/case-studies/get-britain-building-carlisle-park" - refute page.has_text?("alpha") + assert_not page.has_text?("alpha") 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 1a914ba58..8b83488e2 100644 --- a/test/integration/service_sign_in/choose_sign_in_test.rb +++ b/test/integration/service_sign_in/choose_sign_in_test.rb @@ -17,7 +17,7 @@ class ChooseSignInTest < ActionDispatch::IntegrationTest 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_not 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?('form[data-module="track-radio-group"]') @@ -73,7 +73,7 @@ class ChooseSignInTest < ActionDispatch::IntegrationTest assert page.has_css?(".gem-c-radio .govuk-label", text: "Use GOV.UK Verify") assert page.has_css?(".gem-c-radio .govuk-hint", text: "You can use an existing identity account or create a new one. It usually takes about 5 minutes to create an account.") - refute page.has_css?(".govuk-radios__divider", text: "or") + assert_not page.has_css?(".govuk-radios__divider", text: "or") end test "page renders welsh correctly" 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 d2859e903..6f9bee18a 100644 --- a/test/integration/service_sign_in/create_new_account_test.rb +++ b/test/integration/service_sign_in/create_new_account_test.rb @@ -26,7 +26,7 @@ class CreateNewAccount < ActionDispatch::IntegrationTest assert page.has_text?("To use this service, you need to create either a Government Gateway or GOV.UK Verify account. These are used to help fight identity theft.") assert page.has_css?('meta[name="robots"][content="noindex, nofollow"]', visible: false) - refute page.has_css?("#proposition-menu") + assert_not page.has_css?("#proposition-menu") assert page.has_css?( '.gem-c-back-link[href="/log-in-file-self-assessment-tax-return/sign-in/choose-sign-in"]', diff --git a/test/integration/specialist_document_test.rb b/test/integration/specialist_document_test.rb index c16c7bd52..b00f8b156 100644 --- a/test/integration/specialist_document_test.rb +++ b/test/integration/specialist_document_test.rb @@ -141,7 +141,7 @@ def assert_nested_content_item(heading) assert page.has_css?(selector), "Failed to find an element matching: #{selector}" assert page.has_css?(selector, text: text), "Failed to find an element matching #{selector} with text: #{text}" else - refute page.has_css?(selector), "Found a nested heading too deep, there should be no element matching: #{selector}" + assert_not page.has_css?(selector), "Found a nested heading too deep, there should be no element matching: #{selector}" end if heading["headers"].present? @@ -154,7 +154,7 @@ def assert_nested_content_item(heading) 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") + assert_not page.has_css?(".gem-c-button", text: "Find out more") end test "renders start button" do @@ -167,7 +167,7 @@ def assert_nested_content_item(heading) 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") + assert_not page.has_css?("#contents .gem-c-contents-list") end test "renders a link to statutory instruments finder" do diff --git a/test/integration/statistical_data_set_test.rb b/test/integration/statistical_data_set_test.rb index 7fa3b87b7..c741b5368 100644 --- a/test/integration/statistical_data_set_test.rb +++ b/test/integration/statistical_data_set_test.rb @@ -65,6 +65,6 @@ class StatisticalDataSetTest < ActionDispatch::IntegrationTest content_store_has_item(item["base_path"], item.to_json) visit_with_cachebust(item["base_path"]) - refute page.has_css?(".gem-c-contents-list") + assert_not page.has_css?(".gem-c-contents-list") end end diff --git a/test/integration/statistics_announcement_test.rb b/test/integration/statistics_announcement_test.rb index 6062feb24..e495958f0 100644 --- a/test/integration/statistics_announcement_test.rb +++ b/test/integration/statistics_announcement_test.rb @@ -65,6 +65,6 @@ class StatisticsAnnouncementTest < ActionDispatch::IntegrationTest test "cancelled statistics announcements do not display the forthcoming notice" do setup_and_visit_content_item("cancelled_official_statistics") - refute page.has_text?(StatisticsAnnouncementPresenter::FORTHCOMING_NOTICE) + assert_not page.has_text?(StatisticsAnnouncementPresenter::FORTHCOMING_NOTICE) end end diff --git a/test/integration/topical_event_about_page_test.rb b/test/integration/topical_event_about_page_test.rb index 3fc3bb8ed..702bbe6c9 100644 --- a/test/integration/topical_event_about_page_test.rb +++ b/test/integration/topical_event_about_page_test.rb @@ -19,7 +19,7 @@ class TopicalEventAboutPageTest < ActionDispatch::IntegrationTest 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") + assert_not page.has_css?(".contents-list.contents-list-dashed") end test "contents list not displayed when fewer than three items" do @@ -29,7 +29,7 @@ class TopicalEventAboutPageTest < ActionDispatch::IntegrationTest content_store_has_item(@content_item["base_path"], @content_item.to_json) visit_with_cachebust @content_item["base_path"] - refute page.has_css?(".gem-c-contents-list") + assert_not page.has_css?(".gem-c-contents-list") end test "contents list displayed when fewer than three items and first item word count is greater than 100" do diff --git a/test/integration/travel_advice_atom_feed_test.rb b/test/integration/travel_advice_atom_feed_test.rb index 0fc2578dd..b7fa8ff50 100644 --- a/test/integration/travel_advice_atom_feed_test.rb +++ b/test/integration/travel_advice_atom_feed_test.rb @@ -8,7 +8,7 @@ class TravelAdviceAtomFeed < ActionDispatch::IntegrationTest setup do setup_and_parse_travel_advice_atom_feed("full-country") @base_path = @content_item["base_path"] - @updated_at = Time.parse(@content_item["public_updated_at"]) + @updated_at = Time.zone.parse(@content_item["public_updated_at"]) end test "it sets the alternative link correctly" do diff --git a/test/integration/travel_advice_print_test.rb b/test/integration/travel_advice_print_test.rb index 481fac56c..f69faa32f 100644 --- a/test/integration/travel_advice_print_test.rb +++ b/test/integration/travel_advice_print_test.rb @@ -15,7 +15,7 @@ class TravelAdvicePrint < ActionDispatch::IntegrationTest 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("Still current at", Time.zone.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 diff --git a/test/integration/travel_advice_test.rb b/test/integration/travel_advice_test.rb index 0ce703183..cfe2bd738 100644 --- a/test/integration/travel_advice_test.rb +++ b/test/integration/travel_advice_test.rb @@ -17,7 +17,7 @@ class TravelAdviceTest < ActionDispatch::IntegrationTest 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_not 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"]) @@ -33,7 +33,7 @@ class TravelAdviceTest < ActionDispatch::IntegrationTest 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.") - assert_has_component_metadata_pair("Still current at", Date.today.strftime("%-d %B %Y")) + assert_has_component_metadata_pair("Still current at", Time.zone.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 @@ -53,11 +53,11 @@ class TravelAdviceTest < ActionDispatch::IntegrationTest 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_not page.has_css?(".map") + assert_not 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_not page.has_css?(".part-navigation li a", text: first_part["title"]) end test "travel advice includes a discoverable atom feed link" do diff --git a/test/integration/working_group_test.rb b/test/integration/working_group_test.rb index a4ebb65bf..5d709583c 100644 --- a/test/integration/working_group_test.rb +++ b/test/integration/working_group_test.rb @@ -52,6 +52,6 @@ class WorkingGroupTest < ActionDispatch::IntegrationTest content_store_has_item(item["base_path"], item.to_json) visit_with_cachebust(item["base_path"]) - refute page.has_css?(".gem-c-contents-list") + assert_not page.has_css?(".gem-c-contents-list") end end diff --git a/test/integration/world_location_news_article_test.rb b/test/integration/world_location_news_article_test.rb index 269d08e92..f22e1ffd5 100644 --- a/test/integration/world_location_news_article_test.rb +++ b/test/integration/world_location_news_article_test.rb @@ -29,7 +29,7 @@ class WorldLocationNewsArticleTest < ActionDispatch::IntegrationTest assert page.has_content?(:all, "English हिंदी 日本語 中文 中文") - refute page.has_link?("English") + assert_not page.has_link?("English") assert page.has_link?("हिंदी", href: "/government/world-location-news/changes-to-secure-english-language-test-providers-for-uk-visas.hi") assert page.has_link?("日本語", href: "/government/world-location-news/changes-to-secure-english-language-test-providers-for-uk-visas.ja") diff --git a/test/presenters/case_study_presenter_test.rb b/test/presenters/case_study_presenter_test.rb index fb6940659..24c319cca 100644 --- a/test/presenters/case_study_presenter_test.rb +++ b/test/presenters/case_study_presenter_test.rb @@ -97,7 +97,7 @@ def schema_name end def presented_case_study_with_updates - updated_date = Time.new(2013, 3, 21).to_s + updated_date = Time.zone.local(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 diff --git a/test/presenters/consultation_presenter_test.rb b/test/presenters/consultation_presenter_test.rb index 34051fbfa..22d8d8926 100644 --- a/test/presenters/consultation_presenter_test.rb +++ b/test/presenters/consultation_presenter_test.rb @@ -50,16 +50,16 @@ def schema_name test "presents open and closed states" do assert presented_item("open_consultation").open? - refute presented_item("open_consultation").closed? + assert_not presented_item("open_consultation").closed? assert presented_item("closed_consultation").closed? - refute presented_item("closed_consultation").open? + assert_not presented_item("closed_consultation").open? assert presented_item("consultation_outcome").closed? - refute presented_item("consultation_outcome").open? + assert_not presented_item("consultation_outcome").open? - refute presented_item("unopened_consultation").closed? - refute presented_item("unopened_consultation").open? + assert_not presented_item("unopened_consultation").closed? + assert_not presented_item("unopened_consultation").open? end test "presents consultation documents" do @@ -88,10 +88,10 @@ def schema_name 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? + assert_not presented_item("closed_consultation").held_on_another_website? assert_equal "https://consult.education.gov.uk/part-time-maintenance-loans/post-graduate-doctoral-loans/", presented_item("open_consultation").held_on_another_website_url - refute presented_item("closed_consultation").held_on_another_website_url + assert_not presented_item("closed_consultation").held_on_another_website_url end test "content can apply only to a set of nations" do @@ -124,7 +124,7 @@ def schema_name 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? + assert_not presented_without_email.response_form? end test "does not show ways to respond when consultation is closed" do @@ -132,7 +132,7 @@ def schema_name example["details"]["ways_to_respond"] = { "email" => "email@email.com" } presented = presented_item("closed_consultation", example) - refute presented.ways_to_respond? + assert_not presented.ways_to_respond? end test "does not show ways to respond when only an attachment url is provided" do @@ -142,7 +142,7 @@ def schema_name example["details"]["ways_to_respond"].delete("link_url") presented = presented_item("open_consultation_with_participation", example) - refute presented.ways_to_respond? + assert_not presented.ways_to_respond? end test "presents share urls with encoded url and title" do diff --git a/test/presenters/content_item/contents_list_test.rb b/test/presenters/content_item/contents_list_test.rb index 0438587c3..b432d58ba 100644 --- a/test/presenters/content_item/contents_list_test.rb +++ b/test/presenters/content_item/contents_list_test.rb @@ -135,7 +135,7 @@ def body

#{Faker::Lorem.sentence}

" end end - refute @contents_list.show_contents_list? + assert_not @contents_list.show_contents_list? end test "#show_contents_list? returns true if number of table rows in the first item is more than 13" do @@ -160,7 +160,7 @@ def body \n

Two

" end end - refute @contents_list.show_contents_list? + assert_not @contents_list.show_contents_list? end test "#show_contents_list? returns true if image and over 224 characters are present in the first item" do diff --git a/test/presenters/content_item/organisation_branding_test.rb b/test/presenters/content_item/organisation_branding_test.rb index df6505670..5d76f5fbd 100644 --- a/test/presenters/content_item/organisation_branding_test.rb +++ b/test/presenters/content_item/organisation_branding_test.rb @@ -33,7 +33,7 @@ def test_organisation organisation = test_organisation organisation["details"]["logo"]["crest"] = "eo" - refute_equal organisation_brand(organisation), test_organisation["details"]["brand"] + assert_not_equal organisation_brand(organisation), test_organisation["details"]["brand"] assert_equal organisation_brand(organisation), "executive-office" end diff --git a/test/presenters/content_item/parts_test.rb b/test/presenters/content_item/parts_test.rb index aad75113e..5b0d45a08 100644 --- a/test/presenters/content_item/parts_test.rb +++ b/test/presenters/content_item/parts_test.rb @@ -67,7 +67,7 @@ def content_item end end - refute @parts.requesting_a_part? + assert_not @parts.requesting_a_part? end test "is not requesting a part when parts exist and base_path matches requested_content_item_path" do @@ -77,7 +77,7 @@ def requested_content_item_path end end - refute @parts.requesting_a_part? + assert_not @parts.requesting_a_part? end test "is requesting a part when part exists and base_path is different to requested_content_item_path" do @@ -122,7 +122,7 @@ def requested_content_item_path end assert @parts.requesting_a_part? - refute @parts.has_valid_part? + assert_not @parts.has_valid_part? end test "invalid when slug for first part is present in URL" do @@ -137,13 +137,13 @@ def requested_content_item_path end assert @parts.requesting_a_part? - refute @parts.has_valid_part? + assert_not @parts.has_valid_part? end 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_not @parts.requesting_a_part? assert_equal @parts.current_part_body, "first-body" assert_equal @parts.current_part_title, "first-title" end diff --git a/test/presenters/content_item/updatable_test.rb b/test/presenters/content_item/updatable_test.rb index 15b73248a..7a86ac6e9 100644 --- a/test/presenters/content_item/updatable_test.rb +++ b/test/presenters/content_item/updatable_test.rb @@ -71,7 +71,7 @@ def content_item end assert @updatable.history.empty? - refute @updatable.updated + assert_not @updatable.updated end test "#history returns no updates when first_public_at is not present" do @@ -92,7 +92,7 @@ def content_item end assert @updatable.history.empty? - refute @updatable.updated + assert_not @updatable.updated end test "#history returns no updates when public_updated_at not present" do @@ -113,7 +113,7 @@ def content_item end assert @updatable.history.empty? - refute @updatable.updated + assert_not @updatable.updated end test "#history returns an array of hashes when there is change history" do diff --git a/test/presenters/content_item_presenter_test.rb b/test/presenters/content_item_presenter_test.rb index 6365780b0..eaefe3d51 100644 --- a/test/presenters/content_item_presenter_test.rb +++ b/test/presenters/content_item_presenter_test.rb @@ -50,7 +50,7 @@ class ContentItemPresenterTest < ActiveSupport::TestCase 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_not presented_example.requesting_a_part? assert presented_example.part_slug.nil? end end diff --git a/test/presenters/detailed_guide_presenter_test.rb b/test/presenters/detailed_guide_presenter_test.rb index 2ec436a01..6b2bfb812 100644 --- a/test/presenters/detailed_guide_presenter_test.rb +++ b/test/presenters/detailed_guide_presenter_test.rb @@ -39,7 +39,7 @@ def schema_name example = schema_item("political_detailed_guide") presented = presented_item("political_detailed_guide") - refute example["details"]["government"]["current"] + assert_not example["details"]["government"]["current"] assert example["details"]["political"] assert presented.historically_political? diff --git a/test/presenters/html_publication_presenter_test.rb b/test/presenters/html_publication_presenter_test.rb index 10dd34ee6..d51f72f42 100644 --- a/test/presenters/html_publication_presenter_test.rb +++ b/test/presenters/html_publication_presenter_test.rb @@ -63,6 +63,6 @@ def schema_name } assert presented.organisations.count > 1 - refute presented.organisation_logo(organisation)[:organisation][:image] + assert_not presented.organisation_logo(organisation)[:organisation][:image] end end diff --git a/test/presenters/publication_presenter_test.rb b/test/presenters/publication_presenter_test.rb index 08a3831f6..f9b076df8 100644 --- a/test/presenters/publication_presenter_test.rb +++ b/test/presenters/publication_presenter_test.rb @@ -29,7 +29,7 @@ def schema_name example = schema_item("political_publication") presented = presented_item("political_publication") - refute example["details"]["government"]["current"] + assert_not example["details"]["government"]["current"] assert example["details"]["political"] assert presented.historically_political? @@ -51,7 +51,7 @@ def schema_name end test "#national_statistics? matches national statistics documents" do - refute presented_item.national_statistics? + assert_not presented_item.national_statistics? assert presented_item("statistics_publication").national_statistics? end diff --git a/test/presenters/specialist_document_presenter_test.rb b/test/presenters/specialist_document_presenter_test.rb index a3e096cda..a15d97a0a 100644 --- a/test/presenters/specialist_document_presenter_test.rb +++ b/test/presenters/specialist_document_presenter_test.rb @@ -41,7 +41,7 @@ class PresentedSpecialistDocument < SpecialistDocumentTestCase }, ] - refute present_example(example).updated + assert_not present_example(example).updated example["details"]["change_history"] = [ { @@ -76,7 +76,7 @@ class PresentedSpecialistDocument < SpecialistDocumentTestCase ] presented = present_example(example) - assert Time.parse(presented.published) == Time.parse("2002-02-02") + assert Time.zone.parse(presented.published) == Time.zone.parse("2002-02-02") end test "has title without context" do @@ -117,7 +117,7 @@ class PresentedSpecialistDocument < SpecialistDocumentTestCase example = schema_item("aaib-reports") example["details"]["metadata"]["bulk_published"] = true - refute present_example(example).metadata[:first_published] + assert_not present_example(example).metadata[:first_published] example["details"]["metadata"]["bulk_published"] = false assert present_example(example).metadata[:first_published] @@ -336,7 +336,7 @@ def example_facet(overrides = {}) example = example_with_finder_facets(facets, "first_published_at" => "2010-01-01") presented = present_example(example) - refute presented.metadata[:other]["Published"] + assert_not presented.metadata[:other]["Published"] end test "uses first published date in facets as canonical publish date if provided" do @@ -357,7 +357,7 @@ def example_facet(overrides = {}) ] presented = present_example(example) - assert Time.parse(presented.published) == Time.parse("2010-01-01") + assert Time.zone.parse(presented.published) == Time.zone.parse("2010-01-01") end end end diff --git a/test/presenters/statistics_announcement_presenter_test.rb b/test/presenters/statistics_announcement_presenter_test.rb index 3c326f704..94996bc8a 100644 --- a/test/presenters/statistics_announcement_presenter_test.rb +++ b/test/presenters/statistics_announcement_presenter_test.rb @@ -55,13 +55,13 @@ def schema_name end test "knows if an item is a national statistic" do - refute statistics_announcement.national_statistics? + assert_not statistics_announcement.national_statistics? assert statistics_announcement_national.national_statistics? end test "knows if the release date has changed" do assert statistics_announcement_date_changed.release_date_changed? - refute statistics_announcement_national.release_date_changed? + assert_not statistics_announcement_national.release_date_changed? end test "an announcement is forthcoming if it is not cancelled" do @@ -69,7 +69,7 @@ def schema_name end test "a cancelled announcement takes precedence over a forthcoming announcement" do - refute statistics_announcement_cancelled.forthcoming_publication? + assert_not statistics_announcement_cancelled.forthcoming_publication? end def statistics_announcement_cancelled diff --git a/test/presenters/travel_advice_presenter_test.rb b/test/presenters/travel_advice_presenter_test.rb index ef5aa2559..3321d94f9 100644 --- a/test/presenters/travel_advice_presenter_test.rb +++ b/test/presenters/travel_advice_presenter_test.rb @@ -11,7 +11,7 @@ def schema_name end test "part slug set to nil when content item has parts but base path requested" do - refute presented_item("full-country").requesting_a_part? + assert_not presented_item("full-country").requesting_a_part? assert presented_item("full-country").part_slug.nil? end @@ -30,7 +30,7 @@ def schema_name assert presented.requesting_a_part? assert_equal presented.part_slug, "not-a-valid-part" - refute presented.has_valid_part? + assert_not presented.has_valid_part? end test "presents unique titles for each part" do @@ -62,7 +62,7 @@ def schema_name first_part = example_parts.first presented = presented_item("full-country", first_part["slug"]) - refute presented.is_summary? + assert_not 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 @@ -72,8 +72,8 @@ def schema_name 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") - refute presented.has_valid_part? + assert_not example_part_slugs.include?("not-a-valid-part") + assert_not presented.has_valid_part? end test "the summary is included as the first navigation item" do