Merge remote-tracking branch 'consul/master' into iagirre-admin-poll-stats
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -59,6 +59,22 @@ feature 'Polls' do
|
||||
expect(page).to have_link('Incoming')
|
||||
expect(page).to_not have_link('Expired')
|
||||
end
|
||||
|
||||
scenario "Poll title link to stats if enabled" do
|
||||
poll = create(:poll, name: "Poll with stats", stats_enabled: true)
|
||||
|
||||
visit polls_path
|
||||
|
||||
expect(page).to have_link("Poll with stats", href: stats_poll_path(poll))
|
||||
end
|
||||
|
||||
scenario "Poll title link to results if enabled" do
|
||||
poll = create(:poll, name: "Poll with results", stats_enabled: true, results_enabled: true)
|
||||
|
||||
visit polls_path
|
||||
|
||||
expect(page).to have_link("Poll with results", href: results_poll_path(poll))
|
||||
end
|
||||
end
|
||||
|
||||
context 'Show' do
|
||||
@@ -367,17 +383,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 results_poll_path(poll)
|
||||
expect(page).to have_content("Questions")
|
||||
|
||||
visit stats_poll_path(poll)
|
||||
expect(page).to have_content("Participation data")
|
||||
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 results_poll_path(poll)
|
||||
expect(page).to have_content("You do not have permission to carry out the action 'results' on poll.")
|
||||
|
||||
visit stats_poll_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 results_poll_path(poll)
|
||||
expect(page).to have_content("You do not have permission to carry out the action 'results' on poll.")
|
||||
|
||||
visit stats_poll_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 results_poll_path(poll)
|
||||
expect(page).to have_content("Questions")
|
||||
|
||||
visit stats_poll_path(poll)
|
||||
expect(page).to have_content("Participation data")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
55
spec/features/polls/results_spec.rb
Normal file
55
spec/features/polls/results_spec.rb
Normal file
@@ -0,0 +1,55 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Poll Results' do
|
||||
scenario 'List each Poll question', :js do
|
||||
user1 = create(:user, :level_two)
|
||||
user2 = create(:user, :level_two)
|
||||
user3 = create(:user, :level_two)
|
||||
|
||||
poll = create(:poll, results_enabled: true)
|
||||
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 user1
|
||||
vote_for_poll_via_web(poll, question1, 'Yes')
|
||||
vote_for_poll_via_web(poll, question2, 'Blue')
|
||||
expect(Poll::Voter.count).to eq(1)
|
||||
logout
|
||||
|
||||
login_as user2
|
||||
vote_for_poll_via_web(poll, question1, 'Yes')
|
||||
vote_for_poll_via_web(poll, question2, 'Green')
|
||||
expect(Poll::Voter.count).to eq(2)
|
||||
logout
|
||||
|
||||
login_as user3
|
||||
vote_for_poll_via_web(poll, question1, 'No')
|
||||
vote_for_poll_via_web(poll, question2, 'Yellow')
|
||||
expect(Poll::Voter.count).to eq(3)
|
||||
logout
|
||||
|
||||
poll.update(ends_at: 1.day.ago)
|
||||
|
||||
visit results_poll_path(poll)
|
||||
|
||||
expect(page).to have_content(question1.title)
|
||||
expect(page).to have_content(question2.title)
|
||||
|
||||
within("#question_#{question1.id}_results_table") do
|
||||
expect(find("#answer_#{answer1.id}_result")).to have_content("2 (66.0%)")
|
||||
expect(find("#answer_#{answer2.id}_result")).to have_content("1 (33.0%)")
|
||||
end
|
||||
|
||||
within("#question_#{question2.id}_results_table") do
|
||||
expect(find("#answer_#{answer3.id}_result")).to have_content("1 (33.0%)")
|
||||
expect(find("#answer_#{answer4.id}_result")).to have_content("1 (33.0%)")
|
||||
expect(find("#answer_#{answer5.id}_result")).to have_content("1 (33.0%)")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -95,7 +95,8 @@ 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')
|
||||
expect(Poll::Voter.count).to eq(1)
|
||||
|
||||
click_link "Sign out"
|
||||
|
||||
@@ -127,7 +128,8 @@ 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')
|
||||
expect(Poll::Voter.count).to eq(1)
|
||||
|
||||
visit poll_path(poll)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user