Merge pull request #6007 from tchak/fix-test-exports
Instructeur : les champs non-exportables sont correctement exclus de l'export (corrige l'export de certaines démarches) (#6007)
This commit is contained in:
commit
25c85dd0f9
3 changed files with 33 additions and 16 deletions
|
@ -93,7 +93,7 @@ class Procedure < ApplicationRecord
|
||||||
|
|
||||||
def types_de_champ_for_export
|
def types_de_champ_for_export
|
||||||
if brouillon?
|
if brouillon?
|
||||||
draft_types_de_champ
|
draft_types_de_champ.reject(&:exclude_from_export?)
|
||||||
else
|
else
|
||||||
all_types_de_champ
|
all_types_de_champ
|
||||||
.uniq
|
.uniq
|
||||||
|
|
|
@ -193,6 +193,12 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :with_explication do
|
||||||
|
after(:build) do |procedure, _evaluator|
|
||||||
|
build(:type_de_champ_explication, procedure: procedure)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
trait :published do
|
trait :published do
|
||||||
after(:build) do |procedure, _evaluator|
|
after(:build) do |procedure, _evaluator|
|
||||||
procedure.path = generate(:published_path)
|
procedure.path = generate(:published_path)
|
||||||
|
|
|
@ -1345,13 +1345,15 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "champs_for_export" do
|
describe "champs_for_export" do
|
||||||
let(:procedure) { create(:procedure, :with_type_de_champ, :with_datetime, :with_yes_no) }
|
let(:procedure) { create(:procedure, :with_type_de_champ, :with_datetime, :with_yes_no, :with_explication) }
|
||||||
let(:text_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:text) } }
|
let(:text_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:text) } }
|
||||||
let(:yes_no_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:yes_no) } }
|
let(:yes_no_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:yes_no) } }
|
||||||
let(:datetime_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:datetime) } }
|
let(:datetime_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:datetime) } }
|
||||||
|
let(:explication_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:explication) } }
|
||||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||||
let(:dossier_second_revision) { create(:dossier, procedure: procedure) }
|
let(:dossier_second_revision) { create(:dossier, procedure: procedure) }
|
||||||
|
|
||||||
|
context "when procedure published" do
|
||||||
before do
|
before do
|
||||||
procedure.publish!
|
procedure.publish!
|
||||||
dossier
|
dossier
|
||||||
|
@ -1364,13 +1366,22 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should have champs from all revisions" do
|
it "should have champs from all revisions" do
|
||||||
expect(dossier.types_de_champ.map(&:libelle)).to eq([text_type_de_champ.libelle, datetime_type_de_champ.libelle, "Yes/no"])
|
expect(dossier.types_de_champ.map(&:libelle)).to eq([text_type_de_champ.libelle, datetime_type_de_champ.libelle, "Yes/no", explication_type_de_champ.libelle])
|
||||||
expect(dossier_second_revision.types_de_champ.map(&:libelle)).to eq([datetime_type_de_champ.libelle, "Updated yes/no", "New text field"])
|
expect(dossier_second_revision.types_de_champ.map(&:libelle)).to eq([datetime_type_de_champ.libelle, "Updated yes/no", explication_type_de_champ.libelle, "New text field"])
|
||||||
expect(dossier.champs_for_export(dossier.procedure.types_de_champ_for_export).map { |(libelle)| libelle }).to eq([datetime_type_de_champ.libelle, "Updated yes/no", "New text field"])
|
expect(dossier.champs_for_export(dossier.procedure.types_de_champ_for_export).map { |(libelle)| libelle }).to eq([datetime_type_de_champ.libelle, "Updated yes/no", "New text field"])
|
||||||
expect(dossier.champs_for_export(dossier.procedure.types_de_champ_for_export)).to eq(dossier_second_revision.champs_for_export(dossier_second_revision.procedure.types_de_champ_for_export))
|
expect(dossier.champs_for_export(dossier.procedure.types_de_champ_for_export)).to eq(dossier_second_revision.champs_for_export(dossier_second_revision.procedure.types_de_champ_for_export))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when procedure brouillon" do
|
||||||
|
let(:procedure) { create(:procedure, :with_type_de_champ, :with_explication) }
|
||||||
|
|
||||||
|
it "should not contain non-exportable types de champ" do
|
||||||
|
expect(dossier.champs_for_export(dossier.procedure.types_de_champ_for_export).map { |(libelle)| libelle }).to eq([text_type_de_champ.libelle])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "remove_titres_identite!" do
|
describe "remove_titres_identite!" do
|
||||||
let(:dossier) { create(:dossier, :en_instruction, :followed, :with_individual) }
|
let(:dossier) { create(:dossier, :en_instruction, :followed, :with_individual) }
|
||||||
let(:type_de_champ_titre_identite) { create(:type_de_champ_titre_identite, procedure: dossier.procedure) }
|
let(:type_de_champ_titre_identite) { create(:type_de_champ_titre_identite, procedure: dossier.procedure) }
|
||||||
|
|
Loading…
Reference in a new issue