update models specs to use revisions

This commit is contained in:
Paul Chavard 2020-08-27 19:56:19 +02:00
parent d1fb6c559e
commit 1488e0964b
8 changed files with 103 additions and 194 deletions

View file

@ -427,10 +427,9 @@ describe Champ do
end
describe 'repetition' do
let(:procedure) { build(:procedure, :published, :with_type_de_champ, :with_type_de_champ_private) }
let(:tdc_text) { build(:type_de_champ_text, procedure: procedure) }
let(:tdc_integer) { build(:type_de_champ_integer_number, procedure: procedure) }
let(:tdc_repetition) { build(:type_de_champ_repetition, procedure: procedure, types_de_champ: [tdc_text, tdc_integer]) }
let(:procedure) { create(:procedure, :published, :with_type_de_champ, :with_type_de_champ_private, types_de_champ: [build(:type_de_champ_repetition, types_de_champ: [tdc_text, tdc_integer])]) }
let(:tdc_text) { build(:type_de_champ_text) }
let(:tdc_integer) { build(:type_de_champ_integer_number) }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:champ) { dossier.champs.find(&:repetition?) }
@ -438,12 +437,6 @@ describe Champ do
let(:champ_integer) { champ.champs.find { |c| c.type_champ == 'integer_number' } }
let(:champ_text_attrs) { attributes_for(:champ_text, type_de_champ: tdc_text, row: 1) }
before do
procedure.types_de_champ << tdc_repetition
procedure.save!
procedure.reload
end
context 'when creating the model directly' do
let(:champ_text_row_1) { create(:champ_text, type_de_champ: tdc_text, row: 2, parent: champ, dossier: nil) }

View file

@ -2,11 +2,11 @@ describe Champs::HeaderSectionChamp do
describe '#section_index' do
let(:types_de_champ) do
[
create(:type_de_champ_header_section, order_place: 1),
create(:type_de_champ_civilite, order_place: 2),
create(:type_de_champ_text, order_place: 3),
create(:type_de_champ_header_section, order_place: 4),
create(:type_de_champ_email, order_place: 5)
build(:type_de_champ_header_section, position: 1),
build(:type_de_champ_civilite, position: 2),
build(:type_de_champ_text, position: 3),
build(:type_de_champ_header_section, position: 4),
build(:type_de_champ_email, position: 5)
]
end
@ -23,17 +23,12 @@ describe Champs::HeaderSectionChamp do
end
context 'for repetition champs' do
let(:procedure) { create(:procedure, :with_repetition) }
let(:procedure) { create(:procedure, types_de_champ: [build(:type_de_champ_repetition, types_de_champ: types_de_champ)]) }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:repetition_tdc) { procedure.types_de_champ.find(&:repetition?) }
let(:first_header) { dossier.champs.first.champs[0] }
let(:second_header) { dossier.champs.first.champs[3] }
before do
repetition_tdc.types_de_champ = types_de_champ
end
it 'returns the index of the section in the repetition (starting from 1)' do
expect(first_header.section_index).to eq 1
expect(second_header.section_index).to eq 2

View file

