added post voting

This commit is contained in:
albert
2010-02-15 17:45:09 -05:00
parent 80f033f253
commit 9f353c32f4
10 changed files with 112 additions and 19 deletions

View File

@@ -38,7 +38,7 @@ class CommentTest < ActiveSupport::TestCase
post = Factory.create(:post)
c1 = Factory.create(:comment, :post => post)
assert_nothing_raised {c1.vote!(user, true)}
assert_raise(Comment::VotingError) {c1.vote!(user, true)}
assert_raise(CommentVote::Error) {c1.vote!(user, true)}
assert_equal(1, CommentVote.count)
c2 = Factory.create(:comment, :post => post)

View File

@@ -1,8 +0,0 @@
require 'test_helper'
class CommentVoteTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end

View File

@@ -405,4 +405,16 @@ class PostTest < ActiveSupport::TestCase
assert_equal(post3.id, relation.first.id)
end
end
context "Voting on a post" do
should "not allow duplicate votes" do
user = Factory.create(:user)
post = Factory.create(:post)
assert_nothing_raised {post.vote!(user, true)}
assert_raise(PostVote::Error) {post.vote!(user, true)}
post.reload
assert_equal(1, PostVote.count)
assert_equal(1, post.score)
end
end
end