From 02743365eb80cea10aa133a5f8bcc1a4c45977e6 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 30 Mar 2021 16:32:15 +0200 Subject: [PATCH 1/8] specs: make `build` and `create` consistent in `downloadable_file_spec` --- spec/lib/active_storage/downloadable_file_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/active_storage/downloadable_file_spec.rb b/spec/lib/active_storage/downloadable_file_spec.rb index 6fc938311..200c519f7 100644 --- a/spec/lib/active_storage/downloadable_file_spec.rb +++ b/spec/lib/active_storage/downloadable_file_spec.rb @@ -27,7 +27,7 @@ describe ActiveStorage::DownloadableFile do context 'when there is a repetition bloc' do before do - dossier.champs << build(:champ_repetition_with_piece_jointe, dossier: dossier) + dossier.champs << create(:champ_repetition_with_piece_jointe, dossier: dossier) end it 'should have 4 piece_justificatives' do From 9096a3885c40be467233772bff6ab94f27e17721 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 30 Mar 2021 16:58:49 +0200 Subject: [PATCH 2/8] specs: fix creating dossiers :en_construction --- spec/services/dossier_search_service_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/services/dossier_search_service_spec.rb b/spec/services/dossier_search_service_spec.rb index 52f855c27..c004f1d5a 100644 --- a/spec/services/dossier_search_service_spec.rb +++ b/spec/services/dossier_search_service_spec.rb @@ -23,15 +23,15 @@ describe DossierSearchService do let!(:dossier_0) { create(:dossier, state: Dossier.states.fetch(:brouillon), procedure: procedure_1, user: create(:user, email: 'brouillon@clap.fr')) } let!(:etablissement_1) { create(:etablissement, entreprise_raison_sociale: 'OCTO Academy', siret: '41636169600051') } - let!(:dossier_1) { create(:dossier, state: Dossier.states.fetch(:en_construction), procedure: procedure_1, user: create(:user, email: 'contact@test.com'), etablissement: etablissement_1) } + let!(:dossier_1) { create(:dossier, :en_construction, procedure: procedure_1, user: create(:user, email: 'contact@test.com'), etablissement: etablissement_1) } let!(:etablissement_2) { create(:etablissement, entreprise_raison_sociale: 'Plop octo', siret: '41816602300012') } - let!(:dossier_2) { create(:dossier, state: Dossier.states.fetch(:en_construction), procedure: procedure_1, user: create(:user, email: 'plop@gmail.com'), etablissement: etablissement_2) } + let!(:dossier_2) { create(:dossier, :en_construction, procedure: procedure_1, user: create(:user, email: 'plop@gmail.com'), etablissement: etablissement_2) } let!(:etablissement_3) { create(:etablissement, entreprise_raison_sociale: 'OCTO Technology', siret: '41816609600051') } - let!(:dossier_3) { create(:dossier, state: Dossier.states.fetch(:en_construction), procedure: procedure_2, user: create(:user, email: 'peace@clap.fr'), etablissement: etablissement_3) } + let!(:dossier_3) { create(:dossier, :en_construction, procedure: procedure_2, user: create(:user, email: 'peace@clap.fr'), etablissement: etablissement_3) } - let!(:dossier_archived) { create(:dossier, state: Dossier.states.fetch(:en_construction), procedure: procedure_1, archived: true, user: create(:user, email: 'archived@clap.fr')) } + let!(:dossier_archived) { create(:dossier, :en_construction, procedure: procedure_1, archived: true, user: create(:user, email: 'archived@clap.fr')) } describe 'search is empty' do let(:terms) { '' } From 95b6fdf86d8a531c1555651b33078d188042be05 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 30 Mar 2021 19:44:57 +0200 Subject: [PATCH 3/8] controllers: unload failed avis from dossier This avoid the subsequent dossier update to fail because some Avis may be invalid. --- app/controllers/concerns/create_avis_concern.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/concerns/create_avis_concern.rb b/app/controllers/concerns/create_avis_concern.rb index 9854ec405..ea3e9eb3c 100644 --- a/app/controllers/concerns/create_avis_concern.rb +++ b/app/controllers/concerns/create_avis_concern.rb @@ -34,6 +34,7 @@ module CreateAvisConcern end end ) + dossier.avis.reload # unload non-persisted avis from dossier persisted, failed = create_results.partition(&:persisted?) From b65de3e5835227690b429ce4372ba4185cde9e50 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 30 Mar 2021 12:26:44 +0200 Subject: [PATCH 4/8] config: make the queue names explicit With Rails 6.1, the default queue is now the global application queue. We want to retain our custom queues in some cases, so configure them epxlicitely. --- config/application.rb | 6 ++++++ config/initializers/new_framework_defaults_6_1.rb | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/config/application.rb b/config/application.rb index 20e021ce7..319f3be02 100644 --- a/config/application.rb +++ b/config/application.rb @@ -65,6 +65,12 @@ module TPS # disable the check performed by Rails. config.action_dispatch.ip_spoofing_check = false + # Set the queue name for the mail delivery jobs to 'mailers' + config.action_mailer.deliver_later_queue_name = :mailers + + # Set the queue name for the analysis jobs to 'active_storage_analysis' + config.active_storage.queues.analysis = :active_storage_analysis + config.to_prepare do # Make main application helpers available in administrate Administrate::ApplicationController.helper(TPS::Application.helpers) diff --git a/config/initializers/new_framework_defaults_6_1.rb b/config/initializers/new_framework_defaults_6_1.rb index 9526b835a..d4d85e7a6 100644 --- a/config/initializers/new_framework_defaults_6_1.rb +++ b/config/initializers/new_framework_defaults_6_1.rb @@ -48,19 +48,19 @@ # Rails.application.config.action_view.form_with_generates_remote_forms = false # Set the default queue name for the analysis job to the queue adapter default. -# Rails.application.config.active_storage.queues.analysis = nil +Rails.application.config.active_storage.queues.analysis = nil # Set the default queue name for the purge job to the queue adapter default. -# Rails.application.config.active_storage.queues.purge = nil +Rails.application.config.active_storage.queues.purge = nil # Set the default queue name for the incineration job to the queue adapter default. -# Rails.application.config.action_mailbox.queues.incineration = nil +Rails.application.config.action_mailbox.queues.incineration = nil # Set the default queue name for the routing job to the queue adapter default. -# Rails.application.config.action_mailbox.queues.routing = nil +Rails.application.config.action_mailbox.queues.routing = nil # Set the default queue name for the mail deliver job to the queue adapter default. -# Rails.application.config.action_mailer.deliver_later_queue_name = nil +Rails.application.config.action_mailer.deliver_later_queue_name = nil # Generate a `Link` header that gives a hint to modern browsers about # preloading assets when using `javascript_include_tag` and `stylesheet_link_tag`. From c2ce20d40c3368000942d34d300c4294b365a311 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 30 Mar 2021 12:38:10 +0200 Subject: [PATCH 5/8] config: form_with now generates local forms by default We can remove the `local: true` parameter, as it is now implied by default. --- app/views/admin/instructeurs/index.html.haml | 2 +- app/views/new_administrateur/procedures/jeton.html.haml | 2 +- config/initializers/new_framework_defaults_6_1.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/admin/instructeurs/index.html.haml b/app/views/admin/instructeurs/index.html.haml index 8de1e612b..abb6ddbc1 100644 --- a/app/views/admin/instructeurs/index.html.haml +++ b/app/views/admin/instructeurs/index.html.haml @@ -18,7 +18,7 @@ .col-xs-6 %h3 Ajouter un instructeur #procedure_new.section.section-label - = form_with url: { controller: 'admin/instructeurs', action: :create }, local: true do + = form_with url: { controller: 'admin/instructeurs', action: :create } do .row .col-xs-5 = render partial: 'admin/instructeurs/informations' diff --git a/app/views/new_administrateur/procedures/jeton.html.haml b/app/views/new_administrateur/procedures/jeton.html.haml index 2e4341d38..503f601e6 100644 --- a/app/views/new_administrateur/procedures/jeton.html.haml +++ b/app/views/new_administrateur/procedures/jeton.html.haml @@ -9,7 +9,7 @@ .container %h1 - = form_with model: @procedure, url: url_for({ controller: 'new_administrateur/procedures', action: :update_jeton }), local: true, html: { class: 'form' } do |f| + = form_with model: @procedure, url: url_for({ controller: 'new_administrateur/procedures', action: :update_jeton }), html: { class: 'form' } do |f| %p.explication Démarches Simplifiées utilise = link_to 'API Entreprise', "https://entreprise.api.gouv.fr/" diff --git a/config/initializers/new_framework_defaults_6_1.rb b/config/initializers/new_framework_defaults_6_1.rb index d4d85e7a6..d4c94ef73 100644 --- a/config/initializers/new_framework_defaults_6_1.rb +++ b/config/initializers/new_framework_defaults_6_1.rb @@ -45,7 +45,7 @@ # Rails.application.config.active_record.legacy_connection_handling = false # Make `form_with` generate non-remote forms by default. -# Rails.application.config.action_view.form_with_generates_remote_forms = false +Rails.application.config.action_view.form_with_generates_remote_forms = false # Set the default queue name for the analysis job to the queue adapter default. Rails.application.config.active_storage.queues.analysis = nil From 6bc608a821e941db3c45096396478c49831ada1c Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 30 Mar 2021 11:09:11 +0000 Subject: [PATCH 6/8] config: enable most Rails 6.1 defaults --- .../new_framework_defaults_6_1.rb | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/config/initializers/new_framework_defaults_6_1.rb b/config/initializers/new_framework_defaults_6_1.rb index d4c94ef73..48ba442ac 100644 --- a/config/initializers/new_framework_defaults_6_1.rb +++ b/config/initializers/new_framework_defaults_6_1.rb @@ -7,42 +7,42 @@ # Read the Guide for Upgrading Ruby on Rails for more info on each option. # Support for inversing belongs_to -> has_many Active Record associations. -# Rails.application.config.active_record.has_many_inversing = true +ActiveRecord::Base.has_many_inversing = false # Track Active Storage variants in the database. -# Rails.application.config.active_storage.track_variants = true +Rails.application.config.active_storage.track_variants = true # Apply random variation to the delay when retrying failed jobs. -# Rails.application.config.active_job.retry_jitter = 0.15 +Rails.application.config.active_job.retry_jitter = 0.15 # Stop executing `after_enqueue`/`after_perform` callbacks if # `before_enqueue`/`before_perform` respectively halts with `throw :abort`. -# Rails.application.config.active_job.skip_after_callbacks_if_terminated = true +Rails.application.config.active_job.skip_after_callbacks_if_terminated = true # Specify cookies SameSite protection level: either :none, :lax, or :strict. # # This change is not backwards compatible with earlier Rails versions. # It's best enabled when your entire app is migrated and stable on 6.1. -# Rails.application.config.action_dispatch.cookies_same_site_protection = :lax +Rails.application.config.action_dispatch.cookies_same_site_protection = :lax # Generate CSRF tokens that are encoded in URL-safe Base64. # # This change is not backwards compatible with earlier Rails versions. # It's best enabled when your entire app is migrated and stable on 6.1. -# Rails.application.config.action_controller.urlsafe_csrf_tokens = true +Rails.application.config.action_controller.urlsafe_csrf_tokens = true # Specify whether `ActiveSupport::TimeZone.utc_to_local` returns a time with an # UTC offset or a UTC time. -# ActiveSupport.utc_to_local_returns_utc_offset_times = true +ActiveSupport.utc_to_local_returns_utc_offset_times = true # Change the default HTTP status code to `308` when redirecting non-GET/HEAD # requests to HTTPS in `ActionDispatch::SSL` middleware. -# Rails.application.config.action_dispatch.ssl_default_redirect_status = 308 +Rails.application.config.action_dispatch.ssl_default_redirect_status = 308 # Use new connection handling API. For most applications this won't have any # effect. For applications using multiple databases, this new API provides # support for granular connection swapping. -# Rails.application.config.active_record.legacy_connection_handling = false +Rails.application.config.active_record.legacy_connection_handling = false # Make `form_with` generate non-remote forms by default. Rails.application.config.action_view.form_with_generates_remote_forms = false @@ -64,4 +64,4 @@ Rails.application.config.action_mailer.deliver_later_queue_name = nil # Generate a `Link` header that gives a hint to modern browsers about # preloading assets when using `javascript_include_tag` and `stylesheet_link_tag`. -# Rails.application.config.action_view.preload_links_header = true +Rails.application.config.action_view.preload_links_header = true From ce427784e7b4849809fd82c1cb940a5d6ca0d7d6 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 30 Mar 2021 16:34:17 +0200 Subject: [PATCH 7/8] config: enable has_many_inversing --- config/initializers/new_framework_defaults_6_1.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/new_framework_defaults_6_1.rb b/config/initializers/new_framework_defaults_6_1.rb index 48ba442ac..61f91c90f 100644 --- a/config/initializers/new_framework_defaults_6_1.rb +++ b/config/initializers/new_framework_defaults_6_1.rb @@ -7,7 +7,7 @@ # Read the Guide for Upgrading Ruby on Rails for more info on each option. # Support for inversing belongs_to -> has_many Active Record associations. -ActiveRecord::Base.has_many_inversing = false +ActiveRecord::Base.has_many_inversing = true # Track Active Storage variants in the database. Rails.application.config.active_storage.track_variants = true From 42b3ba1e1bec215c4c48742b8afb2529315da6ba Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 30 Mar 2021 16:42:25 +0200 Subject: [PATCH 8/8] config: migrate all config to Rails 6.1 defaults --- config/application.rb | 2 +- .../new_framework_defaults_6_1.rb | 67 ------------------- 2 files changed, 1 insertion(+), 68 deletions(-) delete mode 100644 config/initializers/new_framework_defaults_6_1.rb diff --git a/config/application.rb b/config/application.rb index 319f3be02..4598e3212 100644 --- a/config/application.rb +++ b/config/application.rb @@ -11,7 +11,7 @@ Dotenv::Railtie.load module TPS class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 6.0 + config.load_defaults 6.1 # Configuration for the application, engines, and railties goes here. # diff --git a/config/initializers/new_framework_defaults_6_1.rb b/config/initializers/new_framework_defaults_6_1.rb deleted file mode 100644 index 61f91c90f..000000000 --- a/config/initializers/new_framework_defaults_6_1.rb +++ /dev/null @@ -1,67 +0,0 @@ -# Be sure to restart your server when you modify this file. -# -# This file contains migration options to ease your Rails 6.1 upgrade. -# -# Once upgraded flip defaults one by one to migrate to the new default. -# -# Read the Guide for Upgrading Ruby on Rails for more info on each option. - -# Support for inversing belongs_to -> has_many Active Record associations. -ActiveRecord::Base.has_many_inversing = true - -# Track Active Storage variants in the database. -Rails.application.config.active_storage.track_variants = true - -# Apply random variation to the delay when retrying failed jobs. -Rails.application.config.active_job.retry_jitter = 0.15 - -# Stop executing `after_enqueue`/`after_perform` callbacks if -# `before_enqueue`/`before_perform` respectively halts with `throw :abort`. -Rails.application.config.active_job.skip_after_callbacks_if_terminated = true - -# Specify cookies SameSite protection level: either :none, :lax, or :strict. -# -# This change is not backwards compatible with earlier Rails versions. -# It's best enabled when your entire app is migrated and stable on 6.1. -Rails.application.config.action_dispatch.cookies_same_site_protection = :lax - -# Generate CSRF tokens that are encoded in URL-safe Base64. -# -# This change is not backwards compatible with earlier Rails versions. -# It's best enabled when your entire app is migrated and stable on 6.1. -Rails.application.config.action_controller.urlsafe_csrf_tokens = true - -# Specify whether `ActiveSupport::TimeZone.utc_to_local` returns a time with an -# UTC offset or a UTC time. -ActiveSupport.utc_to_local_returns_utc_offset_times = true - -# Change the default HTTP status code to `308` when redirecting non-GET/HEAD -# requests to HTTPS in `ActionDispatch::SSL` middleware. -Rails.application.config.action_dispatch.ssl_default_redirect_status = 308 - -# Use new connection handling API. For most applications this won't have any -# effect. For applications using multiple databases, this new API provides -# support for granular connection swapping. -Rails.application.config.active_record.legacy_connection_handling = false - -# Make `form_with` generate non-remote forms by default. -Rails.application.config.action_view.form_with_generates_remote_forms = false - -# Set the default queue name for the analysis job to the queue adapter default. -Rails.application.config.active_storage.queues.analysis = nil - -# Set the default queue name for the purge job to the queue adapter default. -Rails.application.config.active_storage.queues.purge = nil - -# Set the default queue name for the incineration job to the queue adapter default. -Rails.application.config.action_mailbox.queues.incineration = nil - -# Set the default queue name for the routing job to the queue adapter default. -Rails.application.config.action_mailbox.queues.routing = nil - -# Set the default queue name for the mail deliver job to the queue adapter default. -Rails.application.config.action_mailer.deliver_later_queue_name = nil - -# Generate a `Link` header that gives a hint to modern browsers about -# preloading assets when using `javascript_include_tag` and `stylesheet_link_tag`. -Rails.application.config.action_view.preload_links_header = true