From 72502dbe2f8f33fb31549ec2ed5a81dcb0610408 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 3 Feb 2017 01:19:03 -0600 Subject: [PATCH] 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 ' 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 ' --- test/unit/comment_test.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index b133a1cdc..b62f2fb5e 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -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