diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb
index 8ba6e934e..90a31192c 100644
--- a/app/controllers/admin/poll/polls_controller.rb
+++ b/app/controllers/admin/poll/polls_controller.rb
@@ -58,9 +58,10 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
end
def poll_params
- params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted, :summary, :description,
- geozone_ids: [],
- image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
+ params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted,
+ :summary, :description, :results_enabled, :stats_enabled,
+ geozone_ids: [],
+ image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
end
def search_params
diff --git a/app/views/admin/poll/polls/_form.html.erb b/app/views/admin/poll/polls/_form.html.erb
index aff19d9d7..c0439af7b 100644
--- a/app/views/admin/poll/polls/_form.html.erb
+++ b/app/views/admin/poll/polls/_form.html.erb
@@ -53,6 +53,17 @@
+ <% if controller_name == "polls" && action_name == "edit" %>
+
+
+
+ <% end %>
+
<%= f.submit t("admin.polls.#{admin_submit_action(@poll)}.submit_button"),
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index aa0fc0f8a..2e5e38dc2 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -569,6 +569,10 @@ en:
geozone_restricted: "Restricted to districts"
new:
title: "New poll"
+ show_results_and_stats: "Show results and stats"
+ show_results: "Show results"
+ show_stats: "Show 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"
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index 2ff4449ec..06ffa6c52 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -569,6 +569,10 @@ es:
geozone_restricted: "Restringida a los distritos"
new:
title: "Nueva votación"
+ show_results_and_stats: "Mostrar resultados y estadísticas"
+ show_results: "Mostrar resultados"
+ show_stats: "Mostrar 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"
diff --git a/db/migrate/20171020163240_add_results_and_stats_to_polls.rb b/db/migrate/20171020163240_add_results_and_stats_to_polls.rb
new file mode 100644
index 000000000..af6f82aaa
--- /dev/null
+++ b/db/migrate/20171020163240_add_results_and_stats_to_polls.rb
@@ -0,0 +1,6 @@
+class AddResultsAndStatsToPolls < ActiveRecord::Migration
+ def change
+ add_column :polls, :results_enabled, :boolean, default: false
+ add_column :polls, :stats_enabled, :boolean, default: false
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index c3ccbeac7..506153b6a 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20171017221546) do
+ActiveRecord::Schema.define(version: 20171020163240) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -759,6 +759,8 @@ ActiveRecord::Schema.define(version: 20171017221546) do
t.integer "comments_count", default: 0
t.integer "author_id"
t.datetime "hidden_at"
+ t.boolean "results_enabled", default: false
+ t.boolean "stats_enabled", default: false
end
add_index "polls", ["starts_at", "ends_at"], name: "index_polls_on_starts_at_and_ends_at", using: :btree
diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb
index 2a2d26ea5..210b2ff6a 100644
--- a/spec/features/admin/poll/polls_spec.rb
+++ b/spec/features/admin/poll/polls_spec.rb
@@ -60,6 +60,10 @@ feature 'Admin polls' do
fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y")
fill_in 'poll_summary', with: "Upcoming poll's summary. This poll..."
fill_in 'poll_description', with: "Upcomming poll's description. This poll..."
+
+ expect(page).to_not have_css("#poll_results_enabled")
+ expect(page).to_not have_css("#poll_stats_enabled")
+
click_button "Create poll"
expect(page).to have_content "Poll created successfully"
@@ -79,14 +83,25 @@ feature 'Admin polls' do
expect(page).to have_css("img[alt='#{poll.image.title}']")
+ expect(page).to have_css("#poll_results_enabled")
+ expect(page).to have_css("#poll_stats_enabled")
+
fill_in "poll_name", with: "Next Poll"
fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y")
+ check 'poll_results_enabled'
+ check 'poll_stats_enabled'
click_button "Update poll"
expect(page).to have_content "Poll updated successfully"
expect(page).to have_content "Next Poll"
expect(page).to have_content I18n.l(end_date.to_date)
+
+ click_link "Edit poll"
+
+ expect(page).to have_field('poll_results_enabled', checked: true)
+ expect(page).to have_field('poll_stats_enabled', checked: true)
+
end
scenario 'Edit from index' do