Add test cases for anon/banned/member voting.

This commit is contained in:
evazion
2016-10-14 04:38:41 +00:00
parent 903eff5c24
commit 5e75dcecea
4 changed files with 35 additions and 2 deletions

View File

@@ -15,6 +15,34 @@ class PostVotesControllerTest < ActionController::TestCase
end
context "create action" do
should "not allow anonymous users to vote" do
p1 = FactoryGirl.create(:post)
post :create, {:post_id => p1.id, :score => "up", :format => "js"}
assert_response 403
assert_equal(0, p1.reload.score)
end
should "not allow banned users to vote" do
CurrentUser.scoped(FactoryGirl.create(:banned_user)) do
p1 = FactoryGirl.create(:post)
post :create, {:post_id => p1.id, :score => "up", :format => "js"}, {:user_id => CurrentUser.id}
assert_response 403
assert_equal(0, p1.reload.score)
end
end
should "not allow members to vote" do
CurrentUser.scoped(FactoryGirl.create(:member_user)) do
p1 = FactoryGirl.create(:post)
post :create, {:post_id => p1.id, :score => "up", :format => "js"}, {:user_id => CurrentUser.id}
assert_response 403
assert_equal(0, p1.reload.score)
end
end
should "increment a post's score if the score is positive" do
post :create, {:post_id => @post.id, :score => "up", :format => "js"}, {:user_id => @user.id}
assert_response :success