Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable options to show stats and results with any type of voter #3155

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/views/admin/poll/results/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@

<h3><%= t("admin.results.index.title") %></h3>

<% if @partial_results.empty? %>
<% if @partial_results.empty? && @poll.voters.empty? %>
<div class="callout primary margin-top">
<%= t("admin.results.index.no_results") %>
</div>
<% else %>
<% end %>

<% if !@partial_results.empty? %>
<%= render "recount", resource: @poll %>
<%= render "result" %>
<%= render "results_by_booth" %>
<% end %>

<% if !@poll.voters.empty? %>
<%= render "show_results", resource: @poll %>
<% end %>
</div>
110 changes: 57 additions & 53 deletions spec/features/admin/poll/polls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,59 +98,6 @@
expect(page).to have_content I18n.l(end_date.to_date)
end

scenario 'Enable stats and results' do
poll = create(:poll)

booth_assignment_1 = create(:poll_booth_assignment, poll: poll)
booth_assignment_2 = create(:poll_booth_assignment, poll: poll)
booth_assignment_3 = create(:poll_booth_assignment, poll: poll)

question_1 = create(:poll_question, poll: poll)
create(:poll_question_answer, title: 'Oui', question: question_1)
create(:poll_question_answer, title: 'Non', question: question_1)

question_2 = create(:poll_question, poll: poll)
create(:poll_question_answer, title: "Aujourd'hui", question: question_2)
create(:poll_question_answer, title: 'Demain', question: question_2)

[booth_assignment_1, booth_assignment_2, booth_assignment_3].each do |ba|
create(:poll_partial_result,
booth_assignment: ba,
question: question_1,
answer: 'Oui',
amount: 11)

create(:poll_partial_result,
booth_assignment: ba,
question: question_2,
answer: 'Demain',
amount: 5)
end

create(:poll_recount,
booth_assignment: booth_assignment_1,
white_amount: 21,
null_amount: 44,
total_amount: 66)

visit admin_poll_results_path(poll)

expect(page).to have_field('poll_stats_enabled', checked: false)
expect(page).to have_field('poll_results_enabled', checked: false)

check 'poll_stats_enabled'
check 'poll_results_enabled'

click_button 'Update poll'

expect(page).to have_content('Poll updated successfully')

click_link 'Results'

expect(page).to have_field('poll_stats_enabled', checked: true)
expect(page).to have_field('poll_results_enabled', checked: true)
end

scenario 'Edit from index' do
poll = create(:poll)
visit admin_polls_path
Expand Down Expand Up @@ -317,6 +264,63 @@
expect(page).to have_content "There are no results"
end

scenario 'Show partial results' do
poll = create(:poll)

booth_assignment_1 = create(:poll_booth_assignment, poll: poll)
booth_assignment_2 = create(:poll_booth_assignment, poll: poll)
booth_assignment_3 = create(:poll_booth_assignment, poll: poll)

question_1 = create(:poll_question, poll: poll)
create(:poll_question_answer, title: 'Oui', question: question_1)
create(:poll_question_answer, title: 'Non', question: question_1)

question_2 = create(:poll_question, poll: poll)
create(:poll_question_answer, title: "Aujourd'hui", question: question_2)
create(:poll_question_answer, title: 'Demain', question: question_2)

[booth_assignment_1, booth_assignment_2, booth_assignment_3].each do |ba|
create(:poll_partial_result,
booth_assignment: ba,
question: question_1,
answer: 'Oui',
amount: 11)

create(:poll_partial_result,
booth_assignment: ba,
question: question_2,
answer: 'Demain',
amount: 5)
end

create(:poll_recount,
booth_assignment: booth_assignment_1,
white_amount: 21,
null_amount: 44,
total_amount: 66)

visit admin_poll_results_path(poll)

expect(page).to have_content 'Results by booth'
end

scenario "Enable stats and results" do
poll = create(:poll)

visit admin_poll_results_path(poll)

expect(page).to have_content 'There are no results'
expect(page).not_to have_content 'Show results and stats'

poll_voter = create(:poll_voter)

visit admin_poll_results_path(poll_voter.poll)

expect(page).to have_content 'Show results and stats'
expect(page).not_to have_content 'There are no results'
expect(page).not_to have_content 'Results by booth'
end

scenario "Results by answer", :js do
poll = create(:poll)
booth_assignment_1 = create(:poll_booth_assignment, poll: poll)
Expand Down