Fix comment voting tests.

2) Error:
CommentTest#test_: A comment created by an unlimited user should not allow duplicate votes. :
ActiveRecord::RecordInvalid: Validation failed: You have already voted for this comment
    app/models/comment.rb:142:in `vote!'
    test/unit/comment_test.rb:164:in `block (3 levels) in <class:CommentTest>'

  3) Error:
CommentTest#test_: A comment created by an unlimited user should not allow upvotes by the creator. :
ActiveRecord::RecordInvalid: Validation failed: You cannot upvote your own comments
    app/models/comment.rb:142:in `vote!'
    test/unit/comment_test.rb:179:in `block (3 levels) in <class:CommentTest>'
This commit is contained in:
evazion
2017-02-03 01:19:03 -06:00
parent 3ee7f0770f
commit 72502dbe2f

View File

@@ -159,16 +159,15 @@ class CommentTest < ActiveSupport::TestCase
user = FactoryGirl.create(:user)
post = FactoryGirl.create(:post)
c1 = FactoryGirl.create(:comment, :post => post)
comment_vote = c1.vote!("down")
assert_equal([], comment_vote.errors.full_messages)
comment_vote = c1.vote!("down")
assert_equal(["You have already voted for this comment"], comment_vote.errors.full_messages)
assert_nothing_raised { c1.vote!("down") }
exception = assert_raises(ActiveRecord::RecordInvalid) { c1.vote!("down") }
assert_equal("Validation failed: You have already voted for this comment", exception.message)
assert_equal(1, CommentVote.count)
assert_equal(-1, CommentVote.last.score)
c2 = FactoryGirl.create(:comment, :post => post)
comment_vote = c2.vote!("down")
assert_equal([], comment_vote.errors.full_messages)
assert_nothing_raised { c2.vote!("down") }
assert_equal(2, CommentVote.count)
end
@@ -176,9 +175,9 @@ class CommentTest < ActiveSupport::TestCase
user = FactoryGirl.create(:user)
post = FactoryGirl.create(:post)
c1 = FactoryGirl.create(:comment, :post => post)
comment_vote = c1.vote!("up")
assert_equal(["You cannot upvote your own comments"], comment_vote.errors.full_messages)
exception = assert_raises(ActiveRecord::RecordInvalid) { c1.vote!("up") }
assert_equal("Validation failed: You cannot upvote your own comments", exception.message)
end
should "allow undoing of votes" do