Merge pull request #8924 from colinux/rubocop-upgrades

Tech: update rubocop, active nouveaux cops Rails/*
This commit is contained in:
Colin Darie 2023-04-19 13:37:10 +00:00 committed by GitHub
commit 9728493bda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 206 additions and 85 deletions

View file

@ -14,6 +14,7 @@ AllCops:
TargetRubyVersion: 3.1 TargetRubyVersion: 3.1
DisabledByDefault: true DisabledByDefault: true
SuggestExtensions: false SuggestExtensions: false
NewCops: enable
Include: Include:
- "app/**/*.prawn" - "app/**/*.prawn"
Exclude: Exclude:
@ -683,9 +684,18 @@ Performance/UriDefaultParser:
Rails: Rails:
Enabled: true Enabled: true
Rails/ActionControllerFlashBeforeRender:
Enabled: true
Rails/ActionControllerTestCase:
Enabled: true
Rails/ActionFilter: Rails/ActionFilter:
Enabled: true Enabled: true
Rails/ActionOrder:
Enabled: false
Rails/ActiveRecordAliases: Rails/ActiveRecordAliases:
Enabled: true Enabled: true
@ -695,18 +705,24 @@ Rails/ActiveRecordCallbacksOrder:
Rails/ActiveSupportAliases: Rails/ActiveSupportAliases:
Enabled: true Enabled: true
Rails/ActiveSupportOnLoad:
Enabled: true
Rails/AddColumnIndex:
Enabled: true
Rails/AfterCommitOverride: Rails/AfterCommitOverride:
Enabled: true Enabled: true
Rails/ApplicationController:
Enabled: false
Rails/ApplicationJob: Rails/ApplicationJob:
Enabled: true Enabled: true
Rails/ApplicationRecord: Rails/ApplicationRecord:
Enabled: true Enabled: true
Rails/ApplicationController:
Enabled: false
Rails/AttributeDefaultBlockValue: Rails/AttributeDefaultBlockValue:
Enabled: true Enabled: true
@ -716,6 +732,9 @@ Rails/Blank:
Rails/BulkChangeTable: Rails/BulkChangeTable:
Enabled: false Enabled: false
Rails/CompactBlank:
Enabled: true
Rails/CreateTableWithTimestamps: Rails/CreateTableWithTimestamps:
Enabled: true Enabled: true
Exclude: Exclude:
@ -734,10 +753,28 @@ Rails/Delegate:
Rails/DelegateAllowBlank: Rails/DelegateAllowBlank:
Enabled: true 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: Rails/DynamicFindBy:
Enabled: true Enabled: true
Exclude: Exclude:
- "spec/system/**/*.rb" - spec/system/**/*.rb
Rails/EagerEvaluationLogMessage:
Enabled: true
Rails/EnumUniqueness: Rails/EnumUniqueness:
Enabled: true Enabled: true
@ -748,6 +785,9 @@ Rails/EnvironmentComparison:
Rails/Exit: Rails/Exit:
Enabled: true Enabled: true
Rails/ExpandedDateRange:
Enabled: true
Rails/FilePath: Rails/FilePath:
Enabled: false Enabled: false
@ -760,6 +800,9 @@ Rails/FindById:
Rails/FindEach: Rails/FindEach:
Enabled: true Enabled: true
Rails/FreezeTime:
Enabled: true
Rails/HasAndBelongsToMany: Rails/HasAndBelongsToMany:
Enabled: false Enabled: false
@ -772,6 +815,18 @@ Rails/HttpPositionalArguments:
Rails/HttpStatus: Rails/HttpStatus:
Enabled: false Enabled: false
Rails/I18nLazyLookup:
Enabled: true
Rails/I18nLocaleAssignment:
Enabled: true
Rails/I18nLocaleTexts:
Enabled: false
Rails/IgnoredColumnsAssignment:
Enabled: true
Rails/Inquiry: Rails/Inquiry:
Enabled: true Enabled: true
@ -787,6 +842,9 @@ Rails/MailerName:
Rails/MatchRoute: Rails/MatchRoute:
Enabled: true Enabled: true
Rails/MigrationClassName:
Enabled: true
Rails/NegateInclude: Rails/NegateInclude:
Enabled: false Enabled: false
@ -823,9 +881,15 @@ Rails/ReadWriteAttribute:
Rails/RedundantAllowNil: Rails/RedundantAllowNil:
Enabled: false Enabled: false
Rails/RedundantPresenceValidationOnBelongsTo:
Enabled: true
Rails/RedundantReceiverInWithOptions: Rails/RedundantReceiverInWithOptions:
Enabled: true Enabled: true
Rails/RedundantTravelBack:
Enabled: true
Rails/RelativeDateConstant: Rails/RelativeDateConstant:
Enabled: true Enabled: true
@ -838,9 +902,21 @@ Rails/RenderPlainText:
Rails/RequestReferer: Rails/RequestReferer:
Enabled: true Enabled: true
Rails/ResponseParsedBody:
Enabled: true
Rails/ReversibleMigration: Rails/ReversibleMigration:
Enabled: false Enabled: false
Rails/RootJoinChain:
Enabled: true
Rails/RootPathnameMethods:
Enabled: true
Rails/RootPublicPath:
Enabled: true
Rails/SaveBang: Rails/SaveBang:
Enabled: false Enabled: false
@ -856,9 +932,37 @@ Rails/SkipsModelValidations:
Rails/SquishedSQLHeredocs: Rails/SquishedSQLHeredocs:
Enabled: true 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: Rails/TimeZone:
EnforcedStyle: strict EnforcedStyle: strict
Rails/TimeZoneAssignment:
Enabled: true
Rails/ToFormattedS:
Enabled: true
Rails/ToSWithArgument:
Enabled: true
Rails/TopLevelHashWithIndifferentAccess:
Enabled: true
Rails/TransactionExitStatement:
Enabled: true
Rails/UniqBeforePluck: Rails/UniqBeforePluck:
Enabled: true Enabled: true
@ -868,6 +972,9 @@ Rails/UniqueValidationWithoutIndex:
Rails/UnknownEnv: Rails/UnknownEnv:
Enabled: false Enabled: false
Rails/UnusedIgnoredColumns:
Enabled: true
Rails/Validation: Rails/Validation:
Enabled: true Enabled: true
@ -877,9 +984,15 @@ Rails/WhereEquals:
Rails/WhereExists: Rails/WhereExists:
Enabled: true Enabled: true
Rails/WhereMissing:
Enabled: true
Rails/WhereNot: Rails/WhereNot:
Enabled: true Enabled: true
Rails/WhereNotWithMultipleConditions:
Enabled: true
RSpec/Focus: RSpec/Focus:
Enabled: true Enabled: true
@ -1039,6 +1152,12 @@ Style/EvenOdd:
Style/ExpandPathArguments: Style/ExpandPathArguments:
Enabled: true Enabled: true
Style/FileRead:
Enabled: true
Style/FileWrite:
Enabled: true
Style/For: Style/For:
Enabled: true Enabled: true

