Skip to content

Commit

Permalink
Correct linting failures
Browse files Browse the repository at this point in the history
  • Loading branch information
brucebolt committed Jun 4, 2021
1 parent e00c410 commit d198c05
Show file tree
Hide file tree
Showing 22 changed files with 40 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ def content_item_path
.compact
.join(".")

"/" + URI.encode_www_form_component(path_and_optional_locale).gsub("%2F", "/")
"/#{URI.encode_www_form_component(path_and_optional_locale).gsub('%2F', '/')}"
end
end
4 changes: 2 additions & 2 deletions app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def service_url(original_url)
url.to_s
end

def with_locale
I18n.with_locale(@content_item.locale || I18n.default_locale) { yield }
def with_locale(&block)
I18n.with_locale(@content_item.locale || I18n.default_locale, &block)
end

def error_403(exception)
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/typography_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ 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
escaped_text.sub(/\s([\w.?!:]+)$/, ' \1').html_safe
end

def strip_trailing_colons(text)
text.gsub(/\:$/, "")
text.gsub(/:$/, "")
end
end
8 changes: 4 additions & 4 deletions app/presenters/consultation_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def opening_date_midnight?
end

def closing_date
display_date_and_time(closing_date_time, true)
display_date_and_time(closing_date_time, rollback_midnight: true)
end

def open?
Expand Down Expand Up @@ -118,16 +118,16 @@ def add_margin?

private

def display_date_and_time(date, rollback_midnight = false)
def display_date_and_time(date, rollback_midnight: false)
time = Time.zone.parse(date)
date_format = "%-e %B %Y"
time_format = "%l:%M%P"

if rollback_midnight
if rollback_midnight && (time.strftime(time_format) == "12:00am")
# 12am, 12:00am and "midnight on" can all be misinterpreted
# Use 11:59pm on the day before to remove ambiguity
# 12am on 10 January becomes 11:59pm on 9 January
time -= 1.second if time.strftime(time_format) == "12:00am"
time -= 1.second
end
I18n.l(time, format: "#{time_format} on #{date_format}").gsub(":00", "").gsub("12pm", "midday").gsub("12am on ", "").strip
end
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/content_item/brexit_hub_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def brexit_links
end

def brexit_link
brexit_links[content_item.dig("content_id")]
brexit_links[content_item["content_id"]]
end
end
end
2 changes: 1 addition & 1 deletion app/presenters/content_item/news_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def default_news_image

def placeholder_image
# this image has been uploaded to asset-manager
if content_item.dig("document_type") == "world_news_story"
if content_item["document_type"] == "world_news_story"
{ "url" => "https://assets.publishing.service.gov.uk/media/5e985599d3bf7f3fc943bbd8/UK_government_logo.jpg" }
else
{ "url" => "https://assets.publishing.service.gov.uk/media/5e59279b86650c53b2cefbfe/placeholder.jpg" }
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/content_item_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def web_url

def canonical_url
if requesting_a_part?
web_url + "/" + part_slug
"#{web_url}/#{part_slug}"
else
web_url
end
Expand Down
4 changes: 2 additions & 2 deletions app/presenters/guide_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def show_guide_navigation?
end

def content_title
if parts.any?
return current_part_title if hide_chapter_navigation?
if parts.any? && hide_chapter_navigation?
return current_part_title
end

title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def part_url(part, index)
if index.zero?
guide_url
else
guide_url + "/" + part["slug"]
"#{guide_url}/#{part['slug']}"
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def self.configured?(content_item)
end

def self.config_path(content_item)
CONFIG_PATH.join(content_item.slug + ".yml").to_s
CONFIG_PATH.join("#{content_item.slug}.yml").to_s
end

def initialize(content_item)
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/service_sign_in/paths.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ServiceSignIn
module Paths
def path
content_item["base_path"] + "/" + content_item["details"][page_type]["slug"]
"#{content_item['base_path']}/#{content_item['details'][page_type]['slug']}"
end

def has_valid_path?
Expand Down
4 changes: 3 additions & 1 deletion app/services/presenter_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def presenter_name
return service_sign_in_presenter_name
end

content_item["schema_name"].classify + "Presenter"
"#{content_item['schema_name'].classify}Presenter"
end

def service_sign_in_format?
Expand Down Expand Up @@ -66,6 +66,8 @@ def initialize(content_item)
@content_item = content_item
end
end

class SpecialRouteReturned < StandardError; end

class GovernmentReturned < StandardError; end
end
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger = ActiveSupport::Logger.new($stdout)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
Expand Down
6 changes: 3 additions & 3 deletions test/controllers/content_items_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class ContentItemsControllerTest < ActionController::TestCase
test "returns 404 for invalid url" do
path = "foreign-travel-advice/egypt]"

stub_content_store_does_not_have_item("/" + path)
stub_content_store_does_not_have_item("/#{path}")

