Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add admin results page for consultations * Add tests for admin results * Changelog entry * english locale normalization * show only published questions to results * Remove locale additions from ca/es * loop n+1 optimization * extra lines
- Loading branch information
1 parent
ab5b8da
commit 7d2bb5b
Showing
9 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
decidim-consultations/app/views/decidim/consultations/admin/consultations/results.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<div class="card" id="consultations"> | ||
<div class="card-divider"> | ||
<h2 class="card-title"> | ||
<%= t "decidim.admin.titles.results" %> | ||
<span class="label button--title"><%= t "decidim.admin.consultations.results.total_votes", count: current_consultation.total_votes %></span> | ||
</h2> | ||
</div> | ||
<div class="card-section"> | ||
<% current_consultation.questions.published.includes(:responses).each do |question| %> | ||
<% unless question.external_voting %> | ||
<table class="table-list"> | ||
<thead> | ||
<tr> | ||
<th><%= decidim_sanitize translated_attribute question.title %></th> | ||
<th class="table-list__actions"> | ||
<%= t "decidim.admin.consultations.results.total_votes", count: question.total_votes %> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% if question.publishable_results? %> | ||
<% question.sorted_results.each do |response| %> | ||
<tr> | ||
<td><%= translated_attribute response.title %></td> | ||
<td><%= response.votes_count %></td> | ||
</tr> | ||
<% end %> | ||
<% else %> | ||
<tr><td><em><%= t "decidim.admin.consultations.results.not_visible" %></em></td><td> </td></tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
decidim-consultations/spec/system/admin/admin_manages_results_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe "Admin manages results", type: :system do | ||
include_context "when administrating a consultation" | ||
let(:votes) { 0 } | ||
let(:total_votes) do | ||
I18n.t("decidim.admin.consultations.results.total_votes", count: votes) | ||
end | ||
|
||
before do | ||
switch_to_host(organization.host) | ||
login_as user, scope: :user | ||
visit decidim_admin_consultations.results_consultation_path(consultation) | ||
end | ||
|
||
describe "viewing active consultation" do | ||
let!(:consultation) { create(:consultation, :active, :unpublished_results, organization: organization) } | ||
|
||
it "Show votes but not responses" do | ||
expect(page).to have_content(/#{total_votes}/i) | ||
expect(page).to have_content(/#{translated(consultation.questions.first.title)}/i) | ||
expect(page).not_to have_content(/#{translated(consultation.questions.first.responses.first.title)}/i) | ||
end | ||
end | ||
|
||
describe "viewing active consultations with votes" do | ||
let!(:consultation) { create(:consultation, :active, :unpublished_results, organization: organization) } | ||
let!(:vote) do | ||
consultation.questions.first.votes.create(author: user, response: consultation.questions.first.responses.first) | ||
end | ||
let(:votes) { consultation.questions.first.total_votes } | ||
|
||
it "Show votes total" do | ||
visit decidim_admin_consultations.results_consultation_path(consultation) | ||
expect(page).to have_content(/#{total_votes}/i) | ||
expect(page).not_to have_content(/#{translated(consultation.questions.first.responses.first.title)}/i) | ||
end | ||
end | ||
|
||
describe "viewing finished consultation" do | ||
let!(:consultation) { create(:consultation, :finished, :unpublished_results, organization: organization) } | ||
|
||
it "Shows votes and responses" do | ||
expect(page).to have_content(/#{total_votes}/i) | ||
expect(page).to have_content(/#{translated(consultation.questions.first.title)}/i) | ||
expect(page).to have_content(/#{translated(consultation.questions.first.responses.first.title)}/i) | ||
end | ||
end | ||
|
||
describe "viewing finished consultations with votes" do | ||
let!(:consultation) { create(:consultation, :finished, :unpublished_results, organization: organization) } | ||
let!(:vote) do | ||
consultation.questions.first.votes.create(author: user, response: consultation.questions.first.responses.first) | ||
end | ||
let(:votes) { consultation.questions.first.total_votes } | ||
|
||
it "Show votes total" do | ||
visit decidim_admin_consultations.results_consultation_path(consultation) | ||
expect(page).to have_content(/#{total_votes}/i) | ||
expect(page).to have_content(/#{translated(consultation.questions.first.responses.first.title)}/i) | ||
end | ||
end | ||
end |