fix pool controller tests
This commit is contained in:
@@ -10,7 +10,7 @@ class PostAppealsController < ApplicationController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
@search = PostAppeal.search(params[:search])
|
@search = PostAppeal.search(params[:search])
|
||||||
@post_appeals = @search.paginate(:page => params[:page])
|
@post_appeals = @search.paginate(params[:page])
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class PostFlagsController < ApplicationController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
@search = PostFlag.search(params[:search])
|
@search = PostFlag.search(params[:search])
|
||||||
@post_flags = @search.paginate(:page => params[:page])
|
@post_flags = @search.paginate(params[:page])
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|||||||
@@ -9,6 +9,6 @@ module PostVotesHelper
|
|||||||
added = current.post_id_array - prev.post_id_array
|
added = current.post_id_array - prev.post_id_array
|
||||||
removed = prev.post_id_array - current.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>–<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>–<a href="/posts/' + x.to_s + '">' + x.to_s + '</a></del>'}.join(" ")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ class PoolVersion < ActiveRecord::Base
|
|||||||
|
|
||||||
validates_presence_of :updater_id, :updater_ip_addr
|
validates_presence_of :updater_id, :updater_ip_addr
|
||||||
belongs_to :pool
|
belongs_to :pool
|
||||||
|
belongs_to :updater, :class_name => "User"
|
||||||
before_validation :initialize_updater
|
before_validation :initialize_updater
|
||||||
|
|
||||||
def initialize_updater
|
def initialize_updater
|
||||||
|
|||||||
@@ -44,7 +44,6 @@
|
|||||||
<%= nav_link_to("Forum", forum_topics_path, :class => (CurrentUser.user.has_forum_been_updated? ? "forum-updated" : nil)) %>
|
<%= nav_link_to("Forum", forum_topics_path, :class => (CurrentUser.user.has_forum_been_updated? ? "forum-updated" : nil)) %>
|
||||||
<% if CurrentUser.is_janitor? %>
|
<% if CurrentUser.is_janitor? %>
|
||||||
<%= nav_link_to("Dashboard", moderator_dashboard_path) %>
|
<%= nav_link_to("Dashboard", moderator_dashboard_path) %>
|
||||||
<%= nav_link_to("Queue", moderator_post_dashboard_path) %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= nav_link_to("»".html_safe, site_map_path) %>
|
<%= nav_link_to("»".html_safe, site_map_path) %>
|
||||||
</menu>
|
</menu>
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
<div id="c-pools">
|
<div id="c-pools">
|
||||||
<div id="a-index">
|
<div id="a-index">
|
||||||
<h3>Pool History: <%= @pool_version.name %></h3>
|
<h3>Pool History</h3>
|
||||||
|
|
||||||
<table width="100%">
|
<table width="100%">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th>Pool</th>
|
||||||
<th>Post Count</th>
|
<th>Post Count</th>
|
||||||
<th>Changes</th>
|
<th>Changes</th>
|
||||||
<th>Updater</th>
|
<th>Updater</th>
|
||||||
@@ -16,7 +17,8 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<% @pool_versions.each do |pool_version| %>
|
<% @pool_versions.each do |pool_version| %>
|
||||||
<tr>
|
<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><%= pool_version_diff(pool_version) %></td>
|
||||||
<td><%= link_to pool_version.updater.name, user_path(pool_version.updater) %></td>
|
<td><%= link_to pool_version.updater.name, user_path(pool_version.updater) %></td>
|
||||||
<td>
|
<td>
|
||||||
@@ -30,11 +32,11 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<div class="paginator">
|
||||||
|
<%= numbered_paginator(@pool_versions) %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="paginator">
|
|
||||||
<%= sequential_paginator(@pool_versions) %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<%= render :partial => "pools/secondary_links" %>
|
<%= render :partial => "pools/secondary_links" %>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<li><%= link_to "Changes", post_versions_path %></li>
|
<li><%= link_to "Changes", post_versions_path %></li>
|
||||||
<li>Approvals</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>
|
<li>Help</li>
|
||||||
</menu>
|
</menu>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class PoolElementsControllerTest < ActionController::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "add a post to a pool once and only once" do
|
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}
|
post :create, {:pool_id => @pool.id, :post_id => @post.id, :format => "json"}, {:user_id => @user.id}
|
||||||
@pool.reload
|
@pool.reload
|
||||||
assert_equal([@post.id], @pool.post_id_array)
|
assert_equal([@post.id], @pool.post_id_array)
|
||||||
@@ -32,7 +32,7 @@ class PoolElementsControllerTest < ActionController::TestCase
|
|||||||
|
|
||||||
context "destroy action" do
|
context "destroy action" do
|
||||||
setup do
|
setup do
|
||||||
@pool.add_post!(@post)
|
@pool.add!(@post)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "remove a post from a pool" do
|
should "remove a post from a pool" do
|
||||||
@@ -42,7 +42,7 @@ class PoolElementsControllerTest < ActionController::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "do nothing if the post is not a member of the pool" do
|
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}
|
post :destroy, {:pool_id => @pool.id, :post_id => @post.id, :format => "json"}, {:user_id => @user.id}
|
||||||
@pool.reload
|
@pool.reload
|
||||||
assert_equal([], @pool.post_id_array)
|
assert_equal([], @pool.post_id_array)
|
||||||
|
|||||||
@@ -16,10 +16,16 @@ class PoolVersionsControllerTest < ActionController::TestCase
|
|||||||
context "index action" do
|
context "index action" do
|
||||||
setup do
|
setup do
|
||||||
@pool = Factory.create(:pool)
|
@pool = Factory.create(:pool)
|
||||||
CurrentUser.id = 20
|
@user_2 = Factory.create(:user)
|
||||||
@pool.versions.create(:post_ids => "1 2")
|
@user_3 = Factory.create(:user)
|
||||||
CurrentUser.id = 30
|
|
||||||
@pool.versions.create(:post_ids => "1 2 3 4")
|
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
|
end
|
||||||
|
|
||||||
should "list all versions" do
|
should "list all versions" do
|
||||||
@@ -30,7 +36,7 @@ class PoolVersionsControllerTest < ActionController::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "list all versions that match the search criteria" do
|
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_response :success
|
||||||
assert_not_nil(assigns(:pool_versions))
|
assert_not_nil(assigns(:pool_versions))
|
||||||
assert_equal(1, assigns(:pool_versions).size)
|
assert_equal(1, assigns(:pool_versions).size)
|
||||||
|
|||||||
@@ -75,18 +75,20 @@ class PoolsControllerTest < ActionController::TestCase
|
|||||||
|
|
||||||
context "revert action" do
|
context "revert action" do
|
||||||
setup 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
|
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"
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
end
|
end
|
||||||
|
|
||||||
should "revert to a previous version" do
|
should "revert to a previous version" do
|
||||||
|
assert_equal(2, PoolVersion.count)
|
||||||
version = @pool.versions(true).first
|
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}
|
post :revert, {:id => @pool.id, :version_id => version.id}
|
||||||
@pool.reload
|
@pool.reload
|
||||||
assert_equal("1", @pool.post_ids)
|
assert_equal("#{@post.id}", @pool.post_ids)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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
|
|
||||||
Reference in New Issue
Block a user