annotate .svn/pristine/24/24c62162ea3371ca1be4a955c3f0b6fc0dac2c81.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1295 19
Chris@1295 20 class AdminControllerTest < ActionController::TestCase
Chris@1295 21 fixtures :projects, :users, :roles
Chris@1295 22
Chris@1295 23 def setup
Chris@1295 24 User.current = nil
Chris@1295 25 @request.session[:user_id] = 1 # admin
Chris@1295 26 end
Chris@1295 27
Chris@1295 28 def test_index
Chris@1295 29 get :index
Chris@1295 30 assert_select 'div.nodata', 0
Chris@1295 31 end
Chris@1295 32
Chris@1295 33 def test_index_with_no_configuration_data
Chris@1295 34 delete_configuration_data
Chris@1295 35 get :index
Chris@1295 36 assert_select 'div.nodata'
Chris@1295 37 end
Chris@1295 38
Chris@1295 39 def test_projects
Chris@1295 40 get :projects
Chris@1295 41 assert_response :success
Chris@1295 42 assert_template 'projects'
Chris@1295 43 assert_not_nil assigns(:projects)
Chris@1295 44 # active projects only
Chris@1295 45 assert_nil assigns(:projects).detect {|u| !u.active?}
Chris@1295 46 end
Chris@1295 47
Chris@1295 48 def test_projects_with_status_filter
Chris@1295 49 get :projects, :status => 1
Chris@1295 50 assert_response :success
Chris@1295 51 assert_template 'projects'
Chris@1295 52 assert_not_nil assigns(:projects)
Chris@1295 53 # active projects only
Chris@1295 54 assert_nil assigns(:projects).detect {|u| !u.active?}
Chris@1295 55 end
Chris@1295 56
Chris@1295 57 def test_projects_with_name_filter
Chris@1295 58 get :projects, :name => 'store', :status => ''
Chris@1295 59 assert_response :success
Chris@1295 60 assert_template 'projects'
Chris@1295 61 projects = assigns(:projects)
Chris@1295 62 assert_not_nil projects
Chris@1295 63 assert_equal 1, projects.size
Chris@1295 64 assert_equal 'OnlineStore', projects.first.name
Chris@1295 65 end
Chris@1295 66
Chris@1295 67 def test_load_default_configuration_data
Chris@1295 68 delete_configuration_data
Chris@1295 69 post :default_configuration, :lang => 'fr'
Chris@1295 70 assert_response :redirect
Chris@1295 71 assert_nil flash[:error]
Chris@1295 72 assert IssueStatus.find_by_name('Nouveau')
Chris@1295 73 end
Chris@1295 74
Chris@1295 75 def test_load_default_configuration_data_should_rescue_error
Chris@1295 76 delete_configuration_data
Chris@1295 77 Redmine::DefaultData::Loader.stubs(:load).raises(Exception.new("Something went wrong"))
Chris@1295 78 post :default_configuration, :lang => 'fr'
Chris@1295 79 assert_response :redirect
Chris@1295 80 assert_not_nil flash[:error]
Chris@1295 81 assert_match /Something went wrong/, flash[:error]
Chris@1295 82 end
Chris@1295 83
Chris@1295 84 def test_test_email
Chris@1295 85 user = User.find(1)
Chris@1295 86 user.pref[:no_self_notified] = '1'
Chris@1295 87 user.pref.save!
Chris@1295 88 ActionMailer::Base.deliveries.clear
Chris@1295 89
Chris@1295 90 get :test_email
Chris@1295 91 assert_redirected_to '/settings?tab=notifications'
Chris@1295 92 mail = ActionMailer::Base.deliveries.last
Chris@1295 93 assert_not_nil mail
Chris@1295 94 user = User.find(1)
Chris@1295 95 assert_equal [user.mail], mail.bcc
Chris@1295 96 end
Chris@1295 97
Chris@1295 98 def test_test_email_failure_should_display_the_error
Chris@1295 99 Mailer.stubs(:test_email).raises(Exception, 'Some error message')
Chris@1295 100 get :test_email
Chris@1295 101 assert_redirected_to '/settings?tab=notifications'
Chris@1295 102 assert_match /Some error message/, flash[:error]
Chris@1295 103 end
Chris@1295 104
Chris@1295 105 def test_no_plugins
Chris@1295 106 Redmine::Plugin.clear
Chris@1295 107
Chris@1295 108 get :plugins
Chris@1295 109 assert_response :success
Chris@1295 110 assert_template 'plugins'
Chris@1295 111 end
Chris@1295 112
Chris@1295 113 def test_plugins
Chris@1295 114 # Register a few plugins
Chris@1295 115 Redmine::Plugin.register :foo do
Chris@1295 116 name 'Foo plugin'
Chris@1295 117 author 'John Smith'
Chris@1295 118 description 'This is a test plugin'
Chris@1295 119 version '0.0.1'
Chris@1295 120 settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings'
Chris@1295 121 end
Chris@1295 122 Redmine::Plugin.register :bar do
Chris@1295 123 end
Chris@1295 124
Chris@1295 125 get :plugins
Chris@1295 126 assert_response :success
Chris@1295 127 assert_template 'plugins'
Chris@1295 128
Chris@1295 129 assert_select 'tr#plugin-foo' do
Chris@1295 130 assert_select 'td span.name', :text => 'Foo plugin'
Chris@1295 131 assert_select 'td.configure a[href=/settings/plugin/foo]'
Chris@1295 132 end
Chris@1295 133 assert_select 'tr#plugin-bar' do
Chris@1295 134 assert_select 'td span.name', :text => 'Bar'
Chris@1295 135 assert_select 'td.configure a', 0
Chris@1295 136 end
Chris@1295 137 end
Chris@1295 138
Chris@1295 139 def test_info
Chris@1295 140 get :info
Chris@1295 141 assert_response :success
Chris@1295 142 assert_template 'info'
Chris@1295 143 end
Chris@1295 144
Chris@1295 145 def test_admin_menu_plugin_extension
Chris@1295 146 Redmine::MenuManager.map :admin_menu do |menu|
Chris@1295 147 menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test'
Chris@1295 148 end
Chris@1295 149
Chris@1295 150 get :index
Chris@1295 151 assert_response :success
Chris@1295 152 assert_select 'div#admin-menu a[href=/foo/bar]', :text => 'Test'
Chris@1295 153
Chris@1295 154 Redmine::MenuManager.map :admin_menu do |menu|
Chris@1295 155 menu.delete :test_admin_menu_plugin_extension
Chris@1295 156 end
Chris@1295 157 end
Chris@1295 158
Chris@1295 159 private
Chris@1295 160
Chris@1295 161 def delete_configuration_data
Chris@1295 162 Role.delete_all('builtin = 0')
Chris@1295 163 Tracker.delete_all
Chris@1295 164 IssueStatus.delete_all
Chris@1295 165 Enumeration.delete_all
Chris@1295 166 end
Chris@1295 167 end