diff --git a/.rubocop.yml b/.rubocop.yml index 4d0d06dfa..44cb2a0e4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -764,7 +764,7 @@ Rails/SkipsModelValidations: Enabled: false Rails/TimeZone: - Enabled: false + Enabled: true Rails/UniqBeforePluck: Enabled: true diff --git a/app/controllers/admin/attestation_templates_controller.rb b/app/controllers/admin/attestation_templates_controller.rb index eaa795d39..43194a5e6 100644 --- a/app/controllers/admin/attestation_templates_controller.rb +++ b/app/controllers/admin/attestation_templates_controller.rb @@ -43,7 +43,7 @@ class Admin::AttestationTemplatesController < AdminController @title = activated_attestation_params[:title] @body = activated_attestation_params[:body] @footer = activated_attestation_params[:footer] - @created_at = DateTime.now + @created_at = Time.zone.now # In a case of a preview, when the user does not change its images, # the images are not uploaded and thus should be retrieved from previous diff --git a/app/controllers/admin/gestionnaires_controller.rb b/app/controllers/admin/gestionnaires_controller.rb index 663edcd45..51ebf2fac 100644 --- a/app/controllers/admin/gestionnaires_controller.rb +++ b/app/controllers/admin/gestionnaires_controller.rb @@ -52,7 +52,7 @@ class Admin::GestionnairesController < AdminController if User.exists?(email: @gestionnaire.email) GestionnaireMailer.user_to_gestionnaire(@gestionnaire.email).deliver_later else - User.create(email: email, password: password, confirmed_at: DateTime.now) + User.create(email: email, password: password, confirmed_at: Time.zone.now) end flash.notice = 'Instructeur ajouté' else diff --git a/app/controllers/france_connect/particulier_controller.rb b/app/controllers/france_connect/particulier_controller.rb index ce042a8a2..aa629b365 100644 --- a/app/controllers/france_connect/particulier_controller.rb +++ b/app/controllers/france_connect/particulier_controller.rb @@ -15,7 +15,7 @@ class FranceConnect::ParticulierController < ApplicationController if fci.user.nil? user = User.find_or_create_by(email: fci.email_france_connect) do |new_user| new_user.password = Devise.friendly_token[0, 20] - new_user.confirmed_at = DateTime.now + new_user.confirmed_at = Time.zone.now end fci.update_attribute('user_id', user.id) diff --git a/app/controllers/new_gestionnaire/avis_controller.rb b/app/controllers/new_gestionnaire/avis_controller.rb index d926de9da..58887ea83 100644 --- a/app/controllers/new_gestionnaire/avis_controller.rb +++ b/app/controllers/new_gestionnaire/avis_controller.rb @@ -89,7 +89,7 @@ module NewGestionnaire if gestionnaire.save user = User.find_by(email: email) if user.blank? - user = User.create(email: email, password: password, confirmed_at: DateTime.now) + user = User.create(email: email, password: password, confirmed_at: Time.zone.now) end sign_in(user) diff --git a/app/controllers/new_user/demarches_controller.rb b/app/controllers/new_user/demarches_controller.rb index 7423002a2..0a354fa05 100644 --- a/app/controllers/new_user/demarches_controller.rb +++ b/app/controllers/new_user/demarches_controller.rb @@ -13,7 +13,7 @@ module NewUser .select("procedures.*, COUNT(*) AS procedures_count") .joins(:dossiers) .publiees - .where(dossiers: { created_at: 7.days.ago..Time.now }) + .where(dossiers: { created_at: 7.days.ago..Time.zone.now }) .group("procedures.id") .order("procedures_count DESC") .limit(5) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index a338729ca..6546c6eda 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -82,7 +82,7 @@ class StatsController < ApplicationController def procedures_numbers(procedures) total = procedures.count - last_30_days_count = procedures.where(published_at: 1.month.ago..Time.now).count + last_30_days_count = procedures.where(published_at: 1.month.ago..Time.zone.now).count previous_count = procedures.where(published_at: 2.months.ago..1.month.ago).count if previous_count != 0 evolution = (((last_30_days_count.to_f / previous_count) - 1) * 100).round(0) @@ -100,7 +100,7 @@ class StatsController < ApplicationController def dossiers_numbers(dossiers) total = dossiers.count - last_30_days_count = dossiers.where(en_construction_at: 1.month.ago..Time.now).count + last_30_days_count = dossiers.where(en_construction_at: 1.month.ago..Time.zone.now).count previous_count = dossiers.where(en_construction_at: 2.months.ago..1.month.ago).count if previous_count != 0 evolution = (((last_30_days_count.to_f / previous_count) - 1) * 100).round(0) @@ -178,9 +178,9 @@ class StatsController < ApplicationController def max_date if administration_signed_in? - Time.now.to_date + Time.zone.now.to_date else - Time.now.beginning_of_month - 1.second + Time.zone.now.beginning_of_month - 1.second end end @@ -232,7 +232,7 @@ class StatsController < ApplicationController # and then computing the average for all the procedures min_date = 11.months.ago - max_date = Time.now.to_date + max_date = Time.zone.now.to_date processed_dossiers = dossiers .where(:processed_at => min_date..max_date) @@ -273,7 +273,7 @@ class StatsController < ApplicationController # for a 24 champs form (the current form mean length) min_date = 11.months.ago - max_date = Time.now.to_date + max_date = Time.zone.now.to_date processed_dossiers = dossiers .where(:processed_at => min_date..max_date) diff --git a/app/decorators/champ_decorator.rb b/app/decorators/champ_decorator.rb index 9722cfb66..151eef64d 100644 --- a/app/decorators/champ_decorator.rb +++ b/app/decorators/champ_decorator.rb @@ -24,7 +24,7 @@ class ChampDecorator < Draper::Decorator if type_champ == TypeDeChamp.type_champs.fetch(:date) object.value elsif type_champ == TypeDeChamp.type_champs.fetch(:datetime) && object.value != ' 00:00' - DateTime.parse(object.value, "%Y-%m-%d %H:%M").strftime("%Y-%m-%d") + Time.zone.strptime(object.value, "%Y-%m-%d %H:%M").strftime("%Y-%m-%d") end end end diff --git a/app/decorators/dossier_decorator.rb b/app/decorators/dossier_decorator.rb index e42ba1496..c4ce6b8e7 100644 --- a/app/decorators/dossier_decorator.rb +++ b/app/decorators/dossier_decorator.rb @@ -5,11 +5,11 @@ class DossierDecorator < Draper::Decorator delegate_all def first_creation - created_at.localtime.strftime('%d/%m/%Y %H:%M') + created_at.strftime('%d/%m/%Y %H:%M') end def last_update - updated_at.localtime.strftime('%d/%m/%Y %H:%M') + updated_at.strftime('%d/%m/%Y %H:%M') end def display_state diff --git a/app/decorators/procedure_decorator.rb b/app/decorators/procedure_decorator.rb index 6b1fc43c3..e4933fbea 100644 --- a/app/decorators/procedure_decorator.rb +++ b/app/decorators/procedure_decorator.rb @@ -2,12 +2,12 @@ class ProcedureDecorator < Draper::Decorator delegate_all def created_at_fr - created_at.localtime.strftime('%d/%m/%Y %H:%M') + created_at.strftime('%d/%m/%Y %H:%M') end def published_at_fr if published_at.present? - published_at.localtime.strftime('%d/%m/%Y %H:%M') + published_at.strftime('%d/%m/%Y %H:%M') end end diff --git a/app/helpers/commentaire_helper.rb b/app/helpers/commentaire_helper.rb index f42450024..684ff2356 100644 --- a/app/helpers/commentaire_helper.rb +++ b/app/helpers/commentaire_helper.rb @@ -20,7 +20,7 @@ module CommentaireHelper def commentaire_date(commentaire) is_current_year = (commentaire.created_at.year == Date.current.year) template = is_current_year ? :message_date : :message_date_with_year - I18n.l(commentaire.created_at.localtime, format: template) + I18n.l(commentaire.created_at, format: template) end private diff --git a/app/jobs/anti_virus_job.rb b/app/jobs/anti_virus_job.rb index 59720f15c..18148ece2 100644 --- a/app/jobs/anti_virus_job.rb +++ b/app/jobs/anti_virus_job.rb @@ -13,7 +13,7 @@ class AntiVirusJob < ApplicationJob else status = VirusScan.statuses.fetch(:infected) end - virus_scan.update(scanned_at: Time.now, status: status) + virus_scan.update(scanned_at: Time.zone.now, status: status) end end end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index 8886fc6ba..779825c4a 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,10 +1,10 @@ class ApplicationJob < ActiveJob::Base before_perform do |job| - Rails.logger.info("#{job.class.name} started at #{Time.now}") + Rails.logger.info("#{job.class.name} started at #{Time.zone.now}") end after_perform do |job| - Rails.logger.info("#{job.class.name} ended at #{Time.now}") + Rails.logger.info("#{job.class.name} ended at #{Time.zone.now}") end def error(job, exception) diff --git a/app/jobs/auto_receive_dossiers_for_procedure_job.rb b/app/jobs/auto_receive_dossiers_for_procedure_job.rb index eff580ddd..ce44c4d46 100644 --- a/app/jobs/auto_receive_dossiers_for_procedure_job.rb +++ b/app/jobs/auto_receive_dossiers_for_procedure_job.rb @@ -7,14 +7,14 @@ class AutoReceiveDossiersForProcedureJob < ApplicationJob when Dossier.states.fetch(:en_instruction) procedure.dossiers.state_en_construction.update_all( state: Dossier.states.fetch(:en_instruction), - en_instruction_at: DateTime.now + en_instruction_at: Time.zone.now ) when Dossier.states.fetch(:accepte) procedure.dossiers.state_en_construction.find_each do |dossier| dossier.update( state: Dossier.states.fetch(:accepte), - en_instruction_at: DateTime.now, - processed_at: DateTime.now + en_instruction_at: Time.zone.now, + processed_at: Time.zone.now ) dossier.attestation = dossier.build_attestation dossier.save diff --git a/app/lib/api_entreprise/entreprise_adapter.rb b/app/lib/api_entreprise/entreprise_adapter.rb index 0798a0d41..989136360 100644 --- a/app/lib/api_entreprise/entreprise_adapter.rb +++ b/app/lib/api_entreprise/entreprise_adapter.rb @@ -10,7 +10,7 @@ class ApiEntreprise::EntrepriseAdapter < ApiEntreprise::Adapter params = data_source[:entreprise].slice(*attr_to_fetch) if valid_params?(params) - params[:date_creation] = Time.at(params[:date_creation]).to_datetime + params[:date_creation] = Time.zone.at(params[:date_creation]).to_datetime params.transform_keys { |k| :"entreprise_#{k}" } else {} diff --git a/app/models/administration.rb b/app/models/administration.rb index ee601caa0..1d350b240 100644 --- a/app/models/administration.rb +++ b/app/models/administration.rb @@ -22,7 +22,7 @@ class Administration < ApplicationRecord User.create({ email: email, password: password, - confirmed_at: DateTime.now + confirmed_at: Time.zone.now }) end diff --git a/app/models/attestation_template.rb b/app/models/attestation_template.rb index 0cf20c5c4..d4919ecac 100644 --- a/app/models/attestation_template.rb +++ b/app/models/attestation_template.rb @@ -79,7 +79,7 @@ class AttestationTemplate < ApplicationRecord body: replace_tags(body, dossier), signature: signature, footer: footer, - created_at: Time.now) + created_at: Time.zone.now) attestation_view = action_view.render(file: 'admin/attestation_templates/show', formats: [:pdf]) diff --git a/app/models/champs/datetime_champ.rb b/app/models/champs/datetime_champ.rb index 0f01fcb2e..a38aa151f 100644 --- a/app/models/champs/datetime_champ.rb +++ b/app/models/champs/datetime_champ.rb @@ -25,12 +25,12 @@ class Champs::DatetimeChamp < Champ begin hash_date = YAML.safe_load(value.gsub('=>', ': ')) year, month, day, hour, minute = hash_date.values_at(1,2,3,4,5) - DateTime.new(year, month, day, hour, minute).strftime("%d/%m/%Y %H:%M") + Time.zone.local(year, month, day, hour, minute).strftime("%d/%m/%Y %H:%M") rescue nil end elsif /^\d{2}\/\d{2}\/\d{4}\s\d{2}:\d{2}$/.match?(value) # old browsers can send with dd/mm/yyyy hh:mm format - self.value = DateTime.parse(value, "%d/%m/%Y %H:%M").strftime("%Y-%m-%d %H:%M") + self.value = Time.zone.strptime(value, "%d/%m/%Y %H:%M").strftime("%Y-%m-%d %H:%M") elsif !(/^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$/.match?(value)) # a datetime not correctly formatted should not be stored self.value = nil end diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index e3b3d2c72..8b510b095 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -14,7 +14,7 @@ class Commentaire < ApplicationRecord after_create :notify def header - "#{sender}, #{I18n.l(created_at.localtime, format: '%d %b %Y %H:%M')}" + "#{sender}, #{I18n.l(created_at, format: '%d %b %Y %H:%M')}" end def sender diff --git a/app/models/concerns/tags_substitution_concern.rb b/app/models/concerns/tags_substitution_concern.rb index b861fd026..c57ac92ef 100644 --- a/app/models/concerns/tags_substitution_concern.rb +++ b/app/models/concerns/tags_substitution_concern.rb @@ -126,7 +126,7 @@ module TagsSubstitutionConcern def format_date(date) if date.present? - date.localtime.strftime('%d/%m/%Y') + date.strftime('%d/%m/%Y') else '' end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index dbbdaf26f..fdcf4336c 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -180,7 +180,7 @@ class Dossier < ApplicationRecord end def retention_expired? - instruction_commencee? && retention_end_date <= DateTime.now + instruction_commencee? && retention_end_date <= Time.zone.now end def text_summary @@ -194,7 +194,7 @@ class Dossier < ApplicationRecord else parts = [ "Dossier déposé le ", - en_construction_at.localtime.strftime("%d/%m/%Y"), + en_construction_at.strftime("%d/%m/%Y"), " sur la démarche ", procedure.libelle, " gérée par l'organisme ", @@ -275,7 +275,7 @@ class Dossier < ApplicationRecord end def delete_and_keep_track - now = Time.now + now = Time.zone.now deleted_dossier = DeletedDossier.create!(dossier_id: id, procedure: procedure, state: state, deleted_at: now) update(hidden_at: now) @@ -309,11 +309,11 @@ class Dossier < ApplicationRecord def update_state_dates if en_construction? && !self.en_construction_at - self.en_construction_at = DateTime.now + self.en_construction_at = Time.zone.now elsif en_instruction? && !self.en_instruction_at - self.en_instruction_at = DateTime.now + self.en_instruction_at = Time.zone.now elsif TERMINE.include?(state) - self.processed_at = DateTime.now + self.processed_at = Time.zone.now end end diff --git a/app/models/follow.rb b/app/models/follow.rb index 4086a1ec7..c94bef80e 100644 --- a/app/models/follow.rb +++ b/app/models/follow.rb @@ -9,9 +9,9 @@ class Follow < ApplicationRecord private def set_default_date - self.demande_seen_at ||= DateTime.now - self.annotations_privees_seen_at ||= DateTime.now - self.avis_seen_at ||= DateTime.now - self.messagerie_seen_at ||= DateTime.now + self.demande_seen_at ||= Time.zone.now + self.annotations_privees_seen_at ||= Time.zone.now + self.avis_seen_at ||= Time.zone.now + self.messagerie_seen_at ||= Time.zone.now end end diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 13978c827..4829a736b 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -64,7 +64,7 @@ class Gestionnaire < ApplicationRecord end def last_week_overview - start_date = DateTime.now.beginning_of_week + start_date = Time.zone.now.beginning_of_week active_procedure_overviews = procedures .publiees @@ -180,7 +180,7 @@ class Gestionnaire < ApplicationRecord def mark_tab_as_seen(dossier, tab) attributes = {} - attributes["#{tab}_seen_at"] = DateTime.now + attributes["#{tab}_seen_at"] = Time.zone.now Follow.where(gestionnaire: self, dossier: dossier).update_all(attributes) end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 58df38f18..c65f49366 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -257,7 +257,7 @@ class Procedure < ApplicationRecord def export_filename procedure_identifier = path || "procedure-#{id}" - "dossiers_#{procedure_identifier}_#{Time.now.strftime('%Y-%m-%d_%H-%M')}" + "dossiers_#{procedure_identifier}_#{Time.zone.now.strftime('%Y-%m-%d_%H-%M')}" end def generate_export @@ -305,7 +305,7 @@ class Procedure < ApplicationRecord end def whitelist! - update_attribute('whitelisted_at', DateTime.now) + update_attribute('whitelisted_at', Time.zone.now) end def closed_mail_template_attestation_inconsistency_state @@ -344,24 +344,24 @@ class Procedure < ApplicationRecord end def after_publish(path) - update!(published_at: Time.now) + update!(published_at: Time.zone.now) publish_with_path!(path) end def after_archive - update!(archived_at: Time.now, path: nil) + update!(archived_at: Time.zone.now, path: nil) end def after_hide - now = Time.now + now = Time.zone.now update!(hidden_at: now, path: nil) procedure_path&.hide! dossiers.update_all(hidden_at: now) end def after_reopen(path) - update!(published_at: Time.now, archived_at: nil) + update!(published_at: Time.zone.now, archived_at: nil) publish_with_path!(path) end diff --git a/app/models/procedure_overview.rb b/app/models/procedure_overview.rb index ddb70a8d1..a514766c5 100644 --- a/app/models/procedure_overview.rb +++ b/app/models/procedure_overview.rb @@ -24,7 +24,7 @@ class ProcedureOverview @created_dossiers_count = procedure .dossiers - .where(created_at: start_date..DateTime.now) + .where(created_at: start_date..Time.zone.now) .state_not_brouillon .count end diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 34ddbdf42..56f5ad1c9 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -111,8 +111,12 @@ class ProcedurePresentation < ApplicationRecord column = sanitized_column(filter) case table when 'self' - date = filter['value'].to_date rescue nil - dossiers.where("DATE_TRUNC('day', #{column}) = ?", date) + date = Time.zone.parse(filter['value']) + if date.present? + dossiers.where("#{column} BETWEEN ? AND ?", date, date + 1.day) + else + [] + end when 'type_de_champ', 'type_de_champ_private' relation = table == 'type_de_champ' ? :champs : :champs_private dossiers @@ -186,7 +190,7 @@ class ProcedurePresentation < ApplicationRecord def get_value(dossier, table, column) case table when 'self' - dossier.send(column) + dossier.send(column)&.strftime('%d/%m/%Y') when 'user', 'individual', 'etablissement' dossier.send(table)&.send(column) when 'type_de_champ' diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml index 7140724b5..c56086e40 100644 --- a/app/views/layouts/_footer.html.haml +++ b/app/views/layouts/_footer.html.haml @@ -1,7 +1,7 @@ #footer %p{ class: "copyright col-md-push-#{12-main_container_size} col-md-#{main_container_size} col-lg-push-#{12-main_container_size} col-lg-#{main_container_size} text-muted small" } = link_to 'DINSIC', "http://etatplateforme.modernisation.gouv.fr" - = Time.now.year + = Time.zone.now.year \- = link_to 'Nouveautés', 'https://github.com/betagouv/tps/releases', target: '_blank' \- diff --git a/app/views/new_gestionnaire/avis/instruction.html.haml b/app/views/new_gestionnaire/avis/instruction.html.haml index 5bef952d5..35e545155 100644 --- a/app/views/new_gestionnaire/avis/instruction.html.haml +++ b/app/views/new_gestionnaire/avis/instruction.html.haml @@ -8,7 +8,7 @@ %h2.claimant Demandeur : %span.email= @avis.claimant.email - %span.date Demande d'avis envoyée le #{I18n.l(@avis.created_at.localtime, format: '%d/%m/%y')} + %span.date Demande d'avis envoyée le #{I18n.l(@avis.created_at, format: '%d/%m/%y')} %p.introduction= @avis.introduction = form_for @avis, url: gestionnaire_avis_path(@avis), html: { class: 'form' } do |f| diff --git a/app/views/new_gestionnaire/shared/avis/_list.html.haml b/app/views/new_gestionnaire/shared/avis/_list.html.haml index fb34568fb..8bbc4654d 100644 --- a/app/views/new_gestionnaire/shared/avis/_list.html.haml +++ b/app/views/new_gestionnaire/shared/avis/_list.html.haml @@ -15,7 +15,7 @@ confidentiel %span.icon.lock{ title: "Cet avis n'est pas affiché avec les autres experts consultés" } %span.date{ class: highlight_if_unseen_class(avis_seen_at, avis.created_at) } - Demande d'avis envoyée le #{I18n.l(avis.created_at.localtime, format: '%d/%m/%y à %H:%M')} + Demande d'avis envoyée le #{I18n.l(avis.created_at, format: '%d/%m/%y à %H:%M')} %p= avis.introduction .answer.flex.align-start @@ -25,7 +25,7 @@ = (avis.email_to_display == current_gestionnaire.email) ? 'Vous' : avis.email_to_display - if avis.answer.present? %span.date{ class: highlight_if_unseen_class(avis_seen_at, avis.updated_at) } - Réponse donnée le #{I18n.l(avis.updated_at.localtime, format: '%d/%m/%y à %H:%M')} + Réponse donnée le #{I18n.l(avis.updated_at, format: '%d/%m/%y à %H:%M')} - else %span.waiting En attente de réponse %p= avis.answer diff --git a/app/views/new_user/dossiers/index.html.haml b/app/views/new_user/dossiers/index.html.haml index 1f9be4d28..80f6a9aff 100644 --- a/app/views/new_user/dossiers/index.html.haml +++ b/app/views/new_user/dossiers/index.html.haml @@ -48,7 +48,7 @@ = render partial: 'shared/dossiers/status_badge', locals: { dossier: dossier } %td.updated-at-col = link_to(url_for_dossier(dossier), class: 'cell-link') do - = dossier.updated_at.localtime.strftime("%d/%m/%Y") + = dossier.updated_at.strftime("%d/%m/%Y") = paginate(@dossiers) - if current_user.feedbacks.empty? || current_user.feedbacks.last.created_at < 1.month.ago diff --git a/app/views/shared/dossiers/_champs.html.haml b/app/views/shared/dossiers/_champs.html.haml index cf69342c6..b7feb25a9 100644 --- a/app/views/shared/dossiers/_champs.html.haml +++ b/app/views/shared/dossiers/_champs.html.haml @@ -73,4 +73,4 @@ %td.updated-at %span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) } modifié le - = c.updated_at.localtime.strftime("%d/%m/%Y à %H:%M") + = c.updated_at.strftime("%d/%m/%Y à %H:%M") diff --git a/app/views/shared/dossiers/_pieces_jointes.html.haml b/app/views/shared/dossiers/_pieces_jointes.html.haml index 78dafa823..ec9218d2e 100644 --- a/app/views/shared/dossiers/_pieces_jointes.html.haml +++ b/app/views/shared/dossiers/_pieces_jointes.html.haml @@ -23,11 +23,11 @@ = link_to pj.content_url, { target: :blank } do %span.filename= display_pj_filename(pj) %span - ajoutée le #{pj.created_at.localtime.strftime('%d/%m/%Y à %H:%M')} + ajoutée le #{pj.created_at.strftime('%d/%m/%Y à %H:%M')} - else %td Pièce non fournie %td.updated-at - if pj %span{ class: highlight_if_unseen_class(demande_seen_at, pj.updated_at) } modifié le - = pj.updated_at.localtime.strftime("%d/%m/%Y à %H:%M") + = pj.updated_at.strftime("%d/%m/%Y à %H:%M") diff --git a/app/views/shared/dossiers/editable_champs/_datetime.html.haml b/app/views/shared/dossiers/editable_champs/_datetime.html.haml index a1fe5e0a9..4eb9c2109 100644 --- a/app/views/shared/dossiers/editable_champs/_datetime.html.haml +++ b/app/views/shared/dossiers/editable_champs/_datetime.html.haml @@ -1,4 +1,4 @@ -- parsed_value = champ.value.present? ? DateTime.parse(champ.value) : DateTime.now +- parsed_value = champ.value.present? ? Time.zone.parse(champ.value) : Time.zone.now .datetime = form.datetime_select(:value, selected: parsed_value, start_year: 1950, end_year: 2100, minute_step: 5) diff --git a/config/application.rb b/config/application.rb index bbb513db5..5514cf471 100644 --- a/config/application.rb +++ b/config/application.rb @@ -16,7 +16,7 @@ module TPS # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - # config.time_zone = 'Central Time (US & Canada)' + config.time_zone = 'Paris' # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] diff --git a/db/migrate/20150922085811_add_time_stamp_to_dossier.rb b/db/migrate/20150922085811_add_time_stamp_to_dossier.rb index 0e00467da..6b7612dc7 100644 --- a/db/migrate/20150922085811_add_time_stamp_to_dossier.rb +++ b/db/migrate/20150922085811_add_time_stamp_to_dossier.rb @@ -1,6 +1,6 @@ class AddTimeStampToDossier < ActiveRecord::Migration def change - add_column :dossiers, :created_at, :datetime, default: Time.now - add_column :dossiers, :updated_at, :datetime, default: Time.now + add_column :dossiers, :created_at, :datetime, default: Time.zone.now + add_column :dossiers, :updated_at, :datetime, default: Time.zone.now end end diff --git a/db/migrate/20180514091001_add_confirmable_to_user_devise.rb b/db/migrate/20180514091001_add_confirmable_to_user_devise.rb index 56b31ec00..5aa95d2eb 100644 --- a/db/migrate/20180514091001_add_confirmable_to_user_devise.rb +++ b/db/migrate/20180514091001_add_confirmable_to_user_devise.rb @@ -7,7 +7,7 @@ class AddConfirmableToUserDevise < ActiveRecord::Migration[5.2] # User.reset_column_information # Need for some types of updates, but not for update_all. # To avoid a short time window between running the migration and updating all existing # users as confirmed, do the following - User.all.update_all confirmed_at: DateTime.now + User.all.update_all confirmed_at: Time.zone.now # All existing user accounts should be able to log in after this. end diff --git a/db/seeds.rb b/db/seeds.rb index 490202191..91472103e 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -12,4 +12,4 @@ puts "Create test user '#{default_user}'" Administration.create!(email: default_user, password: default_password) Administrateur.create!(email: default_user, password: default_password) Gestionnaire.create!(email: default_user, password: default_password) -User.create!(email: default_user, password: default_password, confirmed_at: DateTime.now) +User.create!(email: default_user, password: default_password, confirmed_at: Time.zone.now) diff --git a/lib/cellar/amazon_v2_request_signer.rb b/lib/cellar/amazon_v2_request_signer.rb index 67891e00d..03bec0b04 100644 --- a/lib/cellar/amazon_v2_request_signer.rb +++ b/lib/cellar/amazon_v2_request_signer.rb @@ -10,7 +10,7 @@ module Cellar end def sign(request, key) - date = Time.now.httpdate + date = Time.zone.now.httpdate sig = signature( method: request.method, key: key, diff --git a/lib/tasks/2017_12_05_initialize_timestamps_for_entreprises.rake b/lib/tasks/2017_12_05_initialize_timestamps_for_entreprises.rake index 7c807713a..fdf459107 100644 --- a/lib/tasks/2017_12_05_initialize_timestamps_for_entreprises.rake +++ b/lib/tasks/2017_12_05_initialize_timestamps_for_entreprises.rake @@ -15,7 +15,7 @@ namespace :'2017_12_05_initialize_timestamps_for_entreprises' do entreprise.update_columns(created_at: entreprise.dossier.created_at, updated_at: entreprise.dossier.created_at) else rake_puts "dossier #{entreprise.dossier_id} is missing for entreprise #{entreprise.id}" - entreprise.update_columns(created_at: DateTime.now, updated_at: DateTime.now) + entreprise.update_columns(created_at: Time.zone.now, updated_at: Time.zone.now) end end end diff --git a/lib/tasks/2018_01_18_clean_datetime_in_champs.rake b/lib/tasks/2018_01_18_clean_datetime_in_champs.rake index fead2d063..004685b7b 100644 --- a/lib/tasks/2018_01_18_clean_datetime_in_champs.rake +++ b/lib/tasks/2018_01_18_clean_datetime_in_champs.rake @@ -12,7 +12,7 @@ namespace :'2018_01_18_clean_datetime_in_champs' do # Match "dd/mm/YYYY HH:MM" => "YYYY-mm-dd HH:MM" datetime_champs.select { |c| /^\d{2}\/\d{2}\/\d{4}\s\d{2}:\d{2}$/ =~ c.value }.each do |c| - formated_date = DateTime.parse(c.value, "%d/%m/%Y %H:%M").strftime("%Y-%m-%d %H:%M") + formated_date = Time.zone.strptime(c.value, "%d/%m/%Y %H:%M").strftime("%Y-%m-%d %H:%M") rake_puts "cleaning #{c.value} => #{formated_date}" c.update_columns(value: formated_date) end diff --git a/lib/tasks/2018_03_08_send_missed_accuse_reception.rake b/lib/tasks/2018_03_08_send_missed_accuse_reception.rake index 4af7fbaeb..8ed0fe70e 100644 --- a/lib/tasks/2018_03_08_send_missed_accuse_reception.rake +++ b/lib/tasks/2018_03_08_send_missed_accuse_reception.rake @@ -8,8 +8,8 @@ namespace :'2018_03_08_send_missing_accuse_reception' do # `bug_date` and `fix_date` were determined empirically by looking at the release times, # and checking for dossiers with a missing accusé de réception. - bug_date = DateTime.new(2018, 3, 1, 9, 50) - fix_date = DateTime.new(2018, 3, 5, 18, 40) + bug_date = Time.zone.local(2018, 3, 1, 9, 50) + fix_date = Time.zone.local(2018, 3, 5, 18, 40) # Only send the accusé for dossiers that are still en construction. # For dossiers that have moved on, other mails have been sent since, and a late diff --git a/lib/tasks/2018_05_30_missed_ar_messages.rake b/lib/tasks/2018_05_30_missed_ar_messages.rake index e3e7a4b90..5a6e3be5d 100644 --- a/lib/tasks/2018_05_30_missed_ar_messages.rake +++ b/lib/tasks/2018_05_30_missed_ar_messages.rake @@ -7,7 +7,7 @@ namespace :'2018_05_30_missed_ar_messages' do end def create_commentaires(date_name, template_name, dossiers = Dossier) - error_range = DateTime.new(2018, 05, 28, 13, 33)..DateTime.new(2018, 05, 30, 15, 39) + error_range = Time.zone.local(2018, 05, 28, 13, 33)..Time.zone.local(2018, 05, 30, 15, 39) dossiers.includes(:procedure).where(date_name => error_range).find_each(batch_size: 100) do |dossier| print "#{dossier.id}\n" diff --git a/lib/tasks/2018_06_06_users_for_admins_and_gestionnaires.rake b/lib/tasks/2018_06_06_users_for_admins_and_gestionnaires.rake index d99423ab2..91c56b6af 100644 --- a/lib/tasks/2018_06_06_users_for_admins_and_gestionnaires.rake +++ b/lib/tasks/2018_06_06_users_for_admins_and_gestionnaires.rake @@ -24,7 +24,7 @@ namespace :'2018_06_06_users_for_admins_and_gestionnaires' do User .joins("INNER JOIN #{table_name} ON #{table_name}.email = users.email") .where(confirmed_at: nil) - .update_all(confirmed_at: DateTime.now) + .update_all(confirmed_at: Time.zone.now) rake_puts "Fixed #{count} #{table_name} with unconfirmed user" end diff --git a/lib/tasks/2018_09_12_fix_templates.rake b/lib/tasks/2018_09_12_fix_templates.rake index 127617f33..8ca36b559 100644 --- a/lib/tasks/2018_09_12_fix_templates.rake +++ b/lib/tasks/2018_09_12_fix_templates.rake @@ -7,7 +7,11 @@ namespace :'2018_09_12_fix_templates' do end # 16:15 in Paris -> 14:15 UTC - DEPLOY_DATETIME = DateTime.new(2018, 9, 5, 14, 15, 0) + + # rubocop:disable Rails/TimeZone + # because we are in a ruby context so Time.zone = nil + DEPLOY_DATETIME = Time.local(2018, 9, 5, 14, 15, 0) + # rubocop:enable Rails/TimeZone def find_dossiers_with_sent_and_invalid_attestations invalid_procedures_ids = AttestationTemplate @@ -16,12 +20,12 @@ namespace :'2018_09_12_fix_templates' do dossiers_with_invalid_template_ids = Dossier .where(procedure_id: invalid_procedures_ids) - .where(processed_at: DEPLOY_DATETIME..Time.now) + .where(processed_at: DEPLOY_DATETIME..Time.zone.now) .pluck(:id) Attestation .includes(:dossier) - .where(created_at: DEPLOY_DATETIME..Time.now) + .where(created_at: DEPLOY_DATETIME..Time.zone.now) .where(dossier_id: dossiers_with_invalid_template_ids) .map(&:dossier) end diff --git a/lib/tasks/cloud_storage.rake b/lib/tasks/cloud_storage.rake index 538f5268c..37679086b 100644 --- a/lib/tasks/cloud_storage.rake +++ b/lib/tasks/cloud_storage.rake @@ -104,8 +104,8 @@ namespace :cloudstorage do Rake::Task['cloudstorage:init'].invoke @cont.objects_detail.each { |object, details| - last_modified = DateTime.parse(details[:last_modified]) - @cont.delete_object(object) if last_modified.utc <= (Time.now - 2.years).utc + last_modified = Time.zone.parse(details[:last_modified]) + @cont.delete_object(object) if last_modified.utc <= (Time.zone.now - 2.years).utc } end end diff --git a/spec/controllers/admin/attestation_templates_controller_spec.rb b/spec/controllers/admin/attestation_templates_controller_spec.rb index f72e07227..efae4d4af 100644 --- a/spec/controllers/admin/attestation_templates_controller_spec.rb +++ b/spec/controllers/admin/attestation_templates_controller_spec.rb @@ -12,7 +12,7 @@ describe Admin::AttestationTemplatesController, type: :controller do before do sign_in admin - Timecop.freeze(Time.now) + Timecop.freeze(Time.zone.now) end after { Timecop.return } @@ -47,7 +47,7 @@ describe Admin::AttestationTemplatesController, type: :controller do it { expect(subject.status).to eq(200) } it { expect(assigns).to include(upload_params.stringify_keys) } - it { expect(assigns[:created_at]).to eq(DateTime.now) } + it { expect(assigns[:created_at]).to eq(Time.zone.now) } it { expect(assigns(:logo).read).to eq(logo.read) } it { expect(assigns(:signature).read).to eq(signature.read) } after { procedure.attestation_template.destroy } diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 18585d239..a5c8cdbfe 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -96,8 +96,8 @@ describe Admin::ProceduresController, type: :controller do describe 'DELETE #destroy' do let(:procedure_draft) { create :procedure, administrateur: admin, published_at: nil, archived_at: nil } - let(:procedure_published) { create :procedure, administrateur: admin, aasm_state: :publiee, published_at: Time.now, archived_at: nil } - let(:procedure_archived) { create :procedure, administrateur: admin, aasm_state: :archivee, published_at: nil, archived_at: Time.now } + let(:procedure_published) { create :procedure, administrateur: admin, aasm_state: :publiee, published_at: Time.zone.now, archived_at: nil } + let(:procedure_archived) { create :procedure, administrateur: admin, aasm_state: :archivee, published_at: nil, archived_at: Time.zone.now } subject { delete :destroy, params: { id: procedure.id } } @@ -164,7 +164,7 @@ describe Admin::ProceduresController, type: :controller do end context 'when procedure is published' do - let(:published_at) { Time.now } + let(:published_at) { Time.zone.now } it { is_expected.to have_http_status(:success) } end diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb index ff66fb2f0..6873f031c 100644 --- a/spec/controllers/api/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/v1/dossiers_controller_spec.rb @@ -40,7 +40,7 @@ describe API::V1::DossiersController do context 'when procedure is found and belongs to admin' do let(:procedure_id) { procedure.id } - let(:date_creation) { Time.utc(2008, 9, 1, 10, 5, 0) } + let(:date_creation) { Time.zone.local(2008, 9, 1, 10, 5, 0) } let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, :en_construction, procedure: procedure) } } let(:body) { JSON.parse(retour.body, symbolize_names: true) } @@ -75,8 +75,8 @@ describe API::V1::DossiersController do describe 'dossier' do subject { super().first } it { expect(subject[:id]).to eq(dossier.id) } - it { expect(subject[:updated_at]).to eq("2008-09-01T10:05:00.000Z") } - it { expect(subject[:initiated_at]).to eq("2008-09-01T10:06:00.000Z") } + it { expect(subject[:updated_at]).to eq("2008-09-01T10:05:00.000+02:00") } + it { expect(subject[:initiated_at]).to eq("2008-09-01T10:06:00.000+02:00") } it { expect(subject[:state]).to eq("initiated") } it { expect(subject.keys.size).to eq(4) } end @@ -135,7 +135,7 @@ describe API::V1::DossiersController do context 'when dossier exists and belongs to procedure' do let(:procedure_id) { procedure.id } - let(:date_creation) { Time.utc(2008, 9, 1, 10, 5, 0) } + let(:date_creation) { Time.zone.local(2008, 9, 1, 10, 5, 0) } let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure, motivation: "Motivation") } } let(:dossier_id) { dossier.id } let(:body) { JSON.parse(retour.body, symbolize_names: true) } @@ -148,8 +148,8 @@ describe API::V1::DossiersController do it { expect(subject[:id]).to eq(dossier.id) } it { expect(subject[:state]).to eq(dossier.state) } - it { expect(subject[:created_at]).to eq('2008-09-01T10:05:00.000Z') } - it { expect(subject[:updated_at]).to eq('2008-09-01T10:05:00.000Z') } + it { expect(subject[:created_at]).to eq('2008-09-01T10:05:00.000+02:00') } + it { expect(subject[:updated_at]).to eq('2008-09-01T10:05:00.000+02:00') } it { expect(subject[:archived]).to eq(dossier.archived) } it { expect(subject.keys).to match_array(field_list) } @@ -337,7 +337,7 @@ describe API::V1::DossiersController do it { expect(subject.size).to eq 2 } it { expect(subject.first[:body]).to eq 'plop' } - it { expect(subject.first[:created_at]).to eq '2016-03-14T14:00:00.000Z' } + it { expect(subject.first[:created_at]).to eq '2016-03-14T14:00:00.000+01:00' } it { expect(subject.first[:email]).to eq 'plop@plip.com' } end diff --git a/spec/controllers/france_connect/particulier_controller_spec.rb b/spec/controllers/france_connect/particulier_controller_spec.rb index 0727a3902..498087145 100644 --- a/spec/controllers/france_connect/particulier_controller_spec.rb +++ b/spec/controllers/france_connect/particulier_controller_spec.rb @@ -82,7 +82,7 @@ describe FranceConnect::ParticulierController, type: :controller do before { subject } - it { expect(stored_fci).to have_attributes(user_info.merge(birthdate: DateTime.parse(birthdate))) } + it { expect(stored_fci).to have_attributes(user_info.merge(birthdate: Date.parse(birthdate))) } end it { is_expected.to redirect_to(root_path) } diff --git a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb index 8df4828d7..bd074d314 100644 --- a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb @@ -250,11 +250,11 @@ describe NewGestionnaire::DossiersController, type: :controller do end before do - Timecop.freeze(DateTime.now) + Timecop.freeze(Time.zone.now) expect_any_instance_of(AttestationTemplate) .to receive(:attestation_for) - .with(have_attributes(motivation: "Yallah", processed_at: DateTime.now)) + .with(have_attributes(motivation: "Yallah", processed_at: Time.zone.now)) end after { Timecop.return } diff --git a/spec/controllers/stats_controller_spec.rb b/spec/controllers/stats_controller_spec.rb index 0b9bcb71f..fcb0a1e21 100644 --- a/spec/controllers/stats_controller_spec.rb +++ b/spec/controllers/stats_controller_spec.rb @@ -8,7 +8,7 @@ describe StatsController, type: :controller do FactoryBot.create(:procedure, :created_at => 2.months.ago, :updated_at => 62.days.ago) FactoryBot.create(:procedure, :created_at => 2.months.ago, :updated_at => 62.days.ago) FactoryBot.create(:procedure, :created_at => 2.months.ago, :updated_at => 31.days.ago) - FactoryBot.create(:procedure, :created_at => 2.months.ago, :updated_at => Time.now) + FactoryBot.create(:procedure, :created_at => 2.months.ago, :updated_at => Time.zone.now) @controller = StatsController.new allow(@controller).to receive(:administration_signed_in?).and_return(false) @@ -53,7 +53,7 @@ describe StatsController, type: :controller do describe '#cumulative_hash' do before do - Timecop.freeze(Time.new(2016, 10, 2)) + Timecop.freeze(Time.zone.local(2016, 10, 2)) FactoryBot.create(:procedure, :created_at => 55.days.ago, :updated_at => 43.days.ago) FactoryBot.create(:procedure, :created_at => 45.days.ago, :updated_at => 40.days.ago) FactoryBot.create(:procedure, :created_at => 45.days.ago, :updated_at => 20.days.ago) @@ -72,9 +72,9 @@ describe StatsController, type: :controller do it do expect(subject).to eq({ - 2.months.ago.beginning_of_month => 2, - 1.month.ago.beginning_of_month => 4, - 1.hour.ago.beginning_of_month => 5 + Time.utc(2016, 8, 1) => 2, + Time.utc(2016, 9, 1) => 4, + Time.utc(2016, 10, 1) => 5 }) end end @@ -86,8 +86,8 @@ describe StatsController, type: :controller do it do expect(subject).to eq({ - 2.months.ago.beginning_of_month => 2, - 1.month.ago.beginning_of_month => 4 + Time.utc(2016, 8, 1) => 2, + Time.utc(2016, 9, 1) => 4 }) end end @@ -102,18 +102,18 @@ describe StatsController, type: :controller do before do 3.times do - create(:procedure, published_at: Time.now, administrateur: administrateur_1) + create(:procedure, published_at: Time.zone.now, administrateur: administrateur_1) end 2.times do - create(:procedure, published_at: Time.now, administrateur: administrateur_2) + create(:procedure, published_at: Time.zone.now, administrateur: administrateur_2) end 8.times do - create(:procedure, published_at: Time.now, administrateur: administrateur_3) + create(:procedure, published_at: Time.zone.now, administrateur: administrateur_3) end - create(:procedure, published_at: Time.now, administrateur: administrateur_4) + create(:procedure, published_at: Time.zone.now, administrateur: administrateur_4) end let(:association){ Procedure.all } @@ -234,7 +234,7 @@ describe StatsController, type: :controller do let!(:avis_with_dossier) { create(:avis) } let!(:dossier2) { create(:dossier) } - before { Timecop.freeze(Time.now) } + before { Timecop.freeze(Time.zone.now) } after { Timecop.return } subject { StatsController.new.send(:avis_usage) } @@ -244,7 +244,7 @@ describe StatsController, type: :controller do describe "#avis_average_answer_time" do before do - Timecop.freeze(Time.now) + Timecop.freeze(Time.zone.now) # 1 week ago create(:avis, answer: "voila ma réponse", created_at: 1.week.ago + 1.day, updated_at: 1.week.ago + 2.days) # 1 day @@ -278,7 +278,7 @@ describe StatsController, type: :controller do subject { StatsController.new.send(:avis_answer_percentages) } - before { Timecop.freeze(Time.now) } + before { Timecop.freeze(Time.zone.now) } after { Timecop.return } it { is_expected.to match [[3.weeks.ago.to_i, 0], [2.weeks.ago.to_i, 0], [1.week.ago.to_i, 66.67]] } @@ -289,7 +289,7 @@ describe StatsController, type: :controller do let!(:dossier2) { create(:dossier, processed_at: 1.week.ago) } let!(:dossier3) { create(:dossier, processed_at: 1.week.ago) } - before { Timecop.freeze(Time.now) } + before { Timecop.freeze(Time.zone.now) } after { Timecop.return } subject { StatsController.new.send(:motivation_usage_dossier) } @@ -303,7 +303,7 @@ describe StatsController, type: :controller do let!(:dossier2) { create(:dossier, processed_at: 1.week.ago) } let!(:dossier3) { create(:dossier, processed_at: 1.week.ago) } - before { Timecop.freeze(Time.now) } + before { Timecop.freeze(Time.zone.now) } after { Timecop.return } subject { StatsController.new.send(:motivation_usage_procedure) } @@ -316,7 +316,7 @@ describe StatsController, type: :controller do let!(:procedure2) { create(:procedure, created_at: 2.weeks.ago) } let!(:procedure3) { create(:procedure, created_at: 2.weeks.ago, cloned_from_library: true) } - before { Timecop.freeze(Time.now) } + before { Timecop.freeze(Time.zone.now) } after { Timecop.return } subject { StatsController.new.send(:cloned_from_library_procedures_ratio) } diff --git a/spec/controllers/users/registrations_controller_spec.rb b/spec/controllers/users/registrations_controller_spec.rb index 58faecedd..14af91a6a 100644 --- a/spec/controllers/users/registrations_controller_spec.rb +++ b/spec/controllers/users/registrations_controller_spec.rb @@ -57,7 +57,7 @@ describe Users::RegistrationsController, type: :controller do end context 'and the user is confirmed' do - let(:confirmed_at) { DateTime.now } + let(:confirmed_at) { Time.zone.now } before { subject } diff --git a/spec/decorators/dossier_decorator_spec.rb b/spec/decorators/dossier_decorator_spec.rb index a6be8c83e..184d28407 100644 --- a/spec/decorators/dossier_decorator_spec.rb +++ b/spec/decorators/dossier_decorator_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' describe DossierDecorator do let(:dossier) do - dossier = create(:dossier, created_at: Time.new(2015, 12, 24, 14, 10)) - dossier.update_column('updated_at', Time.new(2015, 12, 24, 14, 10)) + dossier = create(:dossier, created_at: Time.zone.local(2015, 12, 24, 14, 10)) + dossier.update_column('updated_at', Time.zone.local(2015, 12, 24, 14, 10)) dossier end diff --git a/spec/decorators/procedure_decorator_spec.rb b/spec/decorators/procedure_decorator_spec.rb index 8fba48bba..742db1047 100644 --- a/spec/decorators/procedure_decorator_spec.rb +++ b/spec/decorators/procedure_decorator_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' describe ProcedureDecorator do - let(:published_at) { Time.new(2017, 12, 24, 14, 12) } - let(:procedure) { create(:procedure, published_at: published_at, created_at: Time.new(2015, 12, 24, 14, 10)) } + let(:published_at) { Time.zone.local(2017, 12, 24, 14, 12) } + let(:procedure) { create(:procedure, published_at: published_at, created_at: Time.zone.local(2015, 12, 24, 14, 10)) } let!(:procedure_path) { create(:procedure_path, administrateur: create(:administrateur), procedure: procedure) } subject { procedure.decorate } diff --git a/spec/decorators/procedures_decorator_spec.rb b/spec/decorators/procedures_decorator_spec.rb index 6543e539b..92f63c91e 100644 --- a/spec/decorators/procedures_decorator_spec.rb +++ b/spec/decorators/procedures_decorator_spec.rb @@ -2,9 +2,9 @@ require 'spec_helper' describe ProceduresDecorator do before do - create(:procedure, :published, created_at: Time.new(2015, 12, 24, 14, 10)) - create(:procedure, :published, created_at: Time.new(2015, 12, 24, 14, 10)) - create(:procedure, :published, created_at: Time.new(2015, 12, 24, 14, 10)) + create(:procedure, :published, created_at: Time.zone.local(2015, 12, 24, 14, 10)) + create(:procedure, :published, created_at: Time.zone.local(2015, 12, 24, 14, 10)) + create(:procedure, :published, created_at: Time.zone.local(2015, 12, 24, 14, 10)) end let(:procedure) { Procedure.all.page(1) } diff --git a/spec/factories/deleted_dossier.rb b/spec/factories/deleted_dossier.rb index 9a972ae79..f511742ae 100644 --- a/spec/factories/deleted_dossier.rb +++ b/spec/factories/deleted_dossier.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :deleted_dossier do dossier_id { 1111 } state { Dossier.states.fetch(:en_construction) } - deleted_at { DateTime.now } + deleted_at { Time.zone.now } association :procedure, :published end diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index a99134ccf..74a83cf26 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -155,7 +155,7 @@ FactoryBot.define do trait :whitelisted do after(:build) do |procedure, _evaluator| - procedure.update(whitelisted_at: DateTime.now) + procedure.update(whitelisted_at: Time.zone.now) end end diff --git a/spec/factories/user.rb b/spec/factories/user.rb index f39fc3e43..df6666652 100644 --- a/spec/factories/user.rb +++ b/spec/factories/user.rb @@ -3,6 +3,6 @@ FactoryBot.define do factory :user do email { generate(:user_email) } password { 'password' } - confirmed_at { DateTime.now } + confirmed_at { Time.zone.now } end end diff --git a/spec/features/new_gestionnaire/procedure_filters_spec.rb b/spec/features/new_gestionnaire/procedure_filters_spec.rb index 61236213a..64f14661b 100644 --- a/spec/features/new_gestionnaire/procedure_filters_spec.rb +++ b/spec/features/new_gestionnaire/procedure_filters_spec.rb @@ -35,7 +35,7 @@ feature "procedure filters" do add_column("Créé le") within ".dossiers-table" do expect(page).to have_link("Créé le") - expect(page).to have_link(new_unfollow_dossier.created_at) + expect(page).to have_link(new_unfollow_dossier.created_at.strftime('%d/%m/%Y')) end end diff --git a/spec/features/new_user/brouillon_spec.rb b/spec/features/new_user/brouillon_spec.rb index cfe5f6185..51c7bedbb 100644 --- a/spec/features/new_user/brouillon_spec.rb +++ b/spec/features/new_user/brouillon_spec.rb @@ -23,7 +23,7 @@ feature 'The user' do fill_in('text', with: 'super texte') fill_in('textarea', with: 'super textarea') fill_in('date', with: '12/12/2012') - select_date_and_time(DateTime.parse('06/01/1985 7h05'), form_id_for('datetime')) + select_date_and_time(Time.zone.parse('06/01/1985 7h05'), form_id_for('datetime')) fill_in('number', with: '42') check('checkbox') choose('Madame') @@ -67,7 +67,7 @@ feature 'The user' do expect(page).to have_field('text', with: 'super texte') expect(page).to have_field('textarea', with: 'super textarea') expect(page).to have_field('date', with: '2012-12-12') - check_date_and_time(DateTime.parse('06/01/1985 7:05'), form_id_for('datetime')) + check_date_and_time(Time.zone.parse('06/01/1985 7:05'), form_id_for('datetime')) expect(page).to have_field('number', with: '42') expect(page).to have_checked_field('checkbox') expect(page).to have_checked_field('Madame') diff --git a/spec/features/new_user/dossier_details_spec.rb b/spec/features/new_user/dossier_details_spec.rb index 6e7a30a76..fd46cac7f 100644 --- a/spec/features/new_user/dossier_details_spec.rb +++ b/spec/features/new_user/dossier_details_spec.rb @@ -19,7 +19,7 @@ describe 'Dossier details:' do describe "the user can see the mean time they are expected to wait" do context "when the dossier is in construction" do before do - other_dossier = create(:dossier, :accepte, :for_individual, procedure: procedure, en_construction_at: 10.days.ago, en_instruction_at: Time.now) + other_dossier = create(:dossier, :accepte, :for_individual, procedure: procedure, en_construction_at: 10.days.ago, en_instruction_at: Time.zone.now) visit dossier_path(dossier) end @@ -30,7 +30,7 @@ describe 'Dossier details:' do let(:dossier) { create(:dossier, :en_instruction, :for_individual, :with_commentaires, user: user, procedure: procedure) } before do - other_dossier = create(:dossier, :accepte, :for_individual, procedure: procedure, en_instruction_at: 2.months.ago, processed_at: Time.now) + other_dossier = create(:dossier, :accepte, :for_individual, procedure: procedure, en_instruction_at: 2.months.ago, processed_at: Time.zone.now) visit dossier_path(dossier) end diff --git a/spec/helpers/commentaire_helper_spec.rb b/spec/helpers/commentaire_helper_spec.rb index cd1a05608..80150e52b 100644 --- a/spec/helpers/commentaire_helper_spec.rb +++ b/spec/helpers/commentaire_helper_spec.rb @@ -49,7 +49,7 @@ RSpec.describe CommentaireHelper, type: :helper do end describe '.commentaire_date' do - let(:present_date) { Time.local(2018, 9, 2, 10, 5, 0) } + let(:present_date) { Time.zone.local(2018, 9, 2, 10, 5, 0) } let(:creation_date) { present_date } let(:commentaire) do Timecop.freeze(creation_date) { create(:commentaire, email: "michel@pref.fr") } @@ -71,7 +71,7 @@ RSpec.describe CommentaireHelper, type: :helper do end context 'when formatting the first day of the month' do - let(:present_date) { Time.local(2018, 9, 1, 10, 5, 0) } + let(:present_date) { Time.zone.local(2018, 9, 1, 10, 5, 0) } it 'includes the ordinal' do expect(subject).to eq 'le 1er septembre à 10 h 05' end diff --git a/spec/helpers/dossier_helper_spec.rb b/spec/helpers/dossier_helper_spec.rb index d2d3de31d..f5683782c 100644 --- a/spec/helpers/dossier_helper_spec.rb +++ b/spec/helpers/dossier_helper_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' RSpec.describe DossierHelper, type: :helper do describe ".highlight_if_unseen_class" do - let(:seen_at) { DateTime.now } + let(:seen_at) { Time.zone.now } subject { highlight_if_unseen_class(seen_at, updated_at) } @@ -19,7 +19,7 @@ RSpec.describe DossierHelper, type: :helper do end context "when there is no last seen datetime" do - let(:updated_at) { DateTime.now } + let(:updated_at) { Time.zone.now } let(:seen_at) { nil } it { is_expected.to eq nil } diff --git a/spec/jobs/administrateurs/activate_before_expiration_job_spec.rb b/spec/jobs/administrateurs/activate_before_expiration_job_spec.rb index a3039ef39..a7e450f7e 100644 --- a/spec/jobs/administrateurs/activate_before_expiration_job_spec.rb +++ b/spec/jobs/administrateurs/activate_before_expiration_job_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Administrateurs::ActivateBeforeExpirationJob, type: :job do subject { Administrateurs::ActivateBeforeExpirationJob.perform_now } before do - Timecop.freeze(DateTime.new(2018, 03, 20)) + Timecop.freeze(Time.zone.local(2018, 03, 20)) administrateur.reload allow(AdministrateurMailer).to receive(:activate_before_expiration).and_return(mailer_double) end @@ -25,7 +25,7 @@ RSpec.describe Administrateurs::ActivateBeforeExpirationJob, type: :job do context "created a long time ago" do before do - administrateur.update_columns(created_at: DateTime.new(2018, 03, 10)) + administrateur.update_columns(created_at: Time.zone.local(2018, 03, 10)) subject end @@ -34,7 +34,7 @@ RSpec.describe Administrateurs::ActivateBeforeExpirationJob, type: :job do context "created 3 days ago" do before do - administrateur.update_columns(created_at: DateTime.new(2018, 03, 17, 20, 00)) + administrateur.update_columns(created_at: Time.zone.local(2018, 03, 17, 20, 00)) subject end @@ -52,7 +52,7 @@ RSpec.describe Administrateurs::ActivateBeforeExpirationJob, type: :job do context "created a long time ago" do before do - administrateur.update_columns(created_at: DateTime.new(2018, 03, 10)) + administrateur.update_columns(created_at: Time.zone.local(2018, 03, 10)) subject end @@ -61,7 +61,7 @@ RSpec.describe Administrateurs::ActivateBeforeExpirationJob, type: :job do context "created 2 days ago" do before do - administrateur.update_columns(created_at: DateTime.new(2018, 03, 18, 20, 00)) + administrateur.update_columns(created_at: Time.zone.local(2018, 03, 18, 20, 00)) subject end diff --git a/spec/lib/cellar/amazon_v2_request_signer_spec.rb b/spec/lib/cellar/amazon_v2_request_signer_spec.rb index 399975e63..9776b423c 100644 --- a/spec/lib/cellar/amazon_v2_request_signer_spec.rb +++ b/spec/lib/cellar/amazon_v2_request_signer_spec.rb @@ -36,7 +36,7 @@ describe 'AmazonV2RequestSigner' do before { request_signer.sign(subject, 'fichier') } - it { expect(subject['date']).to eq(Time.now.httpdate) } + it { expect(subject['date']).to eq(Time.zone.now.httpdate) } it { expect(subject['authorization']).to eq('AWS AKIAJFTRSGRH3RXX6D5Q:nkvviwZYb1V9HDrKyJZmY3Z8sSA=') } end end diff --git a/spec/lib/tasks/2018_03_06_clean_html_textareas_spec.rb b/spec/lib/tasks/2018_03_06_clean_html_textareas_spec.rb index cff7056d0..756326baf 100644 --- a/spec/lib/tasks/2018_03_06_clean_html_textareas_spec.rb +++ b/spec/lib/tasks/2018_03_06_clean_html_textareas_spec.rb @@ -4,8 +4,8 @@ describe '2018_03_06_clean_html_textareas#clean' do let(:procedure) { create(:procedure) } let(:type_champ) { create(:type_de_champ_textarea, procedure: procedure) } let(:champ) { type_champ.champ.create(value: "

