fix comment votes affecting comment updater_id
This commit is contained in:
@@ -105,15 +105,15 @@ class Comment < ActiveRecord::Base
|
|||||||
do_not_bump_post == "1"
|
do_not_bump_post == "1"
|
||||||
end
|
end
|
||||||
|
|
||||||
def vote!(score)
|
def vote!(val)
|
||||||
numerical_score = score == "up" ? 1 : -1
|
numerical_score = val == "up" ? 1 : -1
|
||||||
vote = votes.create(:score => numerical_score)
|
vote = votes.create(:score => numerical_score)
|
||||||
|
|
||||||
if vote.errors.empty?
|
if vote.errors.empty?
|
||||||
if vote.is_positive?
|
if vote.is_positive?
|
||||||
increment!(:score)
|
update_column(:score, score + 1)
|
||||||
elsif vote.is_negative?
|
elsif vote.is_negative?
|
||||||
decrement!(:score)
|
update_column(:score, score - 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,17 @@ class CommentTest < ActiveSupport::TestCase
|
|||||||
assert_equal(c1.created_at.to_s, p.last_commented_at.to_s)
|
assert_equal(c1.created_at.to_s, p.last_commented_at.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "not record the user id of the voter" do
|
||||||
|
user = FactoryGirl.create(:user)
|
||||||
|
post = FactoryGirl.create(:post)
|
||||||
|
c1 = FactoryGirl.create(:comment, :post => post)
|
||||||
|
CurrentUser.scoped(user, "127.0.0.1") do
|
||||||
|
c1.vote!("up")
|
||||||
|
c1.reload
|
||||||
|
assert_not_equal(user.id, c1.updater_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
should "not allow duplicate votes" do
|
should "not allow duplicate votes" do
|
||||||
user = FactoryGirl.create(:user)
|
user = FactoryGirl.create(:user)
|
||||||
post = FactoryGirl.create(:post)
|
post = FactoryGirl.create(:post)
|
||||||
|
|||||||
Reference in New Issue
Block a user