archived proposals can not accept votes

This commit is contained in:
Juanjo Bazán
2016-09-12 18:47:56 +02:00
parent acae610995
commit da03311f99
3 changed files with 13 additions and 2 deletions

View File

@@ -121,7 +121,7 @@ class Proposal < ActiveRecord::Base
end
def register_vote(user, vote_value)
if votable_by?(user)
if votable_by?(user) && !archived?
vote_by(voter: user, vote: vote_value)
end
end

View File

@@ -163,6 +163,10 @@ FactoryGirl.define do
end
end
trait :archived do
created_at (Setting["months_to_archive_proposals"].to_i + 1).months.ago
end
trait :with_hot_score do
before(:save) { |d| d.calculate_hot_score }
end

View File

@@ -204,6 +204,13 @@ describe Proposal do
expect {proposal.register_vote(user, 'yes')}.to change{proposal.reload.votes_for.size}.by(0)
end
end
it "should not register vote for archived proposals" do
user = create(:user, verified_at: Time.now)
archived_proposal = create(:proposal, :archived)
expect {archived_proposal.register_vote(user, 'yes')}.to change{proposal.reload.votes_for.size}.by(0)
end
end
describe '#cached_votes_up' do
@@ -814,7 +821,7 @@ describe Proposal do
describe "archived" do
before(:all) do
@new_proposal = create(:proposal)
@archived_proposal = create(:proposal, created_at: (Setting["months_to_archive_proposals"].to_i + 1).months.ago)
@archived_proposal = create(:proposal, :archived)
end
it "archived? is true only for proposals created more than n (configured months) ago" do