View file

@ -473,9 +473,9 @@ GEM
validate_url validate_url
webfinger (>= 1.0.1) webfinger (>= 1.0.1)
orm_adapter (0.5.0) orm_adapter (0.5.0)
parallel (1.22.1) parallel (1.23.0)
parsby (1.1.1) parsby (1.1.1)
parser (3.1.2.1) parser (3.2.2.0)
ast (~> 2.4.1) ast (~> 2.4.1)
pdf-core (0.9.0) pdf-core (0.9.0)
pg (1.2.3) pg (1.2.3)
@ -577,7 +577,7 @@ GEM
rb-inotify (0.10.1) rb-inotify (0.10.1)
ffi (~> 1.0) ffi (~> 1.0)
redcarpet (3.6.0) redcarpet (3.6.0)
regexp_parser (2.7.0) regexp_parser (2.8.0)
request_store (1.5.0) request_store (1.5.0)
rack (>= 1.4) rack (>= 1.4)
responders (3.0.1) responders (3.0.1)
@ -621,31 +621,33 @@ GEM
rspec-support (3.10.2) rspec-support (3.10.2)
rspec_junit_formatter (0.4.1) rspec_junit_formatter (0.4.1)
rspec-core (>= 2, < 4, != 2.12.0) rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.36.0) rubocop (1.50.2)
json (~> 2.3) json (~> 2.3)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 3.1.2.1) parser (>= 3.2.0.0)
rainbow (>= 2.2.2, < 4.0) rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0) regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.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) ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0) unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.21.0) rubocop-ast (1.28.0)
parser (>= 3.1.1.0) parser (>= 3.2.1.0)
rubocop-performance (1.9.2) rubocop-capybara (2.17.1)
rubocop (>= 0.90.0, < 2.0) rubocop (~> 1.41)
rubocop-performance (1.17.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0) rubocop-ast (>= 0.4.0)
rubocop-rails (2.9.1) rubocop-rails (2.19.1)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
rack (>= 1.1) rack (>= 1.1)
rubocop (>= 0.90.0, < 2.0) rubocop (>= 1.33.0, < 2.0)
rubocop-rspec (2.4.0) rubocop-rspec (2.20.0)
rubocop (~> 1.0) rubocop (~> 1.33)
rubocop-ast (>= 1.1.0) rubocop-capybara (~> 2.17)
ruby-graphviz (1.2.5) ruby-graphviz (1.2.5)
rexml rexml
ruby-progressbar (1.11.0) ruby-progressbar (1.13.0)
ruby-vips (2.1.4) ruby-vips (2.1.4)
ffi (~> 1.12) ffi (~> 1.12)
ruby2_keywords (0.0.5) ruby2_keywords (0.0.5)
@ -756,7 +758,7 @@ GEM
unf (0.1.4) unf (0.1.4)
unf_ext unf_ext
unf_ext (0.0.7.7) unf_ext (0.0.7.7)
unicode-display_width (2.3.0) unicode-display_width (2.4.2)
uri_template (0.7.0) uri_template (0.7.0)
validate_email (0.1.6) validate_email (0.1.6)
activemodel (>= 3.0) activemodel (>= 3.0)

