From f231104edc1e7d0dc59dae95c740ecbac1c75894 Mon Sep 17 00:00:00 2001 From: David Gil Date: Tue, 15 Sep 2015 21:08:01 +0200 Subject: [PATCH 1/4] adds setting to control max number of votes for a Debate to be editable --- app/models/debate.rb | 2 +- config/locales/settings.en.yml | 3 ++- config/locales/settings.es.yml | 3 ++- db/seeds.rb | 3 +++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/debate.rb b/app/models/debate.rb index d141e4330..5e58ce23f 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -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) diff --git a/config/locales/settings.en.yml b/config/locales/settings.en.yml index 8cc261c1e..88846e308 100644 --- a/config/locales/settings.en.yml +++ b/config/locales/settings.en.yml @@ -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" \ No newline at end of file + votes_for_proposal_success: "Number of votes needed for Proposal approval" diff --git a/config/locales/settings.es.yml b/config/locales/settings.es.yml index fa80fbdad..1a0bf67f2 100644 --- a/config/locales/settings.es.yml +++ b/config/locales/settings.es.yml @@ -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" \ No newline at end of file + votes_for_proposal_success: "Número de votos necesarios para aprobar una Propuesta" diff --git a/db/seeds.rb b/db/seeds.rb index 27da98e1c..f74e1abb7 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -18,6 +18,9 @@ Setting.create(key: 'max_ratio_anon_votes_on_debates', value: '50') # Max votes where a proposal is still editable Setting.create(key: 'max_votes_for_proposal_edit', value: '1000') +# Max votes where a debate is still editable +Setting.create(key: 'max_votes_for_debate_edit', value: '1000') + # Prefix for the Proposal codes Setting.create(key: 'proposal_code_prefix', value: 'MAD') From 42f1ffb171d7f8d8e3c14fe79369671a9f9d2cc2 Mon Sep 17 00:00:00 2001 From: David Gil Date: Tue, 15 Sep 2015 21:28:01 +0200 Subject: [PATCH 2/4] adds tests for debate editable with max votes --- spec/features/debates_spec.rb | 4 +++- spec/models/debate_spec.rb | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 98be639e1..667dae60d 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -244,7 +244,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) diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index 907bcef5b..eb5bccc68 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -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 proposal 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 proposal 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 From 3345f91d45f62572fa0f0171c2ed02cb0281d461 Mon Sep 17 00:00:00 2001 From: David Gil Date: Thu, 17 Sep 2015 15:52:35 +0200 Subject: [PATCH 3/4] adds max_votes_for_debate_edit setting to dev_seeds --- db/dev_seeds.rb | 6 +----- db/seeds.rb | 6 +++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index b9232f055..f7ec1cd9b 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -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) - - - - - diff --git a/db/seeds.rb b/db/seeds.rb index f74e1abb7..cef67b0f6 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -15,12 +15,12 @@ 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 proposal is still editable -Setting.create(key: 'max_votes_for_proposal_edit', value: '1000') - # 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') + # Prefix for the Proposal codes Setting.create(key: 'proposal_code_prefix', value: 'MAD') From e985391a8e7b976338fdbbd3016a5ae597c8baf9 Mon Sep 17 00:00:00 2001 From: David Gil Date: Thu, 17 Sep 2015 15:52:49 +0200 Subject: [PATCH 4/4] fixes test names --- spec/models/debate_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index eb5bccc68..3183fa53a 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -55,13 +55,13 @@ describe Debate do expect(debate.editable?).to be true end - it "should be true if proposal has less than limit votes" do + 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 proposal has more than limit votes" do + 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