diff --git a/Gemfile b/Gemfile index 14ff90162..3756c7764 100644 --- a/Gemfile +++ b/Gemfile @@ -2,35 +2,36 @@ source "https://rubygems.org" ruby File.read(".ruby-version").strip -gem "asset_bom_removal-rails", "~> 1.0" +gem "rails", "6.0.3.2" + 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 "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 "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-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 "jasmine-rails" - gem "rubocop-govuk", "~> 3" - gem "scss_lint-govuk", "~> 0.2" + gem "govuk_schemas" + gem "jasmine" + gem "jasmine_selenium_runner", require: false + gem "rubocop-govuk" + gem "scss_lint-govuk", require: false 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 +40,6 @@ group :test do gem "govuk_test" gem "minitest-reporters" gem "mocha" - gem "webmock", "~> 3.8.3", require: false + gem "webdrivers" + gem "webmock", require: false end diff --git a/Gemfile.lock b/Gemfile.lock index a87850266..1768d6d9f 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,10 +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) ast (2.4.1) better_errors (2.7.1) coderay (>= 1.0.0) @@ -61,7 +71,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 @@ -75,8 +85,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) @@ -90,7 +100,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 @@ -128,14 +138,17 @@ GEM i18n (1.8.5) 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 - json (2.3.0) + io-like (0.3.1) + 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.1) json-schema (2.8.1) addressable (>= 2.4) kgio (2.11.3) @@ -160,7 +173,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) @@ -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) @@ -267,24 +282,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) @@ -319,7 +338,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) @@ -343,41 +362,43 @@ GEM thor xpath (3.2.0) nokogiri (~> 1.8) + zeitwerk (2.4.0) PLATFORMS ruby DEPENDENCIES - asset_bom_removal-rails (~> 1.0) 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) - jasmine-rails + htmlentities + jasmine + jasmine_selenium_runner minitest-reporters mocha - plek (~> 4.0) + plek pry - rack_strip_client_ip (~> 0.0.2) - 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) + rack_strip_client_ip + rails (= 6.0.3.2) + rails-controller-testing + rails-i18n + rails_translation_manager + rubocop-govuk + sass-rails + scss_lint-govuk + slimmer + uglifier + webdrivers + webmock + wraith RUBY VERSION ruby 2.6.6 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] 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..ac74f1238 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. @@ -103,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/development.rb b/config/environments/development.rb index 919467e1a..d96dc88e9 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,10 +38,15 @@ # 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, # 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 diff --git a/config/environments/production.rb b/config/environments/production.rb index efe3d385f..dc3bab9a2 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -14,28 +14,31 @@ 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 + # 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' # 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 +53,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 +64,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/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/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: 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