View file

@ -1,7 +1,7 @@
class PingController < ApplicationController class PingController < ApplicationController
def index def index
Rails.logger.silence do 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 # See https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#4.2-http-check%20disable-on-404
:not_found :not_found
elsif (ActiveRecord::Base.connection.execute('select 1 as test;').first['test'] == 1) elsif (ActiveRecord::Base.connection.execute('select 1 as test;').first['test'] == 1)

View file

@ -73,7 +73,7 @@ class SupportController < ApplicationController
[params[:tags], params[:type]].flatten.compact [params[:tags], params[:type]].flatten.compact
.map { |tag| tag.split(',') } .map { |tag| tag.split(',') }
.flatten .flatten
.reject(&:blank?).uniq .compact_blank.uniq
end end
def browser_name def browser_name

View file

@ -84,10 +84,10 @@ module DossierHelper
def deletion_reason_badge(reason) def deletion_reason_badge(reason)
if reason.present? 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('_', '-') status_class = reason.tr('_', '-')
else 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' status_class = 'unknown'
end end

View file

@ -14,6 +14,6 @@ class Cron::Datagouv::AccountByMonthJob < Cron::CronJob
end end
def data 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
end end

View file

@ -14,6 +14,6 @@ class Cron::Datagouv::AdministrateurByMonthJob < Cron::CronJob
end end
def data 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
end end

View file

@ -14,6 +14,6 @@ class Cron::Datagouv::FileByMonthJob < Cron::CronJob
end end
def data 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
end end

View file

@ -14,6 +14,6 @@ class Cron::Datagouv::FileDeposeByMonthJob < Cron::CronJob
end end
def data 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
end end

View file

@ -14,6 +14,6 @@ class Cron::Datagouv::InstructeurByMonthJob < Cron::CronJob
end end
def data 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
end end

View file

