Merge pull request #627 from AyuntamientoMadrid/refactor-votes-spec

refactors votes_spec
This commit is contained in:
Enrique García
2015-10-20 19:51:21 +02:00
4 changed files with 50 additions and 56 deletions

View File

@@ -72,6 +72,7 @@ class Debate < ActiveRecord::Base
end
def votable_by?(user)
return false unless user
total_votes <= 100 ||
!user.unverified? ||
Setting.value_for('max_ratio_anon_votes_on_debates').to_i == 100 ||

View File

@@ -55,7 +55,7 @@ class Proposal < ActiveRecord::Base
end
def votable_by?(user)
user.level_two_or_three_verified?
user && user.level_two_or_three_verified?
end
def register_vote(user, vote_value)

View File

@@ -34,13 +34,10 @@ feature 'Localization' do
end
scenario 'Locale switcher not present if only one locale' do
initial_locales = I18n.available_locales
I18n.available_locales = [:en]
expect(I18n).to receive(:available_locales).and_return([:en])
visit '/'
expect(page).to_not have_content('Language')
expect(page).to_not have_css('div.locale')
I18n.available_locales = initial_locales
end
end

View File

@@ -5,13 +5,13 @@ feature 'Votes' do
background do
@manuela = create(:user, verified_at: Time.now)
@pablo = create(:user)
login_as(@manuela)
end
feature 'Debates' do
background { login_as(@manuela) }
scenario "Index shows user votes on debates" do
debate1 = create(:debate)
debate2 = create(:debate)
debate3 = create(:debate)
@@ -105,7 +105,9 @@ feature 'Votes' do
visit debate_path(@debate)
find('.in-favor a').click
expect(page).to have_content "1 vote"
find('.in-favor a').click
expect(page).to_not have_content "2 votes"
within('.in-favor') do
expect(page).to have_content "100%"
@@ -114,8 +116,6 @@ feature 'Votes' do
within('.against') do
expect(page).to have_content "0%"
end
expect(page).to have_content "1 vote"
end
scenario 'Show' do
@@ -178,49 +178,11 @@ feature 'Votes' do
end
end
scenario 'Not logged user trying to vote', :js do
debate = create(:debate)
visit "/"
click_link "Logout"
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 'Proposals' do
background { login_as(@manuela) }
scenario "Index shows user votes on proposals" do
proposal1 = create(:proposal)
@@ -260,9 +222,9 @@ feature 'Votes' do
within('.supports') do
find('.in-favor a').click
find('.in-favor a').click
expect(page).to have_content "1 support"
expect(page).to_not have_selector ".in-favor a"
end
end
@@ -302,12 +264,24 @@ feature 'Votes' do
end
end
scenario 'Not logged user trying to vote', :js do
proposal = create(:proposal)
scenario 'Not logged user trying to vote debates', :js do
debate = create(:debate)
visit "/"
click_link "Logout"
expect(page).to have_content "Signed out successfully."
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 'Not logged user trying to vote proposals', :js do
proposal = create(:proposal)
visit proposals_path
within("#proposal_#{proposal.id}") do
@@ -322,7 +296,29 @@ feature 'Votes' do
end
end
scenario "Anonymous user trying to vote", :js do
scenario 'Anonymous user trying to vote debates', :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
scenario "Anonymous user trying to vote proposals", :js do
user = create(:user)
proposal = create(:proposal)