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.
This commit is contained in:
decabeza
2020-03-16 12:54:00 +01:00
committed by Javi Martín
parent f35a88cf4f
commit c0c458bb38
8 changed files with 105 additions and 75 deletions

View File

@@ -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 }}

View File

@@ -21,13 +21,6 @@
class: "html-area",
hint: t("admin.budget_phases.edit.description_help_text") %>
</div>
<div class="small-12 column">
<%= translations_form.text_area :summary,
maxlength: Budget::Phase::SUMMARY_MAX_LENGTH,
class: "html-area",
hint: t("admin.budget_phases.edit.summary_help_text") %>
</div>
<% end %>
</div>

View File

@@ -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

View File

@@ -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

View File

@@ -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 << "<br>"
translation.description << translation.summary
translation.update!(summary: nil) if translation.save
end
end
end
end

View File

@@ -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

View File

@@ -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<br>English summary"
expect(budget_phase.description_es).to eq "Spanish description"
expect(budget_phase.description_fr).to eq "French description<br>French summary"
expect(budget_phase.summary).to be nil
end
end
end

View File

@@ -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