Skip to content

Commit 4548d2d

Browse files
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.
1 parent 119b0ab commit 4548d2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+102
-96
lines changed

.rubocop.yml

+6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
inherit_gem:
22
rubocop-govuk:
33
- "config/default.yml"
4+
- "config/rails.yml"
45

56
Metrics/BlockLength:
67
Exclude:
78
- "test/**/*_test.rb"
9+
10+
Rails/OutputSafety:
11+
Enabled: false
12+
Rails/HelperInstanceVariable:
13+
Enabled: false

app/controllers/content_items_controller.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,19 @@ def with_locale
144144
end
145145

146146
def error_403(exception)
147-
render plain: exception.message, status: 403
147+
render plain: exception.message, status: :forbidden
148148
end
149149

150150
def error_notfound
151151
render plain: "Not found", status: :not_found
152152
end
153153

154154
def error_406
155-
render plain: "Not acceptable", status: 406
155+
render plain: "Not acceptable", status: :not_acceptable
156156
end
157157

158158
def error_410
159-
render plain: "Gone", status: 410
159+
render plain: "Gone", status: :gone
160160
end
161161

162162
def error_redirect(exception)

app/helpers/webchat_availability_helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ module WebchatAvailabilityHelper
66
/government/organisations/hm-revenue-customs/contact/self-assessment
77
/government/organisations/hm-revenue-customs/contact/tax-credits-enquiries
88
).freeze
9-
UNAVAILABILITY_START = Time.parse("2018-05-12 16:00 BST").freeze
10-
UNAVAILABILITY_END = Time.parse("2018-05-14 09:00 BST").freeze
9+
UNAVAILABILITY_START = Time.zone.parse("2018-05-12 16:00 BST").freeze
10+
UNAVAILABILITY_END = Time.zone.parse("2018-05-14 09:00 BST").freeze
1111

1212
def webchat_unavailable?(now = Time.zone.now)
1313
show_unavailability = now >= UNAVAILABILITY_START && now < UNAVAILABILITY_END

app/presenters/coming_soon_presenter.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def formatted_publish_date
1515
end
1616

1717
def formatted_publish_time
18-
display_time(Time.parse(@publish_time))
18+
display_time(Time.zone.parse(@publish_time))
1919
end
2020

2121
def page_title

app/presenters/content_item/updatable.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def change_history
3838
# The direction of change history isn’t guaranteed
3939
# https://github.com/alphagov/govuk-content-schemas/issues/545
4040
def reverse_chronological_change_history
41-
change_history.sort_by { |item| Time.parse(item[:timestamp]) }.reverse
41+
change_history.sort_by { |item| Time.zone.parse(item[:timestamp]) }.reverse
4242
end
4343

4444
def any_updates?

app/presenters/travel_advice_presenter.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def atom_change_description
8989
end
9090

9191
def atom_public_updated_at
92-
Time.parse(content_item["public_updated_at"])
92+
Time.zone.parse(content_item["public_updated_at"])
9393
end
9494

9595
def cache_control_max_age(format)

lib/tasks/wraith.rake

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require "rest-client"
2-
require "#{Rails.root}/lib/helpers/wraith_config_helper.rb"
3-
require "#{Rails.root}/lib/helpers/document_types_helper.rb"
2+
require Rails.root.join("lib/helpers/wraith_config_helper.rb")
3+
require Rails.root.join("lib/helpers/document_types_helper.rb")
44

55
namespace :wraith do
66
desc "check top 10 content items for document_type using wraith"
7-
task :document_type, [:document_type] do |_t, args|
7+
task :document_type, [:document_type] => :environment do |_t, args|
88
document_type = args[:document_type]
99
document_type_paths = DocumentTypesHelper.new.type_paths(document_type)
1010
wraith_config_file = WraithConfigHelper.new(document_type, document_type_paths).create_config
@@ -13,7 +13,7 @@ namespace :wraith do
1313
end
1414

