Add test cases for anon/banned/member voting.
This commit is contained in:
@@ -38,7 +38,7 @@ class Ban < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize_banner_id
|
def initialize_banner_id
|
||||||
self.banner_id = CurrentUser.id
|
self.banner_id = CurrentUser.id if self.banner_id.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_is_inferior
|
def user_is_inferior
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory(:ban) do |f|
|
factory(:ban) do |f|
|
||||||
|
banner :factory => :admin_user
|
||||||
reason {FFaker::Lorem.words.join(" ")}
|
reason {FFaker::Lorem.words.join(" ")}
|
||||||
duration 60
|
duration 60
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,7 +13,11 @@ FactoryGirl.define do
|
|||||||
|
|
||||||
factory(:banned_user) do
|
factory(:banned_user) do
|
||||||
is_banned true
|
is_banned true
|
||||||
ban {|x| x.association(:ban)}
|
after(:create) { |user| create(:ban, user: user) }
|
||||||
|
end
|
||||||
|
|
||||||
|
factory(:member_user) do
|
||||||
|
level 20
|
||||||
end
|
end
|
||||||
|
|
||||||
factory(:gold_user) do
|
factory(:gold_user) do
|
||||||
|
|||||||
@@ -15,6 +15,34 @@ class PostVotesControllerTest < ActionController::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "create action" do
|
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
|
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}
|
post :create, {:post_id => @post.id, :score => "up", :format => "js"}, {:user_id => @user.id}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
|||||||
Reference in New Issue
Block a user