@ -14,6 +14,6 @@ class Cron::Datagouv::InstructeurConnectedByMonthJob < Cron::CronJob
end end
def data 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
end end

View file

@ -14,6 +14,6 @@ class Cron::Datagouv::ProcedureByMonthJob < Cron::CronJob
end end
def data 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
end end

View file

@ -14,6 +14,6 @@ class Cron::Datagouv::ProcedureClosedByMonthJob < Cron::CronJob
end end
def data 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
end end

View file

@ -14,6 +14,6 @@ class Cron::Datagouv::ProcedureDeletedByMonthJob < Cron::CronJob
end end
def data 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
end end

View file

@ -14,6 +14,6 @@ class Cron::Datagouv::UserConnectedWithFranceConnectByMonthJob < Cron::CronJob
end end
def data 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
end end

View file

@ -4,7 +4,6 @@ module Redcarpet
include ApplicationHelper include ApplicationHelper
# won't use rubocop tag method because it is missing output buffer # won't use rubocop tag method because it is missing output buffer
# rubocop:disable Rails/ContentTag
def list(content, list_type) def list(content, list_type)
tag = list_type == :ordered ? :ol : :ul tag = list_type == :ordered ? :ol : :ul
content_tag(tag, content, { class: @options[:class_names_map].fetch(:list) {} }, false) content_tag(tag, content, { class: @options[:class_names_map].fetch(:list) {} }, false)
@ -32,7 +31,5 @@ module Redcarpet
link link
end end
end end
# rubocop:enable Rails/ContentTag
end end
end end

View file

@ -42,7 +42,6 @@ class Avis < ApplicationRecord
size: { less_than: FILE_MAX_SIZE } size: { less_than: FILE_MAX_SIZE }
validates :email, format: { with: Devise.email_regexp, message: "n'est pas valide" }, allow_nil: true 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 :question_answer, inclusion: { in: [true, false] }, on: :update, if: -> { question_label.present? }
validates :piece_justificative_file, size: { less_than: FILE_MAX_SIZE } validates :piece_justificative_file, size: { less_than: FILE_MAX_SIZE }
validates :introduction_file, size: { less_than: FILE_MAX_SIZE } validates :introduction_file, size: { less_than: FILE_MAX_SIZE }

View file

@ -118,7 +118,7 @@ class Champs::MultipleDropDownListChamp < Champ
private private
def values_are_in_options def values_are_in_options
json = selected_options.reject(&:blank?) json = selected_options.compact_blank
return if json.empty? return if json.empty?
return if (json - enabled_non_empty_options).empty? return if (json - enabled_non_empty_options).empty?

View file

@ -15,7 +15,6 @@
class Commentaire < ApplicationRecord class Commentaire < ApplicationRecord
include Discard::Model include Discard::Model
self.ignored_columns = [:user_id]
belongs_to :dossier, inverse_of: :commentaires, touch: true, optional: false belongs_to :dossier, inverse_of: :commentaires, touch: true, optional: false
belongs_to :instructeur, inverse_of: :commentaires, optional: true belongs_to :instructeur, inverse_of: :commentaires, optional: true

View file

@ -2,7 +2,7 @@ module BlobVirusScannerConcern
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
self.ignored_columns = [:lock_version] self.ignored_columns += [:lock_version]
before_create :set_pending before_create :set_pending
end end

View file

@ -108,7 +108,7 @@ module ProcedureStatsConcern
end end
def last_considered_processed_at def last_considered_processed_at
(Time.zone.now - 1.month).end_of_month (1.month.ago).end_of_month
end end
def convert_seconds_in_days(seconds) def convert_seconds_in_days(seconds)

View file