@ -97,8 +97,8 @@ describe TagsSubstitutionConcern, type: :model do
context 'when the procedure has a type de champ named libelleA et libelleB' do
let(:types_de_champ) do
[
create(:type_de_champ, libelle: 'libelleA'),
create(:type_de_champ, libelle: 'libelleB')
build(:type_de_champ, libelle: 'libelleA'),
build(:type_de_champ, libelle: 'libelleB')
]
end
@ -141,7 +141,7 @@ describe TagsSubstitutionConcern, type: :model do
context 'when the procedure has a type de champ with apostrophes' do
let(:types_de_champ) do
[
create(:type_de_champ, libelle: "Intitulé de l'‘«\"évènement\"»’")
build(:type_de_champ, libelle: "Intitulé de l'‘«\"évènement\"»’")
]
end
@ -165,9 +165,9 @@ describe TagsSubstitutionConcern, type: :model do
let(:template) { '--Répétition--' }
let(:types_de_champ) do
[
create(:type_de_champ_repetition, libelle: 'Répétition', types_de_champ: [
create(:type_de_champ_text, libelle: 'Nom', order_place: 1),
create(:type_de_champ_text, libelle: 'Prénom', order_place: 2)
build(:type_de_champ_repetition, libelle: 'Répétition', types_de_champ: [
build(:type_de_champ_text, libelle: 'Nom', order_place: 1),
build(:type_de_champ_text, libelle: 'Prénom', order_place: 2)
])
]
end
@ -190,7 +190,7 @@ describe TagsSubstitutionConcern, type: :model do
context 'when the procedure has a linked drop down menus type de champ' do
let(:type_de_champ) do
create(:type_de_champ_linked_drop_down_list, libelle: 'libelle')
build(:type_de_champ_linked_drop_down_list, libelle: 'libelle')
end
let(:types_de_champ) { [type_de_champ] }
let(:template) { 'tout : --libelle--, primaire : --libelle/primaire--, secondaire : --libelle/secondaire--' }
@ -219,7 +219,7 @@ describe TagsSubstitutionConcern, type: :model do
let(:types_de_champ) do
[
type_de_champ,
create(:type_de_champ_header_section, libelle: 'libelle')
build(:type_de_champ_header_section, libelle: 'libelle')
]
end
@ -253,7 +253,7 @@ describe TagsSubstitutionConcern, type: :model do
end
context 'when the procedure has a type de champ prive named libelleA' do
let(:types_de_champ_private) { [create(:type_de_champ, :private, libelle: 'libelleA')] }
let(:types_de_champ_private) { [build(:type_de_champ, :private, libelle: 'libelleA')] }
context 'and it is used in the template' do
let(:template) { '--libelleA--' }
@ -274,13 +274,13 @@ describe TagsSubstitutionConcern, type: :model do
# The dossier just transitionned from brouillon to en construction,
# so champs private are not valid tags yet
let(:types_de_champ_private) { [create(:type_de_champ, :private, libelle: 'libelleA')] }
let(:types_de_champ_private) { [build(:type_de_champ, :private, libelle: 'libelleA')] }
it { is_expected.to eq('--libelleA--') }
end
context 'champs publics are valid tags' do
let(:types_de_champ) { [create(:type_de_champ, libelle: 'libelleA')] }
let(:types_de_champ) { [build(:type_de_champ, libelle: 'libelleA')] }
before { dossier.champs.first.update(value: 'libelle1') }
@ -291,8 +291,8 @@ describe TagsSubstitutionConcern, type: :model do
context 'when the procedure has 2 types de champ date and datetime' do
let(:types_de_champ) do
[
create(:type_de_champ_date, libelle: TypeDeChamp.type_champs.fetch(:date)),
create(:type_de_champ_datetime, libelle: TypeDeChamp.type_champs.fetch(:datetime))
build(:type_de_champ_date, libelle: TypeDeChamp.type_champs.fetch(:date)),
build(:type_de_champ_datetime, libelle: TypeDeChamp.type_champs.fetch(:datetime))
]
end
@ -358,13 +358,13 @@ describe TagsSubstitutionConcern, type: :model do
shared_examples "treat all kinds of space as equivalent" do
context 'and the champ has a non breaking space' do
let(:types_de_champ) { [create(:type_de_champ, libelle: 'mon tag')] }
let(:types_de_champ) { [build(:type_de_champ, libelle: 'mon tag')] }
it { is_expected.to eq('valeur') }
end
context 'and the champ has an ordinary space' do
let(:types_de_champ) { [create(:type_de_champ, libelle: 'mon tag')] }
let(:types_de_champ) { [build(:type_de_champ, libelle: 'mon tag')] }
it { is_expected.to eq('valeur') }
end
@ -401,12 +401,12 @@ describe TagsSubstitutionConcern, type: :model do
let(:types_de_champ) do
[
create(:type_de_champ, libelle: 'public'),
create(:type_de_champ_header_section, libelle: 'entête de section'),
create(:type_de_champ_explication, libelle: 'explication')
build(:type_de_champ, libelle: 'public'),
build(:type_de_champ_header_section, libelle: 'entête de section'),
build(:type_de_champ_explication, libelle: 'explication')
]
end
let(:types_de_champ_private) { [create(:type_de_champ, :private, libelle: 'privé')] }
let(:types_de_champ_private) { [build(:type_de_champ, :private, libelle: 'privé')] }
context 'do not generate tags for champs that cannot have usager content' do
it { is_expected.not_to include(include({ libelle: 'entête de section' })) }

View file

@ -29,14 +29,8 @@ describe Dossier do
end
describe 'with_champs' do
let(:procedure) { create(:procedure) }
let(:dossier) { Dossier.create(user: create(:user), groupe_instructeur: procedure.defaut_groupe_instructeur) }
before do
create(:type_de_champ, libelle: 'l1', order_place: 1, procedure: procedure)
create(:type_de_champ, libelle: 'l3', order_place: 3, procedure: procedure)
create(:type_de_champ, libelle: 'l2', order_place: 2, procedure: procedure)
end
let(:procedure) { create(:procedure, types_de_champ: [build(:type_de_champ, libelle: 'l1', position: 1), build(:type_de_champ, libelle: 'l3', position: 3), build(:type_de_champ, libelle: 'l2', position: 2)]) }
let(:dossier) { create(:dossier, procedure: procedure) }
it do
expect(Dossier.with_champs.find(dossier.id).champs.map(&:libelle)).to match(['l1', 'l2', 'l3'])
@ -255,27 +249,15 @@ describe Dossier do
end
describe '#champs' do
let(:procedure) { create(:procedure) }
let(:dossier) { Dossier.create(user: create(:user), groupe_instructeur: procedure.defaut_groupe_instructeur) }
before do
create(:type_de_champ, libelle: 'l1', order_place: 1, procedure: procedure)
create(:type_de_champ, libelle: 'l3', order_place: 3, procedure: procedure)
create(:type_de_champ, libelle: 'l2', order_place: 2, procedure: procedure)
end
let(:procedure) { create(:procedure, types_de_champ: [build(:type_de_champ, :private, libelle: 'l1', position: 1), build(:type_de_champ, :private, libelle: 'l3', position: 3), build(:type_de_champ, :private, libelle: 'l2', position: 2)]) }
let(:dossier) { create(:dossier, procedure: procedure) }
it { expect(dossier.champs.pluck(:libelle)).to match(['l1', 'l2', 'l3']) }
end
describe '#champs_private' do
let(:procedure) { create :procedure }
let(:dossier) { Dossier.create(user: create(:user), groupe_instructeur: procedure.defaut_groupe_instructeur) }
before do
create :type_de_champ, :private, libelle: 'l1', order_place: 1, procedure: procedure
create :type_de_champ, :private, libelle: 'l3', order_place: 3, procedure: procedure
create :type_de_champ, :private, libelle: 'l2', order_place: 2, procedure: procedure
end
let(:procedure) { create(:procedure, types_de_champ_private: [build(:type_de_champ, :private, libelle: 'l1', position: 1), build(:type_de_champ, :private, libelle: 'l3', position: 3), build(:type_de_champ, :private, libelle: 'l2', position: 2)]) }
let(:dossier) { create(:dossier, procedure: procedure) }
it { expect(dossier.champs_private.pluck(:libelle)).to match(['l1', 'l2', 'l3']) }
end
@ -525,7 +507,7 @@ describe Dossier do
dossier = nil
expect do
perform_enqueued_jobs do
dossier = Dossier.create(groupe_instructeur: procedure.defaut_groupe_instructeur, state: Dossier.states.fetch(:brouillon), user: user)
dossier = create(:dossier, procedure: procedure, state: Dossier.states.fetch(:brouillon), user: user)
end
end.to change(ActionMailer::Base.deliveries, :size).from(0).to(1)
@ -535,17 +517,19 @@ describe Dossier do
end
it "does not send an email when the dossier is created with a non brouillon state" do
expect { Dossier.create(groupe_instructeur: procedure.defaut_groupe_instructeur, state: Dossier.states.fetch(:en_construction), user: user) }.not_to change(ActionMailer::Base.deliveries, :size)
expect { Dossier.create(groupe_instructeur: procedure.defaut_groupe_instructeur, state: Dossier.states.fetch(:en_instruction), user: user) }.not_to change(ActionMailer::Base.deliveries, :size)
expect { Dossier.create(groupe_instructeur: procedure.defaut_groupe_instructeur, state: Dossier.states.fetch(:accepte), user: user) }.not_to change(ActionMailer::Base.deliveries, :size)
expect { Dossier.create(groupe_instructeur: procedure.defaut_groupe_instructeur, state: Dossier.states.fetch(:refuse), user: user) }.not_to change(ActionMailer::Base.deliveries, :size)
expect { Dossier.create(groupe_instructeur: procedure.defaut_groupe_instructeur, state: Dossier.states.fetch(:sans_suite), user: user) }.not_to change(ActionMailer::Base.deliveries, :size)
expect { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_construction), user: user) }.not_to change(ActionMailer::Base.deliveries, :size)
expect { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction), user: user) }.not_to change(ActionMailer::Base.deliveries, :size)
expect { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:accepte), user: user) }.not_to change(ActionMailer::Base.deliveries, :size)
expect { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:refuse), user: user) }.not_to change(ActionMailer::Base.deliveries, :size)
expect { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:sans_suite), user: user) }.not_to change(ActionMailer::Base.deliveries, :size)
end
end
describe "#unspecified_attestation_champs" do
let(:procedure) { create(:procedure, attestation_template: attestation_template) }
let(:procedure) { create(:procedure, attestation_template: attestation_template, types_de_champ: types_de_champ, types_de_champ_private: types_de_champ_private) }
let(:dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) }
let(:types_de_champ) { [] }
let(:types_de_champ_private) { [] }
subject { dossier.unspecified_attestation_champs.map(&:libelle) }
@ -574,14 +558,17 @@ describe Dossier do
context "wich is enabled" do
let(:activated) { true }
let!(:tdc_1) { create(:type_de_champ, libelle: "specified champ-in-title", procedure: procedure) }
let!(:tdc_2) { create(:type_de_champ, libelle: "unspecified champ-in-title", procedure: procedure) }
let!(:tdc_3) { create(:type_de_champ, libelle: "specified champ-in-body", procedure: procedure) }
let!(:tdc_4) { create(:type_de_champ, libelle: "unspecified champ-in-body", procedure: procedure) }
let!(:tdc_5) { create(:type_de_champ, private: true, libelle: "specified annotation privée-in-title", procedure: procedure) }
let!(:tdc_6) { create(:type_de_champ, private: true, libelle: "unspecified annotation privée-in-title", procedure: procedure) }
let!(:tdc_7) { create(:type_de_champ, private: true, libelle: "specified annotation privée-in-body", procedure: procedure) }
let!(:tdc_8) { create(:type_de_champ, private: true, libelle: "unspecified annotation privée-in-body", procedure: procedure) }
let(:types_de_champ) { [tdc_1, tdc_2, tdc_3, tdc_4] }
let(:types_de_champ_private) { [tdc_5, tdc_6, tdc_7, tdc_8] }
let(:tdc_1) { build(:type_de_champ, libelle: "specified champ-in-title") }
let(:tdc_2) { build(:type_de_champ, libelle: "unspecified champ-in-title") }
let(:tdc_3) { build(:type_de_champ, libelle: "specified champ-in-body") }
let(:tdc_4) { build(:type_de_champ, libelle: "unspecified champ-in-body") }
let(:tdc_5) { build(:type_de_champ, private: true, libelle: "specified annotation privée-in-title") }
let(:tdc_6) { build(:type_de_champ, private: true, libelle: "unspecified annotation privée-in-title") }
let(:tdc_7) { build(:type_de_champ, private: true, libelle: "specified annotation privée-in-body") }
let(:tdc_8) { build(:type_de_champ, private: true, libelle: "unspecified annotation privée-in-body") }
before do
(dossier.champs + dossier.champs_private)
@ -1014,7 +1001,7 @@ describe Dossier do
end
context "with mandatory SIRET champ" do
let(:type_de_champ) { create(:type_de_champ_siret, mandatory: true) }
let(:type_de_champ) { create(:type_de_champ_siret, mandatory: true, procedure: procedure) }
let(:champ_siret) { create(:champ_siret, type_de_champ: type_de_champ) }
before do
@ -1041,12 +1028,11 @@ describe Dossier do
end
context "with champ repetition" do
let(:procedure) { create(:procedure) }
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, mandatory: true) }
let(:procedure) { create(:procedure, types_de_champ: [type_de_champ_repetition]) }
let(:type_de_champ_repetition) { build(:type_de_champ_repetition, mandatory: true) }
before do
procedure.types_de_champ << type_de_champ_repetition
type_de_champ_repetition.types_de_champ << create(:type_de_champ_text, mandatory: true)
create(:type_de_champ_text, mandatory: true, parent: type_de_champ_repetition)
end
context "when no champs" do
@ -1261,9 +1247,14 @@ describe Dossier do
end
describe "to_feature_collection" do
let(:dossier) { create(:dossier) }
let(:type_de_champ_carte) { create(:type_de_champ_carte, procedure: dossier.procedure) }
let(:geo_area) { create(:geo_area, :selection_utilisateur, :polygon) }
let(:champ) { create(:champ_carte, geo_areas: [geo_area]) }
let(:dossier) { create(:dossier, champs: [champ]) }
let(:champ_carte) { create(:champ_carte, type_de_champ: type_de_champ_carte, geo_areas: [geo_area]) }
before do
dossier.champs << champ_carte
end
it 'should have all champs carto' do
expect(dossier.to_feature_collection).to eq({
@ -1279,7 +1270,7 @@ describe Dossier do
},
properties: {
area: 219.0,
champ_id: champ.stable_id,
champ_id: champ_carte.stable_id,
dossier_id: dossier.id,
id: geo_area.id,
source: 'selection_utilisateur'

View file

@ -50,7 +50,7 @@ describe ProcedurePresentation do
describe "#fields" do
context 'when the procedure can have a SIRET number' do
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private, :types_de_champ_count => 4, :types_de_champ_private_count => 4) }
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private, types_de_champ_count: 4, types_de_champ_private_count: 4) }
let(:tdc_1) { procedure.types_de_champ[0] }
let(:tdc_2) { procedure.types_de_champ[1] }
let(:tdc_private_1) { procedure.types_de_champ_private[0] }

