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.
This commit is contained in:
Javi Martín
2023-09-07 19:05:14 +02:00
parent 11b962da8f
commit 21ca96ae1c
2 changed files with 8 additions and 3 deletions

View File

@@ -2,7 +2,7 @@ module Conflictable
extend ActiveSupport::Concern extend ActiveSupport::Concern
def conflictive? 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 cached_votes_up / flags_count.to_f < 5
end end

View File

@@ -452,10 +452,15 @@ describe Debate do
expect(debate).not_to be_conflictive expect(debate).not_to be_conflictive
end end
it "returns false when it has not votes up" do it "returns false when it has no flags and no votes up" do
debate.update!(cached_votes_up: 0) debate.update!(flags_count: 0, cached_votes_up: 0)
expect(debate).not_to be_conflictive expect(debate).not_to be_conflictive
end 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 end
describe "search" do describe "search" do