From 033808043029ab82011ff3d2eb8815efe7eb4d40 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 26 Jun 2020 14:07:00 +0200 Subject: [PATCH] Remove unused procedure move type_de_champ code --- app/models/procedure.rb | 67 --------------------- spec/models/procedure_spec.rb | 110 ---------------------------------- 2 files changed, 177 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 847019ea4..a316e15c3 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -273,29 +273,6 @@ class Procedure < ApplicationRecord publiees.find(id) end - def switch_types_de_champ(index_of_first_element) - switch_list_order(types_de_champ, index_of_first_element) - end - - def switch_types_de_champ_private(index_of_first_element) - switch_list_order(types_de_champ_private, index_of_first_element) - end - - def switch_list_order(list, index_of_first_element) - if index_of_first_element < 0 || - index_of_first_element == list.count - 1 || - list.count < 1 - - false - else - list[index_of_first_element].update(order_place: index_of_first_element + 1) - list[index_of_first_element + 1].update(order_place: index_of_first_element) - reload - - true - end - end - def clone(admin, from_library) # FIXUP: needed during transition to revisions RevisionsMigration.add_revisions(self) @@ -498,34 +475,6 @@ class Procedure < ApplicationRecord result end - def move_type_de_champ(type_de_champ, new_index) - types_de_champ, collection_attribute_name = if type_de_champ.parent&.repetition? - if type_de_champ.parent.private? - [type_de_champ.parent.types_de_champ, :types_de_champ_private_attributes] - else - [type_de_champ.parent.types_de_champ, :types_de_champ_attributes] - end - elsif type_de_champ.private? - [self.types_de_champ_private, :types_de_champ_private_attributes] - else - [self.types_de_champ, :types_de_champ_attributes] - end - - attributes = move_type_de_champ_attributes(types_de_champ.to_a, type_de_champ, new_index) - - if type_de_champ.parent&.repetition? - attributes = [ - { - id: type_de_champ.parent.id, - libelle: type_de_champ.parent.libelle, - types_de_champ_attributes: attributes - } - ] - end - - update!(collection_attribute_name => attributes) - end - def process_dossiers! case declarative_with_state when Procedure.declarative_with_states.fetch(:en_instruction) @@ -607,22 +556,6 @@ class Procedure < ApplicationRecord private - def move_type_de_champ_attributes(types_de_champ, type_de_champ, new_index) - old_index = types_de_champ.index(type_de_champ) - if types_de_champ.delete_at(old_index) - types_de_champ.insert(new_index, type_de_champ) - .map.with_index do |type_de_champ, index| - { - id: type_de_champ.id, - libelle: type_de_champ.libelle, - order_place: index - } - end - else - [] - end - end - def before_publish update!(closed_at: nil, unpublished_at: nil) end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index bfaba7445..9e03d78fe 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -288,40 +288,6 @@ describe Procedure do it { expect(subject.last).to eq(type_de_champ_0) } end - describe '#switch_types_de_champ' do - let(:procedure) { create(:procedure) } - let(:index) { 0 } - subject { procedure.switch_types_de_champ(index) } - - context 'when procedure has no types_de_champ' do - it { expect(subject).to eq(false) } - end - context 'when procedure has 3 types de champ' do - 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, procedure: procedure, order_place: 2) } - context 'when index is not the last element' do - it { expect(subject).to eq(true) } - it 'switches the position of the champ N and N+1' do - subject - expect(procedure.types_de_champ[0]).to eq(type_de_champ_1) - expect(procedure.types_de_champ[0].order_place).to eq(0) - expect(procedure.types_de_champ[1]).to eq(type_de_champ_0) - expect(procedure.types_de_champ[1].order_place).to eq(1) - end - it 'doesn’t move other types de champ' do - subject - expect(procedure.types_de_champ[2]).to eq(type_de_champ_2) - expect(procedure.types_de_champ[2].order_place).to eq(2) - end - end - context 'when index is the last element' do - let(:index) { 2 } - it { expect(subject).to eq(false) } - end - end - end - describe 'active' do let(:procedure) { create(:procedure) } subject { Procedure.active(procedure.id) } @@ -1023,82 +989,6 @@ describe Procedure do end end - describe '#move_type_de_champ' do - let(:procedure) { create(:procedure) } - - context 'type_de_champ' do - let(:type_de_champ) { create(:type_de_champ_text, order_place: 0, procedure: procedure) } - let!(:type_de_champ1) { create(:type_de_champ_text, order_place: 1, procedure: procedure) } - let!(:type_de_champ2) { create(:type_de_champ_text, order_place: 2, procedure: procedure) } - - it 'move down' do - procedure.move_type_de_champ(type_de_champ, 2) - - type_de_champ.reload - procedure.reload - - expect(procedure.types_de_champ.index(type_de_champ)).to eq(2) - expect(type_de_champ.order_place).to eq(2) - end - - context 'repetition' do - let!(:type_de_champ_repetition) do - create(:type_de_champ_repetition, types_de_champ: [ - type_de_champ, - type_de_champ1, - type_de_champ2 - ], procedure: procedure) - end - - it 'move down' do - procedure.move_type_de_champ(type_de_champ, 2) - - type_de_champ.reload - procedure.reload - - expect(type_de_champ.parent.types_de_champ.index(type_de_champ)).to eq(2) - expect(type_de_champ.order_place).to eq(2) - end - - context 'private' do - let!(:type_de_champ_repetition) do - create(:type_de_champ_repetition, types_de_champ: [ - type_de_champ, - type_de_champ1, - type_de_champ2 - ], private: true, procedure: procedure) - end - - it 'move down' do - procedure.move_type_de_champ(type_de_champ, 2) - - type_de_champ.reload - procedure.reload - - expect(type_de_champ.parent.types_de_champ.index(type_de_champ)).to eq(2) - expect(type_de_champ.order_place).to eq(2) - end - end - end - end - - context 'private' do - let(:type_de_champ) { create(:type_de_champ_text, order_place: 0, private: true, procedure: procedure) } - let!(:type_de_champ1) { create(:type_de_champ_text, order_place: 1, private: true, procedure: procedure) } - let!(:type_de_champ2) { create(:type_de_champ_text, order_place: 2, private: true, procedure: procedure) } - - it 'move down' do - procedure.move_type_de_champ(type_de_champ, 2) - - type_de_champ.reload - procedure.reload - - expect(procedure.types_de_champ_private.index(type_de_champ)).to eq(2) - expect(type_de_champ.order_place).to eq(2) - end - end - end - describe '.ensure_a_groupe_instructeur_exists' do let!(:procedure) { create(:procedure) }