From 9a4b889b8390844699c907f674fc1fffdc1f3a3c Mon Sep 17 00:00:00 2001 From: Celia Collins Date: Fri, 3 Jul 2020 11:33:18 +0100 Subject: [PATCH 1/9] Remove specific versions from Gemfile --- Gemfile | 38 +++++++++++++++++++------------------- Gemfile.lock | 38 +++++++++++++++++++------------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Gemfile b/Gemfile index 14ff90162..a55dec38a 100644 --- a/Gemfile +++ b/Gemfile @@ -2,35 +2,35 @@ source "https://rubygems.org" ruby File.read(".ruby-version").strip -gem "asset_bom_removal-rails", "~> 1.0" +gem "asset_bom_removal-rails" gem "dalli" -gem "gds-api-adapters", "~> 67.0" -gem "govuk_ab_testing", "~> 2.4" -gem "govuk_app_config", "~> 2.2" -gem "govuk_publishing_components", "~> 21.60.3" -gem "htmlentities", "~> 4.3" -gem "plek", "~> 4.0" -gem "rack_strip_client_ip", "~> 0.0.2" +gem "gds-api-adapters" +gem "govuk_ab_testing" +gem "govuk_app_config" +gem "govuk_publishing_components" +gem "htmlentities" +gem "plek" +gem "rack_strip_client_ip" gem "rails", "~> 5.2.4" -gem "rails-controller-testing", "~> 1.0" -gem "rails-i18n", ">= 4.0.4" -gem "rails_translation_manager", "~> 0.1.0" -gem "sass-rails", "~> 5.0" -gem "slimmer", "~> 15.0" -gem "uglifier", ">= 1.3.0" +gem "rails-controller-testing" +gem "rails-i18n" +gem "rails_translation_manager" +gem "sass-rails" +gem "slimmer" +gem "uglifier" group :development, :test do - gem "govuk_schemas", "~> 4.1" + gem "govuk_schemas" gem "jasmine-rails" - gem "rubocop-govuk", "~> 3" - gem "scss_lint-govuk", "~> 0.2" + gem "rubocop-govuk" + gem "scss_lint-govuk" end group :development do gem "better_errors" gem "binding_of_caller" gem "pry" - gem "wraith", "~> 4.2" + gem "wraith" end group :test do @@ -39,5 +39,5 @@ group :test do gem "govuk_test" gem "minitest-reporters" gem "mocha" - gem "webmock", "~> 3.8.3", require: false + gem "webmock", require: false end diff --git a/Gemfile.lock b/Gemfile.lock index a87850266..3aaf2a4a2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -348,36 +348,36 @@ PLATFORMS ruby DEPENDENCIES - asset_bom_removal-rails (~> 1.0) + asset_bom_removal-rails better_errors binding_of_caller capybara dalli faker - gds-api-adapters (~> 67.0) - govuk_ab_testing (~> 2.4) - govuk_app_config (~> 2.2) - govuk_publishing_components (~> 21.60.3) - govuk_schemas (~> 4.1) + gds-api-adapters + govuk_ab_testing + govuk_app_config + govuk_publishing_components + govuk_schemas govuk_test - htmlentities (~> 4.3) + htmlentities jasmine-rails minitest-reporters mocha - plek (~> 4.0) + plek pry - rack_strip_client_ip (~> 0.0.2) + rack_strip_client_ip rails (~> 5.2.4) - rails-controller-testing (~> 1.0) - rails-i18n (>= 4.0.4) - rails_translation_manager (~> 0.1.0) - rubocop-govuk (~> 3) - sass-rails (~> 5.0) - scss_lint-govuk (~> 0.2) - slimmer (~> 15.0) - uglifier (>= 1.3.0) - webmock (~> 3.8.3) - wraith (~> 4.2) + rails-controller-testing + rails-i18n + rails_translation_manager + rubocop-govuk + sass-rails + scss_lint-govuk + slimmer + uglifier + webmock + wraith RUBY VERSION ruby 2.6.6 From 953ad650cb4dbd467338dc0f6886ca58de0f812e Mon Sep 17 00:00:00 2001 From: Celia Collins Date: Fri, 3 Jul 2020 11:54:10 +0100 Subject: [PATCH 2/9] Set scss_lint-govuk to 'require: false' in Gemfile When running tests I was getting this error: `ActionView::Template::Error: undefined method `bubbles?' for true:Sass::Script::Tree::Literal` The solution is suggested here https://github.com/sds/scss-lint/issues/278, specifically "You should only require scss-lint explicitly in your code so that the monkey patching code doesn't get loaded automatically. You can then explicitly load it for the cases where you need it" Putting it first in the rake tasks seems to stop it erroring as well. --- Gemfile | 2 +- Rakefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index a55dec38a..d305278af 100644 --- a/Gemfile +++ b/Gemfile @@ -23,7 +23,7 @@ group :development, :test do gem "govuk_schemas" gem "jasmine-rails" gem "rubocop-govuk" - gem "scss_lint-govuk" + gem "scss_lint-govuk", require: false end group :development do diff --git a/Rakefile b/Rakefile index da8c5556c..ed50acf6c 100644 --- a/Rakefile +++ b/Rakefile @@ -17,7 +17,7 @@ unless Rails.env.production? t.files = Dir.glob(["app/assets/stylesheets"]) end - task default: %i[spec rubocop scss_lint] + task default: %i[scss_lint spec rubocop] desc "Lint Ruby and SCSS files" task lint: %i[rubocop scss_lint] From e716934edc88b0064b89189db15b409887114549 Mon Sep 17 00:00:00 2001 From: Celia Collins Date: Fri, 3 Jul 2020 11:44:48 +0100 Subject: [PATCH 3/9] Ugrade Rails gem to 6.0.3.2 and dependent gems Pin rails to specific version and make it stand out, see alphagov/service-manual-frontend@27390cd for reasoning. --- Gemfile | 3 +- Gemfile.lock | 104 +++++++++++++++++++++++++++++---------------------- 2 files changed, 62 insertions(+), 45 deletions(-) diff --git a/Gemfile b/Gemfile index d305278af..e28168daa 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,8 @@ source "https://rubygems.org" ruby File.read(".ruby-version").strip +gem "rails", "6.0.3.2" + gem "asset_bom_removal-rails" gem "dalli" gem "gds-api-adapters" @@ -11,7 +13,6 @@ gem "govuk_publishing_components" gem "htmlentities" gem "plek" gem "rack_strip_client_ip" -gem "rails", "~> 5.2.4" gem "rails-controller-testing" gem "rails-i18n" gem "rails_translation_manager" diff --git a/Gemfile.lock b/Gemfile.lock index 3aaf2a4a2..6ede3c553 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,47 +1,61 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.2.4.3) - actionpack (= 5.2.4.3) + actioncable (6.0.3.2) + actionpack (= 6.0.3.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.4.3) - actionpack (= 5.2.4.3) - actionview (= 5.2.4.3) - activejob (= 5.2.4.3) + actionmailbox (6.0.3.2) + actionpack (= 6.0.3.2) + activejob (= 6.0.3.2) + activerecord (= 6.0.3.2) + activestorage (= 6.0.3.2) + activesupport (= 6.0.3.2) + mail (>= 2.7.1) + actionmailer (6.0.3.2) + actionpack (= 6.0.3.2) + actionview (= 6.0.3.2) + activejob (= 6.0.3.2) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.4.3) - actionview (= 5.2.4.3) - activesupport (= 5.2.4.3) + actionpack (6.0.3.2) + actionview (= 6.0.3.2) + activesupport (= 6.0.3.2) rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.4.3) - activesupport (= 5.2.4.3) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.0.3.2) + actionpack (= 6.0.3.2) + activerecord (= 6.0.3.2) + activestorage (= 6.0.3.2) + activesupport (= 6.0.3.2) + nokogiri (>= 1.8.5) + actionview (6.0.3.2) + activesupport (= 6.0.3.2) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.4.3) - activesupport (= 5.2.4.3) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.0.3.2) + activesupport (= 6.0.3.2) globalid (>= 0.3.6) - activemodel (5.2.4.3) - activesupport (= 5.2.4.3) - activerecord (5.2.4.3) - activemodel (= 5.2.4.3) - activesupport (= 5.2.4.3) - arel (>= 9.0) - activestorage (5.2.4.3) - actionpack (= 5.2.4.3) - activerecord (= 5.2.4.3) + activemodel (6.0.3.2) + activesupport (= 6.0.3.2) + activerecord (6.0.3.2) + activemodel (= 6.0.3.2) + activesupport (= 6.0.3.2) + activestorage (6.0.3.2) + actionpack (= 6.0.3.2) + activejob (= 6.0.3.2) + activerecord (= 6.0.3.2) marcel (~> 0.3.1) - activesupport (5.2.4.3) + activesupport (6.0.3.2) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) + zeitwerk (~> 2.2, >= 2.2.2) addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) anemone (0.7.2) @@ -50,7 +64,6 @@ GEM ansi (1.5.0) archive-zip (0.12.0) io-like (~> 0.3.0) - arel (9.0.0) asset_bom_removal-rails (1.0.2) rails (>= 4.2) sass (> 3.4) @@ -191,18 +204,20 @@ GEM rack-test (1.1.0) rack (>= 1.0, < 3) rack_strip_client_ip (0.0.2) - rails (5.2.4.3) - actioncable (= 5.2.4.3) - actionmailer (= 5.2.4.3) - actionpack (= 5.2.4.3) - actionview (= 5.2.4.3) - activejob (= 5.2.4.3) - activemodel (= 5.2.4.3) - activerecord (= 5.2.4.3) - activestorage (= 5.2.4.3) - activesupport (= 5.2.4.3) + rails (6.0.3.2) + actioncable (= 6.0.3.2) + actionmailbox (= 6.0.3.2) + actionmailer (= 6.0.3.2) + actionpack (= 6.0.3.2) + actiontext (= 6.0.3.2) + actionview (= 6.0.3.2) + activejob (= 6.0.3.2) + activemodel (= 6.0.3.2) + activerecord (= 6.0.3.2) + activestorage (= 6.0.3.2) + activesupport (= 6.0.3.2) bundler (>= 1.3.0) - railties (= 5.2.4.3) + railties (= 6.0.3.2) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) @@ -213,18 +228,18 @@ GEM nokogiri (>= 1.6) rails-html-sanitizer (1.3.0) loofah (~> 2.3) - rails-i18n (5.1.3) + rails-i18n (6.0.0) i18n (>= 0.7, < 2) - railties (>= 5.0, < 6) + railties (>= 6.0.0, < 7) rails_translation_manager (0.1.0) activesupport rails-i18n - railties (5.2.4.3) - actionpack (= 5.2.4.3) - activesupport (= 5.2.4.3) + railties (6.0.3.2) + actionpack (= 6.0.3.2) + activesupport (= 6.0.3.2) method_source rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) + thor (>= 0.20.3, < 2.0) rainbow (3.0.0) raindrops (0.19.1) rake (13.0.1) @@ -343,6 +358,7 @@ GEM thor xpath (3.2.0) nokogiri (~> 1.8) + zeitwerk (2.3.1) PLATFORMS ruby @@ -367,7 +383,7 @@ DEPENDENCIES plek pry rack_strip_client_ip - rails (~> 5.2.4) + rails (= 6.0.3.2) rails-controller-testing rails-i18n rails_translation_manager From 837c7e9faf1326cef0ff0fe703df4a8e6341586f Mon Sep 17 00:00:00 2001 From: Celia Collins Date: Fri, 3 Jul 2020 14:31:08 +0100 Subject: [PATCH 4/9] Run `bundle exec rails app:update` All the changes that come with Rails 6, mainly comments and minor config changes. --- bin/setup | 17 ++---- config/application.rb | 8 ++- config/environments/development.rb | 13 +--- config/environments/production.rb | 59 +++++++++++++------ config/environments/test.rb | 20 +++---- .../application_controller_renderer.rb | 10 ++-- config/initializers/assets.rb | 5 +- .../initializers/content_security_policy.rb | 1 + config/initializers/wrap_parameters.rb | 5 -- config/locales/en.yml | 12 +++- 10 files changed, 85 insertions(+), 65 deletions(-) create mode 100644 config/initializers/content_security_policy.rb diff --git a/bin/setup b/bin/setup index 6ce26b148..2e29ac1c3 100755 --- a/bin/setup +++ b/bin/setup @@ -1,31 +1,22 @@ #!/usr/bin/env ruby -require 'pathname' require 'fileutils' -include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = File.expand_path('..', __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") end -chdir APP_ROOT do - # This script is a starting point to setup your application. +FileUtils.chdir APP_ROOT do + # This script is a way to setup or update your development environment automatically. + # This script is idempotent, so that you can run it at anytime and get an expectable outcome. # Add necessary setup steps to this file. puts '== Installing dependencies ==' system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') - # puts "\n== Copying sample files ==" - # unless File.exist?('config/database.yml') - # cp 'config/database.yml.sample', 'config/database.yml' - # end - - # puts "\n== Preparing database ==" - # system! 'bin/rails db:setup' - puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' diff --git a/config/application.rb b/config/application.rb index 46493f12b..5aec70374 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,7 +1,9 @@ require_relative "boot" +require "rails" # Pick the frameworks you want: require "active_model/railtie" +# require "active_job/railtie" require "action_controller/railtie" require "action_view/railtie" require "sprockets/railtie" @@ -13,9 +15,13 @@ module GovernmentFrontend class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 6.0 + # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers - # -- all .rb files in that directory are automatically loaded. + # -- all .rb files in that directory are automatically loaded after loading + # the framework and any gems in your application. # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. diff --git a/config/environments/development.rb b/config/environments/development.rb index 919467e1a..1105960e0 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -15,10 +15,11 @@ # Enable/disable caching. By default caching is disabled. if Rails.root.join("tmp/caching-dev.txt").exist? config.action_controller.perform_caching = true + config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store config.public_file_server.headers = { - "Cache-Control" => "public, max-age=172800", + "Cache-Control" => "public, max-age=#{2.days.to_i}", } else config.action_controller.perform_caching = false @@ -26,17 +27,9 @@ config.cache_store = :null_store end - # Don't care if the mailer can't send. - # config.action_mailer.raise_delivery_errors = false - - # config.action_mailer.perform_caching = false - # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log - # Raise an error on page load if there are pending migrations. - # config.active_record.migration_error = :page_load - # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. @@ -45,7 +38,7 @@ # Suppress logger output for asset requests. config.assets.quiet = true - # Raises error for missing translations + # Raises error for missing translations. config.action_view.raise_on_missing_translations = true # Use an evented file watcher to asynchronously detect changes in source code, diff --git a/config/environments/production.rb b/config/environments/production.rb index efe3d385f..a6e3061b6 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -14,28 +14,27 @@ config.consider_all_requests_local = false config.action_controller.perform_caching = true + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? - # Compress JavaScripts and CSS. - config.assets.js_compressor = :uglifier + # Compress CSS using a preprocessor. # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false - # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX - # Mount Action Cable outside main process or domain - # config.action_cable.mount_path = nil - # config.action_cable.url = 'wss://example.com/cable' - # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] - # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true @@ -50,14 +49,9 @@ # config.cache_store = :mem_cache_store config.cache_store = :dalli_store, nil, { namespace: :government_frontend, compress: true } - # Use a real queuing backend for Active Job (and separate queues per environment) + # Use a real queuing backend for Active Job (and separate queues per environment). # config.active_job.queue_adapter = :resque - # config.active_job.queue_name_prefix = "government_frontend_#{Rails.env}" - # config.action_mailer.perform_caching = false - - # Ignore bad email addresses and do not raise email delivery errors. - # Set this to true and configure the email server for immediate delivery to raise delivery errors. - # config.action_mailer.raise_delivery_errors = false + # config.active_job.queue_name_prefix = "government_frontend_production" # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). @@ -66,6 +60,37 @@ # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify - # Do not dump schema after migrations. - # config.active_record.dump_schema_after_migration = false + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Inserts middleware to perform automatic connection switching. + # The `database_selector` hash is used to pass options to the DatabaseSelector + # middleware. The `delay` is used to determine how long to wait after a write + # to send a subsequent read to the primary. + # + # The `database_resolver` class is used by the middleware to determine which + # database is appropriate to use based on the time delay. + # + # The `database_resolver_context` class is used by the middleware to set + # timestamps for the last write to the primary. The resolver uses the context + # class timestamps to determine how long to wait before reading from the + # replica. + # + # By default Rails will store a last write timestamp in the session. The + # DatabaseSelector middleware is designed as such you can define your own + # strategy for connection switching and pass that into the middleware through + # these configuration options. + # config.active_record.database_selector = { delay: 2.seconds } + # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver + # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session end diff --git a/config/environments/test.rb b/config/environments/test.rb index 93d979cf9..7ae04a2d0 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,10 +1,11 @@ +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - # The test environment is used exclusively to run your application's - # test suite. You never need to work with it otherwise. Remember that - # your test database is "scratch space" for the test suite and is wiped - # and recreated between test runs. Don't rely on the data there! config.cache_classes = true # Do not eager load code on boot. This avoids loading your whole application @@ -15,29 +16,24 @@ # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - "Cache-Control" => "public, max-age=3600", + "Cache-Control" => "public, max-age=#{1.hour.to_i}", } # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false + config.cache_store = :null_store # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false - # config.action_mailer.perform_caching = false - - # Tell Action Mailer not to deliver emails to the real world. - # The :test delivery method accumulates sent emails in the - # ActionMailer::Base.deliveries array. - # config.action_mailer.delivery_method = :test # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - # Raises error for missing translations + # Raises error for missing translations. config.action_view.raise_on_missing_translations = true # TODO: Re-enable tests to run against compiled assets with digests diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb index 51639b67a..89d2efab2 100644 --- a/config/initializers/application_controller_renderer.rb +++ b/config/initializers/application_controller_renderer.rb @@ -1,6 +1,8 @@ # Be sure to restart your server when you modify this file. -# ApplicationController.renderer.defaults.merge!( -# http_host: 'example.org', -# https: false -# ) +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 0a3eaba10..d187a56e2 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -3,11 +3,12 @@ # Version of your assets, change this if you want to expire all your assets. Rails.application.config.assets.version = "1.0" -# Add additional assets to the asset load path +# Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path # Precompile additional assets. -# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# application.js, application.css, and all non-JS/CSS in app/assets +# folder are already added. Rails.application.config.assets.precompile += %w[ print.css webchat.js diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb new file mode 100644 index 000000000..aa49407c8 --- /dev/null +++ b/config/initializers/content_security_policy.rb @@ -0,0 +1 @@ +GovukContentSecurityPolicy.configure diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index bbfc3961b..633c1c889 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -7,8 +7,3 @@ ActiveSupport.on_load(:action_controller) do wrap_parameters format: [:json] end - -# To enable root element in JSON for ActiveRecord objects. -# ActiveSupport.on_load(:active_record) do -# self.include_root_in_json = true -# end diff --git a/config/locales/en.yml b/config/locales/en.yml index d3ee1ac7b..ba45b4c66 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -15,9 +15,19 @@ # I18n.locale = :es # # This would use the information in config/locales/es.yml. +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# 'true': 'foo' +# # # To learn more, please read the Rails Internationalization guide -# available at http://guides.rubyonrails.org/i18n.html. +# available at https://guides.rubyonrails.org/i18n.html. en: time: From 958e9582eee36d1aaea8bdfc72e58b043ba0a219 Mon Sep 17 00:00:00 2001 From: Celia Collins Date: Fri, 3 Jul 2020 14:44:50 +0100 Subject: [PATCH 5/9] Fix custom alias for local docker development Custom alias domains such as http://government-frontend.dev.gov.uk are not working on any apps running Rails 6, due to the addition of "Host Authorisation" middleware so we need to explicitly add the local domain to their `config.hosts`. Similar PR: alphagov/info-frontend#644 Issue on govuk-docker: alphagov/support#687 --- config/environments/development.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/environments/development.rb b/config/environments/development.rb index 1105960e0..d96dc88e9 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -44,4 +44,9 @@ # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. # config.file_watcher = ActiveSupport::EventedFileUpdateChecker + + config.hosts += [ + "draft-government-frontend.dev.gov.uk", + "government-frontend.dev.gov.uk", + ] end From 1f26cafda52aa2fa45d84710a1bf84a1c91b0158 Mon Sep 17 00:00:00 2001 From: Celia Collins Date: Fri, 24 Jul 2020 16:19:34 +0100 Subject: [PATCH 6/9] Remove jasmine-rails gem According to searls/jasmine-rails#238 the jasmine-rails gem is no longer actively maintained and is reliant on the phantomjs headless browser which has suspended development (ariya/phantomjs#15344). Therefore it makes more sense to switch to the jasmine gem and use the jasmine_selenium_runner gem to switch to headless Chrome for testing. --- Gemfile | 4 +- Gemfile.lock | 19 +- config/initializers/jasmine_rails.rb | 13 -- config/routes.rb | 1 - lib/tasks/jasmine.rake | 1 - spec/javascripts/support/jasmine.yml | 185 +++++++++++++----- spec/javascripts/support/jasmine_helper.rb | 14 ++ .../jasmine-jquery-2.0.5.js | 0 .../{helpers => vendor}/jquery-1.12.4.js | 0 spec/javascripts/{helpers => vendor}/lolex.js | 0 test/test_helper.rb | 2 + 11 files changed, 169 insertions(+), 70 deletions(-) delete mode 100644 config/initializers/jasmine_rails.rb delete mode 100644 lib/tasks/jasmine.rake create mode 100644 spec/javascripts/support/jasmine_helper.rb rename spec/javascripts/{helpers => vendor}/jasmine-jquery-2.0.5.js (100%) rename spec/javascripts/{helpers => vendor}/jquery-1.12.4.js (100%) rename spec/javascripts/{helpers => vendor}/lolex.js (100%) diff --git a/Gemfile b/Gemfile index e28168daa..d17d36f38 100644 --- a/Gemfile +++ b/Gemfile @@ -22,7 +22,8 @@ gem "uglifier" group :development, :test do gem "govuk_schemas" - gem "jasmine-rails" + gem "jasmine" + gem "jasmine_selenium_runner", require: false gem "rubocop-govuk" gem "scss_lint-govuk", require: false end @@ -40,5 +41,6 @@ group :test do gem "govuk_test" gem "minitest-reporters" gem "mocha" + gem "webdrivers" gem "webmock", require: false end diff --git a/Gemfile.lock b/Gemfile.lock index 6ede3c553..03a94df72 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -142,12 +142,15 @@ GEM concurrent-ruby (~> 1.0) image_size (2.0.2) io-like (0.3.0) - jasmine-core (3.5.0) - jasmine-rails (0.15.0) - jasmine-core (>= 1.3, < 4.0) - phantomjs (>= 1.9) - railties (>= 3.2.0) - sprockets-rails + jasmine (3.6.0) + jasmine-core (~> 3.6.0) + phantomjs + rack (>= 1.2.1) + rake + jasmine-core (3.6.0) + jasmine_selenium_runner (3.0.0) + jasmine (~> 3.0) + selenium-webdriver (~> 3.8) json (2.3.0) json-schema (2.8.1) addressable (>= 2.4) @@ -377,7 +380,8 @@ DEPENDENCIES govuk_schemas govuk_test htmlentities - jasmine-rails + jasmine + jasmine_selenium_runner minitest-reporters mocha plek @@ -392,6 +396,7 @@ DEPENDENCIES scss_lint-govuk slimmer uglifier + webdrivers webmock wraith diff --git a/config/initializers/jasmine_rails.rb b/config/initializers/jasmine_rails.rb deleted file mode 100644 index 2859ff5ce..000000000 --- a/config/initializers/jasmine_rails.rb +++ /dev/null @@ -1,13 +0,0 @@ -module JasmineRailsSkipSlimmer - extend ActiveSupport::Concern - - included do - before_action :skip_slimmer - end - - def skip_slimmer - response.headers[Slimmer::Headers::SKIP_HEADER] = "true" - end -end - -JasmineRails::ApplicationController.include(JasmineRailsSkipSlimmer) if defined?(JasmineRails) diff --git a/config/routes.rb b/config/routes.rb index 7abda8934..d6747e131 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,6 @@ Rails.application.routes.draw do unless Rails.env.production? # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html - mount JasmineRails::Engine => "/specs" if defined?(JasmineRails) get "random/:schema" => "randomly_generated_content_item#show" end diff --git a/lib/tasks/jasmine.rake b/lib/tasks/jasmine.rake deleted file mode 100644 index c9ae8b9f2..000000000 --- a/lib/tasks/jasmine.rake +++ /dev/null @@ -1 +0,0 @@ -Rake::Task[:default].enhance ["spec:javascript"] diff --git a/spec/javascripts/support/jasmine.yml b/spec/javascripts/support/jasmine.yml index 830ed8707..8d63e7fd2 100644 --- a/spec/javascripts/support/jasmine.yml +++ b/spec/javascripts/support/jasmine.yml @@ -1,57 +1,148 @@ -# path to parent directory of src_files -# relative path from Rails.root -# defaults to app/assets/javascripts -src_dir: "app/assets/javascripts" - -# path to additional directory of source file that are not part of assets pipeline and need to be included -# relative path from Rails.root -# defaults to [] -# include_dir: -# - ../mobile_app/public/js - -# path to parent directory of css_files -# relative path from Rails.root -# defaults to app/assets/stylesheets -css_dir: "app/assets/stylesheets" - -# list of file expressions to include as source files -# relative path from src_dir +# src_files +# +# Return an array of filepaths relative to src_dir to include before jasmine specs. +# Default: [] +# +# EXAMPLE: +# +# src_files: +# - lib/source1.js +# - lib/source2.js +# - 'dist/**/*.js' +# src_files: - - "../../../spec/javascripts/helpers/jquery-1.12.4.js" - - "../../../spec/javascripts/helpers/jasmine-jquery-2.0.5.js" - - "../../../spec/javascripts/helpers/lolex.js" - - "application.js" - - "webchat.js" + - "spec/javascripts/vendor/jquery-1.12.4.js" + - "spec/javascripts/vendor/jasmine-jquery-2.0.5.js" + - "spec/javascripts/vendor/lolex.js" + - "assets/application.js" + - "assets/webchat.js" -# list of file expressions to include as css files -# relative path from css_dir -css_files: - -# path to parent directory of spec_files -# relative path from Rails.root +# stylesheets +# +# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs. +# Default: [] +# +# EXAMPLE: # -# Alternatively accept an array of directory to include external spec files -# spec_dir: -# - spec/javascripts -# - ../engine/spec/javascripts +# stylesheets: +# - css/style.css +# - 'stylesheets/*.css' # -# defaults to spec/javascripts -spec_dir: spec/javascripts +stylesheets: + - "assets/application.css" -# list of file expressions to include as helpers into spec runner -# relative path from spec_dir +# helpers +# +# Return an array of filepaths relative to spec_dir to include before jasmine specs. +# Default: ["helpers/**/*.js"] +# +# EXAMPLE: +# +# helpers: +# - 'helpers/**/*.js' +# helpers: - - "helpers/**/*.{js.coffee,js,coffee}" + - "helpers/**/*.js" -# list of file expressions to include as specs into spec runner -# relative path from spec_dir +# spec_files +# +# Return an array of filepaths relative to spec_dir to include. +# Default: ["**/*[sS]pec.js"] +# +# EXAMPLE: +# +# spec_files: +# - '**/*[sS]pec.js' +# spec_files: - - "**/*[Ss]pec.{js.coffee,js,coffee}" + - "**/*[sS]pec.js" + +# src_dir +# +# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank. +# Default: project root +# +# EXAMPLE: +# +# src_dir: public +# +src_dir: + +# spec_dir +# +# Spec directory path. Your spec_files must be returned relative to this path. +# Default: spec/javascripts +# +# EXAMPLE: +# +# spec_dir: spec/javascripts +# +spec_dir: "spec/javascripts" + +# spec_helper +# +# Ruby file that Jasmine server will require before starting. +# Returned relative to your root path +# Default spec/javascripts/support/jasmine_helper.rb +# +# EXAMPLE: +# +# spec_helper: spec/javascripts/support/jasmine_helper.rb +# +spec_helper: "spec/javascripts/support/jasmine_helper.rb" + +# boot_dir +# +# Boot directory path. Your boot_files must be returned relative to this path. +# Default: Built in boot file +# +# EXAMPLE: +# +# boot_dir: spec/javascripts/support/boot +# +boot_dir: + +# boot_files +# +# Return an array of filepaths relative to boot_dir to include in order to boot Jasmine +# Default: Built in boot file +# +# EXAMPLE +# +# boot_files: +# - '**/*.js' +# +boot_files: -# path to directory of temporary files -# (spec runner and asset cache) -# defaults to tmp/jasmine -tmp_dir: "tmp/jasmine" +# rack_options +# +# Extra options to be passed to the rack server +# by default, Port and AccessLog are passed. +# +# This is an advanced options, and left empty by default +# +# EXAMPLE +# +# rack_options: +# server: 'thin' -# Stop jasmine from downloading phantom, use pre-installed version. -use_phantom_gem: false +# phantom_cli_options +# +# Extra options to be passed to the phantomjs cli, +# e.g. to enable localStorage in PhantomJs 2.5 +# +# EXAMPLE +# +# phantom_cli_options: +# local-storage-quota: 5000 + +# random +# +# Run specs in semi-random order. +# Default: true +# +# EXAMPLE: +# +# random: false +# +random: diff --git a/spec/javascripts/support/jasmine_helper.rb b/spec/javascripts/support/jasmine_helper.rb new file mode 100644 index 000000000..6892c6f60 --- /dev/null +++ b/spec/javascripts/support/jasmine_helper.rb @@ -0,0 +1,14 @@ +require "jasmine/runners/selenium" +require "webdrivers/chromedriver" + +Jasmine.configure do |config| + config.prevent_phantom_js_auto_install = true + + config.runner = lambda { |formatter, jasmine_server_url| + options = Selenium::WebDriver::Chrome::Options.new + options.headless! + + webdriver = Selenium::WebDriver.for(:chrome, options: options) + Jasmine::Runners::Selenium.new(formatter, jasmine_server_url, webdriver, 50) + } +end diff --git a/spec/javascripts/helpers/jasmine-jquery-2.0.5.js b/spec/javascripts/vendor/jasmine-jquery-2.0.5.js similarity index 100% rename from spec/javascripts/helpers/jasmine-jquery-2.0.5.js rename to spec/javascripts/vendor/jasmine-jquery-2.0.5.js diff --git a/spec/javascripts/helpers/jquery-1.12.4.js b/spec/javascripts/vendor/jquery-1.12.4.js similarity index 100% rename from spec/javascripts/helpers/jquery-1.12.4.js rename to spec/javascripts/vendor/jquery-1.12.4.js diff --git a/spec/javascripts/helpers/lolex.js b/spec/javascripts/vendor/lolex.js similarity index 100% rename from spec/javascripts/helpers/lolex.js rename to spec/javascripts/vendor/lolex.js diff --git a/test/test_helper.rb b/test/test_helper.rb index 2219258e2..2f2bc6c1b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -22,6 +22,8 @@ config.acceptance_test_framework = :active_support end +WebMock.disable_net_connect!(allow_localhost: true) + class ActiveSupport::TestCase include GovukContentSchemaExamples end From 280afdb555ffef00d9caa20ac98cb185f120c831 Mon Sep 17 00:00:00 2001 From: Celia Collins Date: Fri, 24 Jul 2020 17:18:28 +0100 Subject: [PATCH 7/9] Run bundle update --- Gemfile.lock | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 03a94df72..8fe265d17 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -74,7 +74,7 @@ GEM rack (>= 0.9.0) binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) - brakeman (4.7.1) + brakeman (4.8.2) builder (3.2.4) capybara (3.33.0) addressable @@ -88,8 +88,8 @@ GEM chromedriver-helper (1.2.0) archive-zip (~> 0.10) nokogiri (~> 1.8) - coderay (1.1.2) - concurrent-ruby (1.1.7) + coderay (1.1.3) + concurrent-ruby (1.1.6) crack (0.4.3) safe_yaml (~> 1.0.0) crass (1.0.6) @@ -103,7 +103,7 @@ GEM i18n (>= 1.6, < 2) faraday (1.0.1) multipart-post (>= 1.2, < 3) - ffi (1.12.2) + ffi (1.13.1) gds-api-adapters (67.0.1) addressable link_header @@ -141,7 +141,7 @@ GEM i18n (1.8.5) concurrent-ruby (~> 1.0) image_size (2.0.2) - io-like (0.3.0) + io-like (0.3.1) jasmine (3.6.0) jasmine-core (~> 3.6.0) phantomjs @@ -151,7 +151,7 @@ GEM jasmine_selenium_runner (3.0.0) jasmine (~> 3.0) selenium-webdriver (~> 3.8) - json (2.3.0) + json (2.3.1) json-schema (2.8.1) addressable (>= 2.4) kgio (2.11.3) @@ -176,7 +176,7 @@ GEM mime-types-data (~> 3.2015) mime-types-data (3.2020.0512) mimemagic (0.3.5) - mini_magick (4.9.5) + mini_magick (4.10.1) mini_mime (1.0.2) mini_portile2 (2.4.0) minitest (5.14.1) @@ -285,24 +285,28 @@ GEM rubocop-rspec (1.42.0) rubocop (>= 0.87.0) ruby-progressbar (1.10.1) - rubyzip (2.0.0) + rubyzip (2.3.0) safe_yaml (1.0.5) sass (3.7.4) sass-listen (~> 4.0.0) sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - sass-rails (5.1.0) - railties (>= 5.2.0) - sass (~> 3.1) - sprockets (>= 2.8, < 4.0) - sprockets-rails (>= 2.0, < 4.0) - tilt (>= 1.1, < 3) + sass-rails (6.0.0) + sassc-rails (~> 2.1, >= 2.1.1) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt scss_lint (0.59.0) sass (~> 3.5, >= 3.5.5) scss_lint-govuk (0.2.0) scss_lint - selenium-webdriver (3.142.6) + selenium-webdriver (3.142.7) childprocess (>= 0.5, < 4.0) rubyzip (>= 1.2.2) sentry-raven (3.0.0) @@ -337,7 +341,7 @@ GEM unicorn (5.5.5) kgio (~> 2.6) raindrops (~> 0.7) - webdrivers (4.1.3) + webdrivers (4.4.1) nokogiri (~> 1.6) rubyzip (>= 1.3.0) selenium-webdriver (>= 3.0, < 4.0) @@ -361,7 +365,7 @@ GEM thor xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.3.1) + zeitwerk (2.4.0) PLATFORMS ruby From ce19f543c679323455d3d4a731642c5bd8790ee1 Mon Sep 17 00:00:00 2001 From: Celia Collins Date: Fri, 24 Jul 2020 17:18:38 +0100 Subject: [PATCH 8/9] Fix asset pipeline with libsass Using a sass css compressor causes a scss file to be processed twice (once to build, once to compress) which breaks the usage of "unquote" to use CSS that has same function names as SCSS such as max. --- config/application.rb | 6 ++++++ config/environments/production.rb | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/config/application.rb b/config/application.rb index 5aec70374..ac74f1238 100644 --- a/config/application.rb +++ b/config/application.rb @@ -109,6 +109,12 @@ class Application < Rails::Application # Path within public/ where assets are compiled to config.assets.prefix = "/assets/government-frontend" + # Using a sass css compressor causes a scss file to be processed twice + # (once to build, once to compress) which breaks the usage of "unquote" + # to use CSS that has same function names as SCSS such as max. + # https://github.com/alphagov/govuk-frontend/issues/1350 + config.assets.css_compressor = nil + # allow overriding the asset host with an enironment variable, useful for # when router is proxying to this app but asset proxying isn't set up. config.asset_host = ENV["ASSET_HOST"] diff --git a/config/environments/production.rb b/config/environments/production.rb index a6e3061b6..dc3bab9a2 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -28,6 +28,10 @@ # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false + # Rather than use a CSS compressor, use the SASS style to perform compression. + config.sass.style = :compressed + config.sass.line_comments = false + # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' From 2a1df0b1b8544b5ff47d1d0a482b4982fd8c1a3c Mon Sep 17 00:00:00 2001 From: Celia Collins Date: Mon, 27 Jul 2020 13:45:55 +0100 Subject: [PATCH 9/9] Remove gem "asset_bom_removal-rails" To work around the issue with sassc and unquote the accepted solution has been to set css_compressor to nil and then use sass_style to achieve a similar effect. However the gem forces the css_compressor back to :sass thus breaking again on asset compilation. Removing the gem fixes this and the gem itself does not seem to be necessary since it was introduced to fix issues in Firefox 52 and the latest Firefox version is 78 --- Gemfile | 1 - Gemfile.lock | 4 ---- 2 files changed, 5 deletions(-) diff --git a/Gemfile b/Gemfile index d17d36f38..3756c7764 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,6 @@ ruby File.read(".ruby-version").strip gem "rails", "6.0.3.2" -gem "asset_bom_removal-rails" gem "dalli" gem "gds-api-adapters" gem "govuk_ab_testing" diff --git a/Gemfile.lock b/Gemfile.lock index 8fe265d17..1768d6d9f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -64,9 +64,6 @@ GEM ansi (1.5.0) archive-zip (0.12.0) io-like (~> 0.3.0) - asset_bom_removal-rails (1.0.2) - rails (>= 4.2) - sass (> 3.4) ast (2.4.1) better_errors (2.7.1) coderay (>= 1.0.0) @@ -371,7 +368,6 @@ PLATFORMS ruby DEPENDENCIES - asset_bom_removal-rails better_errors binding_of_caller capybara