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