chore(create_procedure_presentation): homogénéise l'interface sur les procédure présentation. pas d'objet 'build', sinon les export/filtres deviennent compliqués

This commit is contained in:
Martin 2022-10-21 17:24:16 +02:00 committed by mfo
parent 50c43f4819
commit 5ced9fb431
4 changed files with 13 additions and 6 deletions

View file

@ -24,7 +24,11 @@ class AssignTo < ApplicationRecord
def procedure_presentation_or_default_and_errors
errors = reset_procedure_presentation_if_invalid
[procedure_presentation || build_procedure_presentation, errors]
if self.procedure_presentation.nil?
self.procedure_presentation = build_procedure_presentation
self.procedure_presentation.save if procedure_presentation.valid? && !procedure_presentation.persisted?
end
[self.procedure_presentation, errors]
end
private

View file

@ -125,7 +125,7 @@ class Export < ApplicationRecord
[
groupe_instructeurs_ids.sort.join('-'),
procedure_presentation.id,
Digest::MD5.hexdigest(procedure_presentation.snapshot.slice('filters', 'sort').to_s)
Digest::MD5.hexdigest(procedure_presentation.snapshot.slice(:filters, :sort).to_s)
].join('--')
else
groupe_instructeurs_ids.sort.join('-')

View file

@ -8,7 +8,7 @@ describe AssignTo, type: :model do
let(:errors) { procedure_presentation_and_errors.second }
context "without a procedure_presentation" do
it { expect(procedure_presentation_or_default).not_to be_persisted }
it { expect(procedure_presentation_or_default).to be_persisted }
it { expect(procedure_presentation_or_default).to be_valid }
it { expect(errors).to be_nil }
end
@ -28,7 +28,7 @@ describe AssignTo, type: :model do
pp
end
it { expect(procedure_presentation_or_default).not_to be_persisted }
it { expect(procedure_presentation_or_default).to be_persisted }
it { expect(procedure_presentation_or_default).to be_valid }
it { expect(errors).to be_present }
it do

View file

@ -169,14 +169,17 @@ describe Instructeur, type: :model do
pp.save(:validate => false)
end
it { expect(procedure_presentation).not_to be_persisted }
it 'recreates a valid prsentation' do
expect(procedure_presentation).to be_persisted
end
it { expect(procedure_presentation).to be_valid }
it { expect(errors).to be_present }
end
context 'with default presentation' do
let(:procedure_id) { procedure_2.id }
it { expect(procedure_presentation).not_to be_persisted }
it { expect(procedure_presentation).to be_persisted }
it { expect(errors).to be_nil }
end
end