From 77c11d8b7939ab198cd082c20e54e6335b623ccf Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 19 Aug 2019 14:05:09 +0200 Subject: [PATCH] fix_procedure_presentation --- ...entation_from_followers_gestionnaires.rake | 30 +++++++ ...ation_from_followers_gestionnaires_spec.rb | 84 +++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 lib/tasks/deployment/20190819100424_clean_procedure_presentation_from_followers_gestionnaires.rake create mode 100644 spec/lib/tasks/deployment/20190819100424_clean_procedure_presentation_from_followers_gestionnaires_spec.rb diff --git a/lib/tasks/deployment/20190819100424_clean_procedure_presentation_from_followers_gestionnaires.rake b/lib/tasks/deployment/20190819100424_clean_procedure_presentation_from_followers_gestionnaires.rake new file mode 100644 index 000000000..33a1997e0 --- /dev/null +++ b/lib/tasks/deployment/20190819100424_clean_procedure_presentation_from_followers_gestionnaires.rake @@ -0,0 +1,30 @@ +namespace :after_party do + desc 'Deployment task: clean_procedure_presentation_from_followers_gestionnaires' + task clean_procedure_presentation_from_followers_gestionnaires: :environment do + ProcedurePresentation.find_each do |pp| + if pp.sort["table"] == "followers_gestionnaires" + pp.sort["table"] = "followers_instructeurs" + end + + pp.displayed_fields.each do |df| + if df["table"] == "followers_gestionnaires" + df["table"] = "followers_instructeurs" + end + end + + pp.filters.each do |(_name, values)| + values.each do |value| + if value["table"] == "followers_gestionnaires" + value["table"] = "followers_instructeurs" + end + end + end + + begin + pp.save! + rescue ActiveRecord::RecordInvalid + end + end + AfterParty::TaskRecord.create version: '20190819100424' + end +end diff --git a/spec/lib/tasks/deployment/20190819100424_clean_procedure_presentation_from_followers_gestionnaires_spec.rb b/spec/lib/tasks/deployment/20190819100424_clean_procedure_presentation_from_followers_gestionnaires_spec.rb new file mode 100644 index 000000000..70f8f27fc --- /dev/null +++ b/spec/lib/tasks/deployment/20190819100424_clean_procedure_presentation_from_followers_gestionnaires_spec.rb @@ -0,0 +1,84 @@ +describe '20190819100424_clean_procedure_presentation_from_followers_gestionnaires.rake' do + let(:rake_task) { Rake::Task['after_party:clean_procedure_presentation_from_followers_gestionnaires'] } + + let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) } + let(:assign_to) { create(:assign_to, procedure: procedure) } + + let!(:procedure_presentation) do + pp = ProcedurePresentation.new( + assign_to: assign_to, + sort: { + "order" => "asc", + "table" => "followers_gestionnaires", + "column" => "email" + }, + filters: { + "tous" => [], + "suivis" => [], + "traites" => [{ + "label" => "Email instructeur", + "table" => "followers_gestionnaires", + "value" => "mail@simon.lehericey.net", + "column" => "email" + } + ], + "a-suivre" => [], + "archives" => [] + }, + displayed_fields: [ + { + "column" => "email", + "label" => "Demandeur", + "table" => "user" + }, + { + "column" => "email", + "label" => "Email instructeur", + "table" => "followers_gestionnaires" + } + ] + ) + pp.save(validate: false) + pp + end + + before do + rake_task.invoke + procedure_presentation.reload + end + + after { rake_task.reenable } + + it do + expect(procedure_presentation.displayed_fields[1]["table"]).to eq("followers_instructeurs") + expect(procedure_presentation.sort["table"]).to eq("followers_instructeurs") + expect(procedure_presentation.filters["traites"][0]["table"]).to eq("followers_instructeurs") + end + + context 'with an invalid procedure_presentation' do + let!(:procedure_presentation) do + pp = ProcedurePresentation.new( + assign_to: assign_to, + filters: { + "tous" => [], + "suivis" => [], + "traites" => [{ + "label" => "Email instructeur", + "table" => "invalid table", + "value" => "mail@simon.lehericey.net", + "column" => "email" + } + ], + "a-suivre" => [], + "archives" => [] + }, + displayed_fields: [] + ) + pp.save(validate: false) + pp + end + + it 'does not stop the script' do + end + end +end