@ -46,7 +46,6 @@
# user_id :integer # user_id :integer
# #
class Dossier < ApplicationRecord class Dossier < ApplicationRecord
self.ignored_columns = [:en_construction_conservation_extension]
include DossierFilteringConcern include DossierFilteringConcern
include DossierPrefillableConcern include DossierPrefillableConcern
include DossierRebaseConcern include DossierRebaseConcern
@ -281,13 +280,13 @@ class Dossier < ApplicationRecord
scope :processed_in_month, -> (date) do scope :processed_in_month, -> (date) do
date = date.to_datetime date = date.to_datetime
state_termine state_termine
.where(processed_at: date.beginning_of_month..date.end_of_month) .where(processed_at: date.all_month)
end end
scope :ordered_for_export, -> { scope :ordered_for_export, -> {
order(depose_at: 'asc') order(depose_at: 'asc')
} }
scope :en_cours, -> { not_archived.state_en_construction_ou_instruction } 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_followers, -> { left_outer_joins(:follows).where.not(follows: { id: nil }) }
scope :with_champs, -> { scope :with_champs, -> {
includes(champs_public: [ includes(champs_public: [

View file

@ -144,7 +144,7 @@ class Etablissement < ApplicationRecord
"#{numero_voie} #{type_voie} #{nom_voie}", "#{numero_voie} #{type_voie} #{nom_voie}",
complement_adresse, complement_adresse,
"#{code_postal} #{localite}" "#{code_postal} #{localite}"
].reject(&:blank?).join(', ').squeeze(' ') ].compact_blank.join(', ').squeeze(' ')
end end
def association? def association?

View file

@ -208,7 +208,7 @@ class Instructeur < ApplicationRecord
h = { h = {
nb_en_construction: groupe.dossiers.visible_by_administration.en_construction.count, nb_en_construction: groupe.dossiers.visible_by_administration.en_construction.count,
nb_en_instruction: groupe.dossiers.visible_by_administration.en_instruction.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 nb_notification: nb_notification
} }

View file

@ -65,7 +65,7 @@ class Procedure < ApplicationRecord
include Discard::Model include Discard::Model
self.discard_column = :hidden_at 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 } default_scope -> { kept }

View file

@ -22,7 +22,8 @@ class Traitement < ApplicationRecord
includes(:dossier) includes(:dossier)
.termine .termine
.where(dossier: procedure.dossiers.visible_by_administration) .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) .order(:processed_at)
end end
end end

View file

@ -15,7 +15,7 @@
# stable_id :bigint # stable_id :bigint
# #
class TypeDeChamp < ApplicationRecord 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 FILE_MAX_SIZE = 200.megabytes
FEATURE_FLAGS = {} FEATURE_FLAGS = {}
@ -431,7 +431,7 @@ class TypeDeChamp < ApplicationRecord
# then rails decided to add this blank ("") option when the select is required # then rails decided to add this blank ("") option when the select is required
# so we revert this change # so we revert this change
def options_without_empty_value_when_mandatory(options) def options_without_empty_value_when_mandatory(options)
mandatory? ? options.reject(&:blank?) : options mandatory? ? options.compact_blank : options
end end
def drop_down_list_options? def drop_down_list_options?

View file

@ -6,7 +6,7 @@ class TypesDeChamp::PrefillRepetitionTypeDeChamp < TypesDeChamp::PrefillTypeDeCh
[ [
I18n.t("views.prefill_descriptions.edit.possible_values.#{type_champ}_html"), I18n.t("views.prefill_descriptions.edit.possible_values.#{type_champ}_html"),
subchamps_all_possible_values subchamps_all_possible_values
].join("</br>").html_safe # rubocop:disable Rails/OutputSafety ].join("</br>").html_safe
end end
def example_value def example_value
@ -18,7 +18,7 @@ class TypesDeChamp::PrefillRepetitionTypeDeChamp < TypesDeChamp::PrefillTypeDeCh
value.map.with_index do |repetition, index| value.map.with_index do |repetition, index|
PrefillRepetitionRow.new(champ, repetition, index, @revision).to_assignable_attributes PrefillRepetitionRow.new(champ, repetition, index, @revision).to_assignable_attributes
end.reject(&:blank?) end.compact_blank
end end
private private

View file

@ -83,6 +83,6 @@ class TypesDeChamp::PrefillTypeDeChamp < SimpleDelegator
end end
def description 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
end end

View file

@ -19,7 +19,7 @@ class ZxcvbnService
# #
# This is slow: loading and parsing the dictionary may take around 1s. # This is slow: loading and parsing the dictionary may take around 1s.
def build_tester 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 = Zxcvbn::Tester.new
tester.add_word_lists(dictionaries) tester.add_word_lists(dictionaries)

View file

@ -154,7 +154,7 @@ def render_single_champ(pdf, champ)
add_libelle(pdf, champ) add_libelle(pdf, champ)
add_optionnal_description(pdf, champ) add_optionnal_description(pdf, champ)
add_explanation(pdf, 'Cochez la mention applicable, une seule valeur possible') 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) format_with_checkbox(pdf, option)
end end
pdf.text "\n" pdf.text "\n"
@ -162,15 +162,15 @@ def render_single_champ(pdf, champ)
add_libelle(pdf, champ) add_libelle(pdf, champ)
add_optionnal_description(pdf, champ) add_optionnal_description(pdf, champ)
add_explanation(pdf, 'Cochez la mention applicable, plusieurs valeurs possibles') 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) format_with_checkbox(pdf, option)
end end
pdf.text "\n" pdf.text "\n"
when 'Champs::LinkedDropDownListChamp' when 'Champs::LinkedDropDownListChamp'
add_libelle(pdf, champ) 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) 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) format_with_checkbox(pdf, secondary_option, 15)
end end
end end

