From f7dce94a451608c0dea70a766b065d63ce1f0acd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 23 Oct 2017 15:50:53 +0200 Subject: [PATCH 01/13] Added tests for Poll results and stats views --- spec/features/polls/polls_spec.rb | 71 ++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index 7bf51473f..424787468 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -367,17 +367,74 @@ feature 'Polls' do end end - + context "Results and stats" do - scenario "See polls statistics", :js do + scenario "Show poll results and stats if enabled and poll expired" do + poll = create(:poll, :expired, results_enabled: true, stats_enabled: true) user = create(:user) - poll = create(:poll, summary: "Summary", description: "Description") + login_as user visit poll_path(poll) - - click_link "Participation statistics" - - expect(page).to have_content("Total participation") + + expect(page).to have_content("Poll results") + expect(page).to have_content("Participation statistics") + + visit poll_results_path(poll) + expect(page.driver.status_code).to eq(200) + + visit poll_stats_path(poll) + expect(page.driver.status_code).to eq(200) + end + + scenario "Don't show poll results and stats if not enabled" do + poll = create(:poll, :expired, results_enabled: false, stats_enabled: false) + user = create(:user) + + login_as user + visit poll_path(poll) + + expect(page).to_not have_content("Poll results") + expect(page).to_not have_content("Participation statistics") + + visit poll_results_path(poll) + expect(page).to have_content("You do not have permission to carry out the action 'results' on poll.") + + visit poll_stats_path(poll) + expect(page).to have_content("You do not have permission to carry out the action 'stats' on poll.") + end + + scenario "Don't show poll results and stats if is not expired" do + poll = create(:poll, :current, results_enabled: true, stats_enabled: true) + user = create(:user) + + login_as user + visit poll_path(poll) + + expect(page).to_not have_content("Poll results") + expect(page).to_not have_content("Participation statistics") + + visit poll_results_path(poll) + expect(page).to have_content("You do not have permission to carry out the action 'results' on poll.") + + visit poll_stats_path(poll) + expect(page).to have_content("You do not have permission to carry out the action 'stats' on poll.") + end + + scenario "Show poll results and stats if user is administrator" do + poll = create(:poll, :current, results_enabled: false, stats_enabled: false) + user = create(:administrator).user + + login_as user + visit poll_path(poll) + + expect(page).to have_content("Poll results") + expect(page).to have_content("Participation statistics") + + visit poll_results_path(poll) + expect(page.driver.status_code).to eq(200) + + visit poll_stats_path(poll) + expect(page.driver.status_code).to eq(200) end end end From da00ac947e38e926b26aacd4e8909ccf57f042de Mon Sep 17 00:00:00 2001 From: decabeza Date: Mon, 23 Oct 2017 19:56:26 +0200 Subject: [PATCH 02/13] replaces link on poll title if results or stats are enabled --- app/views/polls/_poll_group.html.erb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/views/polls/_poll_group.html.erb b/app/views/polls/_poll_group.html.erb index 529e9a99e..9d83d5233 100644 --- a/app/views/polls/_poll_group.html.erb +++ b/app/views/polls/_poll_group.html.erb @@ -19,11 +19,27 @@
<% if poll.questions.count == 1 %> <% poll.questions.each do |question| %> -

<%= link_to question.title, poll %>

+

+ <% if poll.results_enabled? %> + <%= link_to question.title, poll_results_path(poll) %> + <% elsif poll.stats_enabled? %> + <%= link_to question.title, poll_stats_path(poll) %> + <% else %> + <%= link_to question.title, poll %> + <% end %> +

<%= poll_dates(poll) %> <% end %> <% else %> -

<%= link_to poll.name, poll %>

+

+ <% if poll.results_enabled? %> + <%= link_to poll.name, poll_results_path(poll) %> + <% elsif poll.stats_enabled? %> + <%= link_to poll.name, poll_stats_path(poll) %> + <% else %> + <%= link_to poll.name, poll %> + <% end %> +

<%= poll_dates(poll) %>