From 21ca96ae1c74cfba917f56ea223043d46621aeda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 7 Sep 2023 19:05:14 +0200 Subject: [PATCH] Fix conflictive debates with no votes We originally added the `cached_votes_up > 0` in commit 4ce95e273 because back then `cached_votes_up` was used in the denominator. That's no longer the case, and it doesn't make sense to mark a debate with 1 vote and 10 flags as conflictive but not doing it when the debate has no votes and 1000 flags. We're fixing the bug right now because we're about to change the affected line in order to apply a new rubocop rule. --- app/models/concerns/conflictable.rb | 2 +- spec/models/debate_spec.rb | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/conflictable.rb b/app/models/concerns/conflictable.rb index c15fafa8a..faea52032 100644 --- a/app/models/concerns/conflictable.rb +++ b/app/models/concerns/conflictable.rb @@ -2,7 +2,7 @@ module Conflictable extend ActiveSupport::Concern def conflictive? - return false unless flags_count > 0 && cached_votes_up > 0 + return false unless flags_count > 0 cached_votes_up / flags_count.to_f < 5 end diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index 44fba2ec7..91761dc4f 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -452,10 +452,15 @@ describe Debate do expect(debate).not_to be_conflictive end - it "returns false when it has not votes up" do - debate.update!(cached_votes_up: 0) + it "returns false when it has no flags and no votes up" do + debate.update!(flags_count: 0, cached_votes_up: 0) expect(debate).not_to be_conflictive end + + it "returns true when it has flags and no votes up" do + debate.update!(cached_votes_up: 0, flags_count: 10) + expect(debate).to be_conflictive + end end describe "search" do