diff --git a/lib/tasks/budgets.rake b/lib/tasks/budgets.rake index b6d1ed73a..172944420 100644 --- a/lib/tasks/budgets.rake +++ b/lib/tasks/budgets.rake @@ -10,59 +10,4 @@ namespace :budgets do Budget.last.email_unselected end end - - desc "Set published attribute" - task set_published: :environment do - Budget.where(published: nil).each do |budget| - if budget.phase == "drafting" - if budget.phases.enabled.first.present? - next_enabled_phase = budget.phases.enabled.where.not(kind: "drafting").first.kind - else - next_enabled_phase = "informing" - budget.phases.informing.update!(enabled: true) - end - - budget.update!(phase: next_enabled_phase) - budget.update!(published: false) - else - budget.update!(published: true) - end - end - end - - desc "Copies the Budget::Phase summary into description" - task phases_summary_to_description: :environment do - ApplicationLogger.new.info "Adding budget phases summary to descriptions" - - Budget::Phase::Translation.find_each do |translation| - if translation.summary.present? - translation.description << "
" - translation.description << translation.summary - translation.update!(summary: nil) if translation.save - end - end - end - - desc "Add name to existing budget phases" - task add_name_to_existing_phases: :environment do - ApplicationLogger.new.info "Adding names to budgets phases" - - Budget::Phase.find_each do |phase| - if phase.translations.present? - phase.translations.each do |translation| - unless translation.name.present? - if I18n.available_locales.include? translation.locale - locale = translation.locale - else - locale = I18n.default_locale - end - - translation.update!(name: I18n.t("budgets.phase.#{phase.kind}", locale: locale)) - end - end - else - phase.translations.create!(name: I18n.t("budgets.phase.#{phase.kind}"), locale: I18n.default_locale) - end - end - end end diff --git a/lib/tasks/consul.rake b/lib/tasks/consul.rake index 50bcf81a9..a45012ab5 100644 --- a/lib/tasks/consul.rake +++ b/lib/tasks/consul.rake @@ -8,13 +8,4 @@ namespace :consul do task "execute_release_1.4.0_tasks": [ "active_storage:migrate_from_paperclip" ] - - desc "Runs tasks needed to upgrade from 1.2.0 to 1.3.0" - task "execute_release_1.3.0_tasks": [ - "db:load_sdg", - "db:calculate_tsv", - "budgets:set_published", - "budgets:phases_summary_to_description", - "budgets:add_name_to_existing_phases" - ] end diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index fdbffcd97..0c036c609 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -4,17 +4,4 @@ namespace :db do @avoid_log = args[:print_log] == "avoid_log" load(Rails.root.join("db", "dev_seeds.rb")) end - - desc "Load SDG content into database" - task load_sdg: :environment do - ApplicationLogger.new.info "Adding Sustainable Development Goals content" - load(Rails.root.join("db", "sdg.rb")) - WebSection.where(name: "sdg").first_or_create! - end - - desc "Calculates the TSV column for all polls and legislation processes" - task calculate_tsv: :environment do - Poll.find_each(&:calculate_tsvector) - Legislation::Process.find_each(&:calculate_tsvector) - end end diff --git a/spec/lib/tasks/budgets_spec.rb b/spec/lib/tasks/budgets_spec.rb deleted file mode 100644 index e0bd86c6e..000000000 --- a/spec/lib/tasks/budgets_spec.rb +++ /dev/null @@ -1,159 +0,0 @@ -require "rails_helper" - -describe "budget tasks" do - describe "set_published" do - let(:run_rake_task) do - Rake::Task["budgets:set_published"].reenable - Rake.application.invoke_task("budgets:set_published") - end - - it "does not change anything if the published attribute is set" do - budget = create(:budget, published: false, phase: "accepting") - - run_rake_task - budget.reload - - expect(budget.phase).to eq "accepting" - expect(budget.published).to be false - end - - it "publishes budgets which are not in draft mode" do - budget = create(:budget, published: nil, phase: "accepting") - - run_rake_task - budget.reload - - expect(budget.phase).to eq "accepting" - expect(budget.published).to be true - end - - it "changes the published attribute to false on drafting budgets" do - stub_const("Budget::Phase::PHASE_KINDS", ["drafting"] + Budget::Phase::PHASE_KINDS) - budget = create(:budget, published: nil) - budget.update_column(:phase, "drafting") - stub_const("Budget::Phase::PHASE_KINDS", Budget::Phase::PHASE_KINDS - ["drafting"]) - - run_rake_task - budget.reload - - expect(budget.published).to be false - expect(budget.phase).to eq "informing" - end - - it "changes the phase to the first enabled phase" do - budget = create(:budget, published: nil) - budget.update_column(:phase, "drafting") - budget.phases.informing.update!(enabled: false) - - expect(budget.phase).to eq "drafting" - - run_rake_task - budget.reload - - expect(budget.phase).to eq "accepting" - expect(budget.published).to be false - end - - it "enables and select the informing phase if there are not any enabled phases" do - budget = create(:budget, published: nil) - budget.update_column(:phase, "drafting") - budget.phases.each { |phase| phase.update!(enabled: false) } - - expect(budget.phase).to eq "drafting" - - run_rake_task - budget.reload - - expect(budget.phase).to eq "informing" - expect(budget.phases.informing.enabled).to be true - expect(budget.published).to be false - end - end - - describe "phases_summary_to_description" do - let(:run_rake_task) do - Rake::Task["budgets:phases_summary_to_description"].reenable - Rake.application.invoke_task("budgets:phases_summary_to_description") - end - - it "appends the content of summary to the content of description" do - budget = create(:budget) - budget_phase = budget.phases.informing - budget_phase.update!( - description_en: "English description", - description_es: "Spanish description", - description_fr: "French description", - name_es: "Spanish name", - name_fr: "French name", - summary_en: "English summary", - summary_fr: "French summary" - ) - - run_rake_task - - budget_phase.reload - expect(budget_phase.description_en).to eq "English description
English summary" - expect(budget_phase.description_es).to eq "Spanish description" - expect(budget_phase.description_fr).to eq "French description
French summary" - expect(budget_phase.summary).to be nil - end - end - - describe "add_name_to_existing_phases" do - let(:run_rake_task) do - Rake::Task["budgets:add_name_to_existing_phases"].reenable - Rake.application.invoke_task("budgets:add_name_to_existing_phases") - end - - it "adds the name to existing budget phases" do - budget = create(:budget) - informing_phase = budget.phases.informing - accepting_phase = budget.phases.accepting - - accepting_phase.update!(name_en: "Custom accepting", name_es: "Aceptando personalizado") - informing_phase.translations.create!(locale: :es, name: "temp") - informing_phase.translations.update_all(name: "") - - expect(informing_phase.name_en).to eq "" - expect(informing_phase.name_es).to eq "" - expect(informing_phase.name_fr).to be nil - expect(accepting_phase.name_en).to eq "Custom accepting" - expect(accepting_phase.name_es).to eq "Aceptando personalizado" - expect(accepting_phase.name_fr).to be nil - - run_rake_task - - expect(informing_phase.reload.name_en).to eq "Information" - expect(informing_phase.reload.name_es).to eq "Información" - expect(informing_phase.reload.name_fr).to be nil - expect(accepting_phase.reload.name_en).to eq "Custom accepting" - expect(accepting_phase.reload.name_es).to eq "Aceptando personalizado" - expect(accepting_phase.reload.name_fr).to be nil - end - - it "adds the name in default locale to existing translations no longer available" do - budget = create(:budget) - informing_phase = budget.phases.informing - obsolete_translation = informing_phase.translations.build(locale: :fiction) - obsolete_translation.save!(validate: false) - - expect(obsolete_translation.reload.name).to be nil - - run_rake_task - - expect(obsolete_translation.reload.name).to eq "Information" - end - - it "adds a default translation to phases with no translations" do - budget = create(:budget) - informing_phase = budget.phases.informing - informing_phase.translations.destroy_all - - expect(informing_phase.reload.name).to be nil - - run_rake_task - - expect(informing_phase.reload.name).to eq "Information" - end - end -end diff --git a/spec/lib/tasks/db_spec.rb b/spec/lib/tasks/db_spec.rb deleted file mode 100644 index 31448853c..000000000 --- a/spec/lib/tasks/db_spec.rb +++ /dev/null @@ -1,70 +0,0 @@ -require "rails_helper" - -describe "rake db:load_sdg" do - before { Rake::Task["db:load_sdg"].reenable } - - let :run_rake_task do - Rake.application.invoke_task("db:load_sdg") - end - - it "populates empty databases and assigns targets correctly" do - SDG::Goal.destroy_all - SDG::Phase.destroy_all - - run_rake_task - - expect(SDG::Goal.count).to eq 17 - expect(SDG::Target.count).to eq 169 - expect(SDG::Target["17.1"].goal.code).to eq 17 - expect(SDG::Phase.count).to eq 3 - end - - it "does not create additional records on populated databases" do - expect(SDG::Goal.count).to eq 17 - expect(SDG::Target.count).to eq 169 - expect(SDG::Phase.count).to eq 3 - - goal_id = SDG::Goal.last.id - target_id = SDG::Target.last.id - phase_id = SDG::Phase.last.id - - run_rake_task - - expect(SDG::Goal.count).to eq 17 - expect(SDG::Target.count).to eq 169 - expect(SDG::Phase.count).to eq 3 - expect(SDG::Goal.last.id).to eq goal_id - expect(SDG::Target.last.id).to eq target_id - expect(SDG::Phase.last.id).to eq phase_id - end -end - -describe "rake db:calculate_tsv" do - before { Rake::Task["db:calculate_tsv"].reenable } - - let :run_rake_task do - Rake.application.invoke_task("db:calculate_tsv") - end - - it "calculates the tsvector for polls" do - poll = create(:poll) - poll.update_column(:tsv, nil) - - expect(poll.reload.tsv).to be nil - - run_rake_task - - expect(poll.reload.tsv).not_to be nil - end - - it "calculates the tsvector for legislation processes" do - process = create(:legislation_process) - process.update_column(:tsv, nil) - - expect(process.reload.tsv).to be nil - - run_rake_task - - expect(process.reload.tsv).not_to be nil - end -end