Gnahar
greu bouahaha

") } - let(:champ_date) { Time.local(1995) } - let(:rake_date) { Time.local(2018) } + let(:champ_date) { Time.zone.local(1995) } + let(:rake_date) { Time.zone.local(2018) } let(:rake_task) { Rake::Task['2018_03_06_clean_html_textareas:clean'] } before do diff --git a/spec/mailers/gestionnaire_mailer_spec.rb b/spec/mailers/gestionnaire_mailer_spec.rb index de9c17589..40f4ea2a4 100644 --- a/spec/mailers/gestionnaire_mailer_spec.rb +++ b/spec/mailers/gestionnaire_mailer_spec.rb @@ -25,7 +25,7 @@ RSpec.describe GestionnaireMailer, type: :mailer do dossiers_en_instruction_description: 'desc') { - start_date: DateTime.now, + start_date: Time.zone.now, procedure_overviews: [procedure_overview] } end diff --git a/spec/models/attestation_template_spec.rb b/spec/models/attestation_template_spec.rb index f5b6786f4..61e8a64df 100644 --- a/spec/models/attestation_template_spec.rb +++ b/spec/models/attestation_template_spec.rb @@ -115,7 +115,7 @@ describe AttestationTemplate, type: :model do before do @logo = File.open('spec/fixtures/files/white.png') @signature = File.open('spec/fixtures/files/black.png') - Timecop.freeze(Time.now) + Timecop.freeze(Time.zone.now) end after do diff --git a/spec/models/concern/tags_substitution_concern_spec.rb b/spec/models/concern/tags_substitution_concern_spec.rb index 52718bee6..f7b95edf2 100644 --- a/spec/models/concern/tags_substitution_concern_spec.rb +++ b/spec/models/concern/tags_substitution_concern_spec.rb @@ -32,7 +32,7 @@ describe TagsSubstitutionConcern, type: :model do let(:etablissement) { create(:etablissement) } let!(:dossier) { create(:dossier, procedure: procedure, individual: individual, etablissement: etablissement) } - before { Timecop.freeze(Time.now) } + before { Timecop.freeze(Time.zone.now) } subject { template_concern.send(:replace_tags, template, dossier) } @@ -187,9 +187,9 @@ describe TagsSubstitutionConcern, type: :model do context "when using a date tag" do before do - dossier.en_construction_at = DateTime.new(2001, 2, 3) - dossier.en_instruction_at = DateTime.new(2004, 5, 6) - dossier.processed_at = DateTime.new(2007, 8, 9) + dossier.en_construction_at = Time.zone.local(2001, 2, 3) + dossier.en_instruction_at = Time.zone.local(2004, 5, 6) + dossier.processed_at = Time.zone.local(2007, 8, 9) end context "with date de dépôt" do diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 5554f4797..af9a43678 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -479,9 +479,9 @@ describe Dossier do end context 'when they are a lot of advice' do - let!(:avis_1) { Avis.create(dossier: dossier, claimant: expert_1, gestionnaire: expert_2, confidentiel: false, created_at: DateTime.parse('10/01/2010')) } - let!(:avis_2) { Avis.create(dossier: dossier, claimant: expert_1, gestionnaire: expert_2, confidentiel: false, created_at: DateTime.parse('9/01/2010')) } - let!(:avis_3) { Avis.create(dossier: dossier, claimant: expert_1, gestionnaire: expert_2, confidentiel: false, created_at: DateTime.parse('11/01/2010')) } + let!(:avis_1) { Avis.create(dossier: dossier, claimant: expert_1, gestionnaire: expert_2, confidentiel: false, created_at: Time.zone.parse('10/01/2010')) } + let!(:avis_2) { Avis.create(dossier: dossier, claimant: expert_1, gestionnaire: expert_2, confidentiel: false, created_at: Time.zone.parse('9/01/2010')) } + let!(:avis_3) { Avis.create(dossier: dossier, claimant: expert_1, gestionnaire: expert_2, confidentiel: false, created_at: Time.zone.parse('11/01/2010')) } it { expect(dossier.avis_for(gestionnaire)).to match([avis_2, avis_1, avis_3]) } it { expect(dossier.avis_for(expert_1)).to match([avis_2, avis_1, avis_3]) } @@ -491,7 +491,7 @@ describe Dossier do describe '#update_state_dates' do let(:state) { Dossier.states.fetch(:brouillon) } let(:dossier) { create(:dossier, state: state) } - let(:beginning_of_day) { Time.now.beginning_of_day } + let(:beginning_of_day) { Time.zone.now.beginning_of_day } before { Timecop.freeze(beginning_of_day) } after { Timecop.return } @@ -566,9 +566,9 @@ describe Dossier do describe '.downloadable_sorted' do let(:procedure) { create(:procedure) } let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:brouillon)) } - let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_construction), en_construction_at: DateTime.parse('03/01/2010')) } - let!(:dossier3) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_instruction), en_construction_at: DateTime.parse('01/01/2010')) } - let!(:dossier4) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_instruction), archived: true, en_construction_at: DateTime.parse('02/01/2010')) } + let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_construction), en_construction_at: Time.zone.parse('03/01/2010')) } + let!(:dossier3) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_instruction), en_construction_at: Time.zone.parse('01/01/2010')) } + let!(:dossier4) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_instruction), archived: true, en_construction_at: Time.zone.parse('02/01/2010')) } subject { procedure.dossiers.downloadable_sorted } @@ -734,7 +734,7 @@ describe Dossier do describe 'updated_at' do let!(:dossier) { create(:dossier) } - let(:modif_date) { DateTime.parse('01/01/2100') } + let(:modif_date) { Time.zone.parse('01/01/2100') } before { Timecop.freeze(modif_date) } after { Timecop.return } @@ -982,10 +982,10 @@ describe Dossier do context "retention date" do let(:procedure) { create(:procedure, duree_conservation_dossiers_dans_ds: 6) } let(:uninstructed_dossier) { create(:dossier, :en_construction, procedure: procedure) } - let(:young_dossier) { create(:dossier, :en_instruction, en_instruction_at: DateTime.now, procedure: procedure) } + let(:young_dossier) { create(:dossier, :en_instruction, en_instruction_at: Time.zone.now, procedure: procedure) } let(:just_expired_dossier) { create(:dossier, :en_instruction, en_instruction_at: 6.months.ago, procedure: procedure) } let(:long_expired_dossier) { create(:dossier, :en_instruction, en_instruction_at: 1.year.ago, procedure: procedure) } - let(:modif_date) { DateTime.parse('01/01/2100') } + let(:modif_date) { Time.zone.parse('01/01/2100') } before { Timecop.freeze(modif_date) } after { Timecop.return } @@ -993,7 +993,7 @@ describe Dossier do describe "#retention_end_date" do it { expect(uninstructed_dossier.retention_end_date).to be_nil } it { expect(young_dossier.retention_end_date).to eq(6.months.from_now) } - it { expect(just_expired_dossier.retention_end_date).to eq(DateTime.now) } + it { expect(just_expired_dossier.retention_end_date).to eq(Time.zone.now) } it { expect(long_expired_dossier.retention_end_date).to eq(6.months.ago) } end diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index 277692099..00fdfac58 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -138,8 +138,8 @@ describe Gestionnaire, type: :model do describe 'last_week_overview' do let!(:gestionnaire2) { create(:gestionnaire) } subject { gestionnaire2.last_week_overview } - let(:friday) { DateTime.new(2017, 5, 12) } - let(:monday) { DateTime.now.beginning_of_week } + let(:friday) { Time.zone.local(2017, 5, 12) } + let(:monday) { Time.zone.now.beginning_of_week } before { Timecop.freeze(friday) } after { Timecop.return } @@ -313,7 +313,7 @@ describe Gestionnaire, type: :model do context 'when gestionnaire update it s public champs last seen' do let(:follow) { gestionnaire.follows.find_by(dossier: dossier) } - before { follow.update_attribute('demande_seen_at', DateTime.now) } + before { follow.update_attribute('demande_seen_at', Time.zone.now) } it { is_expected.to match([]) } it { expect(gestionnaire_2.notifications_for_procedure(procedure)).to match([dossier.id]) } @@ -376,7 +376,7 @@ describe Gestionnaire, type: :model do describe '#mark_tab_as_seen' do let!(:dossier) { create(:dossier, :followed, state: Dossier.states.fetch(:en_construction)) } let(:gestionnaire) { dossier.follows.first.gestionnaire } - let(:freeze_date) { DateTime.parse('12/12/2012') } + let(:freeze_date) { Time.zone.parse('12/12/2012') } context 'when demande is acknowledged' do let(:follow) { gestionnaire.follows.find_by(dossier: dossier) } diff --git a/spec/models/procedure_overview_spec.rb b/spec/models/procedure_overview_spec.rb index 500955a24..06f0b291d 100644 --- a/spec/models/procedure_overview_spec.rb +++ b/spec/models/procedure_overview_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' describe ProcedureOverview, type: :model do let(:procedure) { create(:procedure, libelle: 'libelle') } - let(:friday) { DateTime.new(2017, 5, 12) } # vendredi 12 mai 2017, de la semaine du 8 mai - let(:monday) { DateTime.new(2017, 5, 8) } + let(:friday) { Time.zone.local(2017, 5, 12) } # vendredi 12 mai 2017, de la semaine du 8 mai + let(:monday) { Time.zone.local(2017, 5, 8) } before { Timecop.freeze(friday) } after { Timecop.return } diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index 3881f7616..0592acbfd 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -133,25 +133,25 @@ describe ProcedurePresentation do context 'for created_at column' do let(:column) { 'created_at' } - let(:dossier) { Timecop.freeze(DateTime.new(1992, 3, 22)) { create(:dossier, procedure: procedure) } } + let(:dossier) { Timecop.freeze(Time.zone.local(1992, 3, 22)) { create(:dossier, procedure: procedure) } } - it { is_expected.to eq(DateTime.new(1992, 3, 22)) } + it { is_expected.to eq(Time.zone.local(1992, 3, 22).strftime('%d/%m/%Y')) } end context 'for en_construction_at column' do let(:column) { 'en_construction_at' } - let(:dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: DateTime.new(2018, 10, 17)) } + let(:dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: Time.zone.local(2018, 10, 17)) } - it { is_expected.to eq(DateTime.new(2018, 10, 17)) } + it { is_expected.to eq(Time.zone.local(2018, 10, 17).strftime('%d/%m/%Y')) } end context 'for updated_at column' do let(:column) { 'updated_at' } let(:dossier) { create(:dossier, procedure: procedure) } - before { dossier.touch(time: DateTime.new(2018, 9, 25)) } + before { dossier.touch(time: Time.zone.local(2018, 9, 25)) } - it { is_expected.to eq(DateTime.new(2018, 9, 25)) } + it { is_expected.to eq(Time.zone.local(2018, 9, 25).strftime('%d/%m/%Y')) } end end @@ -236,11 +236,11 @@ describe ProcedurePresentation do let!(:older_dossier) { create(:dossier, :en_construction, procedure: procedure) } before do - notified_dossier.champs.first.touch(time: DateTime.new(2018, 9, 20)) - create(:follow, gestionnaire: gestionnaire, dossier: notified_dossier, demande_seen_at: DateTime.new(2018, 9, 10)) - notified_dossier.touch(time: DateTime.new(2018, 9, 20)) - recent_dossier.touch(time: DateTime.new(2018, 9, 25)) - older_dossier.touch(time: DateTime.new(2018, 5, 13)) + notified_dossier.champs.first.touch(time: Time.zone.local(2018, 9, 20)) + create(:follow, gestionnaire: gestionnaire, dossier: notified_dossier, demande_seen_at: Time.zone.local(2018, 9, 10)) + notified_dossier.touch(time: Time.zone.local(2018, 9, 20)) + recent_dossier.touch(time: Time.zone.local(2018, 9, 25)) + older_dossier.touch(time: Time.zone.local(2018, 5, 13)) end context 'in ascending order' do @@ -269,16 +269,16 @@ describe ProcedurePresentation do context 'for created_at column' do let(:column) { 'created_at' } - let!(:recent_dossier) { Timecop.freeze(DateTime.new(2018, 10, 17)) { create(:dossier, procedure: procedure) } } - let!(:older_dossier) { Timecop.freeze(DateTime.new(2003, 11, 11)) { create(:dossier, procedure: procedure) } } + let!(:recent_dossier) { Timecop.freeze(Time.zone.local(2018, 10, 17)) { create(:dossier, procedure: procedure) } } + let!(:older_dossier) { Timecop.freeze(Time.zone.local(2003, 11, 11)) { create(:dossier, procedure: procedure) } } it { is_expected.to eq([older_dossier, recent_dossier].map(&:id)) } end context 'for en_construction_at column' do let(:column) { 'en_construction_at' } - let!(:recent_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: DateTime.new(2018, 10, 17)) } - let!(:older_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: DateTime.new(2013, 1, 1)) } + let!(:recent_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: Time.zone.local(2018, 10, 17)) } + let!(:older_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: Time.zone.local(2013, 1, 1)) } it { is_expected.to eq([older_dossier, recent_dossier].map(&:id)) } end @@ -289,8 +289,8 @@ describe ProcedurePresentation do let(:older_dossier) { create(:dossier, procedure: procedure) } before do - recent_dossier.touch(time: DateTime.new(2018, 9, 25)) - older_dossier.touch(time: DateTime.new(2018, 5, 13)) + recent_dossier.touch(time: Time.zone.local(2018, 9, 25)) + older_dossier.touch(time: Time.zone.local(2018, 5, 13)) end it { is_expected.to eq([older_dossier, recent_dossier].map(&:id)) } @@ -377,16 +377,16 @@ describe ProcedurePresentation do context 'for self table' do context 'for created_at column' do - let!(:kept_dossier) { create(:dossier, procedure: procedure, created_at: DateTime.new(2018, 9, 18, 14, 28)) } - let!(:discarded_dossier) { create(:dossier, procedure: procedure, created_at: DateTime.new(2018, 9, 17, 23, 59)) } + let!(:kept_dossier) { create(:dossier, procedure: procedure, created_at: Time.zone.local(2018, 9, 18, 14, 28)) } + let!(:discarded_dossier) { create(:dossier, procedure: procedure, created_at: Time.zone.local(2018, 9, 17, 23, 59)) } let(:filter) { [{ 'table' => 'self', 'column' => 'created_at', 'value' => '18/9/2018' }] } it { is_expected.to contain_exactly(kept_dossier.id) } end context 'for en_construction_at column' do - let!(:kept_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: DateTime.new(2018, 10, 17)) } - let!(:discarded_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: DateTime.new(2013, 1, 1)) } + let!(:kept_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: Time.zone.local(2018, 10, 17)) } + let!(:discarded_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: Time.zone.local(2013, 1, 1)) } let(:filter) { [{ 'table' => 'self', 'column' => 'en_construction_at', 'value' => '17/10/2018' }] } it { is_expected.to contain_exactly(kept_dossier.id) } @@ -398,12 +398,17 @@ describe ProcedurePresentation do let(:filter) { [{ 'table' => 'self', 'column' => 'updated_at', 'value' => '18/9/2018' }] } before do - kept_dossier.touch(time: DateTime.new(2018, 9, 18, 14, 28)) - discarded_dossier.touch(time: DateTime.new(2018, 9, 17, 23, 59)) + kept_dossier.touch(time: Time.zone.local(2018, 9, 18, 14, 28)) + discarded_dossier.touch(time: Time.zone.local(2018, 9, 17, 23, 59)) end it { is_expected.to contain_exactly(kept_dossier.id) } end + + context 'for a malformed date' do + let(:filter) { [{ 'table' => 'self', 'column' => 'updated_at', 'value' => 'malformed date' }] } + it { is_expected.to match([]) } + end end context 'for type_de_champ table' do @@ -436,8 +441,8 @@ describe ProcedurePresentation do context 'for etablissement table' do context 'for entreprise_date_creation column' do - let!(:kept_dossier) { create(:dossier, procedure: procedure, etablissement: create(:etablissement, entreprise_date_creation: DateTime.new(2018, 6, 21))) } - let!(:discarded_dossier) { create(:dossier, procedure: procedure, etablissement: create(:etablissement, entreprise_date_creation: DateTime.new(2008, 6, 21))) } + let!(:kept_dossier) { create(:dossier, procedure: procedure, etablissement: create(:etablissement, entreprise_date_creation: Time.zone.local(2018, 6, 21))) } + let!(:discarded_dossier) { create(:dossier, procedure: procedure, etablissement: create(:etablissement, entreprise_date_creation: Time.zone.local(2008, 6, 21))) } let(:filter) { [{ 'table' => 'etablissement', 'column' => 'entreprise_date_creation', 'value' => '21/6/2018' }] } it { is_expected.to contain_exactly(kept_dossier.id) } diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index a6b34fe02..bdd0f5f45 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -429,7 +429,7 @@ describe Procedure do describe '#publish!' do let(:procedure) { create(:procedure) } - let(:now) { Time.now.beginning_of_minute } + let(:now) { Time.zone.now.beginning_of_minute } before do Timecop.freeze(now) @@ -446,8 +446,8 @@ describe Procedure do describe "#brouillon?" do let(:procedure_brouillon) { Procedure.new() } - let(:procedure_publiee) { Procedure.new(aasm_state: :publiee, published_at: Time.now) } - let(:procedure_archivee) { Procedure.new(aasm_state: :archivee, published_at: Time.now, archived_at: Time.now) } + let(:procedure_publiee) { Procedure.new(aasm_state: :publiee, published_at: Time.zone.now) } + let(:procedure_archivee) { Procedure.new(aasm_state: :archivee, published_at: Time.zone.now, archived_at: Time.zone.now) } it { expect(procedure_brouillon.brouillon?).to be_truthy } it { expect(procedure_publiee.brouillon?).to be_falsey } @@ -456,8 +456,8 @@ describe Procedure do describe "#publiee?" do let(:procedure_brouillon) { Procedure.new() } - let(:procedure_publiee) { Procedure.new(aasm_state: :publiee, published_at: Time.now) } - let(:procedure_archivee) { Procedure.new(aasm_state: :archivee, published_at: Time.now, archived_at: Time.now) } + let(:procedure_publiee) { Procedure.new(aasm_state: :publiee, published_at: Time.zone.now) } + let(:procedure_archivee) { Procedure.new(aasm_state: :archivee, published_at: Time.zone.now, archived_at: Time.zone.now) } it { expect(procedure_brouillon.publiee?).to be_falsey } it { expect(procedure_publiee.publiee?).to be_truthy } @@ -466,8 +466,8 @@ describe Procedure do describe "#archivee?" do let(:procedure_brouillon) { Procedure.new() } - let(:procedure_publiee) { Procedure.new(aasm_state: :publiee, published_at: Time.now) } - let(:procedure_archivee) { Procedure.new(aasm_state: :archivee, published_at: Time.now, archived_at: Time.now) } + let(:procedure_publiee) { Procedure.new(aasm_state: :publiee, published_at: Time.zone.now) } + let(:procedure_archivee) { Procedure.new(aasm_state: :archivee, published_at: Time.zone.now, archived_at: Time.zone.now) } it { expect(procedure_brouillon.archivee?).to be_falsey } it { expect(procedure_publiee.archivee?).to be_falsey } @@ -476,8 +476,8 @@ describe Procedure do describe "#publiee_ou_archivee?" do let(:procedure_brouillon) { Procedure.new() } - let(:procedure_publiee) { Procedure.new(aasm_state: :publiee, published_at: Time.now) } - let(:procedure_archivee) { Procedure.new(aasm_state: :archivee, published_at: Time.now, archived_at: Time.now) } + let(:procedure_publiee) { Procedure.new(aasm_state: :publiee, published_at: Time.zone.now) } + let(:procedure_archivee) { Procedure.new(aasm_state: :archivee, published_at: Time.zone.now, archived_at: Time.zone.now) } it { expect(procedure_brouillon.publiee_ou_archivee?).to be_falsey } it { expect(procedure_publiee.publiee_ou_archivee?).to be_truthy } @@ -487,7 +487,7 @@ describe Procedure do describe 'archive' do let(:procedure) { create(:procedure, :published) } let(:procedure_path) { ProcedurePath.find(procedure.procedure_path.id) } - let(:now) { Time.now.beginning_of_minute } + let(:now) { Time.zone.now.beginning_of_minute } before do Timecop.freeze(now) procedure.archive! @@ -627,7 +627,7 @@ describe Procedure do end describe "#export_filename" do - before { Timecop.freeze(Time.new(2018, 1, 2, 23, 11, 14)) } + before { Timecop.freeze(Time.zone.local(2018, 1, 2, 23, 11, 14)) } subject { procedure.export_filename } @@ -716,7 +716,7 @@ describe Procedure do context 'which is termine' do before do dossier.accepte! - processed_date = DateTime.parse('12/12/2012') + processed_date = Time.zone.parse('12/12/2012') instruction_date = processed_date - 1.day dossier.update(en_instruction_at: instruction_date, processed_at: processed_date) end diff --git a/spec/services/france_connect_service_spec.rb b/spec/services/france_connect_service_spec.rb index 96b2a633b..fb6ba85a2 100644 --- a/spec/services/france_connect_service_spec.rb +++ b/spec/services/france_connect_service_spec.rb @@ -33,7 +33,7 @@ describe FranceConnectService do expect(subject).to have_attributes({ given_name: given_name, family_name: family_name, - birthdate: DateTime.parse(birthdate), + birthdate: Date.parse(birthdate), birthplace: birthplace, gender: gender, email_france_connect: email,