- <% flash.each do |type, msg| %> + <% flash.each do |type, msg| %> <% if type == 'notice' %> <%= render "govuk_publishing_components/components/success_alert", { message: msg @@ -25,7 +25,7 @@ <%= render "govuk_publishing_components/components/error_alert", { message: msg } %> - <% end %> + <% end %> <% end -%> <%= yield %> diff --git a/app/workers/notify_expiring_bets_worker.rb b/app/workers/notify_expiring_bets_worker.rb index 9f6242a1..deb624e5 100644 --- a/app/workers/notify_expiring_bets_worker.rb +++ b/app/workers/notify_expiring_bets_worker.rb @@ -29,6 +29,6 @@ def addresses end def soon_to_expire_bets - @soon_to_expire_bets ||= Bet.impermanent.where(expiration_date: DateTime.now.beginning_of_day + THRESHOLD) + @soon_to_expire_bets ||= Bet.impermanent.where(expiration_date: Time.zone.now.beginning_of_day + THRESHOLD) end end diff --git a/bin/bundle b/bin/bundle deleted file mode 100755 index 67efc37f..00000000 --- a/bin/bundle +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env ruby -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) -load Gem.bin_path("bundler", "bundle") diff --git a/config/application.rb b/config/application.rb index 66804920..1d73f5c5 100644 --- a/config/application.rb +++ b/config/application.rb @@ -16,7 +16,7 @@ module SearchAdmin class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 5.0 + config.load_defaults 6.0 # Settings in config/environments/* take precedence over those specified here. # Application configuration can go into files in config/initializers @@ -24,5 +24,11 @@ class Application < Rails::Application config.action_view.default_form_builder = GenericFormBuilder config.action_view.field_error_proc = proc { |html_tag, _| html_tag } + + # 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 end end diff --git a/config/environments/production.rb b/config/environments/production.rb index 212efc12..265279d1 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -29,6 +29,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 + # `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. diff --git a/config/initializers/csp.rb b/config/initializers/csp.rb new file mode 100644 index 00000000..aa49407c --- /dev/null +++ b/config/initializers/csp.rb @@ -0,0 +1 @@ +GovukContentSecurityPolicy.configure diff --git a/config/initializers/zeitwerk.rb b/config/initializers/zeitwerk.rb new file mode 100644 index 00000000..7ec6463a --- /dev/null +++ b/config/initializers/zeitwerk.rb @@ -0,0 +1,5 @@ +Rails.autoloaders.each do |autoloader| + autoloader.inflector.inflect( + "elastic_search_bet_id_generator" => "ElasticSearchBetIDGenerator", + ) +end diff --git a/lib/tasks/reindex_best_bets.rake b/lib/tasks/reindex_best_bets.rake index 647e19b4..62626067 100644 --- a/lib/tasks/reindex_best_bets.rake +++ b/lib/tasks/reindex_best_bets.rake @@ -12,12 +12,12 @@ task reindex_best_bets: :environment do puts message puts "Starting to reindex #{Query.count} best bets in search_api" - start = Time.now.to_f + start = Time.zone.now.to_f Query.all.each do |query| puts "Processing: #{query.query} (#{query.match_type})" - SearchApiSaver.new(query).save + SearchApiSaver.new(query).save! end - puts "Finished reindexing best bets in search_api (#{(Time.now.to_f - start).round(2)} sec)" + puts "Finished reindexing best bets in search_api (#{(Time.zone.now.to_f - start).round(2)} sec)" end diff --git a/lib/travel_advice_bets_importer.rb b/lib/travel_advice_bets_importer.rb index 40fbb47a..302a1af5 100644 --- a/lib/travel_advice_bets_importer.rb +++ b/lib/travel_advice_bets_importer.rb @@ -16,7 +16,7 @@ def import data.each do |term, link| next unless link =~ /^\/world\// - query = Query.find_or_create_by(query: term) { |q| q.match_type = "exact" } + query = Query.find_or_create_by!(query: term) { |q| q.match_type = "exact" } travel_advice_bet = create_bet(query, travel_advice_path(link), 1) if travel_advice_bet @@ -37,7 +37,7 @@ def import def create_bet(query, link, position) return if Bet.find_by(link: link, query: query) - Bet.create( + Bet.create!( comment: "Created by bets importer.", is_best: true, link: link, diff --git a/spec/models/best_bet_spec.rb b/spec/models/best_bet_spec.rb index 51b771b4..6850cdd3 100644 --- a/spec/models/best_bet_spec.rb +++ b/spec/models/best_bet_spec.rb @@ -25,14 +25,14 @@ it "can be created given valid attributes" do best_bet = Bet.new(@best_bet_attributes) - best_bet.save + best_bet.save! expect(best_bet).to be_valid expect(best_bet).to be_persisted end it "can be deactivated" do - best_bet = Bet.create(@best_bet_attributes) + best_bet = Bet.create!(@best_bet_attributes) expect(best_bet).to be_active best_bet.deactivate expect(best_bet.permanent).to be nil @@ -158,7 +158,7 @@ it "Making a temporary bet permanent deletes its expiration date" do bet_date_attrs = { permanent: false, expiration_date: date + 1.day } best_bet = Bet.new(@best_bet_attributes.merge(bet_date_attrs)) - best_bet.update(permanent: true) + best_bet.update!(permanent: true) expect(best_bet.expiration_date).to be_nil end end @@ -191,7 +191,7 @@ end it "it is valid with a nil expiration date" do - worst_bet = Bet.create(@worst_bet_attributes) + worst_bet = Bet.create!(@worst_bet_attributes) expect(worst_bet.expiration_date).to be nil expect(worst_bet).to be_valid end diff --git a/spec/models/query_spec.rb b/spec/models/query_spec.rb index 5d48ee22..093aa14b 100644 --- a/spec/models/query_spec.rb +++ b/spec/models/query_spec.rb @@ -34,7 +34,7 @@ query = create :query bets = query.bets - query.destroy + query.destroy! expect(bets).to eq [] end