View file

@ -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 require core_ext_file
end end

View file

@ -16,7 +16,7 @@ namespace :after_party do
end end
progress.finish 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) dossiers_without_conservation_extension = Dossier.where(conservation_extension: nil)
progress = ProgressReport.new((dossiers_without_conservation_extension.count.to_f / BATCH_SIZE).round) progress = ProgressReport.new((dossiers_without_conservation_extension.count.to_f / BATCH_SIZE).round)

View file

@ -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 = collectivite.labels.find_or_initialize_by(designated_on: Date.parse('1977-07-30'))
coll_label.update(name: 'Collectivité territoriale') 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| config["ministeres"].each do |ministere|
acronym = ministere.keys.first acronym = ministere.keys.first
zone = Zone.find_or_create_by!(acronym: acronym) zone = Zone.find_or_create_by!(acronym: acronym)

View file

@ -3,10 +3,8 @@ namespace :hotfix do
task dossiers_attestations: :environment do task dossiers_attestations: :environment do
dossiers = Dossier dossiers = Dossier
.joins(procedure: :attestation_template) .joins(procedure: :attestation_template)
.left_outer_joins(:attestation) .where.missing(:attestation)
.where(attestation_templates: { activated: true }, .where(attestation_templates: { activated: true }, state: "accepte")
attestations: { id: nil },
state: "accepte")
.where("dossiers.processed_at > '2022-01-24'") .where("dossiers.processed_at > '2022-01-24'")
progress = ProgressReport.new(dossiers.count) progress = ProgressReport.new(dossiers.count)

View file

