comparison test/functional/admin_controller_test.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbb26bc654de
children 622f24f53b42 261b3d9a4903
comparison
equal deleted inserted replaced
929:5f33065ddc4b 1115:433d4f72a19b
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
14 # You should have received a copy of the GNU General Public License 14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software 15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require File.expand_path('../../test_helper', __FILE__) 18 require File.expand_path('../../test_helper', __FILE__)
19 require 'admin_controller'
20
21 # Re-raise errors caught by the controller.
22 class AdminController; def rescue_action(e) raise e end; end
23 19
24 class AdminControllerTest < ActionController::TestCase 20 class AdminControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles 21 fixtures :projects, :users, :roles
26 22
27 def setup 23 def setup
28 @controller = AdminController.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
31 User.current = nil 24 User.current = nil
32 @request.session[:user_id] = 1 # admin 25 @request.session[:user_id] = 1 # admin
33 end 26 end
34 27
35 def test_index 28 def test_index
52 assert_not_nil assigns(:projects) 45 assert_not_nil assigns(:projects)
53 # active projects only 46 # active projects only
54 assert_nil assigns(:projects).detect {|u| !u.active?} 47 assert_nil assigns(:projects).detect {|u| !u.active?}
55 end 48 end
56 49
50 def test_projects_with_status_filter
51 get :projects, :status => 1
52 assert_response :success
53 assert_template 'projects'
54 assert_not_nil assigns(:projects)
55 # active projects only
56 assert_nil assigns(:projects).detect {|u| !u.active?}
57 end
58
57 def test_projects_with_name_filter 59 def test_projects_with_name_filter
58 get :projects, :name => 'store', :status => '' 60 get :projects, :name => 'store', :status => ''
59 assert_response :success 61 assert_response :success
60 assert_template 'projects' 62 assert_template 'projects'
61 projects = assigns(:projects) 63 projects = assigns(:projects)
70 assert_response :redirect 72 assert_response :redirect
71 assert_nil flash[:error] 73 assert_nil flash[:error]
72 assert IssueStatus.find_by_name('Nouveau') 74 assert IssueStatus.find_by_name('Nouveau')
73 end 75 end
74 76
77 def test_load_default_configuration_data_should_rescue_error
78 delete_configuration_data
79 Redmine::DefaultData::Loader.stubs(:load).raises(Exception.new("Something went wrong"))
80 post :default_configuration, :lang => 'fr'
81 assert_response :redirect
82 assert_not_nil flash[:error]
83 assert_match /Something went wrong/, flash[:error]
84 end
85
75 def test_test_email 86 def test_test_email
87 user = User.find(1)
88 user.pref[:no_self_notified] = '1'
89 user.pref.save!
90 ActionMailer::Base.deliveries.clear
91
76 get :test_email 92 get :test_email
77 assert_redirected_to '/settings/edit?tab=notifications' 93 assert_redirected_to '/settings/edit?tab=notifications'
78 mail = ActionMailer::Base.deliveries.last 94 mail = ActionMailer::Base.deliveries.last
79 assert_kind_of TMail::Mail, mail 95 assert_not_nil mail
80 user = User.find(1) 96 user = User.find(1)
81 assert_equal [user.mail], mail.bcc 97 assert_equal [user.mail], mail.bcc
98 end
99
100 def test_test_email_failure_should_display_the_error
101 Mailer.stubs(:test_email).raises(Exception, 'Some error message')
102 get :test_email
103 assert_redirected_to '/settings/edit?tab=notifications'
104 assert_match /Some error message/, flash[:error]
82 end 105 end
83 106
84 def test_no_plugins 107 def test_no_plugins
85 Redmine::Plugin.clear 108 Redmine::Plugin.clear
86 109