A platform for community discussion. Free, open, simple.
FIX: Store Reviewable's force_review as a boolean. (#11219)
Roman Rizzif2bef7ea8fa4
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rbindex 6b93b3450a1..3fba7ef9c79 100644--- a/app/models/reviewable.rb+++ b/app/models/reviewable.rb@@ -197,11 +197,6 @@ class Reviewable < ActiveRecord::Baseuser_accuracy_bonus = ReviewableScore.user_accuracy_bonus(user)sub_total = ReviewableScore.calculate_score(user, type_bonus, take_action_bonus)- # We can force a reviewable to hit the threshold, for example with queued posts- if force_review && sub_total < Reviewable.min_score_for_priority- sub_total = Reviewable.min_score_for_priority- end-rs = reviewable_scores.new(user: user,status: ReviewableScore.statuses[:pending],@@ -215,7 +210,7 @@ class Reviewable < ActiveRecord::Basers.reason = reason.to_s if reasonrs.save!- update(score: self.score + rs.score, latest_score: rs.created_at)+ update(score: self.score + rs.score, latest_score: rs.created_at, force_review: force_review)topic.update(reviewable_score: topic.reviewable_score + rs.score) if topicrs@@ -475,11 +470,8 @@ class Reviewable < ActiveRecord::Baseresult = result.where("reviewables.created_at >= ?", from_date) if from_dateresult = result.where("reviewables.created_at <= ?", to_date) if to_date- if min_score > 0 && status == :pending && type.nil?- result = result.where(- "reviewables.score >= ? OR reviewables.type IN (?)",- min_score, [ReviewableQueuedPost.name, ReviewableUser.name]- )+ if min_score > 0 && status == :pending+ result = result.where("reviewables.score >= ? OR reviewables.force_review", min_score)elsif min_score > 0result = result.where("reviewables.score >= ?", min_score)enddiff --git a/db/migrate/20201112142419_add_reviewables_force_review.rb b/db/migrate/20201112142419_add_reviewables_force_review.rbnew file mode 100644index 00000000000..2f8a2fcb22a--- /dev/null+++ b/db/migrate/20201112142419_add_reviewables_force_review.rb@@ -0,0 +1,7 @@+# frozen_string_literal: true++class AddReviewablesForceReview < ActiveRecord::Migration[6.0]+ def change+ add_column :reviewables, :force_review, :boolean, default: false, null: false+ end+enddiff --git a/spec/components/new_post_manager_spec.rb b/spec/components/new_post_manager_spec.rbindex 2eca5bfb2b8..b0ec1514e7b 100644--- a/spec/components/new_post_manager_spec.rb+++ b/spec/components/new_post_manager_spec.rb@@ -363,8 +363,6 @@ describe NewPostManager doendit "calls custom enqueuing handlers" do- Reviewable.set_priorities(high: 20.5)- SiteSetting.reviewable_default_visibility = 'high'SiteSetting.tagging_enabled = trueSiteSetting.min_trust_to_create_tag = 0SiteSetting.min_trust_level_to_tag_topics = 0@@ -384,7 +382,7 @@ describe NewPostManager doexpect(reviewable).to be_presentexpect(reviewable.payload['title']).to eq('this is the title of the queued post')expect(reviewable.reviewable_scores).to be_present- expect(reviewable.score).to eq(20.5)+ expect(reviewable.force_review).to eq(true)expect(reviewable.reviewable_by_moderator?).to eq(true)expect(reviewable.category).to be_presentexpect(reviewable.payload['tags']).to eq(['hello', 'world'])diff --git a/spec/components/post_action_creator_spec.rb b/spec/components/post_action_creator_spec.rbindex c8cf812fddd..a68b874c035 100644--- a/spec/components/post_action_creator_spec.rb+++ b/spec/components/post_action_creator_spec.rb@@ -120,15 +120,12 @@ describe PostActionCreator doexpect(post.hidden?).to eq(false)end- it 'forces the review to surpass the minimum priority threshold' do- Reviewable.set_priorities(high: 40.0)- SiteSetting.reviewable_default_visibility = 'high'+ it 'sets the force_review field' doresult = PostActionCreator.create(user, post, :spam)reviewable = result.reviewable- reviewable_score = reviewable.reviewable_scores.find_by(user: user)- expect(reviewable_score.score).to eq(Reviewable.min_score_for_priority)+ expect(reviewable.force_review).to eq(true)endenddiff --git a/spec/models/reviewable_spec.rb b/spec/models/reviewable_spec.rbindex 3205163b070..e5246ef05dd 100644--- a/spec/models/reviewable_spec.rb+++ b/spec/models/reviewable_spec.rb@@ -180,8 +180,8 @@ RSpec.describe Reviewable, type: :model dobefore doSiteSetting.reviewable_default_visibility = :highReviewable.set_priorities(high: 10)- @queued_post = Fabricate(:reviewable_queued_post, score: 0, target: post)- @queued_user = Fabricate(:reviewable_user, score: 0)+ @queued_post = Fabricate(:reviewable_queued_post, score: 0, target: post, force_review: true)+ @queued_user = Fabricate(:reviewable_user, score: 0, force_review: true)endit 'includes queued posts when searching for pending reviewables' do