@ -35,9 +35,9 @@ RSpec.describe API::Public::V1::DossiersController, type: :controller do
dossier = Dossier.last dossier = Dossier.last
dossier_url = "http://test.host#{commencer_path(procedure.path, prefill_token: dossier.prefill_token)}" 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(response.parsed_body["dossier_url"]).to eq(dossier_url)
expect(JSON.parse(response.body)["dossier_id"]).to eq(dossier.to_typed_id) expect(response.parsed_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_number"]).to eq(dossier.id)
end end
context 'when prefill values are given' do context 'when prefill values are given' do
@ -141,7 +141,7 @@ RSpec.describe API::Public::V1::DossiersController, type: :controller do
get :index, params: get :index, params:
end end
let(:body) { JSON.parse(response.body).map(&:deep_symbolize_keys) } let(:body) { response.parsed_body.map(&:deep_symbolize_keys) }
before { create_request } before { create_request }

View file

@ -14,7 +14,7 @@ RSpec.describe API::Public::V1::StatsController, type: :controller do
it { expect(response).to be_successful } it { expect(response).to be_successful }
it { it {
expect(JSON.parse(response.body)).to match({ expect(response.parsed_body).to match({
funnel: procedure.stats_dossiers_funnel.as_json, funnel: procedure.stats_dossiers_funnel.as_json,
processed: procedure.stats_termines_states.as_json, processed: procedure.stats_termines_states.as_json,
processed_by_week: procedure.stats_termines_by_week.as_json, processed_by_week: procedure.stats_termines_by_week.as_json,

View file

@ -65,7 +65,7 @@ describe Champs::PieceJustificativeController, type: :controller do
subject subject
expect(response.status).to eq(422) expect(response.status).to eq(422)
expect(response.header['Content-Type']).to include('application/json') expect(response.header['Content-Type']).to include('application/json')
expect(JSON.parse(response.body)).to eq({ 'errors' => ['La pièce justificative nest pas dun type accepté'] }) expect(response.parsed_body).to eq({ 'errors' => ['La pièce justificative nest pas dun type accepté'] })
end end
end end

View file

@ -13,8 +13,13 @@ describe PingController, type: :controller do
end end
context 'when a maintenance file is present' do context 'when a maintenance file is present' do
let(:filepath) { Rails.root.join('maintenance') }
before do before do
allow(File).to receive(:file?).and_return(true) filepath.write("")
end
after do
filepath.delete
end end
it 'tells HAProxy that the app is in maintenance, but will be available again soon' do it 'tells HAProxy that the app is in maintenance, but will be available again soon' do

View file

@ -6,7 +6,7 @@ describe WebhookController, type: :controller do
describe '#helpscout_support_dev' do describe '#helpscout_support_dev' do
subject(:response) { post :helpscout_support_dev, params: payload } 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" } let(:webhook_url) { "https://notification_url" }
it 'works' do it 'works' do
allow(Rails.application.secrets).to receive(:dig).with(:mattermost, :support_webhook_url).and_return(webhook_url) 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 describe '#sendinblue' do
subject(:response) { post :sendinblue, params: payload } 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 it 'sends notification to mattermost' do
notification_url = "https://notification_url" notification_url = "https://notification_url"

View file

@ -318,7 +318,7 @@ FactoryBot.define do
published published
aasm_state { :close } aasm_state { :close }
published_at { Time.zone.now - 1.second } published_at { 1.second.ago }
closed_at { Time.zone.now } closed_at { Time.zone.now }
end end
@ -326,7 +326,7 @@ FactoryBot.define do
published published
aasm_state { :depubliee } aasm_state { :depubliee }
published_at { Time.zone.now - 1.second } published_at { 1.second.ago }
unpublished_at { Time.zone.now } unpublished_at { Time.zone.now }
end end

View file

@ -1,6 +1,6 @@
describe 'graphql' do describe 'graphql' do
let(:current_defn) { API::V2::Schema.to_definition } 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 it "update the printed schema with `bin/rake graphql:schema:idl`" do
result = GraphQL::SchemaComparator.compare(current_defn, printout_defn) result = GraphQL::SchemaComparator.compare(current_defn, printout_defn)

View file

@ -462,12 +462,12 @@ describe Procedure do
end end
context "with token expired" do 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 } it { is_expected.to be_truthy }
end end
context "with token not expired" do 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 } it { is_expected.to be_falsey }
end end
end end

View file

@ -225,10 +225,12 @@ describe DossierProjectionService do
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :pays }]) } let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :pays }]) }
let(:dossier) { create(:dossier, procedure: procedure) } let(:dossier) { create(:dossier, procedure: procedure) }
let(:column) { dossier.procedure.active_revision.types_de_champ_public.first.stable_id.to_s } let(:column) { dossier.procedure.active_revision.types_de_champ_public.first.stable_id.to_s }
let!(:previous_locale) { I18n.locale }
before { I18n.locale = :fr } around do |example|
after { I18n.locale = previous_locale } I18n.with_locale(:fr) do
example.run
end
end
context 'when external id is set' do context 'when external id is set' do
before do before do