- <%= 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 voted_for?(@proposal_votes, proposal) %>
+
<%= t("proposals.proposal.already_supported") %>
-
+ <% 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 %>
<% if user_signed_in? && current_user.organization? %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index b7d079df3..780b1fe30 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -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
diff --git a/spec/features/votes_spec.rb b/spec/features/votes_spec.rb
index b15a39676..81995397d 100644
--- a/spec/features/votes_spec.rb
+++ b/spec/features/votes_spec.rb
@@ -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
diff --git a/spec/helpers/votes_helper_spec.rb b/spec/helpers/votes_helper_spec.rb
new file mode 100644
index 000000000..3e3c005e0
--- /dev/null
+++ b/spec/helpers/votes_helper_spec.rb
@@ -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
\ No newline at end of file