Ensure at least 0 score for new badge award (#20605)
This commit is contained in:
parent
2f9769a89d
commit
1b083f39a4
2 changed files with 9 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ module Badges
|
|||
Article.joins(:user)
|
||||
.where("articles.published_at > ?", 1.week.ago)
|
||||
.where("articles.published_at < ?", 1.hour.ago)
|
||||
.where("articles.score >= ?", 0)
|
||||
.where(nth_published_by_author: 1)
|
||||
.where.not(users: { id: User.with_role(:spam).or(User.with_role(:suspended)) })
|
||||
.find_each do |article|
|
||||
|
|
|
|||
|
|
@ -33,6 +33,14 @@ RSpec.describe Badges::AwardFirstPost do
|
|||
Timecop.return
|
||||
expect { described_class.call }.to change(BadgeAchievement, :count).by(1)
|
||||
end
|
||||
|
||||
it "does not award the badge if the article score is less than zero" do
|
||||
Timecop.freeze(2.days.ago) do
|
||||
create(:article, user: create(:user), score: -1)
|
||||
end
|
||||
Timecop.return
|
||||
expect { described_class.call }.not_to change(BadgeAchievement, :count)
|
||||
end
|
||||
end
|
||||
|
||||
context "when the user has a spam or suspended role" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue