FIX: Add scores when creating reviewable (#62)

FIX: Add scores when creating reviewable (#62)

diff --git a/app/models/category_expert_endorsement.rb b/app/models/category_expert_endorsement.rb
index 93ce923..867294d 100644
--- a/app/models/category_expert_endorsement.rb
+++ b/app/models/category_expert_endorsement.rb
@@ -12,12 +12,22 @@ class CategoryExpertEndorsement < ActiveRecord::Base
   private
 
   def create_reviewable
-    endorsements_for_category = CategoryExpertEndorsement.where(endorsed_user: endorsed_user, category: category).count
-    if endorsements_for_category == SiteSetting.category_expert_suggestion_threshold
-      ReviewableCategoryExpertSuggestion.needs_review!(
+    endorsements = CategoryExpertEndorsement
+      .includes(:user)
+      .where(endorsed_user: endorsed_user, category: category)
+
+    if endorsements.count == SiteSetting.category_expert_suggestion_threshold
+      reviewable = ReviewableCategoryExpertSuggestion.needs_review!(
         created_by: user,
         target: self
       )
+      endorsements.each do |endorsement|
+        reviewable.add_score(
+          endorsement.user,
+          ReviewableScore.types[:needs_approval],
+          force_review: true
+        )
+      end
     end
   end
 

GitHub sha: 70ebd11c689347810c0d5840bba9551cb9862dfa

This commit appears in #62 which was approved by romanrizzi. It was merged by markvanlan.