Merge pull request #8494 from tchak/fix-only_present_on_draft

fix(only_present_on_draft?): broken when type_de_champ is removed from later revisions
This commit is contained in:
Paul Chavard 2023-01-31 09:34:00 +01:00 committed by GitHub
commit a40c39fc9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View file

@ -242,7 +242,7 @@ class TypeDeChamp < ApplicationRecord
end
def only_present_on_draft?
revisions.size == 1
revisions.one? && revisions.first.draft?
end
def drop_down_other?

View file

@ -872,4 +872,21 @@ describe ProcedureRevision do
it { expect(draft.dependent_conditions(first_champ)).to eq([second_champ]) }
it { expect(draft.dependent_conditions(second_champ)).to eq([]) }
end
describe 'only_present_on_draft?' do
let(:procedure) { create(:procedure, types_de_champ_public: [{ libelle: 'Un champ texte' }]) }
let(:type_de_champ) { procedure.draft_revision.types_de_champ_public.first }
it {
expect(type_de_champ.only_present_on_draft?).to be_truthy
procedure.publish!
expect(type_de_champ.only_present_on_draft?).to be_falsey
procedure.draft_revision.remove_type_de_champ(type_de_champ.stable_id)
expect(type_de_champ.only_present_on_draft?).to be_falsey
expect(type_de_champ.revisions.count).to eq(1)
procedure.publish_revision!
expect(type_de_champ.only_present_on_draft?).to be_falsey
expect(type_de_champ.revisions.count).to eq(1)
}
end
end