clean: ignore obsolete procedure_presentation columns
This commit is contained in:
parent
947ef3498b
commit
cdc45cd6af
9 changed files with 2 additions and 270 deletions
|
@ -1,6 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ProcedurePresentation < ApplicationRecord
|
class ProcedurePresentation < ApplicationRecord
|
||||||
|
self.ignored_columns += ["displayed_fields", "filters", "sort"]
|
||||||
|
|
||||||
belongs_to :assign_to, optional: false
|
belongs_to :assign_to, optional: false
|
||||||
has_many :exports, dependent: :destroy
|
has_many :exports, dependent: :destroy
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,5 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
|
|
||||||
assign_to { association :assign_to, procedure: procedure, instructeur: procedure.instructeurs.first }
|
assign_to { association :assign_to, procedure: procedure, instructeur: procedure.instructeurs.first }
|
||||||
sort { { "table" => "user", "column" => "email", "order" => "asc" } }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -25,18 +25,6 @@ describe ProcedurePresentation do
|
||||||
|
|
||||||
def to_filter((label, filter)) = FilteredColumn.new(column: procedure.find_column(label: label), filter: filter)
|
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
|
describe 'validation' do
|
||||||
it { expect(build(:procedure_presentation)).to be_valid }
|
it { expect(build(:procedure_presentation)).to be_valid }
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
|
@ -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
|
|
Loading…
Reference in a new issue