stubbed in pool controller test

This commit is contained in:
albert 2011-01-20 18:30:36 -05:00
parent d84818366b
commit cd451109e8
12 changed files with 131 additions and 6 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ vendor/cache/*.gem
.sass-cache
.DS_Store
coverage
*~

View File

@ -1,25 +1,49 @@
class PoolsController < ApplicationController
respond_to :html, :xml, :json
before_filter :member_only, :except => [:index, :show]
before_filter :moderator_only, :only => [:destroy]
def new
@pool = Pool.new
respond_with(@pool)
end
def edit
@pool = Pool.find(params[:id])
respond_with(@pool)
end
def index
@search = Pool.search(params[:search])
@pools = @search.paginate(:page => params[:page])
end
def show
@pool = Pool.find(params[:id])
respond_with(@pool)
end
def create
@pool = Pool.create(params[:pool])
respond_with(@pool)
end
def update
@pool = Pool.find(params[:id])
@pool.update_attributes(params[:pool])
respond_with(@pool)
end
def destroy
@pool = Pool.find(params[:id])
@pool.destroy
respond_with(@pool)
end
def revert
@pool = Pool.find(params[:id])
@version = PoolVersion.find(params[:version_id])
@pool.revert_to!(@version)
respond_with(@pool)
end
end

View File

@ -0,0 +1,18 @@
class PoolsPostsController < ApplicationController
respond_to :html, :xml, :json
before_filter :member_only
def create
@pool = Pool.find(params[:pool_id])
@post = Post.find(params[:post_id])
@pool.add_post!(@post)
respond_with(@pool)
end
def destroy
@pool = Pool.find(params[:pool_id])
@post = Post.find(params[:post_id])
@pool.remove_post!(@post)
respond_with(@pool)
end
end

View File

@ -8,7 +8,7 @@ class Pool < ActiveRecord::Base
has_many :versions, :class_name => "PoolVersion", :dependent => :destroy
before_save :normalize_name
after_save :create_version
attr_accessible :name, :description, :post_ids, :is_public, :is_active
attr_accessible :name, :description, :post_ids, :is_active
def self.name_to_id(name)
select_value_sql("SELECT id FROM pools WHERE name = ?", name.downcase)

View File

View File

View File

View File

View File

@ -33,6 +33,7 @@ Danbooru::Application.routes.draw do
end
resources :note_versions
resources :pools do
resources :posts, :controller => "pools_posts", :only => [:create, :destroy]
member do
put :revert
end

View File

@ -4,7 +4,6 @@ class CreatePools < ActiveRecord::Migration
t.column :name, :string
t.column :creator_id, :integer, :null => false
t.column :description, :text
t.column :is_public, :boolean, :null => false, :default => true
t.column :is_active, :boolean, :null => false, :default => true
t.column :post_ids, :text, :null => false, :default => ""
t.timestamps

View File

@ -67,7 +67,7 @@ class NotesControllerTest < ActionController::TestCase
should "destroy a note" do
assert_difference("Note.count", -1) do
post :destroy, {:id => @note.id}
post :destroy, {:id => @note.id}, {:user_id => @user.id}
end
end
end

View File

@ -1,8 +1,90 @@
require 'test_helper'
class PoolsControllerTest < ActionController::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
context "The pools controller" do
setup do
@user = Factory.create(:user)
@mod = Factory.create(:moderator_user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@post = Factory.create(:post)
end
teardown do
CurrentUser.user = nil
end
context "index action" do
setup do
Factory.create(:pool, :name => "abc")
end
should "list all pools" do
get :index
assert_response :success
end
should "list all pools (with search)" do
get :index, {:search => {:name_matches => "abc"}}
assert_response :success
end
end
context "show action" do
setup do
@pool = Factory.create(:pool)
end
should "render" do
get :show, {:id => @pool.id}
assert_response :success
end
end
context "create action" do
should "create a pool" do
assert_difference("Pool.count", 1) do
post :create, {:pool => {:name => "xxx", :description => "abc"}}, {:user_id => @user.id}
end
end
end
context "update action" do
setup do
@pool = Factory.create(:pool)
end
should "update a pool" do
post :update, {:id => @pool.id, :pool => {:name => "xyz"}}, {:user_id => @user.id}
@pool.reload
assert_equal("xyz", @pool.name)
end
end
context "destroy action" do
setup do
@pool = Factory.create(:pool)
end
should "destroy a pool" do
assert_difference("Pool.count", -1) do
post :destroy, {:id => @pool.id}, {:user_id => @mod.id}
end
end
end
context "revert action" do
setup do
@pool = Factory.create(:pool, :name => "000")
@pool.update_attributes(:name => "111")
@pool.update_attributes(:name => "222")
end
should "revert to a previous version" do
post :revert, {:id => @pool.id, :version_id => @pool.versions(true).first.id}
@pool.reload
assert_equal("000", @pool.name)
end
end
end
end