Merge pull request #322 from AyuntamientoMadrid/one-hundred-free-votes
changes rules for allowing debate votes
This commit is contained in:
@@ -75,7 +75,9 @@ class Debate < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def votable_by?(user)
|
||||
!user.unverified? ||
|
||||
total_votes <= 100 ||
|
||||
!user.unverified? ||
|
||||
Setting.value_for('max_ratio_anon_votes_on_debates').to_i == 100 ||
|
||||
anonymous_votes_ratio < Setting.value_for('max_ratio_anon_votes_on_debates').to_i ||
|
||||
user.voted_for?(self)
|
||||
end
|
||||
|
||||
@@ -35,7 +35,7 @@ describe DebatesController do
|
||||
|
||||
it 'should not allow vote if user is not allowed' do
|
||||
Setting.find_by(key: "max_ratio_anon_votes_on_debates").update(value: 0)
|
||||
debate = create(:debate)
|
||||
debate = create(:debate, cached_votes_total: 1000)
|
||||
sign_in create(:user)
|
||||
|
||||
expect do
|
||||
|
||||
@@ -124,7 +124,7 @@ describe Debate do
|
||||
end
|
||||
|
||||
describe "from anonymous users when there are too many anonymous votes" do
|
||||
before(:each) {debate.update(cached_anonymous_votes_total: 52, cached_votes_total: 100)}
|
||||
before(:each) {debate.update(cached_anonymous_votes_total: 520, cached_votes_total: 1000)}
|
||||
|
||||
it "should not register vote " do
|
||||
user = create(:user)
|
||||
@@ -156,13 +156,19 @@ describe Debate do
|
||||
end
|
||||
|
||||
it "should be true for anonymous users if allowed anonymous votes" do
|
||||
debate.update(cached_anonymous_votes_total: 42, cached_votes_total: 100)
|
||||
debate.update(cached_anonymous_votes_total: 420, cached_votes_total: 1000)
|
||||
user = create(:user)
|
||||
expect(debate.votable_by?(user)).to be true
|
||||
end
|
||||
|
||||
it "should be true for anonymous users if less than 100 votes" do
|
||||
debate.update(cached_anonymous_votes_total: 90, cached_votes_total: 92)
|
||||
user = create(:user)
|
||||
expect(debate.votable_by?(user)).to be true
|
||||
end
|
||||
|
||||
it "should be false for anonymous users if too many anonymous votes" do
|
||||
debate.update(cached_anonymous_votes_total: 52, cached_votes_total: 100)
|
||||
debate.update(cached_anonymous_votes_total: 520, cached_votes_total: 1000)
|
||||
user = create(:user)
|
||||
expect(debate.votable_by?(user)).to be false
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user