From 8be8bb07f9b681047154a90d0c808ef22ff56f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 19 Oct 2017 12:17:49 +0200 Subject: [PATCH] Added first poll results tests --- spec/features/polls/results_spec.rb | 26 ++++++++++++++++++++++++++ spec/features/polls/voter_spec.rb | 4 ++-- spec/support/common_actions.rb | 6 +++--- 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 spec/features/polls/results_spec.rb diff --git a/spec/features/polls/results_spec.rb b/spec/features/polls/results_spec.rb new file mode 100644 index 000000000..c67ad3869 --- /dev/null +++ b/spec/features/polls/results_spec.rb @@ -0,0 +1,26 @@ +require 'rails_helper' + +feature 'Poll Results' do + scenario 'List each Poll question' do + user = create(:user, :level_two) + + poll = create(:poll) + question1 = create(:poll_question, poll: poll) + answer1 = create(:poll_question_answer, question: question1, title: 'Yes') + answer2 = create(:poll_question_answer, question: question1, title: 'No') + + question2 = create(:poll_question, poll: poll) + answer3 = create(:poll_question_answer, question: question2, title: 'Blue') + answer4 = create(:poll_question_answer, question: question2, title: 'Green') + answer5 = create(:poll_question_answer, question: question2, title: 'Yellow') + + login_as user + vote_for_poll_via_web(poll, question1, 'Yes') + vote_for_poll_via_web(poll, question1, 'Blue') + + visit poll_results_path(poll) + + expect(page).to have_content(question1.title) + expect(page).to have_content(question2.title) + end +end diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index ff9b71755..7e451be17 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -95,7 +95,7 @@ feature "Voter" do scenario "Trying to vote in web and then in booth", :js do login_as user - vote_for_poll_via_web(poll, question) + vote_for_poll_via_web(poll, question, 'Yes') click_link "Sign out" @@ -127,7 +127,7 @@ feature "Voter" do scenario "Trying to vote in web again", :js do login_as user - vote_for_poll_via_web(poll, question) + vote_for_poll_via_web(poll, question, 'Yes') visit poll_path(poll) diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index b87a54d8e..90deab1b5 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -299,12 +299,12 @@ module CommonActions end end - def vote_for_poll_via_web(poll, question) + def vote_for_poll_via_web(poll, question, answer) visit poll_path(poll) within("#poll_question_#{question.id}_answers") do - click_link 'Yes' - expect(page).to_not have_link('Yes') + click_link "#{answer}" + expect(page).to_not have_link("#{answer}") end expect(Poll::Voter.count).to eq(1)