From c0c458bb38ad4029f587ea946a7abe1ff8614f72 Mon Sep 17 00:00:00 2001 From: decabeza Date: Mon, 16 Mar 2020 12:54:00 +0100 Subject: [PATCH] Remove summary in phases form Since it does not appear in the phases anymore. Also, the rake unifies the fields of the budget summary with the budget description. --- app/models/budget/phase.rb | 2 - app/views/admin/budget_phases/_form.html.erb | 7 - config/locales/en/admin.yml | 1 - config/locales/es/admin.yml | 1 - lib/tasks/budgets.rake | 13 ++ lib/tasks/consul.rake | 3 +- spec/lib/tasks/budgets_spec.rb | 151 +++++++++++-------- spec/system/admin/budget_phases_spec.rb | 2 - 8 files changed, 105 insertions(+), 75 deletions(-) diff --git a/app/models/budget/phase.rb b/app/models/budget/phase.rb index aed6abc01..3430a5d4e 100644 --- a/app/models/budget/phase.rb +++ b/app/models/budget/phase.rb @@ -3,7 +3,6 @@ class Budget PHASE_KINDS = %w[informing accepting reviewing selecting valuating publishing_prices balloting reviewing_ballots finished].freeze PUBLISHED_PRICES_PHASES = %w[publishing_prices balloting reviewing_ballots finished].freeze - SUMMARY_MAX_LENGTH = 1000 DESCRIPTION_MAX_LENGTH = 2000 translates :summary, touch: true @@ -15,7 +14,6 @@ class Budget belongs_to :next_phase, class_name: self.name, inverse_of: :prev_phase has_one :prev_phase, class_name: self.name, foreign_key: :next_phase_id, inverse_of: :next_phase - validates_translation :summary, length: { maximum: SUMMARY_MAX_LENGTH } validates_translation :description, length: { maximum: DESCRIPTION_MAX_LENGTH } validates :budget, presence: true validates :kind, presence: true, uniqueness: { scope: :budget }, inclusion: { in: ->(*) { PHASE_KINDS }} diff --git a/app/views/admin/budget_phases/_form.html.erb b/app/views/admin/budget_phases/_form.html.erb index 609261344..845a404d9 100644 --- a/app/views/admin/budget_phases/_form.html.erb +++ b/app/views/admin/budget_phases/_form.html.erb @@ -21,13 +21,6 @@ class: "html-area", hint: t("admin.budget_phases.edit.description_help_text") %> - -
- <%= translations_form.text_area :summary, - maxlength: Budget::Phase::SUMMARY_MAX_LENGTH, - class: "html-area", - hint: t("admin.budget_phases.edit.summary_help_text") %> -
<% end %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 5404db063..1db16f4da 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -173,7 +173,6 @@ en: help: "Headings are meant to divide the money of the participatory budget. Here you can add headings for this group and assign the amount of money that will be used for each heading." budget_phases: edit: - summary_help_text: This text will inform the user about the phase. To show it even if the phase is not active, select the checkbox below description_help_text: This text will appear in the header when the phase is active enabled_help_text: This phase will be public in the budget's phases timeline, as well as active for any other purpose save_changes: Save changes diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 0a9f28479..ebdf2f8d2 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -173,7 +173,6 @@ es: help: "Las partidas sirven para dividir el dinero del presupuesto participativo. Aquí puedes ir añadiendo partidas para cada grupo y establecer la cantidad de dinero que se gastará en cada partida." budget_phases: edit: - summary_help_text: Este texto informará al usuario sobre la fase. Para mostrarlo aunque la fase no esté activa, marca la opción de más abajo. description_help_text: Este texto aparecerá en la cabecera cuando la fase esté activa enabled_help_text: Esta fase será pública en el calendario de fases del presupuesto y estará activa para otros propósitos save_changes: Guardar cambios diff --git a/lib/tasks/budgets.rake b/lib/tasks/budgets.rake index c5ffa9ef6..a2b92d1b8 100644 --- a/lib/tasks/budgets.rake +++ b/lib/tasks/budgets.rake @@ -29,4 +29,17 @@ namespace :budgets do 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 end diff --git a/lib/tasks/consul.rake b/lib/tasks/consul.rake index b4775c285..acfc3ee23 100644 --- a/lib/tasks/consul.rake +++ b/lib/tasks/consul.rake @@ -8,6 +8,7 @@ namespace :consul do task "execute_release_1.3.0_tasks": [ "db:load_sdg", "db:calculate_tsv", - "budgets:set_published" + "budgets:set_published", + "budgets:phases_summary_to_description" ] end diff --git a/spec/lib/tasks/budgets_spec.rb b/spec/lib/tasks/budgets_spec.rb index 609e218c7..d2e7c58cb 100644 --- a/spec/lib/tasks/budgets_spec.rb +++ b/spec/lib/tasks/budgets_spec.rb @@ -1,70 +1,99 @@ require "rails_helper" -describe Budget do - let(:run_rake_task) do - Rake::Task["budgets:set_published"].reenable - Rake.application.invoke_task("budgets:set_published") +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 - it "does not change anything if the published attribute is set" do - budget = create(:budget, published: false, phase: "accepting") + 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 - run_rake_task - budget.reload + 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", + summary_en: "English summary", + summary_fr: "French summary" + ) - expect(budget.phase).to eq "accepting" - expect(budget.published).to be false - end + run_rake_task - 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 + 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 end diff --git a/spec/system/admin/budget_phases_spec.rb b/spec/system/admin/budget_phases_spec.rb index 96d8fc367..e71d0f46d 100644 --- a/spec/system/admin/budget_phases_spec.rb +++ b/spec/system/admin/budget_phases_spec.rb @@ -9,7 +9,6 @@ describe "Admin budget phases" do fill_in "start_date", with: Date.current + 1.day fill_in "end_date", with: Date.current + 12.days - fill_in_ckeditor "Summary", with: "New summary of the phase." fill_in_ckeditor "Description", with: "New description of the phase." uncheck "budget_phase_enabled" click_button "Save changes" @@ -19,7 +18,6 @@ describe "Admin budget phases" do expect(budget.current_phase.starts_at.to_date).to eq((Date.current + 1.day).to_date) expect(budget.current_phase.ends_at.to_date).to eq((Date.current + 12.days).to_date) - expect(budget.current_phase.summary).to include("New summary of the phase.") expect(budget.current_phase.description).to include("New description of the phase.") expect(budget.current_phase.enabled).to be(false) end