View file

@ -9,10 +9,6 @@ describe ProcedureRevision do
type_de_champ
end
before do
RevisionsMigration.add_revisions(procedure)
end
describe '#add_type_de_champ' do
it 'type_de_champ' do
expect(revision.types_de_champ.size).to eq(2)
@ -20,11 +16,8 @@ describe ProcedureRevision do
type_champ: TypeDeChamp.type_champs.fetch(:text),
libelle: "Un champ text"
})
procedure.reload
revision.reload
expect(revision.types_de_champ.size).to eq(3)
expect(procedure.types_de_champ.size).to eq(3)
expect(procedure.types_de_champ.last).to eq(new_type_de_champ)
expect(revision.types_de_champ.last).to eq(new_type_de_champ)
expect(revision.revision_types_de_champ.last.position).to eq(2)
expect(revision.revision_types_de_champ.last.type_de_champ).to eq(new_type_de_champ)
@ -37,9 +30,8 @@ describe ProcedureRevision do
libelle: "Un champ text",
private: true
})
procedure.reload
revision.reload
expect(revision.types_de_champ_private.size).to eq(2)
expect(procedure.types_de_champ_private.size).to eq(2)
end
it 'type_de_champ_repetition' do
@ -49,7 +41,6 @@ describe ProcedureRevision do
libelle: "Un champ text",
parent_id: type_de_champ_repetition.stable_id
})
type_de_champ_repetition.reload
expect(type_de_champ_repetition.types_de_champ.size).to eq(2)
end
end
@ -113,26 +104,21 @@ describe ProcedureRevision do
revision.remove_type_de_champ(type_de_champ.stable_id)
procedure.reload
expect(revision.types_de_champ.size).to eq(1)
expect(procedure.types_de_champ.size).to eq(1)
end
it 'type_de_champ_private' do
expect(revision.types_de_champ_private.size).to eq(1)
revision.remove_type_de_champ(type_de_champ_private.stable_id)
procedure.reload
expect(revision.types_de_champ_private.size).to eq(0)
expect(procedure.types_de_champ_private.size).to eq(0)
end
it 'type_de_champ_repetition' do
expect(type_de_champ_repetition.types_de_champ.size).to eq(1)
expect(revision.types_de_champ.size).to eq(2)
revision.remove_type_de_champ(type_de_champ_repetition.types_de_champ.first.stable_id)
procedure.reload
type_de_champ_repetition.reload
expect(type_de_champ_repetition.types_de_champ.size).to eq(0)
expect(revision.types_de_champ.size).to eq(2)
expect(procedure.types_de_champ.size).to eq(2)
end
end

