<%= f.submit nil, class: "button success" %>
diff --git a/app/views/admin/shared/_show_results_fields.html.erb b/app/views/admin/shared/_show_results_fields.html.erb
index 47e9b3b92..48c60ae86 100644
--- a/app/views/admin/shared/_show_results_fields.html.erb
+++ b/app/views/admin/shared/_show_results_fields.html.erb
@@ -1,6 +1,6 @@
diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml
index 736f12c0d..c4c4b55e6 100644
--- a/config/i18n-tasks.yml
+++ b/config/i18n-tasks.yml
@@ -127,6 +127,7 @@ ignore_unused:
- "budgets.index.section_header.*"
- "activerecord.*"
- "activemodel.*"
+ - "attributes.*"
- "date.order"
- "unauthorized.*"
- "admin.officials.level_*"
diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml
index f173fb379..83e920012 100644
--- a/config/locales/en/activerecord.yml
+++ b/config/locales/en/activerecord.yml
@@ -1,4 +1,7 @@
en:
+ attributes:
+ results_enabled: "Show results"
+ stats_enabled: "Show stats"
activerecord:
models:
activity:
@@ -212,8 +215,6 @@ en:
geozone_restricted: "Restricted by geozone"
summary: "Summary"
description: "Description"
- results_enabled: "Show results"
- stats_enabled: "Show stats"
poll/translation:
name: "Name"
summary: "Summary"
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index 3916ccdd6..81bc293fe 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -1048,8 +1048,6 @@ en:
geozone_restricted: "Restricted to districts"
new:
title: "New poll"
- show_results_and_stats: "Show results and stats"
- results_and_stats_reminder: "Marking these checkboxes the results and/or stats of this poll will be publicly available and every user will see them."
submit_button: "Create poll"
edit:
title: "Edit poll"
@@ -1327,6 +1325,8 @@ en:
created_at: Created at
delete: Delete
color_help: Hexadecimal format
+ show_results_and_stats: "Show results and stats"
+ results_and_stats_reminder: "Marking these checkboxes the results and/or stats will be publicly available and every user will see them."
spending_proposals:
index:
geozone_filter_all: All zones
diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml
index a46e832e9..66c94a089 100644
--- a/config/locales/es/activerecord.yml
+++ b/config/locales/es/activerecord.yml
@@ -1,4 +1,7 @@
es:
+ attributes:
+ results_enabled: "Mostrar resultados"
+ stats_enabled: "Mostrar estadísticas"
activerecord:
models:
activity:
@@ -212,8 +215,6 @@ es:
geozone_restricted: "Restringida por zonas"
summary: "Resumen"
description: "Descripción"
- results_enabled: "Mostrar resultados"
- stats_enabled: "Mostrar estadísticas"
poll/translation:
name: "Nombre"
summary: "Resumen"
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index 5b51391b6..a636e6b73 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -1047,8 +1047,6 @@ es:
geozone_restricted: "Restringida a los distritos"
new:
title: "Nueva votación"
- show_results_and_stats: "Mostrar resultados y estadísticas"
- results_and_stats_reminder: "Si marcas estas casillas los resultados y/o estadísticas de esta votación serán públicos y podrán verlos todos los usuarios."
submit_button: "Crear votación"
edit:
title: "Editar votación"
@@ -1326,6 +1324,8 @@ es:
created_at: Fecha de creación
delete: Eliminar
color_help: Formato hexadecimal
+ show_results_and_stats: "Mostrar resultados y estadísticas"
+ results_and_stats_reminder: "Si marcas estas casillas los resultados y/o estadísticas serán públicos y podrán verlos todos los usuarios."
spending_proposals:
index:
geozone_filter_all: Todos los ámbitos de actuación
diff --git a/spec/factories/budgets.rb b/spec/factories/budgets.rb
index 0d9faa1ee..66cc1d24f 100644
--- a/spec/factories/budgets.rb
+++ b/spec/factories/budgets.rb
@@ -61,6 +61,8 @@ FactoryBot.define do
trait :finished do
phase "finished"
+ results_enabled true
+ stats_enabled true
end
end
diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb
index 75967555a..4d01a2c12 100644
--- a/spec/features/budgets/investments_spec.rb
+++ b/spec/features/budgets/investments_spec.rb
@@ -522,7 +522,7 @@ feature "Budget Investments" do
context "Results Phase" do
- before { budget.update(phase: "finished") }
+ before { budget.update(phase: "finished", results_enabled: true) }
scenario "show winners by default" do
investment1 = create(:budget_investment, :winner, heading: heading)
diff --git a/spec/models/abilities/everyone_spec.rb b/spec/models/abilities/everyone_spec.rb
index 671294ac5..59ba8cdbe 100644
--- a/spec/models/abilities/everyone_spec.rb
+++ b/spec/models/abilities/everyone_spec.rb
@@ -8,9 +8,6 @@ describe Abilities::Everyone do
let(:debate) { create(:debate) }
let(:proposal) { create(:proposal) }
- let(:reviewing_ballot_budget) { create(:budget, phase: "reviewing_ballots") }
- let(:finished_budget) { create(:budget, phase: "finished") }
-
it { should be_able_to(:index, Debate) }
it { should be_able_to(:show, debate) }
it { should_not be_able_to(:edit, Debate) }
@@ -32,8 +29,6 @@ describe Abilities::Everyone do
it { should be_able_to(:index, Budget) }
- it { should be_able_to(:read_results, finished_budget) }
- it { should_not be_able_to(:read_results, reviewing_ballot_budget) }
it { should_not be_able_to(:manage, Dashboard::Action) }
context "when accessing poll results" do
@@ -74,17 +69,43 @@ describe Abilities::Everyone do
end
end
+ context "when accessing budget results" do
+ context "budget is not finished" do
+ let(:budget) { create(:budget, phase: "reviewing_ballots", results_enabled: true) }
+
+ it { should_not be_able_to(:read_results, budget) }
+ end
+
+ context "budget is finished" do
+ let(:budget) { create(:budget, :finished) }
+
+ it { should be_able_to(:read_results, budget) }
+ end
+
+ context "results disabled" do
+ let(:budget) { create(:budget, :finished, results_enabled: false) }
+
+ it { should_not be_able_to(:read_results, budget) }
+ end
+ end
+
context "when accessing budget stats" do
context "supports phase is not finished" do
- let(:budget) { create(:budget, phase: "selecting") }
+ let(:budget) { create(:budget, phase: "selecting", stats_enabled: true) }
it { should_not be_able_to(:read_stats, budget) }
end
context "supports phase is finished" do
- let(:budget) { create(:budget, phase: "valuating") }
+ let(:budget) { create(:budget, phase: "valuating", stats_enabled: true) }
it { should be_able_to(:read_stats, budget) }
end
+
+ context "stats disabled" do
+ let(:budget) { create(:budget, phase: "valuating", stats_enabled: false) }
+
+ it { should_not be_able_to(:read_stats, budget) }
+ end
end
end
diff --git a/spec/models/budget_spec.rb b/spec/models/budget_spec.rb
index 87063b549..123035732 100644
--- a/spec/models/budget_spec.rb
+++ b/spec/models/budget_spec.rb
@@ -5,6 +5,7 @@ describe Budget do
let(:budget) { create(:budget) }
it_behaves_like "sluggable", updatable_slug_trait: :drafting
+ it_behaves_like "reportable"
describe "name" do
before do
diff --git a/spec/models/concerns/reportable.rb b/spec/models/concerns/reportable.rb
index 06ae8c0c1..c18caa8dd 100644
--- a/spec/models/concerns/reportable.rb
+++ b/spec/models/concerns/reportable.rb
@@ -29,6 +29,8 @@ shared_examples "reportable" do
end
it "uses the `has_one` relation instead of the original column" do
+ skip "there's no original column" unless reportable.has_attribute?(:results_enabled)
+
reportable.update(results_enabled: true)
expect(reportable.read_attribute(:results_enabled)).to be false
@@ -63,6 +65,8 @@ shared_examples "reportable" do
end
it "uses the `has_one` relation instead of the original column" do
+ skip "there's no original column" unless reportable.has_attribute?(:stats_enabled)
+
reportable.update(stats_enabled: true)
expect(reportable.read_attribute(:stats_enabled)).to be false