Test cleanup.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8461 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-01-01 19:50:51 +00:00
parent ed1320f3c9
commit 84f8245abb
1 changed files with 90 additions and 94 deletions

View File

@ -1,94 +1,90 @@
require File.expand_path('../../test_helper', __FILE__) # Redmine - project management software
# Copyright (C) 2006-2011 Jean-Philippe Lang
class AuthSourcesControllerTest < ActionController::TestCase #
# This program is free software; you can redistribute it and/or
def setup # modify it under the terms of the GNU General Public License
@request.session[:user_id] = 1 # as published by the Free Software Foundation; either version 2
end # of the License, or (at your option) any later version.
#
context "get :index" do # This program is distributed in the hope that it will be useful,
setup do # but WITHOUT ANY WARRANTY; without even the implied warranty of
get :index # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
end # GNU General Public License for more details.
#
should_assign_to :auth_sources # You should have received a copy of the GNU General Public License
should_assign_to :auth_source_pages # along with this program; if not, write to the Free Software
should_respond_with :success # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
should_render_template :index
end require File.expand_path('../../test_helper', __FILE__)
context "get :new" do class AuthSourcesControllerTest < ActionController::TestCase
setup do fixtures :users
get :new
end def setup
@request.session[:user_id] = 1
should_assign_to :auth_source end
should_respond_with :success
should_render_template :new def test_index
get :index
should "initilize a new AuthSource" do
assert_equal AuthSource, assigns(:auth_source).class assert_response :success
assert assigns(:auth_source).new_record? assert_template 'index'
end assert_not_nil assigns(:auth_sources)
end end
context "post :create" do def test_new
setup do get :new
post :create, :auth_source => {:name => 'Test'}
end assert_response :success
assert_template 'new'
should_respond_with :redirect assert_kind_of AuthSource, assigns(:auth_source)
should_redirect_to("index") {{:action => 'index'}} assert assigns(:auth_source).new_record?
should_set_the_flash_to /success/i end
end
def test_create
context "get :edit" do assert_difference 'AuthSource.count' do
setup do post :create, :auth_source => {:name => 'Test'}
@auth_source = AuthSource.generate!(:name => 'TestEdit') end
get :edit, :id => @auth_source.id
end assert_redirected_to '/auth_sources'
auth_source = AuthSource.first(:order => 'id DESC')
should_assign_to(:auth_source) {@auth_source} assert_equal 'Test', auth_source.name
should_respond_with :success end
should_render_template :edit
end def test_edit
auth_source = AuthSource.generate!(:name => 'TestEdit')
context "post :update" do get :edit, :id => auth_source.id
setup do
@auth_source = AuthSource.generate!(:name => 'TestEdit') assert_response :success
post :update, :id => @auth_source.id, :auth_source => {:name => 'TestUpdate'} assert_template 'edit'
end assert_equal auth_source, assigns(:auth_source)
end
should_respond_with :redirect
should_redirect_to("index") {{:action => 'index'}} def test_update
should_set_the_flash_to /update/i auth_source = AuthSource.generate!(:name => 'TestEdit')
end post :update, :id => auth_source.id, :auth_source => {:name => 'TestUpdate'}
context "post :destroy" do assert_redirected_to '/auth_sources'
setup do assert_equal 'TestUpdate', auth_source.reload.name
@auth_source = AuthSource.generate!(:name => 'TestEdit') end
end
def test_destroy_without_users
context "without users" do auth_source = AuthSource.generate!(:name => 'TestEdit')
setup do assert_difference 'AuthSource.count', -1 do
post :destroy, :id => @auth_source.id post :destroy, :id => auth_source.id
end end
should_respond_with :redirect assert_redirected_to '/auth_sources'
should_redirect_to("index") {{:action => 'index'}} end
should_set_the_flash_to /deletion/i
end def test_destroy_with_users
auth_source = AuthSource.generate!(:name => 'TestEdit')
context "with users" do User.generate!(:auth_source => auth_source)
setup do assert_no_difference 'AuthSource.count' do
User.generate!(:auth_source => @auth_source) post :destroy, :id => auth_source.id
post :destroy, :id => @auth_source.id end
end
assert_redirected_to '/auth_sources'
should_respond_with :redirect assert AuthSource.find(auth_source.id)
should "not destroy the AuthSource" do end
assert AuthSource.find(@auth_source.id) end
end
end
end
end