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
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

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 }

View file

@ -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?

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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: [

View file

@ -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?

View file

@ -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
}

View file

@ -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 }

View file

@ -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

View file

@ -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?

View file

@ -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("</br>").html_safe # rubocop:disable Rails/OutputSafety
].join("</br>").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

View file

@ -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

View file

@ -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)

View file

@ -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

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
end

View file

@ -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)

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.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)

View file

@ -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)

View file

@ -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 }

View file

@ -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,

View file

@ -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 nest pas dun type accepté'] })
expect(response.parsed_body).to eq({ 'errors' => ['La pièce justificative nest pas dun type accepté'] })
end
end

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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