add spec for dossier weight estimation

This commit is contained in:
Christophe Robillard 2021-06-02 11:10:44 +02:00
parent 4fd0ad71c3
commit aee8db99d0
2 changed files with 27 additions and 2 deletions

View file

@ -138,8 +138,12 @@ FactoryBot.define do
factory :champ_piece_justificative, class: 'Champs::PieceJustificativeChamp' do
type_de_champ { association :type_de_champ_piece_justificative, procedure: dossier.procedure }
after(:build) do |champ, _evaluator|
champ.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
transient do
size { 4 }
end
after(:build) do |champ, evaluator|
champ.piece_justificative_file.attach(io: StringIO.new("x" * evaluator.size), filename: "toto.txt", content_type: "text/plain")
end
end

View file

@ -1069,4 +1069,25 @@ describe Procedure do
expect(procedure.destroy).to be_truthy
end
end
describe '#average_dossier_weight' do
let(:procedure) { create(:procedure, :published) }
before do
create_dossier_with_pj_of_size(4, procedure)
create_dossier_with_pj_of_size(5, procedure)
create_dossier_with_pj_of_size(6, procedure)
end
it 'estimates average dossier weight' do
expect(procedure.reload.average_dossier_weight).to eq 5
end
private
def create_dossier_with_pj_of_size(size, procedure)
dossier = create(:dossier, :accepte, procedure: procedure)
create(:champ_piece_justificative, size: size, dossier: dossier)
end
end
end