Merge pull request #5041 from tchak/cleanup-procedure-expiration-validations

Cleanup procedure duree_conservation_dossiers_dans_ds validations
This commit is contained in:
Paul Chavard 2020-04-17 12:48:26 +02:00 committed by GitHub
commit 25e031f8bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 47 deletions

View file

@ -85,11 +85,8 @@ class Procedure < ApplicationRecord
validate :validate_for_publication, on: :publication
validate :check_juridique
validates :path, presence: true, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, uniqueness: { scope: [:path, :closed_at, :hidden_at, :unpublished_at], case_sensitive: false }
# FIXME: remove duree_conservation_required flag once all procedures are converted to the new style
validates :duree_conservation_dossiers_dans_ds, allow_nil: false, numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: MAX_DUREE_CONSERVATION }, if: :durees_conservation_required
validates :duree_conservation_dossiers_hors_ds, allow_nil: false, numericality: { only_integer: true, greater_than_or_equal_to: 0 }, if: :durees_conservation_required
validates :duree_conservation_dossiers_dans_ds, allow_nil: true, numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: MAX_DUREE_CONSERVATION }, unless: :durees_conservation_required
validates :duree_conservation_dossiers_hors_ds, allow_nil: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }, unless: :durees_conservation_required
validates :duree_conservation_dossiers_dans_ds, allow_nil: false, numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: MAX_DUREE_CONSERVATION }
validates :duree_conservation_dossiers_hors_ds, allow_nil: false, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates_with MonAvisEmbedValidator
validates :notice, content_type: [
"application/msword",
@ -112,7 +109,6 @@ class Procedure < ApplicationRecord
validates :logo, content_type: ['image/png', 'image/jpg', 'image/jpeg'], size: { less_than: 5.megabytes }
before_save :update_juridique_required
before_save :update_durees_conservation_required
after_initialize :ensure_path_exists
before_save :ensure_path_exists
after_create :ensure_default_groupe_instructeur
@ -597,11 +593,6 @@ class Procedure < ApplicationRecord
end
end
def update_durees_conservation_required
self.durees_conservation_required ||= duree_conservation_dossiers_hors_ds.present? && duree_conservation_dossiers_dans_ds.present?
true
end
def percentile_time(start_attribute, end_attribute, p)
times = dossiers
.where.not(start_attribute => nil, end_attribute => nil)

View file

@ -252,22 +252,11 @@ describe Procedure do
shared_examples 'duree de conservation' do
context 'duree_conservation_required it true, the field gets validated' do
before { subject.durees_conservation_required = true }
it { is_expected.not_to allow_value(nil).for(field_name) }
it { is_expected.not_to allow_value('').for(field_name) }
it { is_expected.not_to allow_value('trois').for(field_name) }
it { is_expected.to allow_value(3).for(field_name) }
end
context 'duree_conservation_required is false, the field doesnt get validated' do
before { subject.durees_conservation_required = false }
it { is_expected.to allow_value(nil).for(field_name) }
it { is_expected.to allow_value('').for(field_name) }
it { is_expected.not_to allow_value('trois').for(field_name) }
it { is_expected.to allow_value(3).for(field_name) }
end
end
describe 'duree de conservation dans ds' do
@ -283,31 +272,6 @@ describe Procedure do
end
end
describe '#duree_de_conservation_required' do
it 'automatically jumps to true once both durees de conservation have been set' do
p = build(
:procedure,
durees_conservation_required: false,
duree_conservation_dossiers_dans_ds: nil,
duree_conservation_dossiers_hors_ds: nil
)
p.save
expect(p.durees_conservation_required).to be_falsey
p.duree_conservation_dossiers_hors_ds = 3
p.save
expect(p.durees_conservation_required).to be_falsey
p.duree_conservation_dossiers_dans_ds = 6
p.save
expect(p.durees_conservation_required).to be_truthy
p.duree_conservation_dossiers_dans_ds = nil
p.save
expect(p.durees_conservation_required).to be_truthy
end
end
describe '#types_de_champ (ordered)' do
let(:procedure) { create(:procedure) }
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 1) }