diff --git a/.rubocop.yml b/.rubocop.yml index cb1b411a4..ca7a3de9a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -14,6 +14,7 @@ AllCops: TargetRubyVersion: 3.1 DisabledByDefault: true SuggestExtensions: false + NewCops: enable Include: - "app/**/*.prawn" Exclude: @@ -683,9 +684,18 @@ Performance/UriDefaultParser: Rails: Enabled: true +Rails/ActionControllerFlashBeforeRender: + Enabled: true + +Rails/ActionControllerTestCase: + Enabled: true + Rails/ActionFilter: Enabled: true +Rails/ActionOrder: + Enabled: false + Rails/ActiveRecordAliases: Enabled: true @@ -695,18 +705,24 @@ Rails/ActiveRecordCallbacksOrder: Rails/ActiveSupportAliases: Enabled: true +Rails/ActiveSupportOnLoad: + Enabled: true + +Rails/AddColumnIndex: + Enabled: true + Rails/AfterCommitOverride: Enabled: true +Rails/ApplicationController: + Enabled: false + Rails/ApplicationJob: Enabled: true Rails/ApplicationRecord: Enabled: true -Rails/ApplicationController: - Enabled: false - Rails/AttributeDefaultBlockValue: Enabled: true @@ -716,6 +732,9 @@ Rails/Blank: Rails/BulkChangeTable: Enabled: false +Rails/CompactBlank: + Enabled: true + Rails/CreateTableWithTimestamps: Enabled: true Exclude: @@ -734,10 +753,28 @@ Rails/Delegate: Rails/DelegateAllowBlank: Enabled: true +Rails/DeprecatedActiveModelErrorsMethods: + Enabled: false # re-enable in rails 7 + +Rails/DotSeparatedKeys: + Enabled: true + +Rails/DuplicateAssociation: + Enabled: true + +Rails/DuplicateScope: + Enabled: true + +Rails/DurationArithmetic: + Enabled: true + Rails/DynamicFindBy: Enabled: true Exclude: - - "spec/system/**/*.rb" + - spec/system/**/*.rb + +Rails/EagerEvaluationLogMessage: + Enabled: true Rails/EnumUniqueness: Enabled: true @@ -748,6 +785,9 @@ Rails/EnvironmentComparison: Rails/Exit: Enabled: true +Rails/ExpandedDateRange: + Enabled: true + Rails/FilePath: Enabled: false @@ -760,6 +800,9 @@ Rails/FindById: Rails/FindEach: Enabled: true +Rails/FreezeTime: + Enabled: true + Rails/HasAndBelongsToMany: Enabled: false @@ -772,6 +815,18 @@ Rails/HttpPositionalArguments: Rails/HttpStatus: Enabled: false +Rails/I18nLazyLookup: + Enabled: true + +Rails/I18nLocaleAssignment: + Enabled: true + +Rails/I18nLocaleTexts: + Enabled: false + +Rails/IgnoredColumnsAssignment: + Enabled: true + Rails/Inquiry: Enabled: true @@ -787,6 +842,9 @@ Rails/MailerName: Rails/MatchRoute: Enabled: true +Rails/MigrationClassName: + Enabled: true + Rails/NegateInclude: Enabled: false @@ -823,9 +881,15 @@ Rails/ReadWriteAttribute: Rails/RedundantAllowNil: Enabled: false +Rails/RedundantPresenceValidationOnBelongsTo: + Enabled: true + Rails/RedundantReceiverInWithOptions: Enabled: true +Rails/RedundantTravelBack: + Enabled: true + Rails/RelativeDateConstant: Enabled: true @@ -838,9 +902,21 @@ Rails/RenderPlainText: Rails/RequestReferer: Enabled: true +Rails/ResponseParsedBody: + Enabled: true + Rails/ReversibleMigration: Enabled: false +Rails/RootJoinChain: + Enabled: true + +Rails/RootPathnameMethods: + Enabled: true + +Rails/RootPublicPath: + Enabled: true + Rails/SaveBang: Enabled: false @@ -856,9 +932,37 @@ Rails/SkipsModelValidations: Rails/SquishedSQLHeredocs: Enabled: true +Rails/StripHeredoc: + Enabled: true + +Rails/ThreeStateBooleanColumn: + Enabled: true + Exclude: + - db/migrate/2019* + - db/migrate/2020* + - db/migrate/2021* + - db/migrate/2022* + - db/migrate/202301* + - db/migrate/202303* + Rails/TimeZone: EnforcedStyle: strict +Rails/TimeZoneAssignment: + Enabled: true + +Rails/ToFormattedS: + Enabled: true + +Rails/ToSWithArgument: + Enabled: true + +Rails/TopLevelHashWithIndifferentAccess: + Enabled: true + +Rails/TransactionExitStatement: + Enabled: true + Rails/UniqBeforePluck: Enabled: true @@ -868,6 +972,9 @@ Rails/UniqueValidationWithoutIndex: Rails/UnknownEnv: Enabled: false +Rails/UnusedIgnoredColumns: + Enabled: true + Rails/Validation: Enabled: true @@ -877,9 +984,15 @@ Rails/WhereEquals: Rails/WhereExists: Enabled: true +Rails/WhereMissing: + Enabled: true + Rails/WhereNot: Enabled: true +Rails/WhereNotWithMultipleConditions: + Enabled: true + RSpec/Focus: Enabled: true @@ -1039,6 +1152,12 @@ Style/EvenOdd: Style/ExpandPathArguments: Enabled: true +Style/FileRead: + Enabled: true + +Style/FileWrite: + Enabled: true + Style/For: Enabled: true diff --git a/Gemfile.lock b/Gemfile.lock index 4a5e78231..64ec024eb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -473,9 +473,9 @@ GEM validate_url webfinger (>= 1.0.1) orm_adapter (0.5.0) - parallel (1.22.1) + parallel (1.23.0) parsby (1.1.1) - parser (3.1.2.1) + parser (3.2.2.0) ast (~> 2.4.1) pdf-core (0.9.0) pg (1.2.3) @@ -577,7 +577,7 @@ GEM rb-inotify (0.10.1) ffi (~> 1.0) redcarpet (3.6.0) - regexp_parser (2.7.0) + regexp_parser (2.8.0) request_store (1.5.0) rack (>= 1.4) responders (3.0.1) @@ -621,31 +621,33 @@ GEM rspec-support (3.10.2) rspec_junit_formatter (0.4.1) rspec-core (>= 2, < 4, != 2.12.0) - rubocop (1.36.0) + rubocop (1.50.2) json (~> 2.3) parallel (~> 1.10) - parser (>= 3.1.2.1) + parser (>= 3.2.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.20.1, < 2.0) + rubocop-ast (>= 1.28.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.21.0) - parser (>= 3.1.1.0) - rubocop-performance (1.9.2) - rubocop (>= 0.90.0, < 2.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.28.0) + parser (>= 3.2.1.0) + rubocop-capybara (2.17.1) + rubocop (~> 1.41) + rubocop-performance (1.17.1) + rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) - rubocop-rails (2.9.1) + rubocop-rails (2.19.1) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 0.90.0, < 2.0) - rubocop-rspec (2.4.0) - rubocop (~> 1.0) - rubocop-ast (>= 1.1.0) + rubocop (>= 1.33.0, < 2.0) + rubocop-rspec (2.20.0) + rubocop (~> 1.33) + rubocop-capybara (~> 2.17) ruby-graphviz (1.2.5) rexml - ruby-progressbar (1.11.0) + ruby-progressbar (1.13.0) ruby-vips (2.1.4) ffi (~> 1.12) ruby2_keywords (0.0.5) @@ -756,7 +758,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.7) - unicode-display_width (2.3.0) + unicode-display_width (2.4.2) uri_template (0.7.0) validate_email (0.1.6) activemodel (>= 3.0) diff --git a/app/controllers/ping_controller.rb b/app/controllers/ping_controller.rb index 6fadefcbe..348a1e4fe 100644 --- a/app/controllers/ping_controller.rb +++ b/app/controllers/ping_controller.rb @@ -1,7 +1,7 @@ class PingController < ApplicationController def index Rails.logger.silence do - status_code = if File.file?(Rails.root.join("maintenance")) + status_code = if Rails.root.join("maintenance").file? # See https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#4.2-http-check%20disable-on-404 :not_found elsif (ActiveRecord::Base.connection.execute('select 1 as test;').first['test'] == 1) diff --git a/app/controllers/support_controller.rb b/app/controllers/support_controller.rb index 526d17637..f741f85c4 100644 --- a/app/controllers/support_controller.rb +++ b/app/controllers/support_controller.rb @@ -73,7 +73,7 @@ class SupportController < ApplicationController [params[:tags], params[:type]].flatten.compact .map { |tag| tag.split(',') } .flatten - .reject(&:blank?).uniq + .compact_blank.uniq end def browser_name diff --git a/app/helpers/dossier_helper.rb b/app/helpers/dossier_helper.rb index dd5b96b95..b94ac46e5 100644 --- a/app/helpers/dossier_helper.rb +++ b/app/helpers/dossier_helper.rb @@ -84,10 +84,10 @@ module DossierHelper def deletion_reason_badge(reason) if reason.present? - status_text = I18n.t(reason, scope: [:activerecord, :attributes, :deleted_dossier, :reason]) + status_text = I18n.t(reason, scope: 'activerecord.attributes.deleted_dossier.reason') status_class = reason.tr('_', '-') else - status_text = I18n.t(:unknown, scope: [:activerecord, :attributes, :deleted_dossier, :reason]) + status_text = I18n.t('activerecord.attributes.deleted_dossier.reason.unknown') status_class = 'unknown' end diff --git a/app/jobs/cron/datagouv/account_by_month_job.rb b/app/jobs/cron/datagouv/account_by_month_job.rb index 97f46bf5c..187da87db 100644 --- a/app/jobs/cron/datagouv/account_by_month_job.rb +++ b/app/jobs/cron/datagouv/account_by_month_job.rb @@ -14,6 +14,6 @@ class Cron::Datagouv::AccountByMonthJob < Cron::CronJob end def data - User.where(created_at: 1.month.ago.beginning_of_month..1.month.ago.end_of_month).count + User.where(created_at: 1.month.ago.all_month).count end end diff --git a/app/jobs/cron/datagouv/administrateur_by_month_job.rb b/app/jobs/cron/datagouv/administrateur_by_month_job.rb index 346b9cf90..1391df690 100644 --- a/app/jobs/cron/datagouv/administrateur_by_month_job.rb +++ b/app/jobs/cron/datagouv/administrateur_by_month_job.rb @@ -14,6 +14,6 @@ class Cron::Datagouv::AdministrateurByMonthJob < Cron::CronJob end def data - Administrateur.where(created_at: 1.month.ago.beginning_of_month..1.month.ago.end_of_month).count + Administrateur.where(created_at: 1.month.ago.all_month).count end end diff --git a/app/jobs/cron/datagouv/file_by_month_job.rb b/app/jobs/cron/datagouv/file_by_month_job.rb index 723a48af3..f4375679a 100644 --- a/app/jobs/cron/datagouv/file_by_month_job.rb +++ b/app/jobs/cron/datagouv/file_by_month_job.rb @@ -14,6 +14,6 @@ class Cron::Datagouv::FileByMonthJob < Cron::CronJob end def data - Dossier.where(created_at: 1.month.ago.beginning_of_month..1.month.ago.end_of_month).count + Dossier.where(created_at: 1.month.ago.all_month).count end end diff --git a/app/jobs/cron/datagouv/file_depose_by_month_job.rb b/app/jobs/cron/datagouv/file_depose_by_month_job.rb index 1083d6c28..c7fd2d828 100644 --- a/app/jobs/cron/datagouv/file_depose_by_month_job.rb +++ b/app/jobs/cron/datagouv/file_depose_by_month_job.rb @@ -14,6 +14,6 @@ class Cron::Datagouv::FileDeposeByMonthJob < Cron::CronJob end def data - Dossier.where(depose_at: 1.month.ago.beginning_of_month..1.month.ago.end_of_month).count + Dossier.where(depose_at: 1.month.ago.all_month).count end end diff --git a/app/jobs/cron/datagouv/instructeur_by_month_job.rb b/app/jobs/cron/datagouv/instructeur_by_month_job.rb index cfa232c23..ea98d5dd9 100644 --- a/app/jobs/cron/datagouv/instructeur_by_month_job.rb +++ b/app/jobs/cron/datagouv/instructeur_by_month_job.rb @@ -14,6 +14,6 @@ class Cron::Datagouv::InstructeurByMonthJob < Cron::CronJob end def data - Instructeur.where(created_at: 1.month.ago.beginning_of_month..1.month.ago.end_of_month).count + Instructeur.where(created_at: 1.month.ago.all_month).count end end diff --git a/app/jobs/cron/datagouv/instructeur_connected_by_month_job.rb b/app/jobs/cron/datagouv/instructeur_connected_by_month_job.rb index 8691cb3fe..cbcb20e08 100644 --- a/app/jobs/cron/datagouv/instructeur_connected_by_month_job.rb +++ b/app/jobs/cron/datagouv/instructeur_connected_by_month_job.rb @@ -14,6 +14,6 @@ class Cron::Datagouv::InstructeurConnectedByMonthJob < Cron::CronJob end def data - Instructeur.joins(:user).where(user: { last_sign_in_at: 1.month.ago.beginning_of_month..1.month.ago.end_of_month }).count + Instructeur.joins(:user).where(user: { last_sign_in_at: 1.month.ago.all_month }).count end end diff --git a/app/jobs/cron/datagouv/procedure_by_month_job.rb b/app/jobs/cron/datagouv/procedure_by_month_job.rb index 1327c4ff3..2a044cf43 100644 --- a/app/jobs/cron/datagouv/procedure_by_month_job.rb +++ b/app/jobs/cron/datagouv/procedure_by_month_job.rb @@ -14,6 +14,6 @@ class Cron::Datagouv::ProcedureByMonthJob < Cron::CronJob end def data - Procedure.where(created_at: 1.month.ago.beginning_of_month..1.month.ago.end_of_month).count + Procedure.where(created_at: 1.month.ago.all_month).count end end diff --git a/app/jobs/cron/datagouv/procedure_closed_by_month_job.rb b/app/jobs/cron/datagouv/procedure_closed_by_month_job.rb index 11ab5dbd8..315aa7474 100644 --- a/app/jobs/cron/datagouv/procedure_closed_by_month_job.rb +++ b/app/jobs/cron/datagouv/procedure_closed_by_month_job.rb @@ -14,6 +14,6 @@ class Cron::Datagouv::ProcedureClosedByMonthJob < Cron::CronJob end def data - Procedure.where(closed_at: 1.month.ago.beginning_of_month..1.month.ago.end_of_month).count + Procedure.where(closed_at: 1.month.ago.all_month).count end end diff --git a/app/jobs/cron/datagouv/procedure_deleted_by_month_job.rb b/app/jobs/cron/datagouv/procedure_deleted_by_month_job.rb index d259a4af7..17bdccf63 100644 --- a/app/jobs/cron/datagouv/procedure_deleted_by_month_job.rb +++ b/app/jobs/cron/datagouv/procedure_deleted_by_month_job.rb @@ -14,6 +14,6 @@ class Cron::Datagouv::ProcedureDeletedByMonthJob < Cron::CronJob end def data - Procedure.where(hidden_at: 1.month.ago.beginning_of_month..1.month.ago.end_of_month).count + Procedure.where(hidden_at: 1.month.ago.all_month).count end end diff --git a/app/jobs/cron/datagouv/user_connected_with_france_connect_by_month_job.rb b/app/jobs/cron/datagouv/user_connected_with_france_connect_by_month_job.rb index 58d6ffdab..a4aea9be7 100644 --- a/app/jobs/cron/datagouv/user_connected_with_france_connect_by_month_job.rb +++ b/app/jobs/cron/datagouv/user_connected_with_france_connect_by_month_job.rb @@ -14,6 +14,6 @@ class Cron::Datagouv::UserConnectedWithFranceConnectByMonthJob < Cron::CronJob end def data - User.where(created_at: 1.month.ago.beginning_of_month..1.month.ago.end_of_month, loged_in_with_france_connect: "particulier").count + User.where(created_at: 1.month.ago.all_month, loged_in_with_france_connect: "particulier").count end end diff --git a/app/lib/redcarpet/bare_renderer.rb b/app/lib/redcarpet/bare_renderer.rb index 330195b1e..e672ee39a 100644 --- a/app/lib/redcarpet/bare_renderer.rb +++ b/app/lib/redcarpet/bare_renderer.rb @@ -4,7 +4,6 @@ module Redcarpet include ApplicationHelper # won't use rubocop tag method because it is missing output buffer - # rubocop:disable Rails/ContentTag def list(content, list_type) tag = list_type == :ordered ? :ol : :ul content_tag(tag, content, { class: @options[:class_names_map].fetch(:list) {} }, false) @@ -32,7 +31,5 @@ module Redcarpet link end end - - # rubocop:enable Rails/ContentTag end end diff --git a/app/models/avis.rb b/app/models/avis.rb index 4525be4d6..fed16957d 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -42,7 +42,6 @@ class Avis < ApplicationRecord size: { less_than: FILE_MAX_SIZE } validates :email, format: { with: Devise.email_regexp, message: "n'est pas valide" }, allow_nil: true - validates :claimant, presence: true validates :question_answer, inclusion: { in: [true, false] }, on: :update, if: -> { question_label.present? } validates :piece_justificative_file, size: { less_than: FILE_MAX_SIZE } validates :introduction_file, size: { less_than: FILE_MAX_SIZE } diff --git a/app/models/champs/multiple_drop_down_list_champ.rb b/app/models/champs/multiple_drop_down_list_champ.rb index 8c8999681..7b4d2d99a 100644 --- a/app/models/champs/multiple_drop_down_list_champ.rb +++ b/app/models/champs/multiple_drop_down_list_champ.rb @@ -118,7 +118,7 @@ class Champs::MultipleDropDownListChamp < Champ private def values_are_in_options - json = selected_options.reject(&:blank?) + json = selected_options.compact_blank return if json.empty? return if (json - enabled_non_empty_options).empty? diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index e18728e84..f5e3561e7 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -15,7 +15,6 @@ class Commentaire < ApplicationRecord include Discard::Model - self.ignored_columns = [:user_id] belongs_to :dossier, inverse_of: :commentaires, touch: true, optional: false belongs_to :instructeur, inverse_of: :commentaires, optional: true diff --git a/app/models/concerns/blob_virus_scanner_concern.rb b/app/models/concerns/blob_virus_scanner_concern.rb index 7c9a0d2c1..dd5fbdb51 100644 --- a/app/models/concerns/blob_virus_scanner_concern.rb +++ b/app/models/concerns/blob_virus_scanner_concern.rb @@ -2,7 +2,7 @@ module BlobVirusScannerConcern extend ActiveSupport::Concern included do - self.ignored_columns = [:lock_version] + self.ignored_columns += [:lock_version] before_create :set_pending end diff --git a/app/models/concerns/procedure_stats_concern.rb b/app/models/concerns/procedure_stats_concern.rb index 74f7dacd7..cfffaaa8c 100644 --- a/app/models/concerns/procedure_stats_concern.rb +++ b/app/models/concerns/procedure_stats_concern.rb @@ -108,7 +108,7 @@ module ProcedureStatsConcern end def last_considered_processed_at - (Time.zone.now - 1.month).end_of_month + (1.month.ago).end_of_month end def convert_seconds_in_days(seconds) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 5b6ddc16d..4cd72becb 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -46,7 +46,6 @@ # user_id :integer # class Dossier < ApplicationRecord - self.ignored_columns = [:en_construction_conservation_extension] include DossierFilteringConcern include DossierPrefillableConcern include DossierRebaseConcern @@ -281,13 +280,13 @@ class Dossier < ApplicationRecord scope :processed_in_month, -> (date) do date = date.to_datetime state_termine - .where(processed_at: date.beginning_of_month..date.end_of_month) + .where(processed_at: date.all_month) end scope :ordered_for_export, -> { order(depose_at: 'asc') } scope :en_cours, -> { not_archived.state_en_construction_ou_instruction } - scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) } + scope :without_followers, -> { where.missing(:follows) } scope :with_followers, -> { left_outer_joins(:follows).where.not(follows: { id: nil }) } scope :with_champs, -> { includes(champs_public: [ diff --git a/app/models/etablissement.rb b/app/models/etablissement.rb index fb6c6fc4d..bf870e110 100644 --- a/app/models/etablissement.rb +++ b/app/models/etablissement.rb @@ -144,7 +144,7 @@ class Etablissement < ApplicationRecord "#{numero_voie} #{type_voie} #{nom_voie}", complement_adresse, "#{code_postal} #{localite}" - ].reject(&:blank?).join(', ').squeeze(' ') + ].compact_blank.join(', ').squeeze(' ') end def association? diff --git a/app/models/instructeur.rb b/app/models/instructeur.rb index ac2ee5a29..c6685b57c 100644 --- a/app/models/instructeur.rb +++ b/app/models/instructeur.rb @@ -208,7 +208,7 @@ class Instructeur < ApplicationRecord h = { nb_en_construction: groupe.dossiers.visible_by_administration.en_construction.count, nb_en_instruction: groupe.dossiers.visible_by_administration.en_instruction.count, - nb_accepted: Traitement.where(dossier: groupe.dossiers.accepte, processed_at: Time.zone.yesterday.beginning_of_day..Time.zone.yesterday.end_of_day).count, + nb_accepted: Traitement.where(dossier: groupe.dossiers.accepte, processed_at: Time.zone.yesterday.all_day).count, nb_notification: nb_notification } diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 3b7ffee8b..1b0713dea 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -65,7 +65,7 @@ class Procedure < ApplicationRecord include Discard::Model self.discard_column = :hidden_at - self.ignored_columns = [:direction, :durees_conservation_required, :cerfa_flag, :test_started_at, :lien_demarche] + self.ignored_columns += [:direction, :durees_conservation_required, :cerfa_flag, :test_started_at, :lien_demarche] default_scope -> { kept } diff --git a/app/models/traitement.rb b/app/models/traitement.rb index 459eb3247..ebf3ee0d0 100644 --- a/app/models/traitement.rb +++ b/app/models/traitement.rb @@ -22,7 +22,8 @@ class Traitement < ApplicationRecord includes(:dossier) .termine .where(dossier: procedure.dossiers.visible_by_administration) - .where.not('dossiers.depose_at' => nil, processed_at: nil) + .where.not('dossiers.depose_at' => nil) + .where.not(processed_at: nil) .order(:processed_at) end end diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 3b00828c5..18720bb04 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -15,7 +15,7 @@ # stable_id :bigint # class TypeDeChamp < ApplicationRecord - self.ignored_columns = [:migrated_parent, :revision_id, :parent_id, :order_place] + self.ignored_columns += [:migrated_parent, :revision_id, :parent_id, :order_place] FILE_MAX_SIZE = 200.megabytes FEATURE_FLAGS = {} @@ -431,7 +431,7 @@ class TypeDeChamp < ApplicationRecord # then rails decided to add this blank ("") option when the select is required # so we revert this change def options_without_empty_value_when_mandatory(options) - mandatory? ? options.reject(&:blank?) : options + mandatory? ? options.compact_blank : options end def drop_down_list_options? diff --git a/app/models/types_de_champ/prefill_repetition_type_de_champ.rb b/app/models/types_de_champ/prefill_repetition_type_de_champ.rb index 61e3a15be..7ff8076ed 100644 --- a/app/models/types_de_champ/prefill_repetition_type_de_champ.rb +++ b/app/models/types_de_champ/prefill_repetition_type_de_champ.rb @@ -6,7 +6,7 @@ class TypesDeChamp::PrefillRepetitionTypeDeChamp < TypesDeChamp::PrefillTypeDeCh [ I18n.t("views.prefill_descriptions.edit.possible_values.#{type_champ}_html"), subchamps_all_possible_values - ].join("
").html_safe # rubocop:disable Rails/OutputSafety + ].join("
").html_safe end def example_value @@ -18,7 +18,7 @@ class TypesDeChamp::PrefillRepetitionTypeDeChamp < TypesDeChamp::PrefillTypeDeCh value.map.with_index do |repetition, index| PrefillRepetitionRow.new(champ, repetition, index, @revision).to_assignable_attributes - end.reject(&:blank?) + end.compact_blank end private diff --git a/app/models/types_de_champ/prefill_type_de_champ.rb b/app/models/types_de_champ/prefill_type_de_champ.rb index b36139e65..52b3a7315 100644 --- a/app/models/types_de_champ/prefill_type_de_champ.rb +++ b/app/models/types_de_champ/prefill_type_de_champ.rb @@ -83,6 +83,6 @@ class TypesDeChamp::PrefillTypeDeChamp < SimpleDelegator end def description - @description ||= I18n.t("views.prefill_descriptions.edit.possible_values.#{type_champ}_html", default: nil)&.html_safe # rubocop:disable Rails/OutputSafety + @description ||= I18n.t("views.prefill_descriptions.edit.possible_values.#{type_champ}_html", default: nil)&.html_safe end end diff --git a/app/services/zxcvbn_service.rb b/app/services/zxcvbn_service.rb index a6097ccc0..1930b66fe 100644 --- a/app/services/zxcvbn_service.rb +++ b/app/services/zxcvbn_service.rb @@ -19,7 +19,7 @@ class ZxcvbnService # # This is slow: loading and parsing the dictionary may take around 1s. def build_tester - dictionaries = YAML.safe_load(File.read(Rails.root.join("config", "initializers", "zxcvbn_dictionnaries.yaml"))) + dictionaries = YAML.safe_load(Rails.root.join("config", "initializers", "zxcvbn_dictionnaries.yaml").read) tester = Zxcvbn::Tester.new tester.add_word_lists(dictionaries) diff --git a/app/views/dossiers/dossier_vide.pdf.prawn b/app/views/dossiers/dossier_vide.pdf.prawn index d6146b7b4..13224475e 100644 --- a/app/views/dossiers/dossier_vide.pdf.prawn +++ b/app/views/dossiers/dossier_vide.pdf.prawn @@ -154,7 +154,7 @@ def render_single_champ(pdf, champ) add_libelle(pdf, champ) add_optionnal_description(pdf, champ) add_explanation(pdf, 'Cochez la mention applicable, une seule valeur possible') - champ.options.reject(&:blank?).each do |option| + champ.options.compact_blank.each do |option| format_with_checkbox(pdf, option) end pdf.text "\n" @@ -162,15 +162,15 @@ def render_single_champ(pdf, champ) add_libelle(pdf, champ) add_optionnal_description(pdf, champ) add_explanation(pdf, 'Cochez la mention applicable, plusieurs valeurs possibles') - champ.options.reject(&:blank?).each do |option| + champ.options.compact_blank.each do |option| format_with_checkbox(pdf, option) end pdf.text "\n" when 'Champs::LinkedDropDownListChamp' add_libelle(pdf, champ) - champ.primary_options.reject(&:blank?).each do |o| + champ.primary_options.compact_blank.each do |o| format_with_checkbox(pdf, o) - champ.secondary_options[o].reject(&:blank?).each do |secondary_option| + champ.secondary_options[o].compact_blank.each do |secondary_option| format_with_checkbox(pdf, secondary_option, 15) end end diff --git a/config/initializers/core_ext.rb b/config/initializers/core_ext.rb index 99b320fcd..44ae562d2 100644 --- a/config/initializers/core_ext.rb +++ b/config/initializers/core_ext.rb @@ -1,3 +1,3 @@ -Dir[File.join(Rails.root, "lib", "core_ext", "*.rb")].each do |core_ext_file| +Dir[Rails.root.join("lib", "core_ext", "*.rb")].each do |core_ext_file| require core_ext_file end diff --git a/lib/tasks/deployment/20210429172327_rename_conservation_extension.rake b/lib/tasks/deployment/20210429172327_rename_conservation_extension.rake index 8d4bf2c05..4b18077cf 100644 --- a/lib/tasks/deployment/20210429172327_rename_conservation_extension.rake +++ b/lib/tasks/deployment/20210429172327_rename_conservation_extension.rake @@ -16,7 +16,7 @@ namespace :after_party do end progress.finish - Dossier.ignored_columns = ignored_columns + Dossier.ignored_columns = ignored_columns # rubocop:disable Rails/IgnoredColumnsAssignment dossiers_without_conservation_extension = Dossier.where(conservation_extension: nil) progress = ProgressReport.new((dossiers_without_conservation_extension.count.to_f / BATCH_SIZE).round) diff --git a/lib/tasks/deployment/20220922151100_populate_zones.rake b/lib/tasks/deployment/20220922151100_populate_zones.rake index 3b1b1ad12..3db312eb1 100644 --- a/lib/tasks/deployment/20220922151100_populate_zones.rake +++ b/lib/tasks/deployment/20220922151100_populate_zones.rake @@ -7,7 +7,7 @@ namespace :after_party do coll_label = collectivite.labels.find_or_initialize_by(designated_on: Date.parse('1977-07-30')) coll_label.update(name: 'Collectivité territoriale') - config = Psych.safe_load(File.read(Rails.root.join("config", "zones.yml"))) + config = Psych.safe_load(Rails.root.join("config", "zones.yml").read) config["ministeres"].each do |ministere| acronym = ministere.keys.first zone = Zone.find_or_create_by!(acronym: acronym) diff --git a/lib/tasks/hotfix.rake b/lib/tasks/hotfix.rake index e03c0f35e..97e1625c9 100644 --- a/lib/tasks/hotfix.rake +++ b/lib/tasks/hotfix.rake @@ -3,10 +3,8 @@ namespace :hotfix do task dossiers_attestations: :environment do dossiers = Dossier .joins(procedure: :attestation_template) - .left_outer_joins(:attestation) - .where(attestation_templates: { activated: true }, - attestations: { id: nil }, - state: "accepte") + .where.missing(:attestation) + .where(attestation_templates: { activated: true }, state: "accepte") .where("dossiers.processed_at > '2022-01-24'") progress = ProgressReport.new(dossiers.count) diff --git a/spec/controllers/api/public/v1/dossiers_controller_spec.rb b/spec/controllers/api/public/v1/dossiers_controller_spec.rb index 09f85b55e..b6e40200f 100644 --- a/spec/controllers/api/public/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/public/v1/dossiers_controller_spec.rb @@ -35,9 +35,9 @@ RSpec.describe API::Public::V1::DossiersController, type: :controller do dossier = Dossier.last dossier_url = "http://test.host#{commencer_path(procedure.path, prefill_token: dossier.prefill_token)}" - expect(JSON.parse(response.body)["dossier_url"]).to eq(dossier_url) - expect(JSON.parse(response.body)["dossier_id"]).to eq(dossier.to_typed_id) - expect(JSON.parse(response.body)["dossier_number"]).to eq(dossier.id) + expect(response.parsed_body["dossier_url"]).to eq(dossier_url) + expect(response.parsed_body["dossier_id"]).to eq(dossier.to_typed_id) + expect(response.parsed_body["dossier_number"]).to eq(dossier.id) end context 'when prefill values are given' do @@ -141,7 +141,7 @@ RSpec.describe API::Public::V1::DossiersController, type: :controller do get :index, params: end - let(:body) { JSON.parse(response.body).map(&:deep_symbolize_keys) } + let(:body) { response.parsed_body.map(&:deep_symbolize_keys) } before { create_request } diff --git a/spec/controllers/api/public/v1/stats_controller_spec.rb b/spec/controllers/api/public/v1/stats_controller_spec.rb index 2ce5aa4fd..dac2fe7cf 100644 --- a/spec/controllers/api/public/v1/stats_controller_spec.rb +++ b/spec/controllers/api/public/v1/stats_controller_spec.rb @@ -14,7 +14,7 @@ RSpec.describe API::Public::V1::StatsController, type: :controller do it { expect(response).to be_successful } it { - expect(JSON.parse(response.body)).to match({ + expect(response.parsed_body).to match({ funnel: procedure.stats_dossiers_funnel.as_json, processed: procedure.stats_termines_states.as_json, processed_by_week: procedure.stats_termines_by_week.as_json, diff --git a/spec/controllers/champs/piece_justificative_controller_spec.rb b/spec/controllers/champs/piece_justificative_controller_spec.rb index aa983d745..49be46b79 100644 --- a/spec/controllers/champs/piece_justificative_controller_spec.rb +++ b/spec/controllers/champs/piece_justificative_controller_spec.rb @@ -65,7 +65,7 @@ describe Champs::PieceJustificativeController, type: :controller do subject expect(response.status).to eq(422) expect(response.header['Content-Type']).to include('application/json') - expect(JSON.parse(response.body)).to eq({ 'errors' => ['La pièce justificative n’est pas d’un type accepté'] }) + expect(response.parsed_body).to eq({ 'errors' => ['La pièce justificative n’est pas d’un type accepté'] }) end end diff --git a/spec/controllers/ping_controller_spec.rb b/spec/controllers/ping_controller_spec.rb index c1c811c63..5b9e8c123 100644 --- a/spec/controllers/ping_controller_spec.rb +++ b/spec/controllers/ping_controller_spec.rb @@ -13,8 +13,13 @@ describe PingController, type: :controller do end context 'when a maintenance file is present' do + let(:filepath) { Rails.root.join('maintenance') } before do - allow(File).to receive(:file?).and_return(true) + filepath.write("") + end + + after do + filepath.delete end it 'tells HAProxy that the app is in maintenance, but will be available again soon' do diff --git a/spec/controllers/webhook_controller_spec.rb b/spec/controllers/webhook_controller_spec.rb index e95a00cfb..65931d4fd 100644 --- a/spec/controllers/webhook_controller_spec.rb +++ b/spec/controllers/webhook_controller_spec.rb @@ -6,7 +6,7 @@ describe WebhookController, type: :controller do describe '#helpscout_support_dev' do subject(:response) { post :helpscout_support_dev, params: payload } - let(:payload) { JSON.parse(File.read(Rails.root.join('spec', 'fixtures', 'files', 'helpscout', 'tagged-dev.json'))) } + let(:payload) { JSON.parse(Rails.root.join('spec', 'fixtures', 'files', 'helpscout', 'tagged-dev.json').read) } let(:webhook_url) { "https://notification_url" } it 'works' do allow(Rails.application.secrets).to receive(:dig).with(:mattermost, :support_webhook_url).and_return(webhook_url) @@ -68,7 +68,7 @@ describe WebhookController, type: :controller do describe '#sendinblue' do subject(:response) { post :sendinblue, params: payload } - let(:payload) { JSON.parse(File.read(Rails.root.join('spec', 'fixtures', 'files', 'sendinblue', 'incident.json'))) } + let(:payload) { JSON.parse(Rails.root.join('spec', 'fixtures', 'files', 'sendinblue', 'incident.json').read) } it 'sends notification to mattermost' do notification_url = "https://notification_url" diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index 263af1076..b2b330bec 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -318,7 +318,7 @@ FactoryBot.define do published aasm_state { :close } - published_at { Time.zone.now - 1.second } + published_at { 1.second.ago } closed_at { Time.zone.now } end @@ -326,7 +326,7 @@ FactoryBot.define do published aasm_state { :depubliee } - published_at { Time.zone.now - 1.second } + published_at { 1.second.ago } unpublished_at { Time.zone.now } end diff --git a/spec/lib/tasks/graphql_spec.rb b/spec/lib/tasks/graphql_spec.rb index 24b772c9a..450a9d9e2 100644 --- a/spec/lib/tasks/graphql_spec.rb +++ b/spec/lib/tasks/graphql_spec.rb @@ -1,6 +1,6 @@ describe 'graphql' do let(:current_defn) { API::V2::Schema.to_definition } - let(:printout_defn) { File.read(Rails.root.join('app', 'graphql', 'schema.graphql')) } + let(:printout_defn) { Rails.root.join('app', 'graphql', 'schema.graphql').read } it "update the printed schema with `bin/rake graphql:schema:idl`" do result = GraphQL::SchemaComparator.compare(current_defn, printout_defn) diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index a6b8e0bbf..9a8260720 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -462,12 +462,12 @@ describe Procedure do end context "with token expired" do - let(:expiration_time) { (Time.zone.now - 1.day).to_i } + let(:expiration_time) { (1.day.ago).to_i } it { is_expected.to be_truthy } end context "with token not expired" do - let(:expiration_time) { (Time.zone.now + 1.day).to_i } + let(:expiration_time) { (1.day.from_now).to_i } it { is_expected.to be_falsey } end end diff --git a/spec/services/dossier_projection_service_spec.rb b/spec/services/dossier_projection_service_spec.rb index 6a09c4b26..ea72f3ba3 100644 --- a/spec/services/dossier_projection_service_spec.rb +++ b/spec/services/dossier_projection_service_spec.rb @@ -225,10 +225,12 @@ describe DossierProjectionService do let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :pays }]) } let(:dossier) { create(:dossier, procedure: procedure) } let(:column) { dossier.procedure.active_revision.types_de_champ_public.first.stable_id.to_s } - let!(:previous_locale) { I18n.locale } - before { I18n.locale = :fr } - after { I18n.locale = previous_locale } + around do |example| + I18n.with_locale(:fr) do + example.run + end + end context 'when external id is set' do before do