Skip to content

Commit

Permalink
Fix the linting problems
Browse files Browse the repository at this point in the history
a lot of this was done using the automated rubocop -a option
  • Loading branch information
Andrew Hilton committed May 8, 2017
1 parent 962f8cb commit ec359de
Show file tree
Hide file tree
Showing 27 changed files with 61 additions and 105 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ end
group :test do
gem 'capybara', '~> 2.5.0'
gem 'govuk-content-schema-test-helpers', '~> 1.4'
gem 'mocha', '~> 1.1.0', :require => false
gem 'mocha', '~> 1.1.0', require: false
gem 'shoulda'
gem 'webmock'
gem 'test-unit'
Expand All @@ -44,7 +44,7 @@ gem 'plek', '1.11.0'
gem 'govuk_frontend_toolkit', '~> 6.0.1'

if ENV['GOVUK_TEMPLATE_DEV']
gem 'govuk_template', :path => "../govuk_template"
gem 'govuk_template', path: "../govuk_template"
else
gem 'govuk_template', '0.20.0'
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class ApplicationController < ActionController::Base
protect_from_forgery

protected
protected

def error_404
render :nothing => true, :status => :not_found
render nothing: true, status: :not_found
end
end
4 changes: 2 additions & 2 deletions app/controllers/icon_redirects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class IconRedirectsController < ApplicationController
def show
redirect_to view_context.asset_path(request.path.to_s[1..-1]), :status => 301
redirect_to view_context.asset_path(request.path.to_s[1..-1]), status: 301
end

def apple_60_60
redirect_to view_context.asset_path('apple-touch-icon-60x60.png'), :status => 301
redirect_to view_context.asset_path('apple-touch-icon-60x60.png'), status: 301
end
end
8 changes: 4 additions & 4 deletions app/controllers/root_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def raw_govuk_component_template
def govuk_component_docs
doc_files = Rails.root.join('app', 'views', 'govuk_component', 'docs', '*.yml')
docs = Dir[doc_files].sort.map do |file|
{id: File.basename(file, '.yml')}.merge(YAML::load_file(file))
{ id: File.basename(file, '.yml') }.merge(YAML::load_file(file))
end
render json: docs
end
Expand Down Expand Up @@ -54,16 +54,16 @@ def template
end
end

private
private

def render_yaml_as_json(file_path)
error_404 and return unless File.exists?(file_path)
error_404 && return unless File.exist?(file_path)
render json: YAML::load_file(file_path)
end

def render_raw_template(prefix, file_name)
file_path = Rails.root.join("app", "views", prefix, "#{file_name}.raw.html.erb")
error_404 and return unless File.exists?(file_path)
error_404 && return unless File.exist?(file_path)
render text: File.read(file_path)
end

Expand Down
2 changes: 1 addition & 1 deletion bin/rails
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
2 changes: 1 addition & 1 deletion config.ru
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require ::File.expand_path('../config/environment', __FILE__)
require ::File.expand_path('../config/environment', __FILE__)
run Static::Application
2 changes: 1 addition & 1 deletion config/boot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
2 changes: 1 addition & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
config.action_dispatch.show_exceptions = false

# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
config.action_controller.allow_forgery_protection = false

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/restrict_parsers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Turn off XML parsing:
# https://groups.google.com/forum/#!topic/rubyonrails-security/61bkgvnSGTQ/discussion
ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::XML)
ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::JSON)
ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::JSON)
19 changes: 9 additions & 10 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Static::Application.routes.draw do

controller "root", :format => false do
controller "root", format: false do
get "/templates/:template.raw.html.erb" => :raw_root_template
get "/templates/govuk_component/:template.raw.html.erb" => :raw_govuk_component_template
get "/templates/govuk_component/docs" => :govuk_component_docs
Expand All @@ -10,13 +9,13 @@
end

# Icon redirects
get "/favicon.ico", :to => "icon_redirects#show"
get "/apple-touch-icon.png", :to => "icon_redirects#apple_60_60"
get "/apple-touch-icon-152x152.png", :to => "icon_redirects#show"
get "/apple-touch-icon-120x120.png", :to => "icon_redirects#show"
get "/apple-touch-icon-76x76.png", :to => "icon_redirects#show"
get "/apple-touch-icon-60x60.png", :to => "icon_redirects#show"
get "/apple-touch-icon-precomposed.png", :to => "icon_redirects#apple_60_60"
get "/favicon.ico", to: "icon_redirects#show"
get "/apple-touch-icon.png", to: "icon_redirects#apple_60_60"
get "/apple-touch-icon-152x152.png", to: "icon_redirects#show"
get "/apple-touch-icon-120x120.png", to: "icon_redirects#show"
get "/apple-touch-icon-76x76.png", to: "icon_redirects#show"
get "/apple-touch-icon-60x60.png", to: "icon_redirects#show"
get "/apple-touch-icon-precomposed.png", to: "icon_redirects#apple_60_60"

mount JasmineRails::Engine => '/specs' if defined?(JasmineRails)
mount JasmineRails::Engine => '/specs' if defined?(JasmineRails)
end
4 changes: 2 additions & 2 deletions script/rails
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.

APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
24 changes: 11 additions & 13 deletions test/govuk_component/breadcrumbs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def component_name
end

test "renders a single breadcrumb" do
render_component({ breadcrumbs: [{title: 'Section', url: '/section'}] })
render_component(breadcrumbs: [{ title: 'Section', url: '/section' }])

assert_link_with_text_in('ol li:first-child', '/section', 'Section')
end
Expand Down Expand Up @@ -42,9 +42,9 @@ def component_name
render_component(breadcrumbs: breadcrumbs)

expected_tracking_options = [
{dimension28: "3", dimension29: "Section 1"},
{dimension28: "3", dimension29: "Section 2"},
{dimension28: "3", dimension29: "Section 3"},
{ dimension28: "3", dimension29: "Section 1" },
{ dimension28: "3", dimension29: "Section 2" },
{ dimension28: "3", dimension29: "Section 3" },
]

assert_select "ol li:nth-child(1) a[data-track-options='#{expected_tracking_options[0].to_json}']", 1
Expand All @@ -53,13 +53,11 @@ def component_name
end

test "renders a list of breadcrumbs" do
render_component({
breadcrumbs: [
{title: 'Home', url: '/'},
{title: 'Section', url: '/section'},
{title: 'Sub-section', url: '/sub-section'},
]
})
render_component(breadcrumbs: [
{ title: 'Home', url: '/' },
{ title: 'Section', url: '/section' },
{ title: 'Sub-section', url: '/sub-section' },
])

assert_link_with_text_in('ol li:first-child', '/', 'Home')
assert_link_with_text_in('ol li:first-child + li', '/section', 'Section')
Expand All @@ -69,8 +67,8 @@ def component_name
test "allows the last breadcrumb to be text only" do
render_component(
breadcrumbs: [
{title: 'Topic', url: '/topic'},
{title: 'Current Page'},
{ title: 'Topic', url: '/topic' },
{ title: 'Current Page' },
]
)
assert_select('ol li:last-child', 'Current Page')
Expand Down
32 changes: 11 additions & 21 deletions test/govuk_component/document_footer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,41 @@ def component_name
end

test "renders the deparments a document is from" do
render_component({
from: [
render_component(from: [
"<a href='/space-travel'>Department for Space Travel</a>",
"<a href='/extra-solar-exploration'>Extra Solar Exploration Office</a>"
]
})
])

assert_link_with_text_in(".from .definition", "/space-travel", "Department for Space Travel")
assert_link_with_text_in(".from .definition", "/extra-solar-exploration", "Extra Solar Exploration Office")
end

test "renders things the document is part of" do
render_component({
part_of: [
render_component(part_of: [
"<a href='/space'>Space</a>",
"<a href='/astro-engineering'>Astro Engineering</a>"
]
})
])

assert_link_with_text_in(".part-of .definition", "/space", "Space")
assert_link_with_text_in(".part-of .definition", "/astro-engineering", "Astro Engineering")
end

test "renders custom metadata" do
render_component({
other: {
render_component(other: {
"Space travel type": "<a href='/faster-than-light'>Faster than light</a>"
}
})
})

assert_select 'p', text: /Space travel type/
assert_link_with_text_in(".other .definition", "/faster-than-light", "Faster than light")
end

test "renders custom document dates" do
render_component({
published: "20 January 2092",
render_component(published: "20 January 2092",
updated: "22 January 2092",
other_dates: {
"Date opened": "1 February 2092",
"Date closed": "1 March 2093"
}
})
})

