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

@@ -10,7 +10,7 @@ class PostAppealsController < ApplicationController
def index
@search = PostAppeal.search(params[:search])
@post_appeals = @search.paginate(:page => params[:page])
@post_appeals = @search.paginate(params[:page])
end
def create

View File

@@ -10,7 +10,7 @@ class PostFlagsController < ApplicationController
def index
@search = PostFlag.search(params[:search])
@post_flags = @search.paginate(:page => params[:page])
@post_flags = @search.paginate(params[:page])
end
def create

View File

@@ -9,6 +9,6 @@ module PostVotesHelper
added = current.post_id_array - prev.post_id_array
removed = prev.post_id_array - current.post_id_array
added.map {|x| '<ins>+<a href="/posts/' + x + '">' + x + '</a></ins>'}.join(" ") + removed.map {|x| '<del>&ndash;<a href="/posts/' + x + '">' + x + '</a></del>'}.join(" ")
added.map {|x| '<ins>+<a href="/posts/' + x.to_s + '">' + x.to_s + '</a></ins>'}.join(" ") + removed.map {|x| '<del>&ndash;<a href="/posts/' + x.to_s + '">' + x.to_s + '</a></del>'}.join(" ")
end
end

View File

@@ -3,6 +3,7 @@ class PoolVersion < ActiveRecord::Base
validates_presence_of :updater_id, :updater_ip_addr
belongs_to :pool
belongs_to :updater, :class_name => "User"
before_validation :initialize_updater
def initialize_updater

View File

@@ -44,7 +44,6 @@
<%= nav_link_to("Forum", forum_topics_path, :class => (CurrentUser.user.has_forum_been_updated? ? "forum-updated" : nil)) %>
<% if CurrentUser.is_janitor? %>
<%= nav_link_to("Dashboard", moderator_dashboard_path) %>
<%= nav_link_to("Queue", moderator_post_dashboard_path) %>
<% end %>
<%= nav_link_to("&raquo;".html_safe, site_map_path) %>
</menu>

View File

@@ -1,10 +1,11 @@
<div id="c-pools">
<div id="a-index">
<h3>Pool History: <%= @pool_version.name %></h3>
<h3>Pool History</h3>
<table width="100%">
<thead>
<tr>
<th>Pool</th>
<th>Post Count</th>
<th>Changes</th>
<th>Updater</th>
@@ -16,7 +17,8 @@
<tbody>
<% @pool_versions.each do |pool_version| %>
<tr>
<td><%= link_to pool_version.post_id_array.size, pool_version_path(pool_version) %></td>
<td><%= pool_version.pool.name %></td>
<td><%= link_to pool_version.post_id_array.size, pool_versions_path(pool_version) %></td>
<td><%= pool_version_diff(pool_version) %></td>
<td><%= link_to pool_version.updater.name, user_path(pool_version.updater) %></td>
<td>
@@ -30,11 +32,11 @@
<% end %>
</tbody>
</table>
<div class="paginator">
<%= numbered_paginator(@pool_versions) %>
</div>
</div>
</div>
<div id="paginator">
<%= sequential_paginator(@pool_versions) %>
</div>
<%= render :partial => "pools/secondary_links" %>

View File

@@ -10,7 +10,7 @@
<% end %>
<li><%= link_to "Changes", post_versions_path %></li>
<li>Approvals</li>
<li><%= link_to "Moderate", moderation_post_dashboard_path %></li>
<li><%= link_to "Moderate", moderator_post_dashboard_path %></li>
<li>Help</li>
</menu>
<% end %>

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