* Added note version controller and test
* Added pool version controller and test * Refactored unit tests for post disapprovals * Renamed PostModerationDetail to PostDisapproval
This commit is contained in:
67
test/unit/post_disapproval_test.rb
Normal file
67
test/unit/post_disapproval_test.rb
Normal file
@@ -0,0 +1,67 @@
|
||||
require_relative '../test_helper'
|
||||
|
||||
class PostDisapprovalTest < ActiveSupport::TestCase
|
||||
context "In all cases" do
|
||||
setup do
|
||||
@alice = Factory.create(:moderator_user)
|
||||
CurrentUser.user = @alice
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "A post disapproval" do
|
||||
setup do
|
||||
@post_1 = Factory.create(:post, :is_pending => true)
|
||||
@post_2 = Factory.create(:post, :is_pending => true)
|
||||
end
|
||||
|
||||
context "made by alice" do
|
||||
setup do
|
||||
@disapproval = PostDisapproval.create(:user => @alice, :post => @post_1)
|
||||
end
|
||||
|
||||
context "when the current user is alice" do
|
||||
setup do
|
||||
CurrentUser.user = @alice
|
||||
end
|
||||
|
||||
should "remove the associated post from alice's moderation queue" do
|
||||
assert(!Post.available_for_moderation.map(&:id).include?(@post_1.id))
|
||||
assert(Post.available_for_moderation.map(&:id).include?(@post_2.id))
|
||||
end
|
||||
end
|
||||
|
||||
context "when the current user is brittony" do
|
||||
setup do
|
||||
@brittony = Factory.create(:moderator_user)
|
||||
CurrentUser.user = @brittony
|
||||
end
|
||||
|
||||
should "not remove the associated post from brittony's moderation queue" do
|
||||
assert(Post.available_for_moderation.map(&:id).include?(@post_1.id))
|
||||
assert(Post.available_for_moderation.map(&:id).include?(@post_2.id))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "for a post that has been approved" do
|
||||
setup do
|
||||
@post = Factory.create(:post)
|
||||
@user = Factory.create(:user)
|
||||
@disapproval = PostDisapproval.create(:user => @user, :post => @post)
|
||||
end
|
||||
|
||||
should "be pruned" do
|
||||
assert_difference("PostDisapproval.count", -1) do
|
||||
PostDisapproval.prune!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,52 +0,0 @@
|
||||
require_relative '../test_helper'
|
||||
|
||||
class PostModerationDetailTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
user = Factory.create(:user)
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "A post moderation detail" do
|
||||
should "hide posts" do
|
||||
posts = []
|
||||
posts << Factory.create(:post)
|
||||
posts << Factory.create(:post)
|
||||
posts << Factory.create(:post)
|
||||
user = Factory.create(:user)
|
||||
detail = PostModerationDetail.create(:user => user, :post => posts[0])
|
||||
results = PostModerationDetail.filter(posts, user)
|
||||
assert_equal(2, results.size)
|
||||
assert(results.all? {|x| x.id != posts[0].id})
|
||||
results = PostModerationDetail.filter(posts, user, true)
|
||||
assert_equal(1, results.size)
|
||||
assert_equal(posts[0].id, results[0].id)
|
||||
user = Factory.create(:user)
|
||||
results = PostModerationDetail.filter(posts, user)
|
||||
assert_equal(3, results.size)
|
||||
results = PostModerationDetail.filter(posts, user, true)
|
||||
assert_equal(0, results.size)
|
||||
end
|
||||
|
||||
should "prune itself" do
|
||||
post = Factory.create(:post, :is_flagged => true)
|
||||
user = Factory.create(:user)
|
||||
detail = PostModerationDetail.create(:user => user, :post => post)
|
||||
assert_difference("PostModerationDetail.count", 0) do
|
||||
PostModerationDetail.prune!
|
||||
end
|
||||
post.is_flagged = false
|
||||
post.save
|
||||
assert(post.errors.empty?)
|
||||
assert_difference("PostModerationDetail.count", -1) do
|
||||
PostModerationDetail.prune!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -175,12 +175,11 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "An unapproved post" do
|
||||
context "An unapproved post" do
|
||||
should "preserve the approver's identity when approved" do
|
||||
user = CurrentUser.user
|
||||
post = Factory.create(:post, :is_pending => true)
|
||||
post.approve!
|
||||
assert_equal("approver:#{user.name}", post.approver_string)
|
||||
assert_equal("approver:#{CurrentUser.name}", post.approver_string)
|
||||
end
|
||||
|
||||
should "preserve the unapproval association even when removed" do
|
||||
|
||||
Reference in New Issue
Block a user