Skip to content

Commit

Permalink
Merge pull request #3155 from jaflutz/2824-options-display-results-polls
Browse files Browse the repository at this point in the history
Enable options to show stats and results with any type of voter
  • Loading branch information
microweb10 committed Mar 6, 2019
2 parents cce852d + 47a33ea commit 2f84d17
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 55 deletions.
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 @@ -104,59 +104,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 @@ -323,6 +270,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

0 comments on commit 2f84d17

Please sign in to comment.