1515
desc "check top 10 content items for all known document types"
16-
task :all_document_types, [:sample_size] do |_t, args|
16+
task :all_document_types, [:sample_size] => :environment do |_t, args|
1717
args.with_defaults(sample_size: 10)
1818
# Make sure an up to date document_types file exists
1919
Rake::Task["wraith:update_document_types"].invoke args[:sample_size]
@@ -23,7 +23,7 @@ namespace :wraith do
2323
end
2424

2525
desc "creates a wraith config of document type examples from the search api"
26-
task :update_document_types, [:sample_size] do |_t, args|
26+
task :update_document_types, [:sample_size] => :environment do |_t, args|
2727
args.with_defaults(sample_size: 10)
2828
document_type_paths = DocumentTypesHelper.new(args[:sample_size]).all_type_paths
2929
document_types = { "document_types" => document_type_paths.keys }

test/controllers/content_items_controller_test.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ class ContentItemsControllerTest < ActionController::TestCase
146146

147147
get :show, params: { path: path_for(content_item) }
148148
assert_response :success
149-
refute_empty content_item["links"]["ordered_related_items"], "Content item should have existing related links"
150-
refute_empty content_item["links"]["suggested_ordered_related_items"], "Content item should have existing suggested related links"
149+
assert_not_empty content_item["links"]["ordered_related_items"], "Content item should have existing related links"
150+
assert_not_empty content_item["links"]["suggested_ordered_related_items"], "Content item should have existing suggested related links"
151151
assert_equal content_item["links"]["ordered_related_items"], assigns[:content_item].content_item["links"]["ordered_related_items"]
152152
end
153153

@@ -160,8 +160,8 @@ class ContentItemsControllerTest < ActionController::TestCase
160160
get :show, params: { path: path_for(content_item) }
161161
assert_response :success
162162
assert_nil content_item["links"]["ordered_related_items"], "Content item should not have existing related links"
163-
refute_empty content_item["links"]["ordered_related_items_overrides"], "Content item should have existing related link overrides"
164-
refute_empty content_item["links"]["suggested_ordered_related_items"], "Content item should have existing suggested related links"
163+
assert_not_empty content_item["links"]["ordered_related_items_overrides"], "Content item should have existing related link overrides"
164+
assert_not_empty content_item["links"]["suggested_ordered_related_items"], "Content item should have existing suggested related links"
165165
assert_nil content_item["links"]["ordered_related_items"]
166166
end
167167

@@ -174,7 +174,7 @@ class ContentItemsControllerTest < ActionController::TestCase
174174
get :show, params: { path: path_for(content_item) }
175175
assert_response :success
176176
assert_empty content_item["links"]["ordered_related_items"], "Content item should have existing related links"
177-
refute_empty content_item["links"]["suggested_ordered_related_items"], "Content item should have existing suggested related links"
177+
assert_not_empty content_item["links"]["suggested_ordered_related_items"], "Content item should have existing suggested related links"
178178
assert_equal [], assigns[:content_item].content_item["links"]["ordered_related_items"]
179179
end
180180

@@ -187,7 +187,7 @@ class ContentItemsControllerTest < ActionController::TestCase
187187
get :show, params: { path: path_for(content_item) }
188188
assert_response :success
189189
assert_empty content_item["links"]["ordered_related_items"], "Content item should not have existing related links"
190-
refute_empty content_item["links"]["suggested_ordered_related_items"], "Content item should have existing suggested related links"
190+
assert_not_empty content_item["links"]["suggested_ordered_related_items"], "Content item should have existing suggested related links"
191191
assert_equal assigns[:content_item].content_item["links"]["ordered_related_items"], content_item["links"]["suggested_ordered_related_items"]
192192
end
193193

test/controllers/step_navigation_controller_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ContentItemsControllerTest < ActionController::TestCase
3131
get :show, params: { path: path }
3232