View file

@ -279,15 +279,6 @@ describe Procedure do
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) }
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 0) }
subject { procedure.types_de_champ }
it { expect(subject.first).to eq(type_de_champ_1) }
it { expect(subject.last).to eq(type_de_champ_0) }
end
describe 'active' do
let(:procedure) { create(:procedure) }
subject { Procedure.active(procedure.id) }
@ -333,22 +324,22 @@ describe Procedure do
end
describe 'clone' do
let!(:service) { create(:service) }
let(:procedure) { create(:procedure, received_mail: received_mail, service: service) }
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
let!(:type_de_champ_2) { create(:type_de_champ_drop_down_list, procedure: procedure, order_place: 2) }
let!(:type_de_champ_pj) { create(:type_de_champ_piece_justificative, procedure: procedure, order_place: 3, old_pj: { stable_id: 2713 }) }
let!(:type_de_champ_private_0) { create(:type_de_champ, :private, procedure: procedure, order_place: 0) }
let!(:type_de_champ_private_1) { create(:type_de_champ, :private, procedure: procedure, order_place: 1) }
let!(:type_de_champ_private_2) { create(:type_de_champ_drop_down_list, :private, procedure: procedure, order_place: 2) }
let(:service) { create(:service) }
let(:procedure) { create(:procedure, received_mail: received_mail, service: service, types_de_champ: [type_de_champ_0, type_de_champ_1, type_de_champ_2, type_de_champ_pj], types_de_champ_private: [type_de_champ_private_0, type_de_champ_private_1, type_de_champ_private_2]) }
let(:type_de_champ_0) { build(:type_de_champ, position: 0) }
let(:type_de_champ_1) { build(:type_de_champ, position: 1) }
let(:type_de_champ_2) { build(:type_de_champ_drop_down_list, position: 2) }
let(:type_de_champ_pj) { build(:type_de_champ_piece_justificative, position: 3, old_pj: { stable_id: 2713 }) }
let(:type_de_champ_private_0) { build(:type_de_champ, :private, position: 0) }
let(:type_de_champ_private_1) { build(:type_de_champ, :private, position: 1) }
let(:type_de_champ_private_2) { build(:type_de_champ_drop_down_list, :private, position: 2) }
let(:received_mail) { build(:received_mail) }
let(:from_library) { false }
let(:administrateur) { procedure.administrateurs.first }
let!(:groupe_instructeur_1) { create(:groupe_instructeur, procedure: procedure, label: "groupe_1") }
let!(:instructeur_1) { create(:instructeur) }
let!(:instructeur_2) { create(:instructeur) }
let(:groupe_instructeur_1) { create(:groupe_instructeur, procedure: procedure, label: "groupe_1") }
let(:instructeur_1) { create(:instructeur) }
let(:instructeur_2) { create(:instructeur) }
let!(:assign_to_1) { create(:assign_to, procedure: procedure, groupe_instructeur: groupe_instructeur_1, instructeur: instructeur_1) }
let!(:assign_to_2) { create(:assign_to, procedure: procedure, groupe_instructeur: groupe_instructeur_1, instructeur: instructeur_2) }
@ -379,28 +370,18 @@ describe Procedure do
it 'should duplicate specific objects with different id' do
expect(subject.id).not_to eq(procedure.id)
expect(subject.types_de_champ.size).to eq(procedure.types_de_champ.size)
expect(subject.types_de_champ_private.size).to eq procedure.types_de_champ_private.size
expect(subject.types_de_champ.map(&:drop_down_options).compact.size).to eq procedure.types_de_champ.map(&:drop_down_options).compact.size
expect(subject.types_de_champ_private.map(&:drop_down_options).compact.size).to eq procedure.types_de_champ_private.map(&:drop_down_options).compact.size
expect(subject.draft_revision.types_de_champ.size).to eq(procedure.draft_revision.types_de_champ.size)
expect(subject.draft_revision.types_de_champ_private.size).to eq(procedure.draft_revision.types_de_champ_private.size)
expect(subject.draft_types_de_champ.size).to eq(procedure.draft_types_de_champ.size)
expect(subject.draft_types_de_champ_private.size).to eq(procedure.draft_types_de_champ_private.size)
procedure.types_de_champ.zip(subject.types_de_champ).each do |ptc, stc|
procedure.draft_types_de_champ.zip(subject.draft_types_de_champ).each do |ptc, stc|
expect(stc).to have_same_attributes_as(ptc, except: ["revision_id"])
expect(stc.revision).to eq(subject.draft_revision)
end
procedure.types_de_champ.zip(procedure.draft_revision.types_de_champ).each do |ptc, rtc|
expect(ptc).to eq(rtc)
end
subject.types_de_champ_private.zip(procedure.types_de_champ_private).each do |stc, ptc|
procedure.draft_types_de_champ_private.zip(subject.draft_types_de_champ_private).each do |ptc, stc|
expect(stc).to have_same_attributes_as(ptc, except: ["revision_id"])
expect(stc.revision).to eq(subject.draft_revision)
end
procedure.types_de_champ_private.zip(procedure.draft_revision.types_de_champ_private).each do |ptc, rtc|
expect(ptc).to eq(rtc)
end
expect(subject.attestation_template.title).to eq(procedure.attestation_template.title)
@ -423,7 +404,7 @@ describe Procedure do
end
it 'should discard old pj information' do
subject.types_de_champ.each do |stc|
subject.draft_types_de_champ.each do |stc|
expect(stc.old_pj).to be_nil
end
end
@ -459,7 +440,7 @@ describe Procedure do
end
it 'should discard old pj information' do
subject.types_de_champ.each do |stc|
subject.draft_types_de_champ.each do |stc|
expect(stc.old_pj).to be_nil
end
end
@ -519,12 +500,12 @@ describe Procedure do
end
it 'should keep types_de_champ ids stable' do
expect(subject.types_de_champ.first.id).not_to eq(procedure.types_de_champ.first.id)
expect(subject.types_de_champ.first.stable_id).to eq(procedure.types_de_champ.first.id)
expect(subject.draft_types_de_champ.first.id).not_to eq(procedure.draft_types_de_champ.first.id)
expect(subject.draft_types_de_champ.first.stable_id).to eq(procedure.draft_types_de_champ.first.id)
end
it 'should duplicate piece_justificative_template on a type_de_champ' do
expect(subject.types_de_champ.where(type_champ: "piece_justificative").first.piece_justificative_template.attached?).to be true
expect(subject.draft_types_de_champ.where(type_champ: "piece_justificative").first.piece_justificative_template.attached?).to be true
end
context 'with a notice attached' do
@ -805,7 +786,7 @@ describe Procedure do
end
describe 'suggested_path' do
let(:procedure) { create :procedure, aasm_state: :publiee, libelle: 'Inscription au Collège' }
let(:procedure) { create(:procedure, aasm_state: :publiee, libelle: 'Inscription au Collège') }
subject { procedure.suggested_path(procedure.administrateurs.first) }
@ -821,7 +802,7 @@ describe Procedure do
context 'when the suggestion conflicts with one procedure' do
before do
create :procedure, aasm_state: :publiee, path: 'inscription-au-college'
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college')
end
it { is_expected.to eq 'inscription-au-college-2' }
@ -829,8 +810,8 @@ describe Procedure do
context 'when the suggestion conflicts with several procedures' do
before do
create :procedure, aasm_state: :publiee, path: 'inscription-au-college'
create :procedure, aasm_state: :publiee, path: 'inscription-au-college-2'
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college')
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college-2')
end
it { is_expected.to eq 'inscription-au-college-3' }
@ -838,7 +819,7 @@ describe Procedure do
context 'when the suggestion conflicts with another procedure of the same admin' do
before do
create :procedure, aasm_state: :publiee, path: 'inscription-au-college', administrateurs: procedure.administrateurs
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college', administrateurs: procedure.administrateurs)
end
it { is_expected.to eq 'inscription-au-college' }
@ -903,13 +884,14 @@ describe Procedure do
describe '#new_dossier' do
let(:procedure) do
procedure = create(:procedure)
create(:type_de_champ_text, procedure: procedure, order_place: 1)
create(:type_de_champ_number, procedure: procedure, order_place: 2)
create(:type_de_champ_textarea, :private, procedure: procedure)
procedure
create(:procedure,
types_de_champ: [
build(:type_de_champ_text, position: 0),
build(:type_de_champ_number, position: 1)
],
types_de_champ_private: [
build(:type_de_champ_textarea, :private)
])
end
let(:dossier) { procedure.new_dossier }

