From 48949f979a7d132ccbbc2239cd9e4ecf35fdeef5 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 13 Dec 2007 18:52:09 +0000 Subject: [PATCH] Added some functional tests and a CVS test repository. git-svn-id: http://redmine.rubyforge.org/svn/trunk@987 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/admin_controller.rb | 2 +- doc/RUNNING_TESTS | 4 + .../repositories/cvs_repository.tar.gz | Bin 0 -> 12248 bytes test/fixtures/roles.yml | 2 + test/functional/account_controller_test.rb | 73 ++++++++++++++++++ test/functional/admin_controller_test.rb | 61 +++++++++++++++ test/functional/issues_controller_test.rb | 12 ++- test/functional/messages_controller_test.rb | 50 ++++++++++++ test/functional/my_controller_test.rb | 2 +- ...repositories_subversion_controller_test.rb | 2 +- test/functional/users_controller_test.rb | 62 +++++++++++++++ test/functional/versions_controller_test.rb | 31 ++++++++ test/functional/welcome_controller_test.rb | 49 ++++++++++++ test/unit/repository_cvs_test.rb | 60 ++++++++++++++ 14 files changed, 406 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/repositories/cvs_repository.tar.gz create mode 100644 test/functional/account_controller_test.rb create mode 100644 test/functional/admin_controller_test.rb create mode 100644 test/functional/users_controller_test.rb create mode 100644 test/functional/welcome_controller_test.rb create mode 100644 test/unit/repository_cvs_test.rb diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 58d6115ee..5ad3d696b 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -48,7 +48,7 @@ class AdminController < ApplicationController def mail_options @notifiables = %w(issue_added issue_updated news_added document_added file_added message_posted) if request.post? - settings = (params[:settings] || {}).dup + settings = (params[:settings] || {}).dup.symbolize_keys settings[:notified_events] ||= [] settings.each { |name, value| Setting[name] = value } flash[:notice] = l(:notice_successful_update) diff --git a/doc/RUNNING_TESTS b/doc/RUNNING_TESTS index bd72ac71a..eb8787d95 100644 --- a/doc/RUNNING_TESTS +++ b/doc/RUNNING_TESTS @@ -8,6 +8,10 @@ Subversion svnadmin create tmp/test/subversion_repository gunzip < test/fixtures/repositories/subversion_repository.dump.gz | svnadmin load tmp/test/subversion_repository +CVS +--- +gunzip < test/fixtures/repositories/cvs_repository.tar.gz | tar -xv -C tmp/test + Bazaar ------ gunzip < test/fixtures/repositories/bazaar_repository.tar.gz | tar -xv -C tmp/test \ No newline at end of file diff --git a/test/fixtures/repositories/cvs_repository.tar.gz b/test/fixtures/repositories/cvs_repository.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..638b166b5e8ef53821313bb1e3f4e5ecb4637377 GIT binary patch literal 12248 zcmZA71yfy3v@Ys}yM*BG65I(MT!L$mpuydJ;qDNETX1&>?(QzZ-Q8i$n{V%Ps&1Ws zFspm?nB#rA$)XSuEBuV4K`16}&IV3D9PFJfUF@AaSzL^qKq z*11KQd86-0lQR)v6QtNOIA$JQdi;BBfk(1xdqTSeT%Z2>HI-xVLmt7p0#IpN54;z# zYPh}MlufUP{H$(;S?O>a3b1|dNwJ+TThJ`$2EVVJhw1=kwyGY@xA~-W#~_2nJ}ar`?(1duXH7A{^~1ljR*LFX1&i3w*L%}7#A;r>=PGG6jIr_AhhE0?zMDt#nM|o%MvgpIMb><= zM1~q8EGM+P(*1;59Zq2K2y~cu z5SclU^j?d0N50u-;k)B7Zo*`$;g`FtN45;59uO1q7h0I$O~c)g&$q0GDq+_F44poK z#bxx-o%&*rRvQ!b1Wgd0#^GApR6US%k>0Dkn zu|;t`X;4?F-AhZiuoKDvzQ%_MeWPoeEdg4mb5aMN$3nAC3hdfuPi7e!a9qOHYIJG`p3G3vageyR!>M1reg+^ zGCd=HGC?$#_W64^DdMZP(dVDVaY?wt;9~Q8PD_)BH-tQcj1*wOEf#Q3?8IXILB7$E z>2E`n9UIgmd@=4G+ZK0b2%F>-RAIdpYdg21m1yvkO!C-xD1uMW2|o3r-3}@1;jN*Lwe%=zIe^x7Y!6H_xA#|8+5$vm zgZ2!TV@Dky{9rY%v@3j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On+GyNwoJr~TNu zhGMt!W2;sm{VHT3Xeg}Y9@_hz%#v>(4`!@Mii%+p&BZa#TJ9`Sf;Z#pCXVih_CjrH ziwXa0SPHYjCh6X?IR-t)>NNMvZ@5lEwRyH!&;gq7`QNME0mf^p^^LlLD953u)}6m6 zaznp-`kaF|pJ5(sx}lY75Lh)Z`aiZuORy*ny-?NqoM40Eci3Q_ckQr)x-4S4UH|U0>&p8>+{a@SbZcWYhfn>FW70M%_f}Xdl4$?*uz5ZW_REx z_xJ$EpiVk{ONu`<`l`6q>F4~uzEJ$>eI}iE#L0YTe;!g~E9g9Fj&YbHiWQqxu_g#j zIWnz@%-(;1R`Me0G%?D+#%)Ij4;V`rY_Iidm=yOql{!@<8rC$|C;OH^?5nMbI$8b9 zBJTOHwRh}yl3Bftb!Q&Ep-YScqv|)=eg1SI7^K!o+ZkRyD)aaP9aQ$dj+880ImnXm zsQrwXI5;@`di$ywn9iMBB8R3av46q<0|kNCr^pq`XC?c!9^ng76f<+Bhuj*$5^o1}1DeTdkGfWl2KTt1G{GGqBb~yC zVe0uRWDu>!pm0e*Ya&*LJzEQ{1zldhtShVe~|q;A|g>2iV?Xu{Lj!jlh*$7@oJwLGKT zGl2b+Kd_j`WFYNXenBmGx7Rg@>q9%`roH|o*el(dlqb?v$Z)9`FE>FYxWabS#Tmga h8~*%3Ci^D2Sa6>~$#YaK`$GH$Ox!7t0cwE){eOE(X;lCK literal 0 HcmV?d00001 diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml index bc4d65641..70490286f 100644 --- a/test/fixtures/roles.yml +++ b/test/fixtures/roles.yml @@ -76,6 +76,8 @@ roles_001: - :edit_wiki_pages - :delete_wiki_pages - :add_messages + - :edit_messages + - :delete_messages - :manage_boards - :view_files - :manage_files diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb new file mode 100644 index 000000000..a923de3ea --- /dev/null +++ b/test/functional/account_controller_test.rb @@ -0,0 +1,73 @@ +# redMine - project management software +# Copyright (C) 2006-2007 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.dirname(__FILE__) + '/../test_helper' +require 'account_controller' + +# Re-raise errors caught by the controller. +class AccountController; def rescue_action(e) raise e end; end + +class AccountControllerTest < Test::Unit::TestCase + fixtures :users + + def setup + @controller = AccountController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + User.current = nil + end + + def test_show + get :show, :id => 2 + assert_response :success + assert_template 'show' + assert_not_nil assigns(:user) + end + + def test_show_inactive + get :show, :id => 5 + assert_response 404 + assert_nil assigns(:user) + end + + def test_login_with_wrong_password + post :login, :login => 'admin', :password => 'bad' + assert_response :success + assert_template 'login' + assert_tag 'div', + :attributes => { :class => "flash error" }, + :content => /Invalid user or password/ + end + + def test_autologin + Setting.autologin = "7" + Token.delete_all + post :login, :login => 'admin', :password => 'admin', :autologin => 1 + assert_redirected_to 'my/page' + token = Token.find :first + assert_not_nil token + assert_equal User.find_by_login('admin'), token.user + assert_equal 'autologin', token.action + end + + def test_logout + @request.session[:user_id] = 2 + get :logout + assert_redirected_to '' + assert_nil @request.session[:user_id] + end +end diff --git a/test/functional/admin_controller_test.rb b/test/functional/admin_controller_test.rb new file mode 100644 index 000000000..d49fe2dda --- /dev/null +++ b/test/functional/admin_controller_test.rb @@ -0,0 +1,61 @@ +# redMine - project management software +# Copyright (C) 2006-2007 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.dirname(__FILE__) + '/../test_helper' +require 'admin_controller' + +# Re-raise errors caught by the controller. +class AdminController; def rescue_action(e) raise e end; end + +class AdminControllerTest < Test::Unit::TestCase + fixtures :projects, :users + + def setup + @controller = AdminController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + User.current = nil + @request.session[:user_id] = 1 # admin + end + + def test_get_mail_options + get :mail_options + assert_response :success + assert_template 'mail_options' + end + + def test_post_mail_options + post :mail_options, :settings => {'mail_from' => 'functional@test.foo'} + assert_redirected_to 'admin/mail_options' + assert_equal 'functional@test.foo', Setting.mail_from + end + + def test_test_email + get :test_email + assert_redirected_to 'admin/mail_options' + mail = ActionMailer::Base.deliveries.last + assert_kind_of TMail::Mail, mail + user = User.find(1) + assert_equal [user.mail], mail.bcc + end + + def test_info + get :info + assert_response :success + assert_template 'info' + end +end diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index b9d232bfd..638362dbe 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -22,7 +22,17 @@ require 'issues_controller' class IssuesController; def rescue_action(e) raise e end; end class IssuesControllerTest < Test::Unit::TestCase - fixtures :projects, :users, :roles, :members, :issues, :enabled_modules, :enumerations + fixtures :projects, + :users, + :roles, + :members, + :issues, + :issue_statuses, + :trackers, + :issue_categories, + :enabled_modules, + :enumerations, + :attachments def setup @controller = IssuesController.new diff --git a/test/functional/messages_controller_test.rb b/test/functional/messages_controller_test.rb index 25fc1363e..dcfe0caa7 100644 --- a/test/functional/messages_controller_test.rb +++ b/test/functional/messages_controller_test.rb @@ -40,10 +40,60 @@ class MessagesControllerTest < Test::Unit::TestCase assert_not_nil assigns(:topic) end + def test_show_message_not_found + get :show, :board_id => 1, :id => 99999 + assert_response 404 + end + + def test_get_new + @request.session[:user_id] = 2 + get :new, :board_id => 1 + assert_response :success + assert_template 'new' + end + + def test_post_new + @request.session[:user_id] = 2 + post :new, :board_id => 1, + :message => { :subject => 'Test created message', + :content => 'Message body'} + assert_redirected_to 'messages/show' + message = Message.find_by_subject('Test created message') + assert_not_nil message + assert_equal 'Message body', message.content + assert_equal 2, message.author_id + assert_equal 1, message.board_id + end + + def test_get_edit + @request.session[:user_id] = 2 + get :edit, :board_id => 1, :id => 1 + assert_response :success + assert_template 'edit' + end + + def test_post_edit + @request.session[:user_id] = 2 + post :edit, :board_id => 1, :id => 1, + :message => { :subject => 'New subject', + :content => 'New body'} + assert_redirected_to 'messages/show' + message = Message.find(1) + assert_equal 'New subject', message.subject + assert_equal 'New body', message.content + end + def test_reply @request.session[:user_id] = 2 post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' } assert_redirected_to 'messages/show' assert Message.find_by_subject('Test reply') end + + def test_destroy_topic + @request.session[:user_id] = 2 + post :destroy, :board_id => 1, :id => 1 + assert_redirected_to 'boards/show' + assert_nil Message.find_by_id(1) + end end diff --git a/test/functional/my_controller_test.rb b/test/functional/my_controller_test.rb index 5df2932ed..c1349ace4 100644 --- a/test/functional/my_controller_test.rb +++ b/test/functional/my_controller_test.rb @@ -22,7 +22,7 @@ require 'my_controller' class MyController; def rescue_action(e) raise e end; end class MyControllerTest < Test::Unit::TestCase - fixtures :users + fixtures :users, :issues, :issue_statuses, :trackers, :enumerations def setup @controller = MyController.new diff --git a/test/functional/repositories_subversion_controller_test.rb b/test/functional/repositories_subversion_controller_test.rb index 9cc7048df..d7ce45640 100644 --- a/test/functional/repositories_subversion_controller_test.rb +++ b/test/functional/repositories_subversion_controller_test.rb @@ -21,7 +21,7 @@ require 'repositories_controller' # Re-raise errors caught by the controller. class RepositoriesController; def rescue_action(e) raise e end; end -class RepositoriesControllerTest < Test::Unit::TestCase +class RepositoriesSubversionControllerTest < Test::Unit::TestCase fixtures :projects, :users, :roles, :members, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers # No '..' in the repository path for svn diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb new file mode 100644 index 000000000..8629a7131 --- /dev/null +++ b/test/functional/users_controller_test.rb @@ -0,0 +1,62 @@ +# redMine - project management software +# Copyright (C) 2006-2007 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.dirname(__FILE__) + '/../test_helper' +require 'users_controller' + +# Re-raise errors caught by the controller. +class UsersController; def rescue_action(e) raise e end; end + +class UsersControllerTest < Test::Unit::TestCase + fixtures :users, :projects, :members + + def setup + @controller = UsersController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + User.current = nil + @request.session[:user_id] = 1 # admin + end + + def test_index + get :index + assert_response :success + assert_template 'list' + end + + def test_list + get :list + assert_response :success + assert_template 'list' + assert_not_nil assigns(:users) + # active users only + assert_nil assigns(:users).detect {|u| !u.active?} + end + + def test_edit_membership + post :edit_membership, :id => 2, :membership_id => 1, + :membership => { :role_id => 2} + assert_redirected_to 'users/edit/2' + assert_equal 2, Member.find(1).role_id + end + + def test_destroy_membership + post :destroy_membership, :id => 2, :membership_id => 1 + assert_redirected_to 'users/edit/2' + assert_nil Member.find_by_id(1) + end +end diff --git a/test/functional/versions_controller_test.rb b/test/functional/versions_controller_test.rb index e8327938a..17ebd3518 100644 --- a/test/functional/versions_controller_test.rb +++ b/test/functional/versions_controller_test.rb @@ -39,4 +39,35 @@ class VersionsControllerTest < Test::Unit::TestCase assert_tag :tag => 'h2', :content => /1.0/ end + + def test_get_edit + @request.session[:user_id] = 2 + get :edit, :id => 2 + assert_response :success + assert_template 'edit' + end + + def test_post_edit + @request.session[:user_id] = 2 + post :edit, :id => 2, + :version => { :name => 'New version name', + :effective_date => Date.today.strftime("%Y-%m-%d")} + assert_redirected_to 'projects/settings/1' + version = Version.find(2) + assert_equal 'New version name', version.name + assert_equal Date.today, version.effective_date + end + + def test_destroy + @request.session[:user_id] = 2 + post :destroy, :id => 2 + assert_redirected_to 'projects/settings/1' + assert_nil Version.find_by_id(2) + end + + def test_issue_status_by + xhr :get, :status_by, :id => 2 + assert_response :success + assert_template '_issue_counts' + end end diff --git a/test/functional/welcome_controller_test.rb b/test/functional/welcome_controller_test.rb new file mode 100644 index 000000000..18146c6aa --- /dev/null +++ b/test/functional/welcome_controller_test.rb @@ -0,0 +1,49 @@ +# redMine - project management software +# Copyright (C) 2006-2007 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.dirname(__FILE__) + '/../test_helper' +require 'welcome_controller' + +# Re-raise errors caught by the controller. +class WelcomeController; def rescue_action(e) raise e end; end + +class WelcomeControllerTest < Test::Unit::TestCase + fixtures :projects, :news + + def setup + @controller = WelcomeController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + User.current = nil + end + + def test_index + get :index + assert_response :success + assert_template 'index' + assert_not_nil assigns(:news) + assert_not_nil assigns(:projects) + assert !assigns(:projects).include?(Project.find(:first, :conditions => {:is_public => false})) + end + + def test_browser_language + Setting.default_language = 'en' + @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3' + get :index + assert_equal :fr, @controller.current_language + end +end diff --git a/test/unit/repository_cvs_test.rb b/test/unit/repository_cvs_test.rb new file mode 100644 index 000000000..3f6db06eb --- /dev/null +++ b/test/unit/repository_cvs_test.rb @@ -0,0 +1,60 @@ +# redMine - project management software +# Copyright (C) 2006-2007 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.dirname(__FILE__) + '/../test_helper' +require 'pp' +class RepositoryCvsTest < Test::Unit::TestCase + fixtures :projects + + # No '..' in the repository path + REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/cvs_repository' + REPOSITORY_PATH.gsub!(/\//, "\\") if RUBY_PLATFORM =~ /mswin/ + # CVS module + MODULE_NAME = 'test' + + def setup + @project = Project.find(1) + assert @repository = Repository::Cvs.create(:project => @project, + :root_url => REPOSITORY_PATH, + :url => MODULE_NAME) + end + + if File.directory?(REPOSITORY_PATH) + def test_fetch_changesets_from_scratch + @repository.fetch_changesets + @repository.reload + + assert_equal 5, @repository.changesets.count + assert_equal 14, @repository.changes.count + assert_equal 'Two files changed', @repository.changesets.find_by_revision(3).comments + end + + def test_fetch_changesets_incremental + @repository.fetch_changesets + # Remove changesets with revision > 2 + @repository.changesets.find(:all, :conditions => 'revision > 2').each(&:destroy) + @repository.reload + assert_equal 2, @repository.changesets.count + + @repository.fetch_changesets + assert_equal 5, @repository.changesets.count + end + else + puts "CVS test repository NOT FOUND. Skipping unit tests !!!" + def test_fake; assert true end + end +end