3333
assert_response 200
34-
refute response.body.include?("Learn to drive a car: step by step")
34+
assert_not response.body.include?("Learn to drive a car: step by step")
3535
end
3636
end
3737
end

test/helpers/webchat_availability_helper_test.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ class WebchatAvailabilityHelperTest < ActionView::TestCase
99
end
1010

1111
test "webchat_unavailable? indicates unavailability" do
12-
refute webchat_unavailable?(Time.parse("2018-05-12 15:59 BST"))
13-
assert webchat_unavailable?(Time.parse("2018-05-12 16:00 BST"))
14-
assert webchat_unavailable?(Time.parse("2018-05-14 08:59 BST"))
15-
refute webchat_unavailable?(Time.parse("2018-05-14 09:00 BST"))
12+
assert_not webchat_unavailable?(Time.zone.parse("2018-05-12 15:59 BST"))
13+
assert webchat_unavailable?(Time.zone.parse("2018-05-12 16:00 BST"))
14+
assert webchat_unavailable?(Time.zone.parse("2018-05-14 08:59 BST"))
15+
assert_not webchat_unavailable?(Time.zone.parse("2018-05-14 09:00 BST"))
1616
end
1717
end

test/integration/contact_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ContactTest < ActionDispatch::IntegrationTest
3939

4040
assert_equal 1, @content_item["details"]["phone_numbers"].size
4141
first_phone = @content_item["details"]["phone_numbers"].first
42-
refute page.has_css?("h3", text: first_phone["title"])
42+
assert_not page.has_css?("h3", text: first_phone["title"])
4343
end
4444

4545
test "posts are rendered" do

test/integration/corporate_information_page_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CorporateInformationPageTest < ActionDispatch::IntegrationTest
2727
content_store_has_item(item["base_path"], item.to_json)
2828
visit_with_cachebust(item["base_path"])
2929

30-
refute page.has_css?(".gem-c-contents-list")
30+
assert_not page.has_css?(".gem-c-contents-list")
3131
end
3232

3333
test "renders corporate information with body when present" do

test/integration/detailed_guide_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class DetailedGuideTest < ActionDispatch::IntegrationTest
7777

7878
test "renders without contents list if it has fewer than 3 items" do
7979
setup_and_visit_content_item("national_applicability_alternative_url_detailed_guide")
80-
refute page.has_css?(".gem-c-contents-list")
80+
assert_not page.has_css?(".gem-c-contents-list")
8181
end
8282

8383
test "conditionally renders a logo" do

test/integration/document_collection_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class DocumentCollectionTest < ActionDispatch::IntegrationTest
5656
content_store_has_item(item["base_path"], item.to_json)
5757
visit_with_cachebust(item["base_path"])
5858

59-
refute page.has_css?(".gem-c-contents-list")
59+
assert_not page.has_css?(".gem-c-contents-list")
6060
end
6161

6262
test "renders each collection group" do

test/integration/fatality_notice_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class FatalityNoticeTest < ActionDispatch::IntegrationTest
1818
assert page.has_content?("Operations in Zululand")
1919
assert_has_component_title("Sir George Pomeroy Colley killed in Boer War")
2020

21-
refute page.has_css?(".gem-c-notice")
21+
assert_not page.has_css?(".gem-c-notice")
2222

