adds proposal votes

This commit is contained in:
rgarcia
2015-09-13 21:56:52 +02:00
parent d4b3e8be94
commit ad8880d02c
13 changed files with 311 additions and 26 deletions

View File

@@ -10,7 +10,9 @@ feature 'Votes' do
end
feature 'Debates' do
scenario "Home shows user votes on featured debates" do
xscenario "Home shows user votes on featured debates" do
pending "logged in user cannot see this page"
debate1 = create(:debate)
debate2 = create(:debate)
debate3 = create(:debate)
@@ -200,7 +202,8 @@ feature 'Votes' do
expect(page).to have_content "1 vote"
end
scenario 'Create in featured', :js do
xscenario 'Create in featured', :js do
pending "logged in user cannot see this page"
visit root_path
find('.in-favor a').click
@@ -241,6 +244,52 @@ feature 'Votes' do
expect(current_path).to eq(debates_path)
end
end
scenario 'Not logged user trying to vote', :js do
debate = create(:debate)
visit "/"
click_link "Logout"
within("#debate_#{debate.id}") do
find("div.votes").hover
expect_message_you_need_to_sign_in
end
visit debates_path
within("#debate_#{debate.id}") do
find("div.votes").hover
expect_message_you_need_to_sign_in
end
visit debate_path(debate)
within("#debate_#{debate.id}") do
find("div.votes").hover
expect_message_you_need_to_sign_in
end
end
scenario 'Anonymous user trying to vote', :js do
user = create(:user)
debate = create(:debate)
Setting.find_by(key: "max_ratio_anon_votes_on_debates").update(value: 50)
debate.update(cached_anonymous_votes_total: 520, cached_votes_total: 1000)
login_as(user)
visit debates_path
within("#debate_#{debate.id}") do
find("div.votes").hover
expect_message_to_many_anonymous_votes
end
visit debate_path(debate)
within("#debate_#{debate.id}") do
find("div.votes").hover
expect_message_to_many_anonymous_votes
end
end
end
feature 'Comments' do
@@ -324,4 +373,199 @@ feature 'Votes' do
end
end
end
feature 'Proposals' do
xscenario "Home shows user votes on featured proposals" do
pending "logged in user cannot see this page"
proposal1 = create(:proposal)
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 root_path
within("#featured-proposals") do
within("#proposal_#{proposal1.id}_votes") do
within(".supports") do
expect(page).to have_css("a.voted")
expect(page).to_not have_css("a.no-voted")
end
end
within("#proposal_#{proposal2.id}_votes") do
within(".supports") do
expect(page).to_not have_css("a.voted")
expect(page).to_not have_css("a.no-voted")
end
end
within("#proposal_#{proposal3.id}_votes") do
within(".supports") do
expect(page).to have_css("a.no-voted")
expect(page).to_not have_css("a.voted")
end
end
end
end
scenario "Index shows user votes on proposals" do
proposal1 = create(:proposal)
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")
end
within("#proposal_#{proposal2.id}_votes") do
expect(page).to_not have_css("a.voted")
expect(page).to_not have_css("a.no-voted")
end
within("#proposal_#{proposal3.id}_votes") do
expect(page).to have_css("a.no-voted")
expect(page).to_not have_css("a.voted")
end
end
end
feature 'Single proposal' do
background do
@proposal = create(:proposal)
end
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 'Update', :js do
visit proposal_path(@proposal)
within('.supports') do
find('.in-favor a').click
expect(page).to have_content "1 support"
expect(page).to have_css("a.voted")
find('.in-favor a').click
expect(page).to have_content "No supports"
expect(page).to_not have_css("a.no-voted")
end
end
scenario 'Trying to vote multiple times', :js do
visit proposal_path(@proposal)
within('.supports') do
find('.in-favor a').click
find('.in-favor a').click
expect(page).to have_content "1 support"
end
end
scenario 'Show' do
create(:vote, voter: @manuela, votable: @proposal, vote_flag: true)
create(:vote, voter: @pablo, votable: @proposal, vote_flag: true)
visit proposal_path(@proposal)
within('.supports') do
expect(page).to have_content "2 supports / 53.726"
end
end
scenario 'Create from proposal show', :js do
visit proposal_path(@proposal)
within('.supports') do
find('.in-favor a').click
expect(page).to have_content "1 support"
expect(page).to have_css("a.voted")
end
end
xscenario 'Create in featured', :js do
pending "logged in user cannot see this page"
visit root_path
within("#featured-proposals") do
find('.in-favor a').click
expect(page).to have_content "1 support"
expect(page).to have_css("a.voted")
end
expect(URI.parse(current_url).path).to eq(root_path)
end
scenario 'Create in index', :js do
visit proposals_path
within("#proposals") do
find('.in-favor a').click
expect(page).to have_content "1 support"
expect(page).to have_css("a.voted")
end
expect(URI.parse(current_url).path).to eq(proposals_path)
end
end
end
scenario 'Not logged user trying to vote', :js do
proposal = create(:proposal)
visit "/"
click_link "Logout"
within("#proposal_#{proposal.id}") do
find("div.supports").hover
expect_message_you_need_to_sign_in
end
visit proposals_path
within("#proposal_#{proposal.id}") do
find("div.supports").hover
expect_message_you_need_to_sign_in
end
visit proposal_path(proposal)
within("#proposal_#{proposal.id}") do
find("div.supports").hover
expect_message_you_need_to_sign_in
end
end
scenario "Anonymous user trying to vote", :js do
user = create(:user)
proposal = create(:proposal)
login_as(user)
visit proposals_path
within("#proposal_#{proposal.id}") do
find("div.supports").hover
expect_message_only_verified_can_vote
end
visit proposal_path(proposal)
within("#proposal_#{proposal.id}") do
find("div.supports").hover
expect_message_only_verified_can_vote
end
end
end