From 3c7393c6a36ef799a9d5c85e1674f6c369f9f9a5 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Mon, 20 Jan 2014 20:22:45 -0600 Subject: [PATCH] give tedu his karma back fix bug introduced in 3757b279 that gave comment vote karma to the voter rather than the commenter --- app/models/user.rb | 7 +++++++ app/models/vote.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 98a1187..f37c090 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -50,6 +50,13 @@ class User < ActiveRecord::Base BANNED_USERNAMES = [ "admin", "administrator", "hostmaster", "mailer-daemon", "postmaster", "root", "security", "support", "webmaster", ] + def self.recalculate_all_karmas! + User.all.each do |u| + u.karma = u.stories.map(&:score).sum + u.comments.map(&:score).sum + u.save! + end + end + def as_json(options = {}) h = super(:only => [ :username, diff --git a/app/models/vote.rb b/app/models/vote.rb index 23d0867..30aa09c 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -131,7 +131,7 @@ class Vote < ActiveRecord::Base if v.comment_id c = Comment.find(v.comment_id) if c.user_id != user_id - User.update_counters user_id, :karma => upvote - downvote + User.update_counters c.user_id, :karma => upvote - downvote end c.give_upvote_or_downvote_and_recalculate_confidence!(upvote,