From eea3b0922e0f177012e2d97b239a9572547ffa81 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 14 Sep 2015 21:21:34 +0200 Subject: [PATCH] adds already supported proposals --- app/helpers/votes_helper.rb | 4 ++++ app/views/proposals/_votes.html.erb | 19 +++++++++---------- config/locales/en.yml | 2 +- spec/features/votes_spec.rb | 22 +++++----------------- spec/helpers/votes_helper_spec.rb | 21 +++++++++++++++++++++ 5 files changed, 40 insertions(+), 28 deletions(-) create mode 100644 spec/helpers/votes_helper_spec.rb diff --git a/app/helpers/votes_helper.rb b/app/helpers/votes_helper.rb index b3c5fc9b5..602f21954 100644 --- a/app/helpers/votes_helper.rb +++ b/app/helpers/votes_helper.rb @@ -11,4 +11,8 @@ module VotesHelper end end + def voted_for?(votes, votable) + return false unless votes[votable.id] + end + end diff --git a/app/views/proposals/_votes.html.erb b/app/views/proposals/_votes.html.erb index 924dd42d3..526b114d5 100644 --- a/app/views/proposals/_votes.html.erb +++ b/app/views/proposals/_votes.html.erb @@ -1,4 +1,3 @@ -<% voted_classes = css_classes_for_vote(@proposal_votes, proposal) %>
@@ -7,9 +6,7 @@ <%= t("proposals.proposal.supports", count: proposal.total_votes) %>  - (<%= supports_percentage(proposal) %>) - "> <%= t("proposals.proposal.supports_necessary") %> @@ -18,15 +15,17 @@
- <%= 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_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