get :show, params: { path: path }
assert_response :not_found
Expand All @@ -303,7 +303,7 @@ class ContentItemsControllerTest < ActionController::TestCase
test "returns 404 for item not in content store" do
path = "government/case-studies/boost-chocolate-production"

stub_content_store_does_not_have_item("/" + path)
stub_content_store_does_not_have_item("/#{path}")

get :show, params: { path: path }
assert_response :not_found
Expand All @@ -323,7 +323,7 @@ class ContentItemsControllerTest < ActionController::TestCase

test "returns 403 for access-limited item" do
path = "government/case-studies/super-sekrit-document"
url = content_store_endpoint + "/content/" + path
url = "#{content_store_endpoint}/content/#{path}"
stub_request(:get, url).to_return(status: 403, headers: {})

get :show, params: { path: path }
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/step_navigation_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ContentItemsControllerTest < ActionController::TestCase
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]
path = content_item["base_path"][1..]

stub_content_store_has_item(content_item["base_path"], content_item)

Expand All @@ -22,7 +22,7 @@ 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]
path = content_item["base_path"][1..]

stub_content_store_has_item(content_item["base_path"], content_item)

Expand Down
2 changes: 1 addition & 1 deletion test/integration/answer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AnswerTest < ActionDispatch::IntegrationTest
first_related_link = @content_item["details"]["external_related_links"].first

within(".gem-c-related-navigation") do
assert page.has_css?('.gem-c-related-navigation__section-link--other[href="' + first_related_link["url"] + '"]', text: first_related_link["title"])
assert page.has_css?(".gem-c-related-navigation__section-link--other[href=\"#{first_related_link['url']}\"]", text: first_related_link["title"])
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CreateNewAccount < ActionDispatch::IntegrationTest

def setup_and_visit_create_new_account_page
content_item = get_content_example("service_sign_in")
path = content_item["base_path"] + "/create-new-account"
path = "#{content_item['base_path']}/create-new-account"
stub_content_store_has_item(path, content_item.to_json)
visit(path)
end
Expand Down
2 changes: 1 addition & 1 deletion test/integration/specialist_document_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
8 changes: 4 additions & 4 deletions test/presenters/content_item/parts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def part_slug
end

def requested_path
base_path + "/second-slug"
"#{base_path}/second-slug"
end
end

Expand All @@ -105,7 +105,7 @@ def part_slug
end

def requested_path
base_path + "/" + part_slug
"#{base_path}/#{part_slug}"
end
end

Expand All @@ -121,7 +121,7 @@ def part_slug
end

def requested_path
base_path + "/" + part_slug
"#{base_path}/#{part_slug}"
end
end

Expand All @@ -136,7 +136,7 @@ def part_slug
end

def requested_path
base_path + "/" + part_slug
"#{base_path}/#{part_slug}"
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/presenters/content_item/shareable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize
end

def expected_path
url_encode(Plek.current.website_root + "/a/base/path")
url_encode("#{Plek.current.website_root}/a/base/path")
end

test "presents the twitter share url" do
Expand Down
2 changes: 1 addition & 1 deletion test/presenters/content_item_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ContentItemPresenterTest < PresenterTestCase

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"
request_path = "#{example_with_parts['base_path']}/safety-and-security"
presenter = create_presenter(
TravelAdvicePresenter,
content_item: example_with_parts,
Expand Down
10 changes: 5 additions & 5 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ActiveSupport::TestCase
include GovukContentSchemaExamples
end

# Note: This is so that slimmer is skipped, preventing network requests for
# NOTE: This is so that slimmer is skipped, preventing network requests for
# content from static (i.e. core_layout.html.erb).
class ActionController::Base
before_action :set_skip_slimmer_header
Expand Down Expand Up @@ -85,7 +85,7 @@ def assert_has_contents_list(contents)
end
end

def assert_has_published_dates(first_published = nil, last_updated = nil, history_link = false)
def assert_has_published_dates(first_published = nil, last_updated = nil, history_link: false)
text = []
text << first_published if first_published
text << last_updated if last_updated
Expand Down Expand Up @@ -135,7 +135,7 @@ def assert_has_metadata_local(metadata, term_selector, definition_selector)

def assert_has_publisher_metadata(options)
within(".app-c-publisher-metadata") do
assert_has_published_dates(options[:first_published], options[:last_updated], options[:history_link])
assert_has_published_dates(options[:first_published], options[:last_updated], history_link: options[:history_link])
assert_has_publisher_metadata_other(options[:metadata])
end
end
Expand All @@ -148,8 +148,8 @@ def assert_has_important_metadata(metadata)
end
end

def assert_footer_has_published_dates(first_published = nil, last_updated = nil, history_link = false)
assert_has_published_dates(first_published, last_updated, history_link)
def assert_footer_has_published_dates(first_published = nil, last_updated = nil, history_link: false)
assert_has_published_dates(first_published, last_updated, history_link: history_link)
end

def setup_and_visit_content_item(name, parameter_string = "")
Expand Down

0 comments on commit d198c05

Please sign in to comment.