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

@@ -38,7 +38,7 @@ class Ban < ActiveRecord::Base
end
def initialize_banner_id
self.banner_id = CurrentUser.id
self.banner_id = CurrentUser.id if self.banner_id.blank?
end
def user_is_inferior

View File

@@ -1,5 +1,6 @@
FactoryGirl.define do
factory(:ban) do |f|
banner :factory => :admin_user
reason {FFaker::Lorem.words.join(" ")}
duration 60
end

View File

@@ -13,7 +13,11 @@ FactoryGirl.define do
factory(:banned_user) do
is_banned true
ban {|x| x.association(:ban)}
after(:create) { |user| create(:ban, user: user) }
end
factory(:member_user) do
level 20
end
factory(:gold_user) do

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