From d9ea415d4484bf4954c41dc4cbba76f97b045409 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 23 Feb 2021 08:25:24 +0100 Subject: [PATCH 01/17] specs: fix rspec warning about raise_error specificity --- spec/controllers/instructeurs/dossiers_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/instructeurs/dossiers_controller_spec.rb b/spec/controllers/instructeurs/dossiers_controller_spec.rb index 650725dec..c477fb06c 100644 --- a/spec/controllers/instructeurs/dossiers_controller_spec.rb +++ b/spec/controllers/instructeurs/dossiers_controller_spec.rb @@ -772,7 +772,7 @@ describe Instructeurs::DossiersController, type: :controller do end it 'does not delete the dossier' do - expect { dossier.reload }.not_to raise_error ActiveRecord::RecordNotFound + expect { dossier.reload }.not_to raise_error # A deleted dossier would raise an ActiveRecord::RecordNotFound end it 'does not add a record into deleted_dossiers table' do From a2175ed6e3a9edba3b1badce8f062fbcb7eaea4b Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 17 Feb 2021 18:01:36 +0100 Subject: [PATCH 02/17] config: reload compatibility aliases on classes reload Fixes zeitwerk complaining that the compatibility aliases loaded in an initializer will never be reloaded. In our case it doesn't matter that much, but it will reduce the console spam. --- .../initializers/active_job_compatibility.rb | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/config/initializers/active_job_compatibility.rb b/config/initializers/active_job_compatibility.rb index 054ae18c9..a73482124 100644 --- a/config/initializers/active_job_compatibility.rb +++ b/config/initializers/active_job_compatibility.rb @@ -13,18 +13,20 @@ require 'excon' -module ApiEntreprise - Job = APIEntreprise::Job - AssociationJob = APIEntreprise::AssociationJob - AttestationFiscaleJob = APIEntreprise::AttestationFiscaleJob - AttestationSocialeJob = APIEntreprise::AttestationSocialeJob - BilansBdfJob = APIEntreprise::BilansBdfJob - EffectifsAnnuelsJob = APIEntreprise::EffectifsAnnuelsJob - EffectifsJob = APIEntreprise::EffectifsJob - EntrepriseJob = APIEntreprise::EntrepriseJob - ExercicesJob = APIEntreprise::ExercicesJob -end +Rails.application.reloader.to_prepare do + module ApiEntreprise + Job = APIEntreprise::Job + AssociationJob = APIEntreprise::AssociationJob + AttestationFiscaleJob = APIEntreprise::AttestationFiscaleJob + AttestationSocialeJob = APIEntreprise::AttestationSocialeJob + BilansBdfJob = APIEntreprise::BilansBdfJob + EffectifsAnnuelsJob = APIEntreprise::EffectifsAnnuelsJob + EffectifsJob = APIEntreprise::EffectifsJob + EntrepriseJob = APIEntreprise::EntrepriseJob + ExercicesJob = APIEntreprise::ExercicesJob + end -module Cron - FixMissingAntivirusAnalysis = FixMissingAntivirusAnalysisJob + module Cron + FixMissingAntivirusAnalysis = FixMissingAntivirusAnalysisJob + end end From 46a839e7f7bd688fe2b35a3ca1c41f86f7a6d978 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 17 Feb 2021 19:03:45 +0100 Subject: [PATCH 03/17] Remove a spec that was testing bug in libgeos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit we don’t use libgeos anymore --- spec/factories/geo_area.rb | 45 ------------------------------------ spec/models/geo_area_spec.rb | 6 ----- 2 files changed, 51 deletions(-) diff --git a/spec/factories/geo_area.rb b/spec/factories/geo_area.rb index 699d5bca2..772ee91ac 100644 --- a/spec/factories/geo_area.rb +++ b/spec/factories/geo_area.rb @@ -77,51 +77,6 @@ FactoryBot.define do end end - trait :invalid_multi_polygon do - geometry do - { - "type": "MultiPolygon", - "coordinates": [ - [ - [ - [5.894422531127931, 48.22810341752755], - [5.893049240112306, 48.22427237832278], - [5.892534255981446, 48.22593062452037], - [5.892791748046875, 48.2260449843468], - [5.894422531127931, 48.229933066408215], - [5.894422531127931, 48.22810341752755] - ] - ], - [ - [ - [5.8950233459472665, 48.229933066408215], - [5.893478393554688, 48.228961073585126], - [5.892791748046875, 48.228903896961775], - [5.892705917358398, 48.230390468407535], - [5.8950233459472665, 48.229933066408215] - ] - ], - [ - [ - [5.893220901489259, 48.229246955743626], - [5.893392562866212, 48.22884672027457], - [5.892705917358398, 48.22878954352343], - [5.892019271850587, 48.22856083588024], - [5.892019271850587, 48.2277031731152], - [5.890989303588868, 48.22787470681807], - [5.889959335327149, 48.22787470681807], - [5.890560150146485, 48.22838930447709], - [5.890645980834962, 48.22878954352343], - [5.890989303588868, 48.229018250144584], - [5.892362594604493, 48.22930413198368], - [5.893220901489259, 48.229246955743626] - ] - ] - ] - } - end - end - trait :line_string do geometry do { diff --git a/spec/models/geo_area_spec.rb b/spec/models/geo_area_spec.rb index e4c0e0179..700403643 100644 --- a/spec/models/geo_area_spec.rb +++ b/spec/models/geo_area_spec.rb @@ -45,12 +45,6 @@ RSpec.describe GeoArea, type: :model do it { expect(geo_area.geometry).to eq(polygon) } - context 'invalid' do - let(:geo_area) { build(:geo_area, :invalid_multi_polygon) } - - it { expect(geo_area.rgeo_geometry).to be_nil } - end - context 'polygon_with_extra_coordinate' do let(:geo_area) { build(:geo_area, :polygon_with_extra_coordinate) } From a03d812d19f3b3bbcb03194a44d1d65971192a3a Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 17 Feb 2021 19:06:55 +0100 Subject: [PATCH 04/17] Add github actions CI --- .github/workflows/ci.yml | 101 +++++++++++++++++++++++++++++++++++++++ .rubocop.yml | 1 + lib/tasks/lint.rake | 2 +- 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..137d9384b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,101 @@ +name: Continuous Integration +on: + push: + branches: 'main' + pull_request: + branches: 'main' + +jobs: + linters: + name: Linters + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version: '14' + - name: Find yarn cache location + id: yarn-cache + run: echo "::set-output name=dir::$(yarn cache dir)" + - name: JS package cache + uses: actions/cache@v2 + with: + path: ${{ steps.yarn-cache.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + - name: Install packages + run: | + yarn install --pure-lockfile + + - name: Run linters + run: | + bundle exec rake lint + + tests: + name: Tests + runs-on: ubuntu-latest + services: + postgres: + image: postgres:12 + env: + POSTGRES_USER: tps_test + POSTGRES_DB: tps_test + POSTGRES_PASSWORD: tps_test + ports: ["5432:5432"] + + strategy: + matrix: + pattern: + - spec/controllers + - spec/features + - spec/helpers spec/lib spec/middlewares + - spec/mailers spec/jobs spec/policies + - spec/models + - spec/serializers spec/services + - spec/views + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version: '14' + - name: Find yarn cache location + id: yarn-cache + run: echo "::set-output name=dir::$(yarn cache dir)" + - name: JS package cache + uses: actions/cache@v2 + with: + path: ${{ steps.yarn-cache.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + - name: Install packages + run: | + yarn install --pure-lockfile + + - name: Setup test database + env: + RAILS_ENV: test + DATABASE_URL: "postgres://tps_test@localhost:5432/tps_test" + run: | + bundle exec rake db:create db:schema:load db:migrate + + - name: Run tests + run: bundle exec rspec ${{ matrix.pattern }} diff --git a/.rubocop.yml b/.rubocop.yml index ccf103e5a..e9c5ebdc4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,6 +12,7 @@ AllCops: - "db/migrate/20190730153555_recreate_structure.rb" - "bin/*" - "node_modules/**/*" + - "vendor/**/*" DS/Unscoped: Enabled: true diff --git a/lib/tasks/lint.rake b/lib/tasks/lint.rake index a5c8a0985..640d26a50 100644 --- a/lib/tasks/lint.rake +++ b/lib/tasks/lint.rake @@ -1,5 +1,5 @@ task :lint do - sh "bundle exec rubocop" + sh "bundle exec rubocop --parallel" sh "bundle exec haml-lint app/views/" sh "bundle exec scss-lint app/assets/stylesheets/" sh "bundle exec brakeman --no-pager" From fb305e31c41d6e671261ba5fea321d4e35b686cd Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 24 Feb 2021 14:06:33 +0000 Subject: [PATCH 05/17] config: move application_name to an initializer It seems cleaner not to require a file before the Rails configuration runs. --- .rubocop.yml | 2 +- config/application.rb | 1 - .../01_application_name.rb} | 3 +++ 3 files changed, 4 insertions(+), 2 deletions(-) rename config/{application_name.rb => initializers/01_application_name.rb} (58%) diff --git a/.rubocop.yml b/.rubocop.yml index e9c5ebdc4..4cc76166b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -20,7 +20,7 @@ DS/Unscoped: DS/ApplicationName: Enabled: true Exclude: - - './config/application_name.rb' + - './config/initializers/01_application_name.rb' - './lib/cops/application_name.rb' - './lib/linters/application_name_linter.rb' - "./spec/**/*" diff --git a/config/application.rb b/config/application.rb index ab6c2cf5e..2a4a8aa1f 100644 --- a/config/application.rb +++ b/config/application.rb @@ -7,7 +7,6 @@ require 'rails/all' Bundler.require(*Rails.groups) Dotenv::Railtie.load -require_relative 'application_name' module TPS class Application < Rails::Application diff --git a/config/application_name.rb b/config/initializers/01_application_name.rb similarity index 58% rename from config/application_name.rb rename to config/initializers/01_application_name.rb index b8c7bf61d..60523cdb1 100644 --- a/config/application_name.rb +++ b/config/initializers/01_application_name.rb @@ -1,3 +1,6 @@ +# This file is named '01-application-name.rb' to load it before the other +# initializers, and thus make the APPLICATION_ constants available in +# the other initializers. APPLICATION_NAME = ENV.fetch("APPLICATION_NAME", "demarches-simplifiees.fr") APPLICATION_SHORTNAME = ENV.fetch("APPLICATION_SHORTNAME", "d-s.fr") APPLICATION_BASE_URL = ENV.fetch("APPLICATION_BASE_URL", "https://www.demarches-simplifiees.fr") From 3304cb3d43a57f3ceeb44635594606e5d88016d3 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 24 Feb 2021 16:27:35 +0100 Subject: [PATCH 06/17] ci: split controller tests into 3 groups Ideally we'd like: - One group with `spec/controllers/api/**/*_spec.rb` files - One group with everything else But due to the way globbing works (and doesn't allow to say "Files NOT starting with `api`"), this looks like a sensible and future-proof configuration. --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 137d9384b..00651ac06 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,7 +55,9 @@ jobs: strategy: matrix: pattern: - - spec/controllers + - spec/controllers/*_spec.rb + - spec/controllers/[a-l]**/*_spec.rb + - spec/controllers/[m-z]**/*_spec.rb - spec/features - spec/helpers spec/lib spec/middlewares - spec/mailers spec/jobs spec/policies From e1a450fd6f93114ae772f6442b8cbda81ec7f1fa Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 23 Feb 2021 14:09:25 +0100 Subject: [PATCH 07/17] gems: remove xray-rails It is not compatible with sprockets-4. --- Gemfile | 1 - Gemfile.lock | 3 --- 2 files changed, 4 deletions(-) diff --git a/Gemfile b/Gemfile index ed20a87bb..91c4693e3 100644 --- a/Gemfile +++ b/Gemfile @@ -112,7 +112,6 @@ group :development do gem 'rubocop-rspec-focused', require: false gem 'scss_lint', require: false gem 'web-console' - gem 'xray-rails' end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index b559be011..b4e5fa2d7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -799,8 +799,6 @@ GEM websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - xray-rails (0.3.2) - rails (>= 3.1.0) zeitwerk (2.4.2) zip_tricks (5.5.0) zipline (1.3.0) @@ -927,7 +925,6 @@ DEPENDENCIES webdrivers (~> 4.0) webmock webpacker - xray-rails zipline zxcvbn-ruby From e51948ab5c4b9abf2b72cf7e1337c2380accd1c6 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 23 Feb 2021 14:09:01 +0100 Subject: [PATCH 08/17] stylesheets: merge print rules with the application stylesheet - Having a separate stylesheet for print rules is not a best practice (it makes an extra network request) - It makes migrating to Sprockets 4 easier --- app/assets/stylesheets/application.scss | 1 - app/assets/stylesheets/print.scss | 104 ++++++++++++------------ app/views/layouts/application.html.haml | 1 - config/initializers/assets.rb | 5 +- 4 files changed, 56 insertions(+), 55 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index eaf0c0b98..1fc589860 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -5,4 +5,3 @@ // = require ./fonts // = require leaflet // = require_tree . -// = stub ./print.scss diff --git a/app/assets/stylesheets/print.scss b/app/assets/stylesheets/print.scss index cbb30fc56..4c0e9749c 100644 --- a/app/assets/stylesheets/print.scss +++ b/app/assets/stylesheets/print.scss @@ -1,63 +1,65 @@ @import "colors"; @import "fonts"; -.new-header, -.sub-header, -footer { - display: none; -} - -.print-header { - display: block; - margin-top: 30px; - font-size: 30px; - line-height: 50px; - font-weight: bold; -} - -body { - font-family: "Muli"; -} - -.subtitle { - margin-top: -20px; - color: $dark-grey; -} - -th, -td { - vertical-align: top; -} - -th { - text-align: left; - - &.header-section { - padding-top: 1.2em; - font-size: 1.2em; +@media print { + .new-header, + .sub-header, + footer { + display: none; } -} -.messagerie { - .messages-list { - list-style: none; - padding-left: 0; - max-height: none; + .print-header { + display: block; + margin-top: 30px; + font-size: 30px; + line-height: 50px; + font-weight: bold; + } - h2 { - font-size: 110%; - } + body { + font-family: "Muli"; + } - .person-icon { - display: none; + .subtitle { + margin-top: -20px; + color: $dark-grey; + } + + th, + td { + vertical-align: top; + } + + th { + text-align: left; + + &.header-section { + padding-top: 1.2em; + font-size: 1.2em; } } -} -.message { - margin-bottom: 40px; -} + .messagerie { + .messages-list { + list-style: none; + padding-left: 0; + max-height: none; -.updated-at { - display: none; + h2 { + font-size: 110%; + } + + .person-icon { + display: none; + } + } + } + + .message { + margin-bottom: 40px; + } + + .updated-at { + display: none; + } } diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index d2ed48a5c..28285f2ea 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -20,7 +20,6 @@ = preload_link_tag(asset_url("Muli-Bold.woff2")) = stylesheet_link_tag 'application', media: 'all' - = stylesheet_link_tag 'print', media: 'print' = Gon::Base.render_data(camel_case: true, init: true, nonce: request.content_security_policy_nonce) diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index c97536ee3..86d374be3 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -10,5 +10,6 @@ Rails.application.config.assets.paths << Rails.root.join('node_modules', '@reach Rails.application.config.assets.paths << Rails.root.join('node_modules', '@mapbox', 'mapbox-gl-draw', 'dist') # Precompile additional assets. -# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. -Rails.application.config.assets.precompile += ['print.css'] +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. +# Rails.application.config.assets.precompile += %w( admin.js admin.css ) From 2e3ddd61905b7402c7d1160530345dd612cb1793 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 23 Feb 2021 15:42:10 +0000 Subject: [PATCH 09/17] gems: upgrade to Sprockets 4 --- Gemfile | 1 - Gemfile.lock | 3 +-- app/assets/config/manifest.js | 5 +++++ 3 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 app/assets/config/manifest.js diff --git a/Gemfile b/Gemfile index 91c4693e3..aec824937 100644 --- a/Gemfile +++ b/Gemfile @@ -74,7 +74,6 @@ gem 'sib-api-v3-sdk' gem 'skylight' gem 'smart_listing' gem 'spreadsheet_architect' -gem 'sprockets', '< 4' gem 'typhoeus' gem 'warden' gem 'webpacker' diff --git a/Gemfile.lock b/Gemfile.lock index b4e5fa2d7..374f79742 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -730,7 +730,7 @@ GEM spring (2.1.1) spring-commands-rspec (1.0.4) spring (>= 0.9.1) - sprockets (3.7.2) + sprockets (4.0.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.2.2) @@ -916,7 +916,6 @@ DEPENDENCIES spreadsheet_architect spring spring-commands-rspec - sprockets (< 4) timecop typhoeus vcr diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 000000000..8890f53b3 --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,5 @@ +//= link application.css +//= link_tree ../images +//= link_tree ../fonts +//= link administrate/application.css +//= link administrate/application.js From 68425929c6cc565ddcd1982970d48be369deafaa Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 24 Feb 2021 17:45:18 +0100 Subject: [PATCH 10/17] config: disable Sentry sampling when not enabled This removes spam in the debug console when running locally. Removed messages look like a swarm of: > [Tracing] Discarding transaction because it's not included in the random sample (sampling rate = 0.001) --- config/initializers/sentry.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/sentry.rb b/config/initializers/sentry.rb index a65106b50..2d4008a4f 100644 --- a/config/initializers/sentry.rb +++ b/config/initializers/sentry.rb @@ -3,5 +3,5 @@ Sentry.init do |config| config.send_default_pii = false config.enabled_environments = ['production'] config.breadcrumbs_logger = [:active_support_logger] - config.traces_sample_rate = 0.001 + config.traces_sample_rate = ENV['SENTRY_ENABLED'] == 'enabled' ? 0.001 : nil end From 9f676c76e105742ac00e0bc11da3bd17ca862697 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 24 Feb 2021 17:51:48 +0000 Subject: [PATCH 11/17] config: fix zeitwerk warning about DynamicSmtpSettingsInterceptor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix a warning when running tests: > DEPRECATION WARNING: Initialization autoloaded the constant DynamicSmtpSettingsInterceptor. > > Being able to do this is deprecated. Autoloading during initialization is going to be an error condition in future versions of Rails. > > Reloading does not reboot the application, and therefore code executed during > initialization does not run again. So, if you reload DynamicSmtpSettingsInterceptor, for example, > the expected changes won't be reflected in that stale Class object. > > This autoloaded constant has been unloaded. > > Please, check the "Autoloading and Reloading Constants" guide for solutions. However if we fix as recommanded, the interceptor will get added each time the classes are reloaded. And as the actual class instance changed after the reloading, they won't be de-duplicated – *and* there's no way to remove the old interceptor without having a reference to the (now-deleted) class. Instead we load the interceptor once, and add a message about the class not being auto-reloaded. --- app/models/dynamic_smtp_settings_interceptor.rb | 6 ++++++ config/initializers/dynamic_smtp_settings_interceptor.rb | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/dynamic_smtp_settings_interceptor.rb b/app/models/dynamic_smtp_settings_interceptor.rb index 885c4b8e9..91d6398f8 100644 --- a/app/models/dynamic_smtp_settings_interceptor.rb +++ b/app/models/dynamic_smtp_settings_interceptor.rb @@ -1,3 +1,9 @@ +# Note: this class is instanciated when being added as an interceptor +# during the app initialization. +# +# If you edit this file in development env, you will need to restart +# the app to see the changes. + class DynamicSmtpSettingsInterceptor def self.delivering_email(message) if ENV['SENDINBLUE_BALANCING'] == 'enabled' diff --git a/config/initializers/dynamic_smtp_settings_interceptor.rb b/config/initializers/dynamic_smtp_settings_interceptor.rb index a3f8e2d13..26a5d4d96 100644 --- a/config/initializers/dynamic_smtp_settings_interceptor.rb +++ b/config/initializers/dynamic_smtp_settings_interceptor.rb @@ -1 +1,3 @@ -ActionMailer::Base.register_interceptor "DynamicSmtpSettingsInterceptor" +ActiveSupport.on_load(:action_mailer) do + ActionMailer::Base.register_interceptor "DynamicSmtpSettingsInterceptor" +end From d36a68431565eb4d54da5ac1e36e6a8df4a7fc24 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 24 Feb 2021 19:01:27 +0100 Subject: [PATCH 12/17] config: fix zeitwekr warning when reloading the app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Turns out we need not only to load the Job constants later, but also not to do the same work twice – otherwise we'll get a > ApiEntreprise::Job constant is already defined when attempting to re-define the constant. --- .../initializers/active_job_compatibility.rb | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/config/initializers/active_job_compatibility.rb b/config/initializers/active_job_compatibility.rb index a73482124..9a90cfe50 100644 --- a/config/initializers/active_job_compatibility.rb +++ b/config/initializers/active_job_compatibility.rb @@ -11,22 +11,24 @@ # - but let's keep these for a while to make external integrators's life easier. # To keep some margin, let's say this file can be safely deleted in May 2021.) -require 'excon' - Rails.application.reloader.to_prepare do - module ApiEntreprise - Job = APIEntreprise::Job - AssociationJob = APIEntreprise::AssociationJob - AttestationFiscaleJob = APIEntreprise::AttestationFiscaleJob - AttestationSocialeJob = APIEntreprise::AttestationSocialeJob - BilansBdfJob = APIEntreprise::BilansBdfJob - EffectifsAnnuelsJob = APIEntreprise::EffectifsAnnuelsJob - EffectifsJob = APIEntreprise::EffectifsJob - EntrepriseJob = APIEntreprise::EntrepriseJob - ExercicesJob = APIEntreprise::ExercicesJob - end + if !defined?(ApiEntreprise) + require 'excon' - module Cron - FixMissingAntivirusAnalysis = FixMissingAntivirusAnalysisJob + module ApiEntreprise + Job = APIEntreprise::Job + AssociationJob = APIEntreprise::AssociationJob + AttestationFiscaleJob = APIEntreprise::AttestationFiscaleJob + AttestationSocialeJob = APIEntreprise::AttestationSocialeJob + BilansBdfJob = APIEntreprise::BilansBdfJob + EffectifsAnnuelsJob = APIEntreprise::EffectifsAnnuelsJob + EffectifsJob = APIEntreprise::EffectifsJob + EntrepriseJob = APIEntreprise::EntrepriseJob + ExercicesJob = APIEntreprise::ExercicesJob + end + + module Cron + FixMissingAntivirusAnalysis = FixMissingAntivirusAnalysisJob + end end end From 0fa3d367c097afe00d70e104bfccd124e7f4add7 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 16 Feb 2021 11:41:45 +0100 Subject: [PATCH 13/17] gems: use a version of devise-two-factors compatible with Rails 6.1 --- Gemfile | 2 +- Gemfile.lock | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index aec824937..2fddbc025 100644 --- a/Gemfile +++ b/Gemfile @@ -21,7 +21,7 @@ gem 'delayed_job_web' gem 'devise' # Gestion des comptes utilisateurs gem 'devise-async' gem 'devise-i18n' -gem 'devise-two-factor', github: 'bryanfagan/devise-two-factor' +gem 'devise-two-factor', github: 'jason-hobbs/devise-two-factor', branch: 'master' # Rails 6.1 compatibility: https://github.com/tinfoil/devise-two-factor/issues/183 gem 'discard' gem 'dotenv-rails', require: 'dotenv/rails-now' # dotenv should always be loaded before rails gem 'ffi-geos', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 374f79742..09a201545 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,13 +1,14 @@ GIT - remote: https://github.com/bryanfagan/devise-two-factor.git - revision: 60038a699b1847266f6ce0a3457fdc2cd24715be + remote: https://github.com/jason-hobbs/devise-two-factor.git + revision: e153f16ab86de01df034672dfffa321acd891c45 + branch: master specs: - devise-two-factor (3.1.1) - activesupport (< 6.1) + devise-two-factor (3.1.0) + activesupport (< 7.0) attr_encrypted (>= 1.3, < 4, != 2) - devise (~> 4.0) - railties (< 6.1) - rotp (~> 4.0) + devise + railties (< 7.0) + rotp (~> 6) GIT remote: https://github.com/mina-deploy/mina.git @@ -595,8 +596,7 @@ GEM builder (>= 3.0) dry-inflector (~> 0.1) rubyzip (>= 1.0) - rotp (4.1.0) - addressable (~> 2.5) + rotp (6.2.0) rouge (3.26.0) rqrcode (1.2.0) chunky_png (~> 1.0) From 1d7c4f5b020251a4387e98343e3ec17dc8caa83b Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 23 Feb 2021 10:20:20 +0000 Subject: [PATCH 14/17] gems: remove ffi-geos We don't need it now that we don't link to a compiled geos version anymore. --- Gemfile | 1 - Gemfile.lock | 3 --- 2 files changed, 4 deletions(-) diff --git a/Gemfile b/Gemfile index 2fddbc025..561817145 100644 --- a/Gemfile +++ b/Gemfile @@ -24,7 +24,6 @@ gem 'devise-i18n' gem 'devise-two-factor', github: 'jason-hobbs/devise-two-factor', branch: 'master' # Rails 6.1 compatibility: https://github.com/tinfoil/devise-two-factor/issues/183 gem 'discard' gem 'dotenv-rails', require: 'dotenv/rails-now' # dotenv should always be loaded before rails -gem 'ffi-geos', require: false gem 'flipper' gem 'flipper-active_record' gem 'flipper-ui' diff --git a/Gemfile.lock b/Gemfile.lock index 09a201545..e5c9b76cd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -255,8 +255,6 @@ GEM ruby2_keywords faraday-net_http (1.0.1) ffi (1.14.2) - ffi-geos (2.1.0) - ffi (>= 1.0.0) flipper (0.20.3) flipper-active_record (0.20.3) activerecord (>= 5.0, < 7) @@ -843,7 +841,6 @@ DEPENDENCIES discard dotenv-rails factory_bot - ffi-geos flipper flipper-active_record flipper-ui From 473a86b861ed7c1fcaf681ea3f4d1399fa8fb4fe Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 23 Feb 2021 14:01:04 +0000 Subject: [PATCH 15/17] gems: remove guard - It doesn't seem used a lot these days - It has some incompatibility with rspec 4 We need to explicitely add the 'listen' gem now though. --- Gemfile | 4 +--- Gemfile.lock | 38 +------------------------------------- spec/spec_helper.rb | 1 - 3 files changed, 2 insertions(+), 41 deletions(-) diff --git a/Gemfile b/Gemfile index 561817145..fdb7823bd 100644 --- a/Gemfile +++ b/Gemfile @@ -45,6 +45,7 @@ gem 'image_processing' gem 'json_schemer' gem 'jwt' gem 'kaminari', '1.2.1' # Pagination +gem 'listen' # Required by ActiveSupport::EventedFileUpdateChecker gem 'lograge' gem 'logstash-event' gem 'mailjet' @@ -86,9 +87,6 @@ group :test do gem 'capybara-selenium' gem 'database_cleaner' gem 'factory_bot' - gem 'guard' - gem 'guard-livereload', require: false - gem 'guard-rspec', require: false gem 'launchy' gem 'rails-controller-testing' gem 'shoulda-matchers', require: false diff --git a/Gemfile.lock b/Gemfile.lock index e5c9b76cd..9bda1b249 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -233,9 +233,6 @@ GEM dumb_delegator (0.8.1) ecma-re-validator (0.3.0) regexp_parser (~> 2.0) - em-websocket (0.5.2) - eventmachine (>= 0.12.9) - http_parser.rb (~> 0.6.0) encryptor (3.0.0) equalizer (0.0.11) erubi (1.10.0) @@ -244,7 +241,6 @@ GEM tzinfo ethon (0.12.0) ffi (>= 1.3.0) - eventmachine (1.2.7) excon (0.79.0) execjs (2.7.0) factory_bot (6.1.0) @@ -306,25 +302,6 @@ GEM rails (>= 5.1.0) groupdate (5.2.2) activesupport (>= 5) - guard (2.16.2) - formatador (>= 0.2.4) - listen (>= 2.7, < 4.0) - lumberjack (>= 1.0.12, < 2.0) - nenv (~> 0.1) - notiffany (~> 0.0) - pry (>= 0.9.12) - shellany (~> 0.0) - thor (>= 0.18.1) - guard-compat (1.2.1) - guard-livereload (2.5.2) - em-websocket (~> 0.5) - guard (~> 2.8) - guard-compat (~> 1.0) - multi_json (~> 1.8) - guard-rspec (4.7.3) - guard (~> 2.1) - guard-compat (~> 1.1) - rspec (>= 2.99.0, < 4.0) haml (5.2.1) temple (>= 0.8.0) tilt @@ -356,7 +333,6 @@ GEM http-cookie (1.0.3) domain_name (~> 0.5) http_accept_language (2.1.1) - http_parser.rb (0.6.0) httpclient (2.8.3) i18n (1.8.9) concurrent-ruby (~> 1.0) @@ -424,7 +400,6 @@ GEM loofah (2.9.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) - lumberjack (1.2.8) mail (2.7.1) mini_mime (>= 0.1.1) mailjet (1.6.0) @@ -448,15 +423,11 @@ GEM multipart-post (2.1.1) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) - nenv (0.3.0) netrc (0.11.0) nio4r (2.5.5) nokogiri (1.11.1) mini_portile2 (~> 2.5.0) racc (~> 1.4) - notiffany (0.1.3) - nenv (~> 0.1) - shellany (~> 0.0) open4 (1.3.4) openid_connect (1.2.0) activemodel @@ -600,10 +571,6 @@ GEM chunky_png (~> 1.0) rqrcode_core (~> 0.2) rqrcode_core (0.2.0) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) rspec-core (3.10.1) rspec-support (~> 3.10.0) rspec-expectations (3.10.1) @@ -698,7 +665,6 @@ GEM concurrent-ruby faraday sexp_processor (4.15.2) - shellany (0.0.1) shoulda-matchers (4.5.1) activesupport (>= 4.2.0) sib-api-v3-sdk (7.4.0) @@ -854,9 +820,6 @@ DEPENDENCIES graphql-schema_comparator graphql_playground-rails groupdate - guard - guard-livereload - guard-rspec haml-lint haml-rails hashie @@ -869,6 +832,7 @@ DEPENDENCIES kaminari (= 1.2.1) launchy letter_opener_web + listen lograge logstash-event mailjet diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 869896403..684ff0d2b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -17,7 +17,6 @@ # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration -require 'rspec' require 'capybara/rspec' require 'capybara-screenshot/rspec' require 'capybara/email/rspec' From 1ebfdef411bf6471cdb62a5b0ff7c43c4b096f57 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 23 Feb 2021 15:55:13 +0100 Subject: [PATCH 16/17] gems: remove ruby-debug-ide - It was included to make Rubymine happy, but nowadays Rubymine seems to load the debugger without touching the Gemfile - It keeps matching an invalid version when `bundle upgrade`-ing the dependencies. --- Gemfile | 1 - Gemfile.lock | 3 --- 2 files changed, 4 deletions(-) diff --git a/Gemfile b/Gemfile index fdb7823bd..b7708896a 100644 --- a/Gemfile +++ b/Gemfile @@ -117,7 +117,6 @@ group :development, :test do gem 'pry-byebug' # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'rspec_junit_formatter', require: false gem 'rspec-rails' - gem 'ruby-debug-ide', require: false gem 'simple_xlsx_reader' gem 'spring' # Spring speeds up development by keeping your application running in the background gem 'spring-commands-rspec' diff --git a/Gemfile.lock b/Gemfile.lock index 9bda1b249..081650c09 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -619,8 +619,6 @@ GEM rubocop-rails (~> 2.0) rubocop-rspec-focused (1.0.0) rubocop (>= 0.51) - ruby-debug-ide (0.7.2) - rake (>= 0.8.1) ruby-graphviz (1.2.5) rexml ruby-progressbar (1.11.0) @@ -861,7 +859,6 @@ DEPENDENCIES rubocop rubocop-rails_config rubocop-rspec-focused - ruby-debug-ide ruby-saml-idp sanitize-url sassc-rails From ff8ccbd0881ecd21b74b1c5795b487a5b2ebf929 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 25 Feb 2021 15:20:14 +0100 Subject: [PATCH 17/17] Try to parse SIB email date when it is a string --- app/views/manager/users/emails.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/manager/users/emails.html.erb b/app/views/manager/users/emails.html.erb index 13575b96a..6af6416d3 100644 --- a/app/views/manager/users/emails.html.erb +++ b/app/views/manager/users/emails.html.erb @@ -47,7 +47,7 @@ <%= email.subject %> - <%= l(email.date, format: '%d/%m/%y à %H:%M') %> + <%= l(email.date.is_a?(String) ? Time.zone.parse(email.date) : email.date, format: '%d/%m/%y à %H:%M') %>