diff --git a/.rubocop.yml b/.rubocop.yml index f5abc6b74..6c9c0f40a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -640,22 +640,22 @@ Performance/UriDefaultParser: Enabled: true Rails/ActionFilter: - Enabled: false + Enabled: true Rails/ActiveRecordAliases: Enabled: true Rails/ActiveSupportAliases: - Enabled: false + Enabled: true Rails/ApplicationJob: - Enabled: false + Enabled: true Rails/ApplicationRecord: - Enabled: false + Enabled: true Rails/Blank: - Enabled: false + Enabled: true Rails/CreateTableWithTimestamps: Enabled: false @@ -667,28 +667,30 @@ Rails/Delegate: Enabled: false Rails/DelegateAllowBlank: - Enabled: false + Enabled: true Rails/DynamicFindBy: - Enabled: false + Enabled: true + Exclude: + - "spec/features/**/*.rb" Rails/EnumUniqueness: - Enabled: false + Enabled: true Rails/EnvironmentComparison: Enabled: false Rails/Exit: - Enabled: false + Enabled: true Rails/FilePath: - Enabled: false + Enabled: true Rails/FindBy: - Enabled: false + Enabled: true Rails/FindEach: - Enabled: false + Enabled: true Rails/HasAndBelongsToMany: Enabled: false @@ -697,7 +699,7 @@ Rails/HasManyOrHasOneDependent: Enabled: false Rails/HttpPositionalArguments: - Enabled: false + Enabled: true Rails/InverseOf: Enabled: false @@ -715,10 +717,10 @@ Rails/OutputSafety: Enabled: true Rails/PluralizationGrammar: - Enabled: false + Enabled: true Rails/Presence: - Enabled: false + Enabled: true Rails/Present: Enabled: true @@ -730,22 +732,22 @@ Rails/RedundantReceiverInWithOptions: Enabled: true Rails/RelativeDateConstant: - Enabled: false + Enabled: true Rails/RequestReferer: - Enabled: false + Enabled: true Rails/ReversibleMigration: Enabled: false Rails/SafeNavigation: - Enabled: false + Enabled: true Rails/SaveBang: Enabled: false Rails/ScopeArgs: - Enabled: false + Enabled: true Rails/SkipsModelValidations: Enabled: false @@ -754,13 +756,13 @@ Rails/TimeZone: Enabled: false Rails/UniqBeforePluck: - Enabled: false + Enabled: true Rails/UnknownEnv: Enabled: false Rails/Validation: - Enabled: false + Enabled: true Rails: Enabled: true diff --git a/app/controllers/admin/gestionnaires_controller.rb b/app/controllers/admin/gestionnaires_controller.rb index f6bdb1966..2ca3bdaa9 100644 --- a/app/controllers/admin/gestionnaires_controller.rb +++ b/app/controllers/admin/gestionnaires_controller.rb @@ -19,7 +19,7 @@ class Admin::GestionnairesController < AdminController def create email = params[:gestionnaire][:email].downcase - @gestionnaire = Gestionnaire.find_by_email(email) + @gestionnaire = Gestionnaire.find_by(email: email) procedure_id = params[:procedure_id] if @gestionnaire.nil? diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 511024182..e3e834d55 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -132,7 +132,7 @@ class Admin::ProceduresController < AdminController return redirect_to admin_procedures_path end - procedure_path = ProcedurePath.find_by_path(params[:procedure_path]) + procedure_path = ProcedurePath.find_by(path: params[:procedure_path]) if procedure_path if procedure_path.administrateur_id == current_administrateur.id procedure_path.procedure.archive @@ -154,7 +154,7 @@ class Admin::ProceduresController < AdminController end def transfer - admin = Administrateur.find_by_email(params[:email_admin].downcase) + admin = Administrateur.find_by(email: params[:email_admin].downcase) if admin.nil? render '/admin/procedures/transfer', formats: 'js', status: 404 diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 255f9809a..3f561fb23 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -13,7 +13,7 @@ class APIController < ApplicationController end def current_administrateur - @administrateur ||= Administrateur.find_by_api_token(params[:token]) + @administrateur ||= Administrateur.find_by(api_token: params[:token]) end def default_format_json diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb index 9a3c635fc..6405bca0f 100644 --- a/app/controllers/invites_controller.rb +++ b/app/controllers/invites_controller.rb @@ -9,7 +9,7 @@ class InvitesController < ApplicationController email = params[:email].downcase - user = User.find_by_email(email) + user = User.find_by(email: email) invite = class_var.create(dossier: dossier, user: user, email: email, email_sender: email_sender) if invite.valid? diff --git a/app/controllers/new_gestionnaire/avis_controller.rb b/app/controllers/new_gestionnaire/avis_controller.rb index 814f3c4ba..07367a7fd 100644 --- a/app/controllers/new_gestionnaire/avis_controller.rb +++ b/app/controllers/new_gestionnaire/avis_controller.rb @@ -13,7 +13,7 @@ module NewGestionnaire @avis_a_donner = gestionnaire_avis.without_answer @avis_donnes = gestionnaire_avis.with_answer - @statut = params[:statut].present? ? params[:statut] : A_DONNER_STATUS + @statut = params[:statut].presence || A_DONNER_STATUS @avis = case @statut when A_DONNER_STATUS diff --git a/app/controllers/new_gestionnaire/procedures_controller.rb b/app/controllers/new_gestionnaire/procedures_controller.rb index a7b557d54..aefe3fa26 100644 --- a/app/controllers/new_gestionnaire/procedures_controller.rb +++ b/app/controllers/new_gestionnaire/procedures_controller.rb @@ -76,7 +76,7 @@ module NewGestionnaire filtered_sorted_ids = sorted_ids end - page = params[:page].present? ? params[:page] : 1 + page = params[:page].presence || 1 filtered_sorted_paginated_ids = Kaminari .paginate_array(filtered_sorted_ids) @@ -187,7 +187,7 @@ module NewGestionnaire private def statut - @statut ||= params[:statut].present? ? params[:statut] : 'a-suivre' + @statut ||= (params[:statut].presence || 'a-suivre') end def procedure diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 470710103..c0e7c37b7 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -170,7 +170,7 @@ class StatsController < ApplicationController end def avis_usage - [3.week.ago, 2.week.ago, 1.week.ago].map do |min_date| + [3.weeks.ago, 2.weeks.ago, 1.week.ago].map do |min_date| max_date = min_date + 1.week weekly_dossiers = Dossier.includes(:avis).where(created_at: min_date..max_date).to_a @@ -189,7 +189,7 @@ class StatsController < ApplicationController end def avis_average_answer_time - [3.week.ago, 2.week.ago, 1.week.ago].map do |min_date| + [3.weeks.ago, 2.weeks.ago, 1.week.ago].map do |min_date| max_date = min_date + 1.week average = Avis.with_answer @@ -203,7 +203,7 @@ class StatsController < ApplicationController end def avis_answer_percentages - [3.week.ago, 2.week.ago, 1.week.ago].map do |min_date| + [3.weeks.ago, 2.weeks.ago, 1.week.ago].map do |min_date| max_date = min_date + 1.week weekly_avis = Avis.where(created_at: min_date..max_date) @@ -222,7 +222,7 @@ class StatsController < ApplicationController end def motivation_usage_dossier - [3.week.ago, 2.week.ago, 1.week.ago].map do |date| + [3.weeks.ago, 2.weeks.ago, 1.week.ago].map do |date| min_date = date.beginning_of_week max_date = date.end_of_week @@ -241,7 +241,7 @@ class StatsController < ApplicationController end def motivation_usage_procedure - [3.week.ago, 2.week.ago, 1.week.ago].map do |date| + [3.weeks.ago, 2.weeks.ago, 1.week.ago].map do |date| min_date = date.beginning_of_week max_date = date.end_of_week diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb index ccf4b48fc..5c10df942 100644 --- a/app/controllers/users/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -88,7 +88,7 @@ class Users::DescriptionController < UsersController flash.notice = 'Nouveaux fichiers envoyés' if flash.alert.nil? end - return redirect_to users_dossiers_invite_path(id: current_user.invites.find_by_dossier_id(@dossier.id).id) if invite + return redirect_to users_dossiers_invite_path(id: current_user.invites.find_by(dossier_id: @dossier.id).id) if invite redirect_to users_dossier_recapitulatif_path end diff --git a/app/controllers/users/dossiers/invites_controller.rb b/app/controllers/users/dossiers/invites_controller.rb index bb891eddd..89ac80a3c 100644 --- a/app/controllers/users/dossiers/invites_controller.rb +++ b/app/controllers/users/dossiers/invites_controller.rb @@ -1,7 +1,7 @@ class Users::Dossiers::InvitesController < UsersController def authenticate_user! session["user_return_to"] = request.fullpath - return redirect_to new_user_registration_path(user_email: params[:email]) if params[:email].present? && User.find_by_email(params[:email]).nil? + return redirect_to new_user_registration_path(user_email: params[:email]) if params[:email].present? && User.find_by(email: params[:email]).nil? super end diff --git a/app/decorators/entreprise_decorator.rb b/app/decorators/entreprise_decorator.rb index 21d32e4d9..9cb958ca3 100644 --- a/app/decorators/entreprise_decorator.rb +++ b/app/decorators/entreprise_decorator.rb @@ -2,7 +2,7 @@ class EntrepriseDecorator < Draper::Decorator delegate_all def raison_sociale_or_name - raison_sociale.blank? ? "#{nom} #{prenom}" : raison_sociale + raison_sociale.presence || "#{nom} #{prenom}" end def effectif diff --git a/app/models/administrateur.rb b/app/models/administrateur.rb index f1f2e379b..ffd21bd17 100644 --- a/app/models/administrateur.rb +++ b/app/models/administrateur.rb @@ -1,4 +1,4 @@ -class Administrateur < ActiveRecord::Base +class Administrateur < ApplicationRecord devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable diff --git a/app/models/administration.rb b/app/models/administration.rb index b9805b3cc..d053a2c0a 100644 --- a/app/models/administration.rb +++ b/app/models/administration.rb @@ -1,4 +1,4 @@ -class Administration < ActiveRecord::Base +class Administration < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :rememberable, :trackable, :validatable, :omniauthable, omniauth_providers: [:github] diff --git a/app/models/assign_to.rb b/app/models/assign_to.rb index 5865e61bc..e044014c7 100644 --- a/app/models/assign_to.rb +++ b/app/models/assign_to.rb @@ -1,4 +1,4 @@ -class AssignTo < ActiveRecord::Base +class AssignTo < ApplicationRecord belongs_to :procedure belongs_to :gestionnaire has_one :procedure_presentation, dependent: :destroy diff --git a/app/models/cadastre.rb b/app/models/cadastre.rb index c2e318ba9..4d356f3cc 100644 --- a/app/models/cadastre.rb +++ b/app/models/cadastre.rb @@ -1,4 +1,4 @@ -class Cadastre < ActiveRecord::Base +class Cadastre < ApplicationRecord belongs_to :dossier, touch: true def geometry diff --git a/app/models/cerfa.rb b/app/models/cerfa.rb index 8d83a6324..62432039e 100644 --- a/app/models/cerfa.rb +++ b/app/models/cerfa.rb @@ -1,4 +1,4 @@ -class Cerfa < ActiveRecord::Base +class Cerfa < ApplicationRecord belongs_to :dossier, touch: true belongs_to :user diff --git a/app/models/champ.rb b/app/models/champ.rb index 5003161b6..ac45708a0 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -1,4 +1,4 @@ -class Champ < ActiveRecord::Base +class Champ < ApplicationRecord self.inheritance_column = :_type_disabled belongs_to :dossier, touch: true diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index 5db55fd13..2425e29da 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -1,4 +1,4 @@ -class Commentaire < ActiveRecord::Base +class Commentaire < ApplicationRecord belongs_to :dossier, touch: true belongs_to :champ belongs_to :piece_justificative @@ -6,7 +6,7 @@ class Commentaire < ActiveRecord::Base mount_uploader :file, CommentaireFileUploader validates :file, file_size: { maximum: 20.megabytes, message: "La taille du fichier doit être inférieure à 20 Mo" } validate :is_virus_free? - validates_presence_of :body, message: "Votre message ne peut être vide" + validates :body, presence: { message: "Votre message ne peut être vide" } default_scope { order(created_at: :asc) } scope :updated_since?, -> (date) { where('commentaires.updated_at > ?', date) } diff --git a/app/models/dossier.rb b/app/models/dossier.rb index cf266f3d8..9772d1bc5 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -1,4 +1,4 @@ -class Dossier < ActiveRecord::Base +class Dossier < ApplicationRecord enum state: { brouillon: 'brouillon', en_construction: 'en_construction', diff --git a/app/models/drop_down_list.rb b/app/models/drop_down_list.rb index 91e49f9b3..45a0f23bc 100644 --- a/app/models/drop_down_list.rb +++ b/app/models/drop_down_list.rb @@ -1,4 +1,4 @@ -class DropDownList < ActiveRecord::Base +class DropDownList < ApplicationRecord belongs_to :type_de_champ def options diff --git a/app/models/entreprise.rb b/app/models/entreprise.rb index 3e92635c9..db62b88ec 100644 --- a/app/models/entreprise.rb +++ b/app/models/entreprise.rb @@ -1,10 +1,10 @@ -class Entreprise < ActiveRecord::Base +class Entreprise < ApplicationRecord belongs_to :dossier has_one :etablissement, dependent: :destroy has_one :rna_information, dependent: :destroy - validates_presence_of :siren - validates_uniqueness_of :dossier_id + validates :siren, presence: true + validates :dossier_id, uniqueness: true accepts_nested_attributes_for :rna_information diff --git a/app/models/etablissement.rb b/app/models/etablissement.rb index 2b51f17ea..ff2885c46 100644 --- a/app/models/etablissement.rb +++ b/app/models/etablissement.rb @@ -1,4 +1,4 @@ -class Etablissement < ActiveRecord::Base +class Etablissement < ApplicationRecord belongs_to :dossier belongs_to :entreprise @@ -7,7 +7,7 @@ class Etablissement < ActiveRecord::Base accepts_nested_attributes_for :exercices accepts_nested_attributes_for :entreprise - validates_uniqueness_of :dossier_id + validates :dossier_id, uniqueness: true def geo_adresse [numero_voie, type_voie, nom_voie, complement_adresse, code_postal, localite].join(' ') diff --git a/app/models/exercice.rb b/app/models/exercice.rb index 7336d3f38..0902916ee 100644 --- a/app/models/exercice.rb +++ b/app/models/exercice.rb @@ -1,4 +1,4 @@ -class Exercice < ActiveRecord::Base +class Exercice < ApplicationRecord belongs_to :etablissement validates :ca, presence: true, allow_blank: false, allow_nil: false diff --git a/app/models/follow.rb b/app/models/follow.rb index ea18f9e0f..4086a1ec7 100644 --- a/app/models/follow.rb +++ b/app/models/follow.rb @@ -1,8 +1,8 @@ -class Follow < ActiveRecord::Base +class Follow < ApplicationRecord belongs_to :gestionnaire belongs_to :dossier - validates_uniqueness_of :gestionnaire_id, :scope => :dossier_id + validates :gestionnaire_id, uniqueness: { scope: :dossier_id } before_create :set_default_date diff --git a/app/models/france_connect_information.rb b/app/models/france_connect_information.rb index a4cdcad85..124437f63 100644 --- a/app/models/france_connect_information.rb +++ b/app/models/france_connect_information.rb @@ -1,4 +1,4 @@ -class FranceConnectInformation < ActiveRecord::Base +class FranceConnectInformation < ApplicationRecord belongs_to :user validates :france_connect_particulier_id, presence: true, allow_blank: false, allow_nil: false diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index f46ab8af4..a01eddad9 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -1,4 +1,4 @@ -class Gestionnaire < ActiveRecord::Base +class Gestionnaire < ApplicationRecord devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable diff --git a/app/models/individual.rb b/app/models/individual.rb index a1a2b9d82..3a0c1410c 100644 --- a/app/models/individual.rb +++ b/app/models/individual.rb @@ -1,7 +1,7 @@ -class Individual < ActiveRecord::Base +class Individual < ApplicationRecord belongs_to :dossier - validates_uniqueness_of :dossier_id + validates :dossier_id, uniqueness: true validates :gender, presence: true, allow_nil: false, on: :update validates :nom, presence: true, allow_blank: false, allow_nil: false, on: :update validates :prenom, presence: true, allow_blank: false, allow_nil: false, on: :update diff --git a/app/models/invite.rb b/app/models/invite.rb index dde8b2c6f..526026634 100644 --- a/app/models/invite.rb +++ b/app/models/invite.rb @@ -1,9 +1,9 @@ -class Invite < ActiveRecord::Base +class Invite < ApplicationRecord belongs_to :dossier belongs_to :user - validates_presence_of :email - validates_uniqueness_of :email, :scope => :dossier_id + validates :email, presence: true + validates :email, uniqueness: { scope: :dossier_id } validates :email, email_format: true end diff --git a/app/models/module_api_carto.rb b/app/models/module_api_carto.rb index 1b9e47df1..94d7a34c5 100644 --- a/app/models/module_api_carto.rb +++ b/app/models/module_api_carto.rb @@ -1,4 +1,4 @@ -class ModuleAPICarto < ActiveRecord::Base +class ModuleAPICarto < ApplicationRecord belongs_to :procedure validates :use_api_carto, presence: true, allow_blank: true, allow_nil: false diff --git a/app/models/piece_justificative.rb b/app/models/piece_justificative.rb index 8d32d0543..0dd196d2f 100644 --- a/app/models/piece_justificative.rb +++ b/app/models/piece_justificative.rb @@ -1,4 +1,4 @@ -class PieceJustificative < ActiveRecord::Base +class PieceJustificative < ApplicationRecord belongs_to :dossier, touch: true belongs_to :type_de_piece_justificative has_one :commentaire diff --git a/app/models/procedure.rb b/app/models/procedure.rb index e750d7a21..436a43a7c 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -1,4 +1,4 @@ -class Procedure < ActiveRecord::Base +class Procedure < ApplicationRecord has_many :types_de_piece_justificative, -> { order "order_place ASC" }, dependent: :destroy has_many :types_de_champ, -> { public_only }, dependent: :destroy has_many :types_de_champ_private, -> { private_only }, class_name: 'TypeDeChamp', dependent: :destroy diff --git a/app/models/procedure_path.rb b/app/models/procedure_path.rb index 98fd4e3d1..62dc924b3 100644 --- a/app/models/procedure_path.rb +++ b/app/models/procedure_path.rb @@ -1,4 +1,4 @@ -class ProcedurePath < ActiveRecord::Base +class ProcedurePath < ApplicationRecord validates :path, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, presence: true, allow_blank: false, allow_nil: false validates :administrateur_id, presence: true, allow_blank: false, allow_nil: false validates :procedure_id, presence: true, allow_blank: false, allow_nil: false diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 8982cc7db..ce0fc8b9d 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -1,4 +1,4 @@ -class ProcedurePresentation < ActiveRecord::Base +class ProcedurePresentation < ApplicationRecord belongs_to :assign_to def displayed_fields diff --git a/app/models/quartier_prioritaire.rb b/app/models/quartier_prioritaire.rb index c8ac1f712..5e3f37e0b 100644 --- a/app/models/quartier_prioritaire.rb +++ b/app/models/quartier_prioritaire.rb @@ -1,4 +1,4 @@ -class QuartierPrioritaire < ActiveRecord::Base +class QuartierPrioritaire < ApplicationRecord belongs_to :dossier, touch: true def geometry diff --git a/app/models/rna_information.rb b/app/models/rna_information.rb index 409f7bd10..9797d1072 100644 --- a/app/models/rna_information.rb +++ b/app/models/rna_information.rb @@ -1,4 +1,4 @@ -class RNAInformation < ActiveRecord::Base +class RNAInformation < ApplicationRecord belongs_to :entreprise validates :association_id, presence: true, allow_blank: false, allow_nil: false diff --git a/app/models/search.rb b/app/models/search.rb index 7e455f4a8..3ab9adbd0 100644 --- a/app/models/search.rb +++ b/app/models/search.rb @@ -1,7 +1,7 @@ # See: # - https://robots.thoughtbot.com/implementing-multi-table-full-text-search-with-postgres # - http://calebthompson.io/talks/search.html -class Search < ActiveRecord::Base +class Search < ApplicationRecord # :nodoc: # # Englobs a search result (actually a collection of Search objects) so it acts diff --git a/app/models/siret.rb b/app/models/siret.rb index d9e12ff11..f1b9cda8a 100644 --- a/app/models/siret.rb +++ b/app/models/siret.rb @@ -4,7 +4,7 @@ class Siret attr_accessor :siret - validates_presence_of :siret + validates :siret, presence: true validates :siret, siret_format: true before_validation :remove_whitespace diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index ecc42691a..1facb4220 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -1,4 +1,4 @@ -class TypeDeChamp < ActiveRecord::Base +class TypeDeChamp < ApplicationRecord self.inheritance_column = :_type_disabled enum type_champs: { diff --git a/app/models/type_de_piece_justificative.rb b/app/models/type_de_piece_justificative.rb index 7bdb8ac42..a2527461f 100644 --- a/app/models/type_de_piece_justificative.rb +++ b/app/models/type_de_piece_justificative.rb @@ -1,4 +1,4 @@ -class TypeDePieceJustificative < ActiveRecord::Base +class TypeDePieceJustificative < ApplicationRecord has_many :pieces_justificatives, dependent: :destroy belongs_to :procedure diff --git a/app/models/user.rb b/app/models/user.rb index 362eba6b7..a495d2f84 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,4 @@ -class User < ActiveRecord::Base +class User < ApplicationRecord enum loged_in_with_france_connect: { particulier: 'particulier', entreprise: 'entreprise' @@ -21,7 +21,7 @@ class User < ActiveRecord::Base include CredentialsSyncableConcern def self.find_for_france_connect email, siret - user = User.find_by_email(email) + user = User.find_by(email: email) if user.nil? return User.create(email: email, password: Devise.friendly_token[0, 20], siret: siret) else diff --git a/app/services/staging_auth_service.rb b/app/services/staging_auth_service.rb index c6886f5a2..c4dd250d8 100644 --- a/app/services/staging_auth_service.rb +++ b/app/services/staging_auth_service.rb @@ -1,5 +1,5 @@ class StagingAuthService - CONFIG_PATH = Rails.root.join("config/basic_auth.yml") + CONFIG_PATH = Rails.root.join("config", "basic_auth.yml") def self.authenticate(username, password) if enabled? diff --git a/app/uploaders/attestation_template_logo_uploader.rb b/app/uploaders/attestation_template_logo_uploader.rb index 727938758..b9d7d83cc 100644 --- a/app/uploaders/attestation_template_logo_uploader.rb +++ b/app/uploaders/attestation_template_logo_uploader.rb @@ -1,6 +1,6 @@ class AttestationTemplateLogoUploader < BaseUploader def root - File.join(Rails.root, 'public') + Rails.root.join("public") end # Choose what kind of storage to use for this uploader: diff --git a/app/uploaders/attestation_template_signature_uploader.rb b/app/uploaders/attestation_template_signature_uploader.rb index 9f74d43ab..3a740e2d1 100644 --- a/app/uploaders/attestation_template_signature_uploader.rb +++ b/app/uploaders/attestation_template_signature_uploader.rb @@ -1,6 +1,6 @@ class AttestationTemplateSignatureUploader < BaseUploader def root - File.join(Rails.root, 'public') + Rails.root.join("public") end # Choose what kind of storage to use for this uploader: diff --git a/app/uploaders/attestation_uploader.rb b/app/uploaders/attestation_uploader.rb index 80fd751f5..1c3cf0e44 100644 --- a/app/uploaders/attestation_uploader.rb +++ b/app/uploaders/attestation_uploader.rb @@ -1,6 +1,6 @@ class AttestationUploader < BaseUploader def root - File.join(Rails.root, 'public') + Rails.root.join("public") end # Choose what kind of storage to use for this uploader: diff --git a/app/uploaders/commentaire_file_uploader.rb b/app/uploaders/commentaire_file_uploader.rb index 6b5d95fcb..c681d25b1 100644 --- a/app/uploaders/commentaire_file_uploader.rb +++ b/app/uploaders/commentaire_file_uploader.rb @@ -1,6 +1,6 @@ class CommentaireFileUploader < BaseUploader def root - File.join(Rails.root, 'public') + Rails.root.join("public") end if Features.remote_storage diff --git a/app/uploaders/local_downloader.rb b/app/uploaders/local_downloader.rb index 26a07e3d2..82f33d12f 100644 --- a/app/uploaders/local_downloader.rb +++ b/app/uploaders/local_downloader.rb @@ -1,7 +1,7 @@ require 'securerandom' class LocalDownloader - BASE_PATH_DISK = File.join(Rails.root, "public/downloads/") + BASE_PATH_DISK = Rails.root.join("public", "downloads") def initialize(filename, filename_suffix = '') @filename = filename.to_s diff --git a/app/uploaders/procedure_logo_uploader.rb b/app/uploaders/procedure_logo_uploader.rb index 288076b0d..73c4b1fc4 100644 --- a/app/uploaders/procedure_logo_uploader.rb +++ b/app/uploaders/procedure_logo_uploader.rb @@ -1,6 +1,6 @@ class ProcedureLogoUploader < BaseUploader def root - File.join(Rails.root, "public") + Rails.root.join("public") end # Choose what kind of storage to use for this uploader: diff --git a/config/initializers/apipie.rb b/config/initializers/apipie.rb index 7a72a71a8..394b7a5d4 100644 --- a/config/initializers/apipie.rb +++ b/config/initializers/apipie.rb @@ -2,7 +2,7 @@ Apipie.configure do |config| config.app_name = "API demarches-simplifiees.fr" config.api_base_url = "/api/v1" config.doc_base_url = "/docs" - config.api_controllers_matcher = File.join(Rails.root, "app", "controllers","api","v1", "**","*.rb") + config.api_controllers_matcher = Rails.root.join("app", "controllers"," api", "v1", "**", "*.rb") config.markup = Apipie::Markup::Markdown.new config.default_version = '1.0' config.validate = false diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb index cd43a1b78..4bb01d1b9 100644 --- a/config/initializers/carrierwave.rb +++ b/config/initializers/carrierwave.rb @@ -1,9 +1,9 @@ require_relative 'features' if Rails.env.test? - Fog.credentials_path = Rails.root.join('config/fog_credentials.test.yml') + Fog.credentials_path = Rails.root.join('config', 'fog_credentials.test.yml') else - Fog.credentials_path = Rails.root.join('config/fog_credentials.yml') + Fog.credentials_path = Rails.root.join('config', 'fog_credentials.yml') end CarrierWave.configure do |config| @@ -20,7 +20,7 @@ CarrierWave.configure do |config| # they will not be available for public (non-authenticated) downloading config.root = Rails.root - config.cache_dir = "#{Rails.root}/uploads" + config.cache_dir = Rails.root.join("uploads") config.fog_public = true diff --git a/config/initializers/france_connect.rb b/config/initializers/france_connect.rb index a3702335b..493058fd9 100644 --- a/config/initializers/france_connect.rb +++ b/config/initializers/france_connect.rb @@ -11,7 +11,7 @@ FRANCE_CONNECT = if Rails.env.test? } } else - fc_config_file_path = "#{Rails.root}/config/france_connect.yml" + fc_config_file_path = Rails.root.join("config", "france_connect.yml") # FIXME: with a yaml with a { particulier: {} } structure config_hash = YAML.safe_load(File.read(fc_config_file_path)) diff --git a/db/migrate/20151207140202_update_module_api_carto.rb b/db/migrate/20151207140202_update_module_api_carto.rb index 25549224d..9641d5c61 100644 --- a/db/migrate/20151207140202_update_module_api_carto.rb +++ b/db/migrate/20151207140202_update_module_api_carto.rb @@ -1,8 +1,8 @@ class UpdateModuleAPICarto < ActiveRecord::Migration - class Procedure < ActiveRecord::Base + class Procedure < ApplicationRecord end - class ModuleAPICarto < ActiveRecord::Base + class ModuleAPICarto < ApplicationRecord end def up diff --git a/db/migrate/20160120094750_create_france_connect_information.rb b/db/migrate/20160120094750_create_france_connect_information.rb index 2178c02eb..3363092c0 100644 --- a/db/migrate/20160120094750_create_france_connect_information.rb +++ b/db/migrate/20160120094750_create_france_connect_information.rb @@ -1,8 +1,8 @@ class CreateFranceConnectInformation < ActiveRecord::Migration - class User < ActiveRecord::Base + class User < ApplicationRecord end - class FranceConnectInformation < ActiveRecord::Base + class FranceConnectInformation < ApplicationRecord end def up diff --git a/db/migrate/20160317135217_d_bremove_piece_justificative_empty.rb b/db/migrate/20160317135217_d_bremove_piece_justificative_empty.rb index b1d16c346..f9e34f7f2 100644 --- a/db/migrate/20160317135217_d_bremove_piece_justificative_empty.rb +++ b/db/migrate/20160317135217_d_bremove_piece_justificative_empty.rb @@ -1,5 +1,5 @@ class DBremovePieceJustificativeEmpty < ActiveRecord::Migration - class PieceJustificative < ActiveRecord::Base + class PieceJustificative < ApplicationRecord end def change diff --git a/db/migrate/20160317144949_piece_justificative_have_user.rb b/db/migrate/20160317144949_piece_justificative_have_user.rb index 23ddd81a3..d8584d997 100644 --- a/db/migrate/20160317144949_piece_justificative_have_user.rb +++ b/db/migrate/20160317144949_piece_justificative_have_user.rb @@ -1,13 +1,13 @@ class PieceJustificativeHaveUser < ActiveRecord::Migration - class PieceJustificative < ActiveRecord::Base + class PieceJustificative < ApplicationRecord belongs_to :dossier end - class Dossier < ActiveRecord::Base + class Dossier < ApplicationRecord belongs_to :user end - class User < ActiveRecord::Base + class User < ApplicationRecord end def change diff --git a/db/migrate/20160317153115_cerfa_have_user.rb b/db/migrate/20160317153115_cerfa_have_user.rb index a50cbf4c4..44ebf2db9 100644 --- a/db/migrate/20160317153115_cerfa_have_user.rb +++ b/db/migrate/20160317153115_cerfa_have_user.rb @@ -1,13 +1,13 @@ class CerfaHaveUser < ActiveRecord::Migration - class Cerfa < ActiveRecord::Base + class Cerfa < ApplicationRecord belongs_to :dossier end - class Dossier < ActiveRecord::Base + class Dossier < ApplicationRecord belongs_to :user end - class User < ActiveRecord::Base + class User < ApplicationRecord end def change diff --git a/db/migrate/20160519100904_admin_has_and_belong_gestionnaire.rb b/db/migrate/20160519100904_admin_has_and_belong_gestionnaire.rb index 9eb2bc05b..d655b9366 100644 --- a/db/migrate/20160519100904_admin_has_and_belong_gestionnaire.rb +++ b/db/migrate/20160519100904_admin_has_and_belong_gestionnaire.rb @@ -1,8 +1,8 @@ class AdminHasAndBelongGestionnaire < ActiveRecord::Migration - class Gestionnaire < ActiveRecord::Base + class Gestionnaire < ApplicationRecord end - class AdministrateursGestionnaire < ActiveRecord::Base + class AdministrateursGestionnaire < ApplicationRecord end def up diff --git a/db/migrate/20160519101018_gestionnaire_is_assign_to_procedure.rb b/db/migrate/20160519101018_gestionnaire_is_assign_to_procedure.rb index 120245803..059c8aa48 100644 --- a/db/migrate/20160519101018_gestionnaire_is_assign_to_procedure.rb +++ b/db/migrate/20160519101018_gestionnaire_is_assign_to_procedure.rb @@ -1,20 +1,20 @@ class GestionnaireIsAssignToProcedure < ActiveRecord::Migration - class AssignTo < ActiveRecord::Base + class AssignTo < ApplicationRecord belongs_to :gestionnaire belongs_to :procedure end - class Gestionnaire < ActiveRecord::Base + class Gestionnaire < ApplicationRecord has_and_belongs_to_many :administrateurs has_many :procedures, through: :assign_to end - class Administrateur < ActiveRecord::Base + class Administrateur < ApplicationRecord has_and_belongs_to_many :gestionnaires has_many :procedures end - class Procedure < ActiveRecord::Base + class Procedure < ApplicationRecord belongs_to :administrateur has_many :gestionnaires, through: :assign_to end diff --git a/db/migrate/20160524093540_set_original_filename_for_uploaders.rb b/db/migrate/20160524093540_set_original_filename_for_uploaders.rb index bf8e700f2..2bd688a4e 100644 --- a/db/migrate/20160524093540_set_original_filename_for_uploaders.rb +++ b/db/migrate/20160524093540_set_original_filename_for_uploaders.rb @@ -1,8 +1,8 @@ class SetOriginalFilenameForUploaders < ActiveRecord::Migration - class PieceJustificative < ActiveRecord::Base + class PieceJustificative < ApplicationRecord end - class Cerfa < ActiveRecord::Base + class Cerfa < ApplicationRecord end def change diff --git a/db/migrate/20160609125949_add_procedure_status.rb b/db/migrate/20160609125949_add_procedure_status.rb index 6d4ea7e2e..7e7b38160 100644 --- a/db/migrate/20160609125949_add_procedure_status.rb +++ b/db/migrate/20160609125949_add_procedure_status.rb @@ -1,5 +1,5 @@ class AddProcedureStatus < ActiveRecord::Migration - class Procedure < ActiveRecord::Base + class Procedure < ApplicationRecord end def change diff --git a/db/migrate/20160609145737_delete_default_description_to_dossier.rb b/db/migrate/20160609145737_delete_default_description_to_dossier.rb index feca43f92..7eea84a40 100644 --- a/db/migrate/20160609145737_delete_default_description_to_dossier.rb +++ b/db/migrate/20160609145737_delete_default_description_to_dossier.rb @@ -1,14 +1,14 @@ class DeleteDefaultDescriptionToDossier < ActiveRecord::Migration - class Dossier < ActiveRecord::Base + class Dossier < ApplicationRecord end - class Champ < ActiveRecord::Base + class Champ < ApplicationRecord end - class Procedure < ActiveRecord::Base + class Procedure < ApplicationRecord end - class TypeDeChamp < ActiveRecord::Base + class TypeDeChamp < ApplicationRecord end def up diff --git a/db/migrate/20160622081321_convert_all_datetime_to_date_on_database.rb b/db/migrate/20160622081321_convert_all_datetime_to_date_on_database.rb index 2c61b98c2..96c094166 100644 --- a/db/migrate/20160622081321_convert_all_datetime_to_date_on_database.rb +++ b/db/migrate/20160622081321_convert_all_datetime_to_date_on_database.rb @@ -1,5 +1,5 @@ class ConvertAllDatetimeToDateOnDatabase < ActiveRecord::Migration - class TypeDeChamp < ActiveRecord::Base + class TypeDeChamp < ApplicationRecord end def change diff --git a/db/migrate/20160622081322_add_procedure_path_mapping_table.rb b/db/migrate/20160622081322_add_procedure_path_mapping_table.rb index 9d3eecc1f..ebe600f8f 100644 --- a/db/migrate/20160622081322_add_procedure_path_mapping_table.rb +++ b/db/migrate/20160622081322_add_procedure_path_mapping_table.rb @@ -1,5 +1,5 @@ class AddProcedurePathMappingTable < ActiveRecord::Migration - class ProcedurePath < ActiveRecord::Base + class ProcedurePath < ApplicationRecord end def change diff --git a/db/migrate/20160802113112_build_default_preference_list_dossier.rb b/db/migrate/20160802113112_build_default_preference_list_dossier.rb index a1628f20f..69efaefe1 100644 --- a/db/migrate/20160802113112_build_default_preference_list_dossier.rb +++ b/db/migrate/20160802113112_build_default_preference_list_dossier.rb @@ -1,5 +1,5 @@ class BuildDefaultPreferenceListDossier < ActiveRecord::Migration - class Gestionnaire < ActiveRecord::Base + class Gestionnaire < ApplicationRecord def build_default_preferences_list_dossier PreferenceListDossier.available_columns.each do |table| table.second.each do |column| @@ -47,7 +47,7 @@ class BuildDefaultPreferenceListDossier < ActiveRecord::Migration end end - class PreferenceListDossier < ActiveRecord::Base + class PreferenceListDossier < ApplicationRecord def self.available_columns { dossier: columns_dossier, diff --git a/db/migrate/20160803081304_fix_default_type_on_type_de_champ_table.rb b/db/migrate/20160803081304_fix_default_type_on_type_de_champ_table.rb index 56120ef60..6bc12ed6d 100644 --- a/db/migrate/20160803081304_fix_default_type_on_type_de_champ_table.rb +++ b/db/migrate/20160803081304_fix_default_type_on_type_de_champ_table.rb @@ -1,5 +1,5 @@ class FixDefaultTypeOnTypeDeChampTable < ActiveRecord::Migration - class TypeDeChamp < ActiveRecord::Base + class TypeDeChamp < ApplicationRecord end def up diff --git a/db/migrate/20160804130638_add_type_attr_in_champ_table.rb b/db/migrate/20160804130638_add_type_attr_in_champ_table.rb index df21b33ea..5f42889d9 100644 --- a/db/migrate/20160804130638_add_type_attr_in_champ_table.rb +++ b/db/migrate/20160804130638_add_type_attr_in_champ_table.rb @@ -1,9 +1,9 @@ class AddTypeAttrInChampTable < ActiveRecord::Migration - class TypeDeChamp < ActiveRecord::Base + class TypeDeChamp < ApplicationRecord has_many :champs end - class Champ < ActiveRecord::Base + class Champ < ApplicationRecord belongs_to :type_de_champ end diff --git a/db/migrate/20160822142045_delete_value_of_filter_procedure.rb b/db/migrate/20160822142045_delete_value_of_filter_procedure.rb index 30a12da5f..e1f8c771d 100644 --- a/db/migrate/20160822142045_delete_value_of_filter_procedure.rb +++ b/db/migrate/20160822142045_delete_value_of_filter_procedure.rb @@ -1,5 +1,5 @@ class DeleteValueOfFilterProcedure < ActiveRecord::Migration - class Gestionnaire < ActiveRecord::Base + class Gestionnaire < ApplicationRecord end def change diff --git a/db/migrate/20160901082824_initiated_all_received_mail_for_procedure.rb b/db/migrate/20160901082824_initiated_all_received_mail_for_procedure.rb index a2ccc89d9..edfbec2fd 100644 --- a/db/migrate/20160901082824_initiated_all_received_mail_for_procedure.rb +++ b/db/migrate/20160901082824_initiated_all_received_mail_for_procedure.rb @@ -1,9 +1,9 @@ class InitiatedAllReceivedMailForProcedure < ActiveRecord::Migration - class Procedure < ActiveRecord::Base + class Procedure < ApplicationRecord has_one :mail_received end - class MailTemplate < ActiveRecord::Base + class MailTemplate < ApplicationRecord end class ::MailReceived < MailTemplate diff --git a/db/migrate/20160906134155_build_default_pref_list_dossier_procedure.rb b/db/migrate/20160906134155_build_default_pref_list_dossier_procedure.rb index 103d1454b..26158f299 100644 --- a/db/migrate/20160906134155_build_default_pref_list_dossier_procedure.rb +++ b/db/migrate/20160906134155_build_default_pref_list_dossier_procedure.rb @@ -1,21 +1,21 @@ class BuildDefaultPrefListDossierProcedure < ActiveRecord::Migration - class Gestionnaire < ActiveRecord::Base + class Gestionnaire < ApplicationRecord has_many :assign_to, dependent: :destroy has_many :procedures, through: :assign_to has_many :preference_list_dossiers end - class PreferenceListDossier < ActiveRecord::Base + class PreferenceListDossier < ApplicationRecord belongs_to :gestionnaire belongs_to :procedure end - class AssignTo < ActiveRecord::Base + class AssignTo < ApplicationRecord belongs_to :procedure belongs_to :gestionnaire end - class Procedure < ActiveRecord::Base + class Procedure < ApplicationRecord has_many :gestionnaires, through: :assign_to has_many :preference_list_dossiers end diff --git a/db/migrate/20160927154248_change_emptyto_nil_in_preference_list_dossier_table.rb b/db/migrate/20160927154248_change_emptyto_nil_in_preference_list_dossier_table.rb index e4203c62c..7bc555765 100644 --- a/db/migrate/20160927154248_change_emptyto_nil_in_preference_list_dossier_table.rb +++ b/db/migrate/20160927154248_change_emptyto_nil_in_preference_list_dossier_table.rb @@ -1,5 +1,5 @@ class ChangeEmptytoNilInPreferenceListDossierTable < ActiveRecord::Migration - class PreferenceListDossier < ActiveRecord::Base + class PreferenceListDossier < ApplicationRecord end def change diff --git a/db/migrate/20161004175442_fix_type_de_champ_header_section_with_mandatory_true.rb b/db/migrate/20161004175442_fix_type_de_champ_header_section_with_mandatory_true.rb index 23aec6f90..2282e7e6f 100644 --- a/db/migrate/20161004175442_fix_type_de_champ_header_section_with_mandatory_true.rb +++ b/db/migrate/20161004175442_fix_type_de_champ_header_section_with_mandatory_true.rb @@ -1,5 +1,5 @@ class FixTypeDeChampHeaderSectionWithMandatoryTrue < ActiveRecord::Migration - class TypeDeChamp < ActiveRecord::Base + class TypeDeChamp < ApplicationRecord end def change diff --git a/db/migrate/20161005144657_purge_draft_dossier.rb b/db/migrate/20161005144657_purge_draft_dossier.rb index e81c6cd68..87d604803 100644 --- a/db/migrate/20161005144657_purge_draft_dossier.rb +++ b/db/migrate/20161005144657_purge_draft_dossier.rb @@ -1,5 +1,5 @@ class PurgeDraftDossier < ActiveRecord::Migration - class Dossier < ActiveRecord::Base + class Dossier < ApplicationRecord BROUILLON = %w(draft) def brouillon? @@ -7,11 +7,11 @@ class PurgeDraftDossier < ActiveRecord::Migration end end - class Commentaire < ActiveRecord::Base + class Commentaire < ApplicationRecord belongs_to :dossier end - class Cerfa < ActiveRecord::Base + class Cerfa < ApplicationRecord belongs_to :dossier belongs_to :user end diff --git a/db/migrate/20161007095443_reset_all_preference_list_dossier.rb b/db/migrate/20161007095443_reset_all_preference_list_dossier.rb index 47e44ce44..d0d08f4d3 100644 --- a/db/migrate/20161007095443_reset_all_preference_list_dossier.rb +++ b/db/migrate/20161007095443_reset_all_preference_list_dossier.rb @@ -1,5 +1,5 @@ class ResetAllPreferenceListDossier < ActiveRecord::Migration - class PreferenceListDossier < ActiveRecord::Base + class PreferenceListDossier < ApplicationRecord belongs_to :gestionnaire belongs_to :procedure @@ -91,7 +91,7 @@ class ResetAllPreferenceListDossier < ActiveRecord::Migration end end - class Gestionnaire < ActiveRecord::Base + class Gestionnaire < ApplicationRecord has_many :assign_to, dependent: :destroy has_many :procedures, through: :assign_to @@ -145,7 +145,7 @@ class ResetAllPreferenceListDossier < ActiveRecord::Migration end end - class Procedure < ActiveRecord::Base + class Procedure < ApplicationRecord has_many :assign_to, dependent: :destroy has_many :gestionnaires, through: :assign_to end diff --git a/db/migrate/20161011125345_create_preference_smart_listing_page.rb b/db/migrate/20161011125345_create_preference_smart_listing_page.rb index 510cfc156..39061ad43 100644 --- a/db/migrate/20161011125345_create_preference_smart_listing_page.rb +++ b/db/migrate/20161011125345_create_preference_smart_listing_page.rb @@ -1,5 +1,5 @@ class CreatePreferenceSmartListingPage < ActiveRecord::Migration - class Gestionnaire < ActiveRecord::Base + class Gestionnaire < ApplicationRecord has_one :preference_smart_listing_page, dependent: :destroy def build_default_preferences_smart_listing_page @@ -7,7 +7,7 @@ class CreatePreferenceSmartListingPage < ActiveRecord::Migration end end - class PreferenceSmartListingPage < ActiveRecord::Base + class PreferenceSmartListingPage < ApplicationRecord belongs_to :gestionnaire belongs_to :procedure diff --git a/lib/tasks/2017_07_26_clean_birthdate_on_individual.rake b/lib/tasks/2017_07_26_clean_birthdate_on_individual.rake index 27a61451e..a9fcf1bcc 100644 --- a/lib/tasks/2017_07_26_clean_birthdate_on_individual.rake +++ b/lib/tasks/2017_07_26_clean_birthdate_on_individual.rake @@ -19,7 +19,7 @@ namespace :'2017_07_26_clean_birthdate_on_individual' do puts "cleaning #{i.birthdate}" new_date = Date.strptime(i.birthdate, "%d/%m/%y") if new_date.year > 2017 - new_date = new_date - 100.year + new_date = new_date - 100.years end i.update(birthdate: new_date.iso8601) end diff --git a/lib/tasks/2017_10_30_copy_commentaire_piece_justificative_to_file.rake b/lib/tasks/2017_10_30_copy_commentaire_piece_justificative_to_file.rake index 8e3422582..8f7591941 100644 --- a/lib/tasks/2017_10_30_copy_commentaire_piece_justificative_to_file.rake +++ b/lib/tasks/2017_10_30_copy_commentaire_piece_justificative_to_file.rake @@ -41,7 +41,7 @@ namespace :'2017_10_30_copy_commentaire_piece_justificative_to_file' do end commentaire.save - if !commentaire.file.present? + if commentaire.file.blank? puts "Failed to save file for commentaire #{commentaire.id}" end end diff --git a/lib/tasks/cloud_storage.rake b/lib/tasks/cloud_storage.rake index f4cfb11cf..538f5268c 100644 --- a/lib/tasks/cloud_storage.rake +++ b/lib/tasks/cloud_storage.rake @@ -105,7 +105,7 @@ namespace :cloudstorage do @cont.objects_detail.each { |object, details| last_modified = DateTime.parse(details[:last_modified]) - @cont.delete_object(object) if last_modified.utc <= (Time.now - 2.year).utc + @cont.delete_object(object) if last_modified.utc <= (Time.now - 2.years).utc } end end diff --git a/spec/controllers/admin/gestionnaires_controller_spec.rb b/spec/controllers/admin/gestionnaires_controller_spec.rb index 2398c08cb..9f9f6091a 100644 --- a/spec/controllers/admin/gestionnaires_controller_spec.rb +++ b/spec/controllers/admin/gestionnaires_controller_spec.rb @@ -112,7 +112,7 @@ describe Admin::GestionnairesController, type: :controller do end context 'when an other admin will add the same email' do - let(:gestionnaire) { Gestionnaire.find_by_email(email) } + let(:gestionnaire) { Gestionnaire.find_by(email: email) } before do create :gestionnaire, email: email, administrateurs: [admin] @@ -133,7 +133,7 @@ describe Admin::GestionnairesController, type: :controller do context 'when an other admin will add the same email with some uppercase in it' do let(:email) { 'Test@Plop.com' } - let(:gestionnaire) { Gestionnaire.find_by_email(email.downcase) } + let(:gestionnaire) { Gestionnaire.find_by(email: email.downcase) } before do create :gestionnaire, email: email, administrateurs: [admin] diff --git a/spec/controllers/new_gestionnaire/procedures_controller_spec.rb b/spec/controllers/new_gestionnaire/procedures_controller_spec.rb index daa5aea35..e7c76b2a9 100644 --- a/spec/controllers/new_gestionnaire/procedures_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/procedures_controller_spec.rb @@ -254,9 +254,9 @@ describe NewGestionnaire::ProceduresController, type: :controller do describe 'statut' do let!(:a_suivre__dossier) { Timecop.freeze(1.day.ago){ create(:dossier, procedure: procedure, state: 'en_instruction') } } - let!(:new_followed_dossier) { Timecop.freeze(2.day.ago){ create(:dossier, procedure: procedure, state: 'en_instruction') } } - let!(:termine_dossier) { Timecop.freeze(3.day.ago){ create(:dossier, procedure: procedure, state: 'accepte') } } - let!(:archived_dossier) { Timecop.freeze(4.day.ago){ create(:dossier, procedure: procedure, state: 'en_instruction', archived: true) } } + let!(:new_followed_dossier) { Timecop.freeze(2.days.ago){ create(:dossier, procedure: procedure, state: 'en_instruction') } } + let!(:termine_dossier) { Timecop.freeze(3.days.ago){ create(:dossier, procedure: procedure, state: 'accepte') } } + let!(:archived_dossier) { Timecop.freeze(4.days.ago){ create(:dossier, procedure: procedure, state: 'en_instruction', archived: true) } } before do gestionnaire.followed_dossiers << new_followed_dossier diff --git a/spec/controllers/stats_controller_spec.rb b/spec/controllers/stats_controller_spec.rb index 34594386b..d82a8ce11 100644 --- a/spec/controllers/stats_controller_spec.rb +++ b/spec/controllers/stats_controller_spec.rb @@ -45,7 +45,7 @@ describe StatsController, type: :controller do it do expect(subject).to eq([ [I18n.l(45.days.ago.beginning_of_month, format: "%B %Y"), 1], - [I18n.l(1.days.ago.beginning_of_month, format: "%B %Y"), 2] + [I18n.l(1.day.ago.beginning_of_month, format: "%B %Y"), 2] ]) end end @@ -72,7 +72,7 @@ describe StatsController, type: :controller do it do expect(subject).to eq({ - 2.month.ago.beginning_of_month => 2, + 2.months.ago.beginning_of_month => 2, 1.month.ago.beginning_of_month => 4, 1.hour.ago.beginning_of_month => 5 }) @@ -86,7 +86,7 @@ describe StatsController, type: :controller do it do expect(subject).to eq({ - 2.month.ago.beginning_of_month => 2, + 2.months.ago.beginning_of_month => 2, 1.month.ago.beginning_of_month => 4 }) end @@ -151,22 +151,22 @@ describe StatsController, type: :controller do dossier_p1_b = FactoryBot.create(:dossier, :procedure => procedure_1, :en_construction_at => 2.months.ago.beginning_of_month, - :processed_at => 2.months.ago.beginning_of_month + 1.days) + :processed_at => 2.months.ago.beginning_of_month + 1.day) dossier_p1_c = FactoryBot.create(:dossier, :procedure => procedure_1, - :en_construction_at => 1.months.ago.beginning_of_month, - :processed_at => 1.months.ago.beginning_of_month + 5.days) + :en_construction_at => 1.month.ago.beginning_of_month, + :processed_at => 1.month.ago.beginning_of_month + 5.days) dossier_p2_a = FactoryBot.create(:dossier, :procedure => procedure_2, - :en_construction_at => 2.month.ago.beginning_of_month, - :processed_at => 2.month.ago.beginning_of_month + 4.days) + :en_construction_at => 2.months.ago.beginning_of_month, + :processed_at => 2.months.ago.beginning_of_month + 4.days) # Write directly in the DB to avoid the before_validation hook Dossier.update_all(state: "accepte") @expected_hash = { "#{2.months.ago.beginning_of_month}" => 3.0, - "#{1.months.ago.beginning_of_month}" => 5.0 + "#{1.month.ago.beginning_of_month}" => 5.0 } end @@ -204,21 +204,21 @@ describe StatsController, type: :controller do :processed_at => 2.months.ago.beginning_of_month + 1.day) dossier_p1_c = FactoryBot.create(:dossier, :procedure => procedure_1, - :created_at => 1.months.ago.beginning_of_month, - :en_construction_at => 1.months.ago.beginning_of_month + 50.minutes, - :processed_at => 1.months.ago.beginning_of_month + 1.day) + :created_at => 1.month.ago.beginning_of_month, + :en_construction_at => 1.month.ago.beginning_of_month + 50.minutes, + :processed_at => 1.month.ago.beginning_of_month + 1.day) dossier_p2_a = FactoryBot.create(:dossier, :procedure => procedure_2, - :created_at => 2.month.ago.beginning_of_month, - :en_construction_at => 2.month.ago.beginning_of_month + 80.minutes, - :processed_at => 2.month.ago.beginning_of_month + 1.day) + :created_at => 2.months.ago.beginning_of_month, + :en_construction_at => 2.months.ago.beginning_of_month + 80.minutes, + :processed_at => 2.months.ago.beginning_of_month + 1.day) # Write directly in the DB to avoid the before_validation hook Dossier.update_all(state: "accepte") @expected_hash = { "#{2.months.ago.beginning_of_month}" => 30.0, - "#{1.months.ago.beginning_of_month}" => 50.0 + "#{1.month.ago.beginning_of_month}" => 50.0 } end @@ -239,7 +239,7 @@ describe StatsController, type: :controller do subject { StatsController.new.send(:avis_usage) } - it { expect(subject).to match([[3.week.ago.to_i, 0], [2.week.ago.to_i, 0], [1.week.ago.to_i, 33.33]]) } + it { expect(subject).to match([[3.weeks.ago.to_i, 0], [2.weeks.ago.to_i, 0], [1.week.ago.to_i, 33.33]]) } end describe "#avis_average_answer_time" do @@ -251,10 +251,10 @@ describe StatsController, type: :controller do create(:avis, created_at: 1.week.ago + 2.days) # 2 weeks ago - create(:avis, answer: "voila ma réponse", created_at: 2.week.ago + 1.day, updated_at: 2.week.ago + 2.days) # 1 day - create(:avis, answer: "voila ma réponse2", created_at: 2.week.ago + 3.days, updated_at: 1.week.ago + 6.days) # 10 days - create(:avis, answer: "voila ma réponse2", created_at: 2.week.ago + 2.days, updated_at: 1.week.ago + 6.days) # 11 days - create(:avis, created_at: 2.week.ago + 1.day, updated_at: 2.week.ago + 2.days) + create(:avis, answer: "voila ma réponse", created_at: 2.weeks.ago + 1.day, updated_at: 2.weeks.ago + 2.days) # 1 day + create(:avis, answer: "voila ma réponse2", created_at: 2.weeks.ago + 3.days, updated_at: 1.week.ago + 6.days) # 10 days + create(:avis, answer: "voila ma réponse2", created_at: 2.weeks.ago + 2.days, updated_at: 1.week.ago + 6.days) # 11 days + create(:avis, created_at: 2.weeks.ago + 1.day, updated_at: 2.weeks.ago + 2.days) # 3 weeks ago create(:avis, answer: "voila ma réponse2", created_at: 3.weeks.ago + 1.day, updated_at: 3.weeks.ago + 2.days) # 1 day @@ -267,8 +267,8 @@ describe StatsController, type: :controller do it { expect(subject.count).to eq(3) } it { is_expected.to include [1.week.ago.to_i, 1.0] } - it { is_expected.to include [2.week.ago.to_i, 7.33] } - it { is_expected.to include [3.week.ago.to_i, 9.5] } + it { is_expected.to include [2.weeks.ago.to_i, 7.33] } + it { is_expected.to include [3.weeks.ago.to_i, 9.5] } end describe '#avis_answer_percentages' do @@ -281,7 +281,7 @@ describe StatsController, type: :controller do before { Timecop.freeze(Time.now) } after { Timecop.return } - it { is_expected.to match [[3.week.ago.to_i, 0], [2.week.ago.to_i, 0], [1.week.ago.to_i, 66.67]] } + it { is_expected.to match [[3.weeks.ago.to_i, 0], [2.weeks.ago.to_i, 0], [1.week.ago.to_i, 66.67]] } end describe '#motivation_usage_dossier' do @@ -294,7 +294,7 @@ describe StatsController, type: :controller do subject { StatsController.new.send(:motivation_usage_dossier) } - it { expect(subject).to match([[I18n.l(3.week.ago.end_of_week, format: '%d/%m/%Y'), 0], [I18n.l(2.week.ago.end_of_week, format: '%d/%m/%Y'), 0], [I18n.l(1.week.ago.end_of_week, format: '%d/%m/%Y'), 33.33]]) } + it { expect(subject).to match([[I18n.l(3.weeks.ago.end_of_week, format: '%d/%m/%Y'), 0], [I18n.l(2.weeks.ago.end_of_week, format: '%d/%m/%Y'), 0], [I18n.l(1.week.ago.end_of_week, format: '%d/%m/%Y'), 33.33]]) } end describe '#motivation_usage_procedure' do @@ -308,6 +308,6 @@ describe StatsController, type: :controller do subject { StatsController.new.send(:motivation_usage_procedure) } - it { expect(subject).to match([[I18n.l(3.week.ago.end_of_week, format: '%d/%m/%Y'), 0], [I18n.l(2.week.ago.end_of_week, format: '%d/%m/%Y'), 0], [I18n.l(1.week.ago.end_of_week, format: '%d/%m/%Y'), 33.33]]) } + it { expect(subject).to match([[I18n.l(3.weeks.ago.end_of_week, format: '%d/%m/%Y'), 0], [I18n.l(2.weeks.ago.end_of_week, format: '%d/%m/%Y'), 0], [I18n.l(1.week.ago.end_of_week, format: '%d/%m/%Y'), 33.33]]) } end end diff --git a/spec/controllers/users/description_controller_shared_example.rb b/spec/controllers/users/description_controller_shared_example.rb index f3d024fc8..5c6d440e4 100644 --- a/spec/controllers/users/description_controller_shared_example.rb +++ b/spec/controllers/users/description_controller_shared_example.rb @@ -376,7 +376,7 @@ shared_examples 'description_controller_spec' do it { expect(dossier.pieces_justificatives.size).to eq 2 } it { expect(flash[:notice]).to be_present } - it { is_expected.to redirect_to users_dossiers_invite_path(id: guest.invites.find_by_dossier_id(dossier.id).id) } + it { is_expected.to redirect_to users_dossiers_invite_path(id: guest.invites.find_by(dossier_id: dossier.id).id) } end end @@ -396,7 +396,7 @@ shared_examples 'description_controller_spec' do it { expect(dossier.pieces_justificatives.size).to eq 4 } it { expect(flash[:notice]).to be_present } - it { is_expected.to redirect_to users_dossiers_invite_path(id: guest.invites.find_by_dossier_id(dossier.id).id) } + it { is_expected.to redirect_to users_dossiers_invite_path(id: guest.invites.find_by(dossier_id: dossier.id).id) } end end @@ -413,7 +413,7 @@ shared_examples 'description_controller_spec' do it { expect(dossier.pieces_justificatives.size).to eq 1 } it { expect(flash[:alert]).to be_present } - it { is_expected.to redirect_to users_dossiers_invite_path(id: guest.invites.find_by_dossier_id(dossier.id).id) } + it { is_expected.to redirect_to users_dossiers_invite_path(id: guest.invites.find_by(dossier_id: dossier.id).id) } end end end diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb index 1fda4bbda..e2a73254b 100644 --- a/spec/factories/dossier.rb +++ b/spec/factories/dossier.rb @@ -85,7 +85,7 @@ FactoryBot.define do after(:create) do |dossier, _evaluator| dossier.state = 'en_instruction' dossier.en_construction_at = dossier.created_at + 1.minute - dossier.created_at = dossier.created_at + 2.minute + dossier.created_at = dossier.created_at + 2.minutes dossier.save! end end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 4cd13e70f..72bfbe1c7 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -245,9 +245,9 @@ describe Procedure do it { expect(procedure.archived_at).to eq(nil) } it { expect(procedure.published_at).to eq(now) } - it { expect(ProcedurePath.find_by_path("example-path")).to be } - it { expect(ProcedurePath.find_by_path("example-path").procedure).to eq(procedure) } - it { expect(ProcedurePath.find_by_path("example-path").administrateur).to eq(procedure.administrateur) } + it { expect(ProcedurePath.find_by(path: "example-path")).to be } + it { expect(ProcedurePath.find_by(path: "example-path").procedure).to eq(procedure) } + it { expect(ProcedurePath.find_by(path: "example-path").administrateur).to eq(procedure.administrateur) } end describe "#brouillon?" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a0583ada3..38dd8c731 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -52,8 +52,8 @@ Capybara.default_max_wait_time = 1 # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. -Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } -Dir[Rails.root.join('spec/factories/**/*.rb')].each { |f| require f } +Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } +Dir[Rails.root.join('spec', 'factories', '**', '*.rb')].each { |f| require f } # Checks for pending migrations before tests are run. # If you are not using ActiveRecord, you can remove this line.