View file

@ -153,44 +153,6 @@ shared_examples 'type_de_champ_spec' do
end
end
describe "repetition" do
let(:procedure) { create(:procedure) }
let(:type_de_champ) { create(:type_de_champ_repetition, procedure: procedure) }
let(:type_de_champ_text) { create(:type_de_champ_text, procedure: procedure) }
let(:type_de_champ_integer_number_attrs) { attributes_for(:type_de_champ_integer_number) }
it "associates nested types_de_champ to the parent procedure" do
expect(type_de_champ.types_de_champ.size).to eq(0)
expect(procedure.types_de_champ.size).to eq(1)
procedure.update!(types_de_champ_attributes: [
{
id: type_de_champ.id,
libelle: type_de_champ.libelle,
types_de_champ_attributes: [type_de_champ_integer_number_attrs]
}
])
procedure.reload
type_de_champ.reload
expect(procedure.types_de_champ.size).to eq(1)
expect(type_de_champ.types_de_champ.size).to eq(1)
expect(type_de_champ.types_de_champ.first.parent).to eq(type_de_champ)
expect(type_de_champ.types_de_champ.first.procedure).to eq(procedure)
expect(type_de_champ.types_de_champ.first.private?).to eq(false)
type_de_champ.types_de_champ << type_de_champ_text
expect(type_de_champ.types_de_champ.size).to eq(2)
expect(type_de_champ_text.parent).to eq(type_de_champ)
admin = create(:administrateur)
cloned_procedure = procedure.clone(admin, false)
expect(cloned_procedure.types_de_champ.first.types_de_champ).not_to be_empty
end
end
describe "linked_drop_down_list" do
let(:type_de_champ) { create(:type_de_champ_linked_drop_down_list) }