fixes #69: Comment voting non functional
This commit is contained in:
@@ -38,15 +38,18 @@ class Comment < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def vote!(score)
|
||||
vote = votes.create(:score => score)
|
||||
numerical_score = score == "up" ? 1 : -1
|
||||
vote = votes.create(:score => numerical_score)
|
||||
|
||||
if vote.errors.any?
|
||||
raise CommentVote::Error.new(vote.errors.full_messages.join("; "))
|
||||
elsif vote.is_positive?
|
||||
increment!(:score)
|
||||
elsif vote.is_negative?
|
||||
decrement!(:score)
|
||||
if vote.errors.empty?
|
||||
if vote.is_positive?
|
||||
increment!(:score)
|
||||
elsif vote.is_negative?
|
||||
decrement!(:score)
|
||||
end
|
||||
end
|
||||
|
||||
return vote
|
||||
end
|
||||
|
||||
def creator_name
|
||||
|
||||
@@ -5,7 +5,7 @@ class CommentVote < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
before_validation :initialize_user, :on => :create
|
||||
validates_presence_of :user_id, :comment_id, :score
|
||||
validates_uniqueness_of :user_id, :scope => :comment_id
|
||||
validates_uniqueness_of :user_id, :scope => :comment_id, :message => "has already voted for this comment"
|
||||
validate :validate_user_can_vote
|
||||
validate :validate_comment_can_be_down_voted
|
||||
validates_inclusion_of :score, :in => [-1, 1], :message => "must be 1 or -1"
|
||||
|
||||
@@ -26,7 +26,8 @@ class User < ActiveRecord::Base
|
||||
validate :validate_ip_addr_is_not_banned, :on => :create
|
||||
before_validation :convert_blank_email_to_null
|
||||
before_validation :normalize_blacklisted_tags
|
||||
before_save :encrypt_password
|
||||
before_create :encrypt_password_on_create
|
||||
before_update :encrypt_password_on_update
|
||||
after_save :update_cache
|
||||
before_create :promote_to_admin_if_first_user
|
||||
has_many :feedback, :class_name => "UserFeedback", :dependent => :destroy
|
||||
@@ -99,9 +100,21 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
module PasswordMethods
|
||||
def encrypt_password
|
||||
puts password.inspect
|
||||
self.password_hash = self.class.sha1(password) if password.present?
|
||||
def encrypt_password_on_create
|
||||
self.password_hash = User.sha1(password)
|
||||
end
|
||||
|
||||
def encrypt_password_on_update
|
||||
return if password.blank?
|
||||
return if old_password.blank?
|
||||
|
||||
if User.sha1(old_password) == password_hash
|
||||
self.password_hash = User.sha1(password)
|
||||
return true
|
||||
else
|
||||
errors[:old_password] << "is incorrect"
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def reset_password
|
||||
@@ -270,7 +283,6 @@ class User < ActiveRecord::Base
|
||||
if is_contributor?
|
||||
true
|
||||
elsif created_at > 1.second.ago
|
||||
# TODO: change this to 1 week
|
||||
false
|
||||
else
|
||||
upload_limit > 0
|
||||
@@ -298,7 +310,7 @@ class User < ActiveRecord::Base
|
||||
def upload_limit
|
||||
deleted_count = Post.for_user(id).deleted.count
|
||||
pending_count = Post.for_user(id).pending.count
|
||||
approved_count = Post.where("is_flagged = false and is_pending = false and user_id = ?", id).count
|
||||
approved_count = Post.where("is_flagged = false and is_pending = false and uploader_id = ?", id).count
|
||||
|
||||
if base_upload_limit
|
||||
limit = base_upload_limit - pending_count
|
||||
|
||||
Reference in New Issue
Block a user