adds already supported proposals
This commit is contained in:
@@ -11,4 +11,8 @@ module VotesHelper
|
||||
end
|
||||
end
|
||||
|
||||
def voted_for?(votes, votable)
|
||||
return false unless votes[votable.id]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
<% voted_classes = css_classes_for_vote(@proposal_votes, proposal) %>
|
||||
<div class="supports">
|
||||
|
||||
<div class="progress small-12 round">
|
||||
@@ -7,9 +6,7 @@
|
||||
|
||||
<span class="total-supports">
|
||||
<%= t("proposals.proposal.supports", count: proposal.total_votes) %>
|
||||
<!-- percentage of supports -->
|
||||
(<%= supports_percentage(proposal) %>)
|
||||
<!-- /. percentage of supports -->
|
||||
<span>
|
||||
<abbr title="<%= t("proposals.proposal.census_percent") %>">
|
||||
<%= t("proposals.proposal.supports_necessary") %>
|
||||
@@ -18,15 +15,17 @@
|
||||
</span>
|
||||
|
||||
<div class="in-favor">
|
||||
<%= link_to vote_proposal_path(proposal, value: 'yes'), class: "button button-support tiny radius expand #{voted_classes[:in_favor]}",
|
||||
title: t('proposals.proposal.support_title'), method: "post", remote: true do %>
|
||||
<%= t("proposals.proposal.support") %>
|
||||
<% end %>
|
||||
<!-- if user supported dissapear the button and appear this :) -->
|
||||
<div class="supported" style="display: none;">
|
||||
<% if voted_for?(@proposal_votes, proposal) %>
|
||||
<div class="supported">
|
||||
<%= t("proposals.proposal.already_supported") %>
|
||||
</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>
|
||||
|
||||
<% if user_signed_in? && current_user.organization? %>
|
||||
|
||||
@@ -171,7 +171,7 @@ en:
|
||||
other: "%{count} supports"
|
||||
supports_necessary: "53.726 necessary supports"
|
||||
census_percent: "2% of census"
|
||||
already_supported: "¡You already supported this proposal!"
|
||||
already_supported: "You already supported this proposal!"
|
||||
form:
|
||||
proposal_title: Proposal title
|
||||
proposal_question: Proposal question
|
||||
|
||||
@@ -227,24 +227,20 @@ feature 'Votes' do
|
||||
proposal2 = create(:proposal)
|
||||
proposal3 = create(:proposal)
|
||||
create(:vote, voter: @manuela, votable: proposal1, vote_flag: true)
|
||||
create(:vote, voter: @manuela, votable: proposal3, vote_flag: false)
|
||||
|
||||
visit proposals_path
|
||||
|
||||
within("#proposals") do
|
||||
within("#proposal_#{proposal1.id}_votes") do
|
||||
expect(page).to have_css("a.voted")
|
||||
expect(page).to_not have_css("a.no-voted")
|
||||
expect(page).to have_content "You already supported this proposal!"
|
||||
end
|
||||
|
||||
within("#proposal_#{proposal2.id}_votes") do
|
||||
expect(page).to_not have_css("a.voted")
|
||||
expect(page).to_not have_css("a.no-voted")
|
||||
expect(page).to_not have_content "You already supported this proposal!"
|
||||
end
|
||||
|
||||
within("#proposal_#{proposal3.id}_votes") do
|
||||
expect(page).to have_css("a.no-voted")
|
||||
expect(page).to_not have_css("a.voted")
|
||||
expect(page).to_not have_content "You already supported this proposal!"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -256,13 +252,7 @@ feature 'Votes' do
|
||||
|
||||
scenario 'Show no votes' do
|
||||
visit proposal_path(@proposal)
|
||||
|
||||
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
|
||||
|
||||
scenario 'Trying to vote multiple times', :js do
|
||||
@@ -294,7 +284,7 @@ feature 'Votes' do
|
||||
find('.in-favor a').click
|
||||
|
||||
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
|
||||
|
||||
@@ -305,7 +295,7 @@ feature 'Votes' do
|
||||
find('.in-favor a').click
|
||||
|
||||
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
|
||||
expect(URI.parse(current_url).path).to eq(proposals_path)
|
||||
end
|
||||
@@ -350,6 +340,4 @@ feature 'Votes' do
|
||||
expect_message_only_verified_can_vote_proposals
|
||||
end
|
||||
end
|
||||
|
||||
xscenario "Change button text after voting"
|
||||
end
|
||||
|
||||
21
spec/helpers/votes_helper_spec.rb
Normal file
21
spec/helpers/votes_helper_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user