spec: refactor

This commit is contained in:
simon lehericey 2022-05-05 12:04:54 +02:00
parent 3188719652
commit becdd4a0ed

View file

@ -1,12 +1,12 @@
describe ProcedureRevision do describe ProcedureRevision do
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private, :with_repetition) } let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private, :with_repetition) }
let(:revision) { procedure.active_revision } let(:revision) { procedure.active_revision }
let(:type_de_champ) { revision.types_de_champ_public.first } let(:type_de_champ_public) { revision.types_de_champ_public.first }
let(:type_de_champ_private) { revision.types_de_champ_private.first } let(:type_de_champ_private) { revision.types_de_champ_private.first }
let(:type_de_champ_repetition) do let(:type_de_champ_repetition) do
type_de_champ = revision.types_de_champ_public.repetition.first repetition = revision.types_de_champ_public.repetition.first
type_de_champ.update(stable_id: 3333) repetition.update(stable_id: 3333)
type_de_champ repetition
end end
describe '#add_type_de_champ' do describe '#add_type_de_champ' do
@ -50,13 +50,13 @@ describe ProcedureRevision do
let(:last_type_de_champ) { revision.types_de_champ_public.last } let(:last_type_de_champ) { revision.types_de_champ_public.last }
it 'move down' do it 'move down' do
expect(revision.types_de_champ_public.index(type_de_champ)).to eq(0) expect(revision.types_de_champ_public.index(type_de_champ_public)).to eq(0)
type_de_champ.update(order_place: nil) type_de_champ_public.update(order_place: nil)
revision.move_type_de_champ(type_de_champ.stable_id, 2) revision.move_type_de_champ(type_de_champ_public.stable_id, 2)
revision.reload revision.reload
expect(revision.types_de_champ_public.index(type_de_champ)).to eq(2) expect(revision.types_de_champ_public.index(type_de_champ_public)).to eq(2)
expect(revision.procedure.types_de_champ.index(type_de_champ)).to eq(2) expect(revision.procedure.types_de_champ.index(type_de_champ_public)).to eq(2)
expect(revision.procedure.types_de_champ_for_procedure_presentation.not_repetition.index(type_de_champ)).to eq(2) expect(revision.procedure.types_de_champ_for_procedure_presentation.not_repetition.index(type_de_champ_public)).to eq(2)
end end
it 'move up' do it 'move up' do
@ -70,59 +70,56 @@ describe ProcedureRevision do
end end
context 'repetition' do context 'repetition' do
let(:procedure) { create(:procedure, :with_repetition) } let!(:procedure) { create(:procedure, :with_repetition) }
let(:type_de_champ) { type_de_champ_repetition.types_de_champ.first }
let(:last_type_de_champ) { type_de_champ_repetition.types_de_champ.last }
before do let!(:second_child) do
revision.add_type_de_champ({ revision.add_type_de_champ({
type_champ: TypeDeChamp.type_champs.fetch(:text), type_champ: TypeDeChamp.type_champs.fetch(:text),
libelle: "Un champ text", libelle: "second child",
parent_id: type_de_champ_repetition.stable_id parent_id: type_de_champ_repetition.stable_id
}) })
end
let!(:last_child) do
revision.add_type_de_champ({ revision.add_type_de_champ({
type_champ: TypeDeChamp.type_champs.fetch(:text), type_champ: TypeDeChamp.type_champs.fetch(:text),
libelle: "Un champ text", libelle: "last child",
parent_id: type_de_champ_repetition.stable_id parent_id: type_de_champ_repetition.stable_id
}) })
type_de_champ_repetition.reload
end end
it 'move down' do it 'move down' do
expect(type_de_champ_repetition.types_de_champ.index(type_de_champ)).to eq(0) expect(type_de_champ_repetition.types_de_champ.index(second_child)).to eq(1)
revision.move_type_de_champ(type_de_champ.stable_id, 2) revision.move_type_de_champ(second_child.stable_id, 2)
type_de_champ_repetition.reload type_de_champ_repetition.reload
expect(type_de_champ_repetition.types_de_champ.index(type_de_champ)).to eq(2) expect(type_de_champ_repetition.types_de_champ.index(second_child)).to eq(2)
end end
it 'move up' do it 'move up' do
expect(type_de_champ_repetition.types_de_champ.index(last_type_de_champ)).to eq(2) expect(type_de_champ_repetition.types_de_champ.index(last_child)).to eq(2)
revision.move_type_de_champ(last_type_de_champ.stable_id, 0) revision.move_type_de_champ(last_child.stable_id, 0)
type_de_champ_repetition.reload type_de_champ_repetition.reload
expect(type_de_champ_repetition.types_de_champ.index(last_type_de_champ)).to eq(0) expect(type_de_champ_repetition.types_de_champ.index(last_child)).to eq(0)
end end
end end
end end
describe '#remove_type_de_champ' do describe '#remove_type_de_champ' do
it 'type_de_champ' do it 'type_de_champ' do
expect(revision.types_de_champ_public.size).to eq(2) revision.remove_type_de_champ(type_de_champ_public.stable_id)
revision.remove_type_de_champ(type_de_champ.stable_id)
procedure.reload
expect(revision.types_de_champ_public.size).to eq(1) expect(revision.types_de_champ_public.size).to eq(1)
end end
it 'type_de_champ_private' do 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) revision.remove_type_de_champ(type_de_champ_private.stable_id)
expect(revision.types_de_champ_private.size).to eq(0) expect(revision.types_de_champ_private.size).to eq(0)
end end
it 'type_de_champ_repetition' do it 'type_de_champ_repetition' do
expect(type_de_champ_repetition.types_de_champ.size).to eq(1)
expect(revision.types_de_champ_public.size).to eq(2)
revision.remove_type_de_champ(type_de_champ_repetition.types_de_champ.first.stable_id) revision.remove_type_de_champ(type_de_champ_repetition.types_de_champ.first.stable_id)
type_de_champ_repetition.reload
expect(type_de_champ_repetition.types_de_champ.size).to eq(0) expect(type_de_champ_repetition.types_de_champ.size).to eq(0)
expect(revision.types_de_champ_public.size).to eq(2) expect(revision.types_de_champ_public.size).to eq(2)
end end