From a51ed0094bc0a30b3efe62ee8673aa8a079453d6 Mon Sep 17 00:00:00 2001 From: Damien Le Thiec Date: Tue, 7 Feb 2023 00:28:21 +0100 Subject: [PATCH] Fix tests --- .../api/v1/dossiers_controller_spec.rb | 6 ++-- ...0220705164551_remove_unused_champs_spec.rb | 4 +-- spec/models/champ_spec.rb | 10 ++---- spec/models/procedure_revision_spec.rb | 35 ++++++++++--------- 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb index af705addd..23ba99781 100644 --- a/spec/controllers/api/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/v1/dossiers_controller_spec.rb @@ -279,9 +279,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(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']) + expect(subject[0][:champs].size).to eq(2) + expect(subject[0][:champs].map { |c| c[:value] }).to eq(['text', 42]) + expect(subject[0][:champs].map { |c| c[:type_de_champ][:type_champ] }).to eq(['text', 'integer_number']) end end end diff --git a/spec/lib/tasks/deployment/20220705164551_remove_unused_champs_spec.rb b/spec/lib/tasks/deployment/20220705164551_remove_unused_champs_spec.rb index bd0180fd7..29161bc24 100644 --- a/spec/lib/tasks/deployment/20220705164551_remove_unused_champs_spec.rb +++ b/spec/lib/tasks/deployment/20220705164551_remove_unused_champs_spec.rb @@ -21,9 +21,9 @@ describe '20220705164551_remove_unused_champs' do describe 'remove_unused_champs', vcr: { cassette_name: 'api_geo_all' } do it "with bad champs" do - expect(Champ.where(dossier: dossier).count).to eq(38) + expect(Champ.where(dossier: dossier).count).to eq(40) run_task - expect(Champ.where(dossier: dossier).count).to eq(37) + expect(Champ.where(dossier: dossier).count).to eq(39) end end end diff --git a/spec/models/champ_spec.rb b/spec/models/champ_spec.rb index 84bbbbc6d..622d62cb4 100644 --- a/spec/models/champ_spec.rb +++ b/spec/models/champ_spec.rb @@ -510,10 +510,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_id: ULID.generate) } - before do - procedure.active_revision.add_type_de_champ(libelle: 'sub integer', type_champ: 'integer_number', parent_stable_id: tdc_repetition.stable_id) - end - context 'when creating the model directly' do let(:champ_text_row_1) { create(:champ_text, type_de_champ: tdc_text, row_id: ULID.generate, parent: champ, dossier: nil) } @@ -539,18 +535,18 @@ describe Champ do expect(dossier.champs_public.size).to eq(2) expect(champ.rows.size).to eq(2) - second_row = champ.rows.second + second_row = champ.reload.rows.second expect(second_row.size).to eq(1) expect(second_row.first.dossier).to eq(dossier) champ.champs << champ_integer first_row = champ.reload.rows.first - expect(first_row.size).to eq(3) + expect(first_row.size).to eq(2) expect(first_row.second).to eq(champ_integer) champ.champs << champ_text first_row = champ.reload.rows.first - expect(first_row.size).to eq(3) + expect(first_row.size).to eq(2) expect(first_row.first).to eq(champ_text) expect(champ.rows.size).to eq(2) diff --git a/spec/models/procedure_revision_spec.rb b/spec/models/procedure_revision_spec.rb index 9f3277267..7b85c0d39 100644 --- a/spec/models/procedure_revision_spec.rb +++ b/spec/models/procedure_revision_spec.rb @@ -134,15 +134,15 @@ describe ProcedureRevision do end it 'move down' do - expect(draft.children_of(type_de_champ_repetition).index(second_child)).to eq(1) - - draft.move_type_de_champ(second_child.stable_id, 2) - expect(draft.children_of(type_de_champ_repetition).index(second_child)).to eq(2) + + draft.move_type_de_champ(second_child.stable_id, 3) + + expect(draft.children_of(type_de_champ_repetition).index(second_child)).to eq(3) end it 'move up' do - expect(draft.children_of(type_de_champ_repetition).index(last_child)).to eq(2) + expect(draft.children_of(type_de_champ_repetition).index(last_child)).to eq(3) draft.move_type_de_champ(last_child.stable_id, 0) @@ -205,13 +205,13 @@ describe ProcedureRevision do it 'reorders' do children = draft.children_of(type_de_champ_repetition) - expect(children.pluck(:position)).to eq([0, 1, 2]) + expect(children.pluck(:position)).to eq([0, 1, 2, 3]) draft.remove_type_de_champ(children[1].stable_id) children.reload - expect(children.pluck(:position)).to eq([0, 1]) + expect(children.pluck(:position)).to eq([0, 1, 2]) end end end @@ -242,8 +242,8 @@ describe ProcedureRevision do new_draft.remove_type_de_champ(child.stable_id) expect { child.reload }.not_to raise_error - expect(draft.children_of(type_de_champ_repetition).size).to eq(1) - expect(new_draft.children_of(type_de_champ_repetition)).to be_empty + expect(draft.children_of(type_de_champ_repetition).size).to eq(2) + expect(new_draft.children_of(type_de_champ_repetition).size).to eq(1) end it 'can remove the parent only in the new revision' do @@ -291,7 +291,7 @@ describe ProcedureRevision do let(:procedure) { create(:procedure, :with_repetition) } it 'should have the same tdcs with different links' do - expect(new_draft.types_de_champ.count).to eq(2) + expect(new_draft.types_de_champ.count).to eq(3) expect(new_draft.types_de_champ).to eq(draft.types_de_champ) new_repetition, new_child = new_draft.types_de_champ.partition(&:repetition?).map(&:first) @@ -320,7 +320,7 @@ describe ProcedureRevision do it do expect(procedure.revisions.size).to eq(2) - expect(draft.revision_types_de_champ.where.not(parent_id: nil).size).to eq(1) + expect(draft.revision_types_de_champ.where.not(parent_id: nil).size).to eq(2) end end end @@ -639,9 +639,10 @@ describe ProcedureRevision do context 'with a repetition tdc' do let(:procedure) { create(:procedure, :with_repetition) } let!(:parent) { draft.types_de_champ.find(&:repetition?) } - let!(:child) { draft.types_de_champ.reject(&:repetition?).first } + let!(:first_child) { draft.types_de_champ.reject(&:repetition?).first } + let!(:second_child) { draft.types_de_champ.reject(&:repetition?).second } - it { expect(draft.children_of(parent)).to match([child]) } + it { expect(draft.children_of(parent)).to match([first_child, second_child]) } context 'with multiple child' do let(:child_position_2) { create(:type_de_champ_text) } @@ -654,7 +655,7 @@ describe ProcedureRevision do end it 'returns the children in order' do - expect(draft.children_of(parent)).to eq([child, child_position_1, child_position_2]) + expect(draft.children_of(parent)).to eq([first_child, second_child, child_position_1, child_position_2]) end end @@ -668,13 +669,13 @@ describe ProcedureRevision do before do new_draft .revision_types_de_champ - .where(type_de_champ: child) + .where(type_de_champ: first_child) .update(type_de_champ: new_child) end it 'returns the children regarding the revision' do - expect(draft.children_of(parent)).to match([child]) - expect(new_draft.children_of(parent)).to match([new_child]) + expect(draft.children_of(parent)).to match([first_child, second_child]) + expect(new_draft.children_of(parent)).to match([new_child, second_child]) end end end