Merge pull request #7105 from betagouv/US/fix-dossier.processed_in_month

fix(Dossier.processed_in_month): used by ProcedureArchiveService ; until now we skipped all dossiers from last day of month 🌈🍨
This commit is contained in:
mfo 2022-04-05 13:00:50 +02:00 committed by GitHub
commit a0e144b9a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 3 deletions

View file

@ -125,6 +125,8 @@ group :development, :test do
gem 'pry-byebug' # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'pry-byebug' # Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'rspec-rails' gem 'rspec-rails'
gem 'simple_xlsx_reader' gem 'simple_xlsx_reader'
gem 'sorbet'
gem 'sorbet-runtime'
gem 'spring' # Spring speeds up development by keeping your application running in the background gem 'spring' # Spring speeds up development by keeping your application running in the background
gem 'spring-commands-rspec' gem 'spring-commands-rspec'
end end

View file

@ -677,6 +677,18 @@ GEM
tilt (~> 2.0) tilt (~> 2.0)
skylight (5.0.1) skylight (5.0.1)
activesupport (>= 5.2.0) activesupport (>= 5.2.0)
sorbet (0.5.9827)
sorbet-static (= 0.5.9827)
sorbet-runtime (0.5.9827)
sorbet-static (0.5.9827-universal-darwin-14)
sorbet-static (0.5.9827-universal-darwin-15)
sorbet-static (0.5.9827-universal-darwin-16)
sorbet-static (0.5.9827-universal-darwin-17)
sorbet-static (0.5.9827-universal-darwin-18)
sorbet-static (0.5.9827-universal-darwin-19)
sorbet-static (0.5.9827-universal-darwin-20)
sorbet-static (0.5.9827-universal-darwin-21)
sorbet-static (0.5.9827-x86_64-linux)
spreadsheet_architect (4.1.0) spreadsheet_architect (4.1.0)
axlsx_styler (>= 1.0.0, < 2) axlsx_styler (>= 1.0.0, < 2)
caxlsx (>= 2.0.2, < 4) caxlsx (>= 2.0.2, < 4)
@ -874,6 +886,8 @@ DEPENDENCIES
sib-api-v3-sdk sib-api-v3-sdk
simple_xlsx_reader simple_xlsx_reader
skylight skylight
sorbet
sorbet-runtime
spreadsheet_architect spreadsheet_architect
spring spring
spring-commands-rspec spring-commands-rspec

View file

@ -1,3 +1,4 @@
# typed: true
# == Schema Information # == Schema Information
# #
# Table name: dossiers # Table name: dossiers
@ -38,6 +39,7 @@
# user_id :integer # user_id :integer
# #
class Dossier < ApplicationRecord class Dossier < ApplicationRecord
extend T::Sig
self.ignored_columns = [:en_construction_conservation_extension] self.ignored_columns = [:en_construction_conservation_extension]
include DossierFilteringConcern include DossierFilteringConcern
include DossierRebaseConcern include DossierRebaseConcern
@ -233,10 +235,11 @@ class Dossier < ApplicationRecord
scope :en_instruction, -> { not_archived.state_en_instruction } scope :en_instruction, -> { not_archived.state_en_instruction }
scope :termine, -> { not_archived.state_termine } scope :termine, -> { not_archived.state_termine }
scope :processed_in_month, -> (month) do sig { params(args: DateTime).returns(T.untyped) }
scope :processed_in_month, -> (date) do
state_termine state_termine
.joins(:traitements) .joins(:traitements)
.where(traitements: { processed_at: month.beginning_of_month..month.end_of_month }) .where(traitements: { processed_at: date.beginning_of_month..date.end_of_month })
end end
scope :downloadable_sorted, -> { scope :downloadable_sorted, -> {
state_not_brouillon state_not_brouillon

View file

@ -22,7 +22,7 @@ class ProcedureArchiveService
dossiers = if archive.time_span_type == 'everything' dossiers = if archive.time_span_type == 'everything'
dossiers.state_termine dossiers.state_termine
else else
dossiers.processed_in_month(archive.month) dossiers.processed_in_month(archive.month.to_datetime)
end end
attachments = ActiveStorage::DownloadableFile.create_list_from_dossiers(dossiers) attachments = ActiveStorage::DownloadableFile.create_list_from_dossiers(dossiers)

3
sorbet/config Normal file
View file

@ -0,0 +1,3 @@
--dir
.
--ignore=/vendor/bundle

View file

@ -1720,4 +1720,22 @@ describe Dossier do
expect(rebased_datetime_champ.rebased_at).not_to be_nil expect(rebased_datetime_champ.rebased_at).not_to be_nil
end end
end end
describe '#processed_in_month' do
include ActiveSupport::Testing::TimeHelpers
let(:dossier_accepte_at) { DateTime.new(2022, 3, 31, 12, 0) }
before do
travel_to(dossier_accepte_at) do
dossier = create(:dossier, :accepte)
end
end
context 'given a datetime' do
let(:archive_date) { DateTime.new(2022, 3, 1, 12, 0) }
it 'includes a dossier processed_at at last day of month' do
expect(Dossier.processed_in_month(archive_date).count).to eq(1)
end
end
end
end end

View file

@ -13,6 +13,7 @@ require 'rspec/rails'
require 'axe-rspec' require 'axe-rspec'
require 'devise' require 'devise'
require 'shoulda-matchers' require 'shoulda-matchers'
require 'sorbet-runtime'
# Requires supporting ruby files with custom matchers and macros, etc, in # Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are