implement super voters

This commit is contained in:
r888888888
2016-02-22 14:02:52 -08:00
parent caf4a28b02
commit 2a87aad34e
13 changed files with 189 additions and 12 deletions

View File

@@ -0,0 +1,4 @@
FactoryGirl.define do
factory(:super_voter) do
end
end

View File

@@ -0,0 +1,38 @@
require 'test_helper'
class SuperVoterTest < ActiveSupport::TestCase
def setup
super
@user = FactoryGirl.create(:user)
end
context "#init" do
setup do
@admin = FactoryGirl.create(:admin_user)
Reports::UserSimilarity.any_instance.stubs(:fetch_similar_user_ids).returns("#{@user.id} 1")
end
should "create super voter objects" do
assert_difference("SuperVoter.count") do
SuperVoter.init!
end
end
end
context "creation" do
should "update the is_super_voter field on the user object" do
FactoryGirl.create(:super_voter, user: @user)
@user.reload
assert_equal(true, @user.is_super_voter?)
end
end
context "destruction" do
should "update the is_super_voter field on the user object" do
voter = FactoryGirl.create(:super_voter, user: @user)
voter.destroy
@user.reload
assert_equal(false, @user.is_super_voter?)
end
end
end

View File

@@ -1463,6 +1463,24 @@ class PostTest < ActiveSupport::TestCase
end
context "Voting:" do
context "with a super voter" do
setup do
@user = FactoryGirl.create(:user)
FactoryGirl.create(:super_voter, user: @user)
@post = FactoryGirl.create(:post)
end
should "account for magnitude" do
CurrentUser.scoped(@user, "127.0.0.1") do
assert_nothing_raised {@post.vote!("up")}
assert_raises(PostVote::Error) {@post.vote!("up")}
@post.reload
assert_equal(1, PostVote.count)
assert_equal(SuperVoter::MAGNITUDE, @post.score)
end
end
end
should "not allow duplicate votes" do
user = FactoryGirl.create(:user)
post = FactoryGirl.create(:post)