post_vote_test.rb: add more voting tests.
This commit is contained in:
@@ -4,8 +4,9 @@ class PostVoteTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = user
|
||||
@supervoter = FactoryGirl.create(:user, is_super_voter: true)
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
|
||||
@@ -23,9 +24,38 @@ class PostVoteTest < ActiveSupport::TestCase
|
||||
assert_equal(-1, vote.score)
|
||||
end
|
||||
|
||||
should "interpret up as +3 score for a supervoter" do
|
||||
vote = PostVote.create(:user_id => @supervoter.id, :post_id => @post.id, :vote => "up")
|
||||
assert_equal(3, vote.score)
|
||||
end
|
||||
|
||||
should "not accept any other scores" do
|
||||
vote = PostVote.create(:post_id => @post.id, :vote => "xxx")
|
||||
assert(vote.errors.any?)
|
||||
end
|
||||
|
||||
should "increase the score of the post" do
|
||||
@post.votes.create(vote: "up")
|
||||
@post.reload
|
||||
|
||||
assert_equal(1, @post.score)
|
||||
assert_equal(1, @post.up_score)
|
||||
end
|
||||
|
||||
should "decrease the score of the post when removed" do
|
||||
@post.votes.create(vote: "up").destroy
|
||||
@post.reload
|
||||
|
||||
assert_equal(0, @post.score)
|
||||
assert_equal(0, @post.up_score)
|
||||
end
|
||||
|
||||
should "upvote by 3 points if the voter is a supervoter" do
|
||||
@post.votes.create(user: @supervoter, vote: "up")
|
||||
@post.reload
|
||||
|
||||
assert_equal(3, @post.score)
|
||||
assert_equal(3, @post.up_score)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user