Merge pull request #8165 from tchak/cleanup-repetition-factory
clean(type_de_champ): remove magic factory
This commit is contained in:
commit
a96e12490a
8 changed files with 21 additions and 39 deletions
|
@ -263,9 +263,9 @@ describe API::V1::DossiersController do
|
|||
it 'should have rows' do
|
||||
expect(subject.size).to eq(2)
|
||||
expect(subject[0][:id]).to eq(1)
|
||||
expect(subject[0][:champs].size).to eq(3)
|
||||
expect(subject[0][:champs].map { |c| c[:value] }).to eq(['text', 'text', '42'])
|
||||
expect(subject[0][:champs].map { |c| c[:type_de_champ][:type_champ] }).to eq(['text', 'text', 'number'])
|
||||
expect(subject[0][:champs].size).to eq(1)
|
||||
expect(subject[0][:champs].map { |c| c[:value] }).to eq(['text'])
|
||||
expect(subject[0][:champs].map { |c| c[:type_de_champ][:type_champ] }).to eq(['text'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -226,28 +226,6 @@ FactoryBot.define do
|
|||
parent = revision.revision_types_de_champ.find { |rtdc| rtdc.type_de_champ == champ_repetition.type_de_champ }
|
||||
types_de_champ = revision.revision_types_de_champ.filter { |rtdc| rtdc.parent == parent }.map(&:type_de_champ)
|
||||
|
||||
type_de_champ_text = types_de_champ.find { |tdc| tdc.libelle == 'Nom' }
|
||||
if !type_de_champ_text
|
||||
type_de_champ_text = build(:type_de_champ_text,
|
||||
procedure: champ_repetition.type_de_champ.procedure,
|
||||
position: 0,
|
||||
private: champ_repetition.private?,
|
||||
parent: parent,
|
||||
libelle: 'Nom')
|
||||
types_de_champ.push(type_de_champ_text)
|
||||
end
|
||||
|
||||
type_de_champ_number = types_de_champ.find { |tdc| tdc.libelle == 'Age' }
|
||||
if !type_de_champ_number
|
||||
type_de_champ_number = build(:type_de_champ_number,
|
||||
procedure: champ_repetition.type_de_champ.procedure,
|
||||
position: 1,
|
||||
private: champ_repetition.private?,
|
||||
parent: parent,
|
||||
libelle: 'Age')
|
||||
types_de_champ.push(type_de_champ_number)
|
||||
end
|
||||
|
||||
evaluator.rows.times do |row|
|
||||
champ_repetition.champs << types_de_champ.map do |type_de_champ|
|
||||
build(:"champ_#{type_de_champ.type_champ}", dossier: champ_repetition.dossier, row: row, type_de_champ: type_de_champ, parent: champ_repetition, private: champ_repetition.private?)
|
||||
|
|
|
@ -19,7 +19,6 @@ FactoryBot.define do
|
|||
transient do
|
||||
administrateur {}
|
||||
instructeurs { [] }
|
||||
types_de_champ { [] }
|
||||
types_de_champ_public { [] }
|
||||
types_de_champ_private { [] }
|
||||
updated_at { nil }
|
||||
|
@ -27,10 +26,6 @@ FactoryBot.define do
|
|||
end
|
||||
|
||||
after(:build) do |procedure, evaluator|
|
||||
if evaluator.types_de_champ.present?
|
||||
raise "use types_de_champ_public instead of types_de_champ"
|
||||
end
|
||||
|
||||
initial_revision = build(:procedure_revision, procedure: procedure, dossier_submitted_message: evaluator.dossier_submitted_message)
|
||||
|
||||
if evaluator.types_de_champ_public.present?
|
||||
|
@ -347,7 +342,11 @@ FactoryBot.define do
|
|||
if libelle == 'drop_down_list'
|
||||
libelle = 'simple_drop_down_list'
|
||||
end
|
||||
build(:"type_de_champ_#{type_champ}", procedure: procedure, mandatory: true, libelle: libelle, position: index)
|
||||
if type_champ == 'repetition'
|
||||
build(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure, mandatory: true, libelle: libelle, position: index)
|
||||
else
|
||||
build(:"type_de_champ_#{type_champ}", procedure: procedure, mandatory: true, libelle: libelle, position: index)
|
||||
end
|
||||
end
|
||||
build(:type_de_champ_drop_down_list, :long, procedure: procedure, mandatory: true, libelle: 'simple_choice_drop_down_list_long', position: TypeDeChamp.type_champs.size)
|
||||
build(:type_de_champ_multiple_drop_down_list, :long, procedure: procedure, mandatory: true, libelle: 'multiple_choice_drop_down_list_long', position: TypeDeChamp.type_champs.size + 1)
|
||||
|
@ -360,7 +359,11 @@ FactoryBot.define do
|
|||
if libelle == 'drop_down_list'
|
||||
libelle = 'simple_drop_down_list'
|
||||
end
|
||||
build(:"type_de_champ_#{type_champ}", procedure: procedure, libelle: libelle, position: index)
|
||||
if type_champ == 'repetition'
|
||||
build(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure, libelle: libelle, position: index)
|
||||
else
|
||||
build(:"type_de_champ_#{type_champ}", procedure: procedure, libelle: libelle, position: index)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
RSpec.describe Mutations::DossierModifierAnnotation, type: :graphql do
|
||||
let(:admin) { create(:administrateur) }
|
||||
let(:procedure) { create(:procedure, :published, :for_individual, :with_private_repetition, :with_type_de_champ_private, administrateurs: [admin]) }
|
||||
let(:procedure) { create(:procedure, :published, :for_individual, types_de_champ_private: [{ type: :repetition, children: [{ libelle: 'Nom' }, { type: :integer_number, libelle: 'Age' }] }, {}], administrateurs: [admin]) }
|
||||
let(:dossiers) { [] }
|
||||
let(:instructeur) { create(:instructeur, followed_dossiers: dossiers) }
|
||||
|
||||
|
|
|
@ -14,9 +14,9 @@ describe '20220705164551_remove_unused_champs' do
|
|||
|
||||
describe 'remove_unused_champs' do
|
||||
it "with bad champs" do
|
||||
expect(Champ.where(dossier: dossier).count).to eq(39)
|
||||
expect(Champ.where(dossier: dossier).count).to eq(37)
|
||||
run_task
|
||||
expect(Champ.where(dossier: dossier).count).to eq(38)
|
||||
expect(Champ.where(dossier: dossier).count).to eq(36)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -31,7 +31,7 @@ shared_examples 'champ_spec' do
|
|||
end
|
||||
|
||||
context 'when repetition not blank' do
|
||||
let(:type_de_champ) { build(:type_de_champ_repetition) }
|
||||
let(:type_de_champ) { build(:type_de_champ_repetition, :with_types_de_champ, procedure: build(:procedure)) }
|
||||
let(:champ) { build(:champ_repetition, type_de_champ: type_de_champ) }
|
||||
|
||||
it { expect(champ.blank?).to be(false) }
|
||||
|
|
|
@ -1749,11 +1749,11 @@ describe Dossier do
|
|||
|
||||
context 'for Champs::Repetition with rows, original_champ.repetition and rows are duped' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, procedure: dossier.procedure) }
|
||||
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, :with_types_de_champ, procedure: dossier.procedure) }
|
||||
let(:champ_repetition) { create(:champ_repetition, type_de_champ: type_de_champ_repetition, dossier: dossier) }
|
||||
before { dossier.champs_public << champ_repetition }
|
||||
|
||||
it { expect(Champs::RepetitionChamp.where(dossier: new_dossier).first.champs.count).to eq(4) }
|
||||
it { expect(Champs::RepetitionChamp.where(dossier: new_dossier).first.champs.count).to eq(2) }
|
||||
it { expect(Champs::RepetitionChamp.where(dossier: new_dossier).first.champs.ids).not_to eq(champ_repetition.champs.ids) }
|
||||
end
|
||||
|
||||
|
|
|
@ -342,6 +342,7 @@ describe ProcedureExportService do
|
|||
end
|
||||
|
||||
describe 'Repetitions sheet' do
|
||||
let(:procedure) { create(:procedure, :published, :for_individual, types_de_champ_public: [{ type: :repetition, children: [{ libelle: 'Nom' }, { libelle: 'Age' }] }]) }
|
||||
let!(:dossiers) do
|
||||
[
|
||||
create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure),
|
||||
|
@ -403,7 +404,7 @@ describe ProcedureExportService do
|
|||
context 'with non unique labels' do
|
||||
let(:dossier) { create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure) }
|
||||
let(:champ_repetition) { dossier.champs_public.find { |champ| champ.type_champ == 'repetition' } }
|
||||
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, procedure: procedure, libelle: champ_repetition.libelle) }
|
||||
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure, libelle: champ_repetition.libelle) }
|
||||
let!(:another_champ_repetition) { create(:champ_repetition, type_de_champ: type_de_champ_repetition, dossier: dossier) }
|
||||
|
||||
it 'should have sheets' do
|
||||
|
|
Loading…
Reference in a new issue