adds already supported proposals

This commit is contained in:
rgarcia
2015-09-14 21:21:34 +02:00
parent fff099e72d
commit eea3b0922e
5 changed files with 40 additions and 28 deletions

View File

@@ -11,4 +11,8 @@ module VotesHelper
end end
end end
def voted_for?(votes, votable)
return false unless votes[votable.id]
end
end end

View File

@@ -1,4 +1,3 @@
<% voted_classes = css_classes_for_vote(@proposal_votes, proposal) %>
<div class="supports"> <div class="supports">
<div class="progress small-12 round"> <div class="progress small-12 round">
@@ -7,9 +6,7 @@
<span class="total-supports"> <span class="total-supports">
<%= t("proposals.proposal.supports", count: proposal.total_votes) %>&nbsp; <%= t("proposals.proposal.supports", count: proposal.total_votes) %>&nbsp;
<!-- percentage of supports -->
(<%= supports_percentage(proposal) %>) (<%= supports_percentage(proposal) %>)
<!-- /. percentage of supports -->
<span> <span>
<abbr title="<%= t("proposals.proposal.census_percent") %>"> <abbr title="<%= t("proposals.proposal.census_percent") %>">
<%= t("proposals.proposal.supports_necessary") %> <%= t("proposals.proposal.supports_necessary") %>
@@ -18,15 +15,17 @@
</span> </span>
<div class="in-favor"> <div class="in-favor">
<%= link_to vote_proposal_path(proposal, value: 'yes'), class: "button button-support tiny radius expand #{voted_classes[:in_favor]}", <% if voted_for?(@proposal_votes, proposal) %>
title: t('proposals.proposal.support_title'), method: "post", remote: true do %> <div class="supported">
<%= t("proposals.proposal.support") %>
<% end %>
<!-- if user supported dissapear the button and appear this :) -->
<div class="supported" style="display: none;">
<%= t("proposals.proposal.already_supported") %> <%= t("proposals.proposal.already_supported") %>
</div> </div>
<!-- /. if user supported dissapear the button and appear this :) --> <% else %>
<%= link_to vote_proposal_path(proposal, value: 'yes'),
class: "button button-support tiny radius expand",
title: t('proposals.proposal.support_title'), method: "post", remote: true do %>
<%= t("proposals.proposal.support") %>
<% end %>
<% end %>
</div> </div>
<% if user_signed_in? && current_user.organization? %> <% if user_signed_in? && current_user.organization? %>

View File

@@ -171,7 +171,7 @@ en:
other: "%{count} supports" other: "%{count} supports"
supports_necessary: "53.726 necessary supports" supports_necessary: "53.726 necessary supports"
census_percent: "2% of census" census_percent: "2% of census"
already_supported: "¡You already supported this proposal!" already_supported: "You already supported this proposal!"
form: form:
proposal_title: Proposal title proposal_title: Proposal title
proposal_question: Proposal question proposal_question: Proposal question

View File

@@ -227,24 +227,20 @@ feature 'Votes' do
proposal2 = create(:proposal) proposal2 = create(:proposal)
proposal3 = create(:proposal) proposal3 = create(:proposal)
create(:vote, voter: @manuela, votable: proposal1, vote_flag: true) create(:vote, voter: @manuela, votable: proposal1, vote_flag: true)
create(:vote, voter: @manuela, votable: proposal3, vote_flag: false)
visit proposals_path visit proposals_path
within("#proposals") do within("#proposals") do
within("#proposal_#{proposal1.id}_votes") do within("#proposal_#{proposal1.id}_votes") do
expect(page).to have_css("a.voted") expect(page).to have_content "You already supported this proposal!"
expect(page).to_not have_css("a.no-voted")
end end
within("#proposal_#{proposal2.id}_votes") do within("#proposal_#{proposal2.id}_votes") do
expect(page).to_not have_css("a.voted") expect(page).to_not have_content "You already supported this proposal!"
expect(page).to_not have_css("a.no-voted")
end end
within("#proposal_#{proposal3.id}_votes") do within("#proposal_#{proposal3.id}_votes") do
expect(page).to have_css("a.no-voted") expect(page).to_not have_content "You already supported this proposal!"
expect(page).to_not have_css("a.voted")
end end
end end
end end
@@ -256,13 +252,7 @@ feature 'Votes' do
scenario 'Show no votes' do scenario 'Show no votes' do
visit proposal_path(@proposal) visit proposal_path(@proposal)
expect(page).to have_content "No supports" expect(page).to have_content "No supports"
within('.supports') do
expect(page).to_not have_css("a.voted")
expect(page).to_not have_css("a.no-voted")
end
end end
scenario 'Trying to vote multiple times', :js do scenario 'Trying to vote multiple times', :js do
@@ -294,7 +284,7 @@ feature 'Votes' do
find('.in-favor a').click find('.in-favor a').click
expect(page).to have_content "1 support" expect(page).to have_content "1 support"
expect(page).to have_css("a.voted") expect(page).to have_content "You already supported this proposal!"
end end
end end
@@ -305,7 +295,7 @@ feature 'Votes' do
find('.in-favor a').click find('.in-favor a').click
expect(page).to have_content "1 support" expect(page).to have_content "1 support"
expect(page).to have_css("a.voted") expect(page).to have_content "You already supported this proposal!"
end end
expect(URI.parse(current_url).path).to eq(proposals_path) expect(URI.parse(current_url).path).to eq(proposals_path)
end end
@@ -350,6 +340,4 @@ feature 'Votes' do
expect_message_only_verified_can_vote_proposals expect_message_only_verified_can_vote_proposals
end end
end end
xscenario "Change button text after voting"
end end

View File

@@ -0,0 +1,21 @@
require 'rails_helper'
describe VotesHelper do
describe "#voted_for?" do
it "should return true if voted for a proposal" do
proposal = create(:proposal)
votes = {proposal.id => true}
expect(voted_for?(votes, proposal)).to eq(true)
end
it "should return false if not voted for a proposals" do
proposal = create(:proposal)
votes = {proposal.id => nil}
expect(voted_for?(votes, proposal)).to eq(false)
end
end
end