Replace total votes to cached_votes_score on legislation proposals
This show votes_score as result of votes_up minus votes_down
This commit is contained in:
@@ -96,6 +96,10 @@ class Legislation::Proposal < ActiveRecord::Base
|
|||||||
cached_votes_total
|
cached_votes_total
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def votes_score
|
||||||
|
cached_votes_score
|
||||||
|
end
|
||||||
|
|
||||||
def voters
|
def voters
|
||||||
User.active.where(id: votes_for.voters)
|
User.active.where(id: votes_for.voters)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<span class="total-votes">
|
<span class="total-votes">
|
||||||
<%= t("proposals.proposal.votes", count: proposal.total_votes) %>
|
<%= t("proposals.proposal.votes", count: proposal.votes_score) %>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<% if user_signed_in? && current_user.organization? %>
|
<% if user_signed_in? && current_user.organization? %>
|
||||||
|
|||||||
@@ -145,4 +145,49 @@ feature 'Legislation Proposals' do
|
|||||||
expect(page).to have_content 'Including an image on a legislation proposal'
|
expect(page).to have_content 'Including an image on a legislation proposal'
|
||||||
expect(page).to have_css("img[alt='#{Legislation::Proposal.last.image.title}']")
|
expect(page).to have_css("img[alt='#{Legislation::Proposal.last.image.title}']")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Show votes score on index and show" do
|
||||||
|
legislation_proposal_positive = create(:legislation_proposal,
|
||||||
|
legislation_process_id: process.id,
|
||||||
|
title: "Legislation proposal positive")
|
||||||
|
|
||||||
|
legislation_proposal_zero = create(:legislation_proposal,
|
||||||
|
legislation_process_id: process.id,
|
||||||
|
title: "Legislation proposal zero")
|
||||||
|
|
||||||
|
legislation_proposal_negative = create(:legislation_proposal,
|
||||||
|
legislation_process_id: process.id,
|
||||||
|
title: "Legislation proposal negative")
|
||||||
|
|
||||||
|
10.times { create(:vote, votable: legislation_proposal_positive, vote_flag: true) }
|
||||||
|
3.times { create(:vote, votable: legislation_proposal_positive, vote_flag: false) }
|
||||||
|
|
||||||
|
5.times { create(:vote, votable: legislation_proposal_zero, vote_flag: true) }
|
||||||
|
5.times { create(:vote, votable: legislation_proposal_zero, vote_flag: false) }
|
||||||
|
|
||||||
|
6.times { create(:vote, votable: legislation_proposal_negative, vote_flag: false) }
|
||||||
|
|
||||||
|
visit legislation_process_proposals_path(process)
|
||||||
|
|
||||||
|
within "#legislation_proposal_#{legislation_proposal_positive.id}" do
|
||||||
|
expect(page).to have_content("7 votes")
|
||||||
|
end
|
||||||
|
|
||||||
|
within "#legislation_proposal_#{legislation_proposal_zero.id}" do
|
||||||
|
expect(page).to have_content("No votes")
|
||||||
|
end
|
||||||
|
|
||||||
|
within "#legislation_proposal_#{legislation_proposal_negative.id}" do
|
||||||
|
expect(page).to have_content("-6 votes")
|
||||||
|
end
|
||||||
|
|
||||||
|
visit legislation_process_proposal_path(process, legislation_proposal_positive)
|
||||||
|
expect(page).to have_content("7 votes")
|
||||||
|
|
||||||
|
visit legislation_process_proposal_path(process, legislation_proposal_zero)
|
||||||
|
expect(page).to have_content("No votes")
|
||||||
|
|
||||||
|
visit legislation_process_proposal_path(process, legislation_proposal_negative)
|
||||||
|
expect(page).to have_content("-6 votes")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user