fix pool controller tests

This commit is contained in:
albert
2011-07-22 18:15:43 -04:00
parent d0e8084f0f
commit c74fa18898
12 changed files with 33 additions and 98 deletions

View File

@@ -23,7 +23,7 @@ class PoolElementsControllerTest < ActionController::TestCase
end
should "add a post to a pool once and only once" do
@pool.add_post!(@post)
@pool.add!(@post)
post :create, {:pool_id => @pool.id, :post_id => @post.id, :format => "json"}, {:user_id => @user.id}
@pool.reload
assert_equal([@post.id], @pool.post_id_array)
@@ -32,7 +32,7 @@ class PoolElementsControllerTest < ActionController::TestCase
context "destroy action" do
setup do
@pool.add_post!(@post)
@pool.add!(@post)
end
should "remove a post from a pool" do
@@ -42,7 +42,7 @@ class PoolElementsControllerTest < ActionController::TestCase
end
should "do nothing if the post is not a member of the pool" do
@pool.remove_post!(@post)
@pool.remove!(@post)
post :destroy, {:pool_id => @pool.id, :post_id => @post.id, :format => "json"}, {:user_id => @user.id}
@pool.reload
assert_equal([], @pool.post_id_array)

View File

@@ -16,10 +16,16 @@ class PoolVersionsControllerTest < ActionController::TestCase
context "index action" do
setup do
@pool = Factory.create(:pool)
CurrentUser.id = 20
@pool.versions.create(:post_ids => "1 2")
CurrentUser.id = 30
@pool.versions.create(:post_ids => "1 2 3 4")
@user_2 = Factory.create(:user)
@user_3 = Factory.create(:user)
CurrentUser.scoped(@user_2, "1.2.3.4") do
@pool.update_attributes(:post_ids => "1 2")
end
CurrentUser.scoped(@user_3, "5.6.7.8") do
@pool.update_attributes(:post_ids => "1 2 3 4")
end
end
should "list all versions" do
@@ -30,7 +36,7 @@ class PoolVersionsControllerTest < ActionController::TestCase
end
should "list all versions that match the search criteria" do
get :index, {:search => {:updater_id_equals => "20"}}
get :index, {:search => {:updater_id_equals => @user_2.id}}
assert_response :success
assert_not_nil(assigns(:pool_versions))
assert_equal(1, assigns(:pool_versions).size)

View File

@@ -75,18 +75,20 @@ class PoolsControllerTest < ActionController::TestCase
context "revert action" do
setup do
@pool = Factory.create(:pool, :post_ids => "1")
@post_2 = Factory.create(:post)
@pool = Factory.create(:pool, :post_ids => "#{@post.id}")
CurrentUser.ip_addr = "1.2.3.4" # this is to get around the version collation
@pool.update_attributes(:post_ids => "1 2")
@pool.update_attributes(:post_ids => "#{@post.id} #{@post_2.id}")
CurrentUser.ip_addr = "127.0.0.1"
end
should "revert to a previous version" do
assert_equal(2, PoolVersion.count)
version = @pool.versions(true).first
assert_equal("1", version.post_ids)
assert_equal("#{@post.id}", version.post_ids)
post :revert, {:id => @pool.id, :version_id => version.id}
@pool.reload
assert_equal("1", @pool.post_ids)
assert_equal("#{@post.id}", @pool.post_ids)
end
end
end

View File

@@ -1,75 +0,0 @@
require "test_helper"
class PostModerationControllerTest < ActionController::TestCase
context "The post moderation controller" do
setup do
@mod = Factory.create(:moderator_user)
CurrentUser.user = @mod
CurrentUser.ip_addr = "127.0.0.1"
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "delete action" do
setup do
@post = Factory.create(:post)
end
should "delete a post" do
post :delete, {:post_id => @post.id, :format => "js"}, {:user_id => @mod.id}
@post.reload
assert_equal(true, @post.is_deleted?)
end
end
context "undelete action" do
setup do
@post = Factory.create(:post, :is_deleted => true)
end
should "undelete a post" do
post :undelete, {:post_id => @post.id, :format => "js"}, {:user_id => @mod.id}
@post.reload
assert_equal(false, @post.is_deleted?)
end
end
context "moderate action" do
setup do
@post = Factory.create(:post, :is_pending => true)
end
should "list all pending posts" do
get :moderate, {}, {:user_id => @mod.id}
assert_response :success
end
end
context "approve action" do
setup do
@post = Factory.create(:post, :is_pending => true)
end
should "approve a post" do
post :approve, {:post_id => @post.id}, {:user_id => @mod.id}
@post.reload
assert(!@post.is_pending?)
end
end
context "disapprove action" do
setup do
@post = Factory.create(:post, :is_pending => true)
end
should "disapprove a post" do
assert_difference("PostDisapproval.count", 1) do
post :disapprove, {:post_id => @post.id}, {:user_id => @mod.id}
end
end
end
end
end