assert_select 'p', text: /Published:\s+20 January 2092/
assert_select 'p', text: /Updated:\s+22 January 2092/
Expand All @@ -70,8 +62,7 @@ def component_name
end

test "renders document history" do
render_component({
history: [
render_component(history: [
{
display_time: "22 January 2012",
timestamp: "22-01-2012Z14:19:00T",
Expand All @@ -82,8 +73,7 @@ def component_name
timestamp: "24-01-2012Z14:19:00T",
note: "We updated the document again"
}
]
})
])

assert_timestamp_in('.change-notes', '22-01-2012Z14:19:00T', '22 January 2012')
assert_select 'li', text: /We updated the document$/
Expand All @@ -95,7 +85,7 @@ def component_name
end

test "supports right to left content" do
render_component({direction: "rtl"})
render_component(direction: "rtl")
assert_select '.govuk-document-footer.direction-rtl'
end
end
2 changes: 1 addition & 1 deletion test/govuk_component/government_navigation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def component_name
end

test "can mark a link as active" do
render_component({active: 'departments'})
render_component(active: 'departments')
assert_select "a.active", text: "Departments"
end
end
24 changes: 7 additions & 17 deletions test/govuk_component/metadata_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,33 @@ def component_name
end

test "renders from metadata" do
render_component({
from: "<a href='/link'>Department</a>"
})
render_component(from: "<a href='/link'>Department</a>")

assert_definition('From:', 'Department')
assert_link_with_text_in('dd', '/link', 'Department')
end

test "renders part of metadata" do
render_component({
part_of: "<a href='/link'>Department</a>"
})
render_component(part_of: "<a href='/link'>Department</a>")

assert_definition('Part of:', 'Department')
assert_link_with_text_in('dd', '/link', 'Department')
end

test "renders history metadata" do
render_component({
history: "Updated 2 weeks ago"
})
render_component(history: "Updated 2 weeks ago")

assert_definition('History:', 'Updated 2 weeks ago')
end

test "renders custom metadata" do
render_component({
other: {
render_component(other: {
"Related topics": [
"<a href='/government/topics/arts-and-culture'>Arts and culture</a>",
"<a href='/government/topics/sports-and-leisure'>Sports and leisure</a>"
],
"Applies to": "England"
}
})
})

assert_definition('Related topics:', 'Arts and culture and Sports and leisure')
assert_definition('Applies to:', 'England')
Expand All @@ -57,13 +49,11 @@ def component_name
end

test "renders multiples as a single sentence (except history)" do
render_component({
from: %w( one another ),
render_component(from: %w( one another ),
part_of: %w( this that ),
other: {
"Related topics": %w( a b c )
}
})
})

assert_definition('From:', 'one and another')
assert_definition('Part of:', 'this and that')
Expand Down
5 changes: 1 addition & 4 deletions test/govuk_component/related_items_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,7 @@ def component_name

assert_tracking_link("action", "1.1")
assert_tracking_link("label", "/item")
expected_link_1_tracking_options = {
dimension28: total_links_in_section_1.to_s,
dimension29: "Item title",
}

assert_tracking_link(
"options",
{ dimension28: total_links_in_section_1.to_s, dimension29: "Item title" }.to_json)
Expand Down
8 changes: 2 additions & 6 deletions test/govuk_component/taxonomy_sidebar_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def component_name
)

taxon_titles = css_select(".sidebar-taxon h2").map { |taxon_title| taxon_title.text.strip }
taxon_titles = ["Item 1 title", "Item 2 title"]
assert_equal ["Item 1 title", "Item 2 title"], taxon_titles
end

test "renders related content for the first two taxons" do
Expand Down Expand Up @@ -74,7 +74,7 @@ def component_name
],
)

related_links = css_select(".related-content a").map { |link| link.text }
related_links = css_select(".related-content a").map(&:text)
assert_equal ["Related link B", "Related link A", "Related link C"], related_links
end

Expand Down Expand Up @@ -121,10 +121,6 @@ def component_name
assert_select '.govuk-taxonomy-sidebar[data-module="track-click"]', 1
assert_tracking_link("category", "relatedLinkClicked", 6)

expected_title_tracking_options = {
dimension28: total_sections.to_s,
dimension29: "Item title"
}
assert_tracking_link(
"options",
{ dimension28: total_sections.to_s, dimension29: "Item title" }.to_json)
Expand Down
Loading

0 comments on commit ec359de

Please sign in to comment.