2323
assert_has_publisher_metadata(
2424
published: "Published 27 February 1881",

test/integration/guide_test.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ class GuideTest < ActionDispatch::IntegrationTest
2525
test "does not show part navigation, print link or part title when only one part" do
2626
setup_and_visit_content_item("single-page-guide")
2727

28-
refute page.has_css?("h1", text: @content_item["details"]["parts"].first["title"])
29-
refute page.has_css?(".app-c-print-link")
28+
assert_not page.has_css?("h1", text: @content_item["details"]["parts"].first["title"])
29+
assert_not page.has_css?(".app-c-print-link")
3030
end
3131

3232
test "replaces guide title with part title if in a step by step and hide_chapter_navigation is true" do
3333
setup_and_visit_content_item("guide-with-step-navs-and-hide-navigation")
3434
title = @content_item["title"]
3535
part_title = @content_item["details"]["parts"][0]["title"]
3636

37-
refute page.has_css?("h1", text: title)
37+
assert_not page.has_css?("h1", text: title)
3838
assert_has_component_title(part_title)
3939
end
4040

@@ -52,15 +52,15 @@ class GuideTest < ActionDispatch::IntegrationTest
5252
title = @content_item["title"]
5353
part_title = @content_item["details"]["parts"][0]["title"]
5454

55-
refute page.has_css?("h1", text: title)
55+
assert_not page.has_css?("h1", text: title)
5656
assert_has_component_title(part_title)
5757
end
5858

5959
test "does not show guide navigation and print link if in a step by step and hide_chapter_navigation is true" do
6060
setup_and_visit_content_item("guide-with-step-navs-and-hide-navigation")
6161

62-
refute page.has_css?(".gem-c-pagination")
63-
refute page.has_css?(".app-c-print-link")
62+
assert_not page.has_css?(".gem-c-pagination")
63+
assert_not page.has_css?(".app-c-print-link")
6464
end
6565

6666
test "shows guide navigation and print link if not in a step by step and hide_chapter_navigation is true" do

test/integration/html_publication_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class HtmlPublicationTest < ActionDispatch::IntegrationTest
6464
setup_and_visit_content_item("prime_ministers_office")
6565

6666
within ".gem-c-inverse-header" do
67-
refute page.has_text?("Contents")
67+
assert_not page.has_text?("Contents")
6868
end
6969
end
7070

test/integration/phase_label_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ class PhaseLabelTest < ActionDispatch::IntegrationTest
1919

2020
visit_with_cachebust "/government/case-studies/get-britain-building-carlisle-park"
2121

22-
refute page.has_text?("alpha")
22+
assert_not page.has_text?("alpha")
2323
end
2424
end

test/integration/service_sign_in/choose_sign_in_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ChooseSignInTest < ActionDispatch::IntegrationTest
1717

1818
assert page.has_css?("title", text: "Prove your identity to continue - GOV.UK", visible: false)
1919
assert page.has_css?('meta[name="robots"][content="noindex, nofollow"]', visible: false)
20-
refute page.has_css?("#proposition-menu")
20+
assert_not page.has_css?("#proposition-menu")
2121

2222
assert page.has_css?('.gem-c-back-link[href="/log-in-file-self-assessment-tax-return"]', text: "Back")
2323
assert page.has_css?('form[data-module="track-radio-group"]')
@@ -73,7 +73,7 @@ class ChooseSignInTest < ActionDispatch::IntegrationTest
7373
assert page.has_css?(".gem-c-radio .govuk-label", text: "Use GOV.UK Verify")
7474
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.")
7575

76-
refute page.has_css?(".govuk-radios__divider", text: "or")
76+
assert_not page.has_css?(".govuk-radios__divider", text: "or")
7777
end
7878

7979
test "page renders welsh correctly" do

test/integration/service_sign_in/create_new_account_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CreateNewAccount < ActionDispatch::IntegrationTest
2626

2727
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.")
2828
assert page.has_css?('meta[name="robots"][content="noindex, nofollow"]', visible: false)
29-
refute page.has_css?("#proposition-menu")
29+
assert_not page.has_css?("#proposition-menu")
3030

3131
assert page.has_css?(
3232
'.gem-c-back-link[href="/log-in-file-self-assessment-tax-return/sign-in/choose-sign-in"]',

test/integration/specialist_document_test.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def assert_nested_content_item(heading)
141141
assert page.has_css?(selector), "Failed to find an element matching: #{selector}"
142142
assert page.has_css?(selector, text: text), "Failed to find an element matching #{selector} with text: #{text}"
143143
else
144-
refute page.has_css?(selector), "Found a nested heading too deep, there should be no element matching: #{selector}"
144+
assert_not page.has_css?(selector), "Found a nested heading too deep, there should be no element matching: #{selector}"
145145
end
146146

147147
if heading["headers"].present?
@@ -154,7 +154,7 @@ def assert_nested_content_item(heading)
154154
test "renders no start button when not set" do
155155
setup_and_visit_content_item("aaib-reports")
156156

157-
refute page.has_css?(".gem-c-button", text: "Find out more")
157+
assert_not page.has_css?(".gem-c-button", text: "Find out more")
158158
end
159159

160160
test "renders start button" do
@@ -167,7 +167,7 @@ def assert_nested_content_item(heading)
167167
test "does not render a contents list if there are fewer than three items in the contents list" do
168168
setup_and_visit_content_item("aaib-reports")
169169

170-
refute page.has_css?("#contents .gem-c-contents-list")
170+
assert_not page.has_css?("#contents .gem-c-contents-list")
171171
end
172172

173173
test "renders a link to statutory instruments finder" do

test/integration/statistical_data_set_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ class StatisticalDataSetTest < ActionDispatch::IntegrationTest
6565
content_store_has_item(item["base_path"], item.to_json)
6666
visit_with_cachebust(item["base_path"])
6767

68-
refute page.has_css?(".gem-c-contents-list")
68+
assert_not page.has_css?(".gem-c-contents-list")
6969
end
7070
end

test/integration/statistics_announcement_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ class StatisticsAnnouncementTest < ActionDispatch::IntegrationTest
6565
test "cancelled statistics announcements do not display the forthcoming notice" do
6666
setup_and_visit_content_item("cancelled_official_statistics")
6767

68-
refute page.has_text?(StatisticsAnnouncementPresenter::FORTHCOMING_NOTICE)
68+
assert_not page.has_text?(StatisticsAnnouncementPresenter::FORTHCOMING_NOTICE)
6969
end
7070
end

test/integration/topical_event_about_page_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TopicalEventAboutPageTest < ActionDispatch::IntegrationTest
1919

2020
test "slim topical event about pages have no contents" do
2121
setup_and_visit_content_item("slim")
22-
refute page.has_css?(".contents-list.contents-list-dashed")
22+
assert_not page.has_css?(".contents-list.contents-list-dashed")
2323
end
2424

2525
test "contents list not displayed when fewer than three items" do
@@ -29,7 +29,7 @@ class TopicalEventAboutPageTest < ActionDispatch::IntegrationTest
2929
content_store_has_item(@content_item["base_path"], @content_item.to_json)
3030

3131
visit_with_cachebust @content_item["base_path"]
32-
refute page.has_css?(".gem-c-contents-list")
32+
assert_not page.has_css?(".gem-c-contents-list")
3333
end
3434

3535
test "contents list displayed when fewer than three items and first item word count is greater than 100" do

test/integration/travel_advice_atom_feed_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class TravelAdviceAtomFeed < ActionDispatch::IntegrationTest
88
setup do
99
setup_and_parse_travel_advice_atom_feed("full-country")
1010
@base_path = @content_item["base_path"]
11-
@updated_at = Time.parse(@content_item["public_updated_at"])
11+
@updated_at = Time.zone.parse(@content_item["public_updated_at"])
1212
end
1313

1414
test "it sets the alternative link correctly" do

test/integration/travel_advice_print_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TravelAdvicePrint < ActionDispatch::IntegrationTest
1515
setup_and_visit_travel_advice_print("full-country")
1616
parts = @content_item["details"]["parts"]
1717

18-
assert_has_component_metadata_pair("Still current at", Date.today.strftime("%-d %B %Y"))
18+
assert_has_component_metadata_pair("Still current at", Time.zone.today.strftime("%-d %B %Y"))
1919
assert_has_component_metadata_pair("Updated", Date.parse(@content_item["details"]["reviewed_at"]).strftime("%-d %B %Y"))
2020

2121
within ".gem-c-metadata" do

0 commit comments

Comments
 (0)