Merge pull request #505 from dgilperez/debates_max_votes_editable
Adds setting to control max number of votes for a Debate to be editable
This commit is contained in:
@@ -53,7 +53,7 @@ class Debate < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def editable?
|
||||
total_votes == 0
|
||||
total_votes <= Setting.value_for('max_votes_for_debate_edit').to_i
|
||||
end
|
||||
|
||||
def editable_by?(user)
|
||||
|
||||
@@ -7,5 +7,6 @@ en:
|
||||
official_level_5_name: "Level 5 official positions"
|
||||
max_ratio_anon_votes_on_debates: "Max allowed percentage of anonymous votes per Debate"
|
||||
max_votes_for_proposal_edit: "Number of votes where a Proposal is not editable anymore"
|
||||
max_votes_for_debate_edit: "Number of votes where a Debate is not editable anymore"
|
||||
proposal_code_prefix: "Prefix for Proposals codes"
|
||||
votes_for_proposal_success: "Number of votes needed for Proposal approval"
|
||||
@@ -7,5 +7,6 @@ es:
|
||||
official_level_5_name: "Cargos públicos de nivel 5"
|
||||
max_ratio_anon_votes_on_debates: "Porcentaje máximo de votos anónimos por Debate"
|
||||
max_votes_for_proposal_edit: "Número de votos en que una Propuesta deja de poderse editar"
|
||||
max_votes_for_debate_edit: "Número de votos en que un Debate deja de poderse editar"
|
||||
proposal_code_prefix: "Prefijo para los códigos de Propuestas"
|
||||
votes_for_proposal_success: "Número de votos necesarios para aprobar una Propuesta"
|
||||
@@ -9,6 +9,7 @@ Setting.create(key: 'official_level_3_name', value: 'Directores generales')
|
||||
Setting.create(key: 'official_level_4_name', value: 'Concejales')
|
||||
Setting.create(key: 'official_level_5_name', value: 'Alcaldesa')
|
||||
Setting.create(key: 'max_ratio_anon_votes_on_debates', value: '50')
|
||||
Setting.create(key: 'max_votes_for_debate_edit', value: '1000')
|
||||
Setting.create(key: 'max_votes_for_proposal_edit', value: '1000')
|
||||
Setting.create(key: 'proposal_code_prefix', value: 'MAD')
|
||||
Setting.create(key: 'votes_for_proposal_success', value: '100')
|
||||
@@ -198,8 +199,3 @@ puts "Confirming hiding in debates, comments & proposals"
|
||||
Comment.only_hidden.flagged.reorder("RANDOM()").limit(10).each(&:confirm_hide)
|
||||
Debate.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide)
|
||||
Proposal.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@ Setting.create(key: 'official_level_5_name', value: 'Alcaldesa')
|
||||
# Max percentage of allowed anonymous votes on a debate
|
||||
Setting.create(key: 'max_ratio_anon_votes_on_debates', value: '50')
|
||||
|
||||
# Max votes where a debate is still editable
|
||||
Setting.create(key: 'max_votes_for_debate_edit', value: '1000')
|
||||
|
||||
# Max votes where a proposal is still editable
|
||||
Setting.create(key: 'max_votes_for_proposal_edit', value: '1000')
|
||||
|
||||
|
||||
@@ -254,7 +254,9 @@ feature 'Debates' do
|
||||
|
||||
scenario 'Update should not be posible if debate is not editable' do
|
||||
debate = create(:debate)
|
||||
create(:vote, votable: debate)
|
||||
Setting.find_by(key: "max_votes_for_debate_edit").update(value: 2)
|
||||
3.times { create(:vote, votable: debate) }
|
||||
|
||||
expect(debate).to_not be_editable
|
||||
login_as(debate.author)
|
||||
|
||||
|
||||
@@ -48,28 +48,36 @@ describe Debate do
|
||||
|
||||
describe "#editable?" do
|
||||
let(:debate) { create(:debate) }
|
||||
before(:each) { Setting.find_by(key: "max_votes_for_debate_edit").update(value: 3) }
|
||||
|
||||
it "should be true if debate has no votes yet" do
|
||||
expect(debate.total_votes).to eq(0)
|
||||
expect(debate.editable?).to be true
|
||||
end
|
||||
|
||||
it "should be false if debate has votes" do
|
||||
create(:vote, votable: debate)
|
||||
expect(debate.total_votes).to eq(1)
|
||||
it "should be true if debate has less than limit votes" do
|
||||
create_list(:vote, 2, votable: debate)
|
||||
expect(debate.total_votes).to eq(2)
|
||||
expect(debate.editable?).to be true
|
||||
end
|
||||
|
||||
it "should be false if debate has more than limit votes" do
|
||||
create_list(:vote, 4, votable: debate)
|
||||
expect(debate.total_votes).to eq(4)
|
||||
expect(debate.editable?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe "#editable_by?" do
|
||||
let(:debate) { create(:debate) }
|
||||
before(:each) { Setting.find_by(key: "max_votes_for_debate_edit").update(value: 1) }
|
||||
|
||||
it "should be true if user is the author and debate is editable" do
|
||||
expect(debate.editable_by?(debate.author)).to be true
|
||||
end
|
||||
|
||||
it "should be false if debate is not editable" do
|
||||
create(:vote, votable: debate)
|
||||
create_list(:vote, 2, votable: debate)
|
||||
expect(debate.editable_by?(debate.author)).to be false
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user