From cdc45cd6afa3db0759191361ba8cf20b4fd3592c Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 8 Nov 2024 14:19:53 +0100 Subject: [PATCH] clean: ignore obsolete procedure_presentation columns --- app/models/procedure_presentation.rb | 2 + spec/factories/procedure_presentation.rb | 1 - ...1_migrate_filters_to_use_stable_id_spec.rb | 62 ------------------- ...remove_migration_status_on_filters_spec.rb | 50 --------------- ...n_from_procedure_presentation.rake_spec.rb | 27 -------- ...edure_presentation_to_columns.rake_spec.rb | 56 ----------------- spec/models/procedure_presentation_spec.rb | 12 ---- ...nvalid_procedure_presentation_task_spec.rb | 31 ---------- ...procedure_presentation_naming_task_spec.rb | 31 ---------- 9 files changed, 2 insertions(+), 270 deletions(-) delete mode 100644 spec/lib/tasks/deployment/20201001161931_migrate_filters_to_use_stable_id_spec.rb delete mode 100644 spec/lib/tasks/deployment/20210720133539_remove_migration_status_on_filters_spec.rb delete mode 100644 spec/lib/tasks/deployment/20240912151317_clean_virtual_column_from_procedure_presentation.rake_spec.rb delete mode 100644 spec/lib/tasks/deployment/20240920130741_migrate_procedure_presentation_to_columns.rake_spec.rb delete mode 100644 spec/tasks/maintenance/clean_invalid_procedure_presentation_task_spec.rb delete mode 100644 spec/tasks/maintenance/hotfix_former_procedure_presentation_naming_task_spec.rb diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 2df4db930..45e4e2434 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class ProcedurePresentation < ApplicationRecord + self.ignored_columns += ["displayed_fields", "filters", "sort"] + belongs_to :assign_to, optional: false has_many :exports, dependent: :destroy diff --git a/spec/factories/procedure_presentation.rb b/spec/factories/procedure_presentation.rb index 159678a28..cd0e3c33a 100644 --- a/spec/factories/procedure_presentation.rb +++ b/spec/factories/procedure_presentation.rb @@ -7,6 +7,5 @@ FactoryBot.define do end assign_to { association :assign_to, procedure: procedure, instructeur: procedure.instructeurs.first } - sort { { "table" => "user", "column" => "email", "order" => "asc" } } end end diff --git a/spec/lib/tasks/deployment/20201001161931_migrate_filters_to_use_stable_id_spec.rb b/spec/lib/tasks/deployment/20201001161931_migrate_filters_to_use_stable_id_spec.rb deleted file mode 100644 index 3c2aa7080..000000000 --- a/spec/lib/tasks/deployment/20201001161931_migrate_filters_to_use_stable_id_spec.rb +++ /dev/null @@ -1,62 +0,0 @@ -# frozen_string_literal: true - -describe '20201001161931_migrate_filters_to_use_stable_id' do - let(:rake_task) { Rake::Task['after_party:migrate_filters_to_use_stable_id'] } - - let(:procedure) { create(:procedure, :with_instructeur, :with_type_de_champ) } - let(:type_de_champ) { procedure.active_revision.types_de_champ_public.first } - let(:sort) do - { - "table" => "type_de_champ", - "column" => type_de_champ.id.to_s, - "order" => "asc" - } - end - let(:filters) do - { - 'tous' => [ - { - "label" => "test", - "table" => "type_de_champ", - "column" => type_de_champ.id.to_s, - "value" => "test" - } - ], - 'suivis' => [], - 'traites' => [], - 'a-suivre' => [], - 'archives' => [] - } - end - let(:displayed_fields) do - [ - { - "label" => "test", - "table" => "type_de_champ", - "column" => type_de_champ.id.to_s - } - ] - end - let!(:procedure_presentation) do - type_de_champ.update_column(:stable_id, 13) - procedure_presentation = create(:procedure_presentation, procedure: procedure, assign_to: procedure.groupe_instructeurs.first.assign_tos.first) - procedure_presentation.update_columns(sort: sort, filters: filters, displayed_fields: displayed_fields) - procedure_presentation - end - - before do - rake_task.invoke - procedure_presentation.reload - end - - after { rake_task.reenable } - - context "should migrate procedure_presentation" do - it "columns are updated" do - expect(procedure_presentation.sort['column']).to eq(type_de_champ.stable_id.to_s) - expect(procedure_presentation.filters['tous'][0]['column']).to eq(type_de_champ.stable_id.to_s) - expect(procedure_presentation.displayed_fields[0]['column']).to eq(type_de_champ.stable_id.to_s) - expect(procedure_presentation.filters['migrated']).to eq(true) - end - end -end diff --git a/spec/lib/tasks/deployment/20210720133539_remove_migration_status_on_filters_spec.rb b/spec/lib/tasks/deployment/20210720133539_remove_migration_status_on_filters_spec.rb deleted file mode 100644 index 1eb4e20d5..000000000 --- a/spec/lib/tasks/deployment/20210720133539_remove_migration_status_on_filters_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -# frozen_string_literal: true - -describe '20201001161931_migrate_filters_to_use_stable_id' do - let(:rake_task) { Rake::Task['after_party:remove_migration_status_on_filters'] } - - let(:procedure) { create(:simple_procedure) } - let(:instructeur_1) { create(:instructeur) } - let(:instructeur_2) { create(:instructeur) } - - let(:assign_to_1) { create(:assign_to, procedure: procedure, instructeur: instructeur_1) } - let(:assign_to_2) { create(:assign_to, procedure: procedure, instructeur: instructeur_2) } - - let(:procedure_presentation_with_migration) { create(:procedure_presentation, assign_to: assign_to_1, filters: filters.merge('migrated': true)) } - let(:procedure_presentation_without_migration) { create(:procedure_presentation, assign_to: assign_to_2, filters: filters) } - - let(:filters) do - { "suivis" => [{ "table" => "user", "column" => "email", "value" => "test@example.com" }] } - end - - subject(:run_task) do - procedure_presentation_with_migration - procedure_presentation_without_migration - - rake_task.invoke - - procedure_presentation_with_migration.reload - procedure_presentation_without_migration.reload - end - - after { rake_task.reenable } - - context 'when the procedure presentation has a "migrated" key' do - it 'removes the "migrated" key' do - run_task - expect(procedure_presentation_with_migration.filters).not_to have_key('migrated') - end - - it 'leaves other keys unchanged' do - run_task - expect(procedure_presentation_with_migration.filters['suivis']).to be_present - end - end - - context 'when the procedure presentation doesn’t have a "migrated" key' do - it 'leaves keys unchanged' do - run_task - expect(procedure_presentation_without_migration.filters['suivis']).to be_present - end - end -end diff --git a/spec/lib/tasks/deployment/20240912151317_clean_virtual_column_from_procedure_presentation.rake_spec.rb b/spec/lib/tasks/deployment/20240912151317_clean_virtual_column_from_procedure_presentation.rake_spec.rb deleted file mode 100644 index 803bb7fd4..000000000 --- a/spec/lib/tasks/deployment/20240912151317_clean_virtual_column_from_procedure_presentation.rake_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -describe '20240912151317_clean_virtual_column_from_procedure_presentation.rake' do - let(:rake_task) { Rake::Task['after_party:clean_virtual_column_from_procedure_presentation'] } - - let(:procedure) { create(:procedure) } - let(:instructeur) { create(:instructeur) } - let(:assign_to) { create(:assign_to, procedure:, instructeur:) } - - let!(:procedure_presentation) do - displayed_fields = [{ label: "test1", table: "user", column: "email", virtual: true }] - - create(:procedure_presentation, assign_to:, displayed_fields:) - end - - before do - rake_task.invoke - - procedure_presentation.reload - end - - after { rake_task.reenable } - - it 'removes the virtual field' do - expect(procedure_presentation.displayed_fields).to eq([{ "column" => "email", "label" => "test1", "table" => "user" }]) - end -end diff --git a/spec/lib/tasks/deployment/20240920130741_migrate_procedure_presentation_to_columns.rake_spec.rb b/spec/lib/tasks/deployment/20240920130741_migrate_procedure_presentation_to_columns.rake_spec.rb deleted file mode 100644 index 1e2dfcc10..000000000 --- a/spec/lib/tasks/deployment/20240920130741_migrate_procedure_presentation_to_columns.rake_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -describe '20240920130741_migrate_procedure_presentation_to_columns.rake' do - let(:rake_task) { Rake::Task['after_party:migrate_procedure_presentation_to_columns'] } - - let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :text }]) } - let(:instructeur) { create(:instructeur) } - let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: instructeur) } - let(:stable_id) { procedure.active_revision.types_de_champ.first.stable_id } - let!(:procedure_presentation) do - displayed_fields = [ - { "table" => "etablissement", "column" => "entreprise_raison_sociale" }, - { "table" => "type_de_champ", "column" => stable_id.to_s } - ] - - sort = { "order" => "desc", "table" => "self", "column" => "en_construction_at" } - - filters = { - "tous" => [], - "suivis" => [], - "traites" => [{ "label" => "Libellé NAF", "table" => "etablissement", "value" => "Administration publique générale", "column" => "libelle_naf", "value_column" => "value" }], - "a-suivre" => [], - "archives" => [], - "expirant" => [], - "supprimes" => [], - "supprimes_recemment" => [] - } - - create(:procedure_presentation, assign_to:, displayed_fields:, filters:, sort:) - end - - before do - rake_task.invoke - - procedure_presentation.reload - end - - it 'populates the columns' do - procedure_id = procedure.id - - expect(procedure_presentation.displayed_columns.map(&:label)).to eq(["Entreprise raison sociale", procedure.active_revision.types_de_champ.first.libelle]) - - order, column_id = procedure_presentation - .sorted_column - .then { |sorted| [sorted.order, sorted.column.h_id] } - - expect(order).to eq('desc') - expect(column_id).to eq(procedure_id: procedure_id, column_id: "self/en_construction_at") - - expect(procedure_presentation.tous_filters).to eq([]) - - traites = procedure_presentation.traites_filters.map { [_1.label, _1.filter] } - - expect(traites).to eq([["Libellé NAF", "Administration publique générale"]]) - end -end diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index 36c4197d3..aff99a030 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -25,18 +25,6 @@ describe ProcedurePresentation do def to_filter((label, filter)) = FilteredColumn.new(column: procedure.find_column(label: label), filter: filter) - describe "#displayed_fields" do - it { expect(procedure_presentation.displayed_fields).to eq([{ "label" => "test1", "table" => "user", "column" => "email" }, { "label" => "test2", "table" => "type_de_champ", "column" => first_type_de_champ_id }]) } - end - - describe "#sort" do - it { expect(procedure_presentation.sort).to eq({ "table" => "user", "column" => "email", "order" => "asc" }) } - end - - describe "#filters" do - it { expect(procedure_presentation.filters).to eq({ "a-suivre" => [], "suivis" => [{ "label" => "label1", "table" => "self", "column" => "created_at" }] }) } - end - describe 'validation' do it { expect(build(:procedure_presentation)).to be_valid } diff --git a/spec/tasks/maintenance/clean_invalid_procedure_presentation_task_spec.rb b/spec/tasks/maintenance/clean_invalid_procedure_presentation_task_spec.rb deleted file mode 100644 index ba0915b52..000000000 --- a/spec/tasks/maintenance/clean_invalid_procedure_presentation_task_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -module Maintenance - RSpec.describe CleanInvalidProcedurePresentationTask do - describe "#process" do - subject(:process) { described_class.process(element) } - let(:procedure) { create(:procedure) } - let(:groupe_instructeur) { create(:groupe_instructeur, procedure:, instructeurs: [build(:instructeur)]) } - let(:assign_to) { create(:assign_to, procedure:, instructeur: groupe_instructeur.instructeurs.first) } - let(:element) { create(:procedure_presentation, procedure:, assign_to:) } - - before { element.update_column(:filters, filters) } - - context 'when filter is valid' do - let(:filters) { { "suivis" => [{ 'table' => "self", 'column' => "id", "value" => (FilteredColumn::PG_INTEGER_MAX_VALUE - 1).to_s }] } } - it 'keeps it filters' do - expect { subject }.not_to change { element.reload.filters } - end - end - - context 'when filter is invalid, drop it' do - let(:filters) { { "suivis" => [{ 'table' => "self", 'column' => "id", "value" => (FilteredColumn::PG_INTEGER_MAX_VALUE).to_s }] } } - it 'drop invalid filters' do - expect { subject }.to change { element.reload.filters }.to({ "suivis" => [] }) - end - end - end - end -end diff --git a/spec/tasks/maintenance/hotfix_former_procedure_presentation_naming_task_spec.rb b/spec/tasks/maintenance/hotfix_former_procedure_presentation_naming_task_spec.rb deleted file mode 100644 index 4fe8dd3ec..000000000 --- a/spec/tasks/maintenance/hotfix_former_procedure_presentation_naming_task_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -# this commit : https://github.com/demarches-simplifiees/demarches-simplifiees.fr/pull/10625/commits/305b8c13c75a711a85521d0b19659293d8d92805 -# it brokes a naming convention on ProcedurePresentation.filters|displayed_fields|sort -# we adjust live data to fit new convention -module Maintenance - RSpec.describe HotfixFormerProcedurePresentationNamingTask do - let(:procedure) { create(:procedure, types_de_champ_private: [{ type: :text }]) } - let(:groupe_instructeur) { create(:groupe_instructeur, procedure: procedure, instructeurs: [build(:instructeur)]) } - let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: groupe_instructeur.instructeurs.first) } - let(:procedure_presentation) { create(:procedure_presentation, procedure: procedure, assign_to: assign_to) } - - describe "#process" do - subject(:process) { described_class.process(procedure_presentation) } - - it "fix table naming" do - stable_id = procedure.draft_revision.types_de_champ.first.stable_id.to_s - procedure_presentation.update_column(:displayed_fields, [{ table: 'type_de_champ_private', column: stable_id }]) - procedure_presentation.update_column(:filters, "a-suivre" => [{ table: 'type_de_champ_private', column: stable_id }]) - procedure_presentation.update_column(:sort, table: 'type_de_champ_private', column: stable_id, order: 'asc') - subject - procedure_presentation.reload - expect(procedure_presentation.displayed_fields.map { _1['table'] }).to eq(['type_de_champ']) - expect(procedure_presentation.filters.flat_map { |_, filters| filters.map { _1['table'] } }).to eq(['type_de_champ']) - expect(procedure_presentation.sort['table']).to eq('type_de_champ') - end - end - end -end