annotate .svn/pristine/fb/fb831ceb031f77a301df0cd90da94f30274b8153.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-2012 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_no_tag :tag => 'div',
Chris@1295 31 :attributes => { :class => /nodata/ }
Chris@1295 32 end
Chris@1295 33
Chris@1295 34 def test_index_with_no_configuration_data
Chris@1295 35 delete_configuration_data
Chris@1295 36 get :index
Chris@1295 37 assert_tag :tag => 'div',
Chris@1295 38 :attributes => { :class => /nodata/ }
Chris@1295 39 end
Chris@1295 40
Chris@1295 41 def test_projects
Chris@1295 42 get :projects
Chris@1295 43 assert_response :success
Chris@1295 44 assert_template 'projects'
Chris@1295 45 assert_not_nil assigns(:projects)
Chris@1295 46 # active projects only
Chris@1295 47 assert_nil assigns(:projects).detect {|u| !u.active?}
Chris@1295 48 end
Chris@1295 49
Chris@1295 50 def test_projects_with_status_filter
Chris@1295 51 get :projects, :status => 1
Chris@1295 52 assert_response :success
Chris@1295 53 assert_template 'projects'
Chris@1295 54 assert_not_nil assigns(:projects)
Chris@1295 55 # active projects only
Chris@1295 56 assert_nil assigns(:projects).detect {|u| !u.active?}
Chris@1295 57 end
Chris@1295 58
Chris@1295 59 def test_projects_with_name_filter
Chris@1295 60 get :projects, :name => 'store', :status => ''
Chris@1295 61 assert_response :success
Chris@1295 62 assert_template 'projects'
Chris@1295 63 projects = assigns(:projects)
Chris@1295 64 assert_not_nil projects
Chris@1295 65 assert_equal 1, projects.size
Chris@1295 66 assert_equal 'OnlineStore', projects.first.name
Chris@1295 67 end
Chris@1295 68
Chris@1295 69 def test_load_default_configuration_data
Chris@1295 70 delete_configuration_data
Chris@1295 71 post :default_configuration, :lang => 'fr'
Chris@1295 72 assert_response :redirect
Chris@1295 73 assert_nil flash[:error]
Chris@1295 74 assert IssueStatus.find_by_name('Nouveau')
Chris@1295 75 end
Chris@1295 76
Chris@1295 77 def test_load_default_configuration_data_should_rescue_error
Chris@1295 78 delete_configuration_data
Chris@1295 79 Redmine::DefaultData::Loader.stubs(:load).raises(Exception.new("Something went wrong"))
Chris@1295 80 post :default_configuration, :lang => 'fr'
Chris@1295 81 assert_response :redirect
Chris@1295 82 assert_not_nil flash[:error]
Chris@1295 83 assert_match /Something went wrong/, flash[:error]
Chris@1295 84 end
Chris@1295 85
Chris@1295 86 def test_test_email
Chris@1295 87 user = User.find(1)
Chris@1295 88 user.pref[:no_self_notified] = '1'
Chris@1295 89 user.pref.save!
Chris@1295 90 ActionMailer::Base.deliveries.clear
Chris@1295 91
Chris@1295 92 get :test_email
Chris@1295 93 assert_redirected_to '/settings/edit?tab=notifications'
Chris@1295 94 mail = ActionMailer::Base.deliveries.last
Chris@1295 95 assert_not_nil mail
Chris@1295 96 user = User.find(1)
Chris@1295 97 assert_equal [user.mail], mail.bcc
Chris@1295 98 end
Chris@1295 99
Chris@1295 100 def test_test_email_failure_should_display_the_error
Chris@1295 101 Mailer.stubs(:test_email).raises(Exception, 'Some error message')
Chris@1295 102 get :test_email
Chris@1295 103 assert_redirected_to '/settings/edit?tab=notifications'
Chris@1295 104 assert_match /Some error message/, flash[:error]
Chris@1295 105 end
Chris@1295 106
Chris@1295 107 def test_no_plugins
Chris@1295 108 Redmine::Plugin.clear
Chris@1295 109
Chris@1295 110 get :plugins
Chris@1295 111 assert_response :success
Chris@1295 112 assert_template 'plugins'
Chris@1295 113 end
Chris@1295 114
Chris@1295 115 def test_plugins
Chris@1295 116 # Register a few plugins
Chris@1295 117 Redmine::Plugin.register :foo do
Chris@1295 118 name 'Foo plugin'
Chris@1295 119 author 'John Smith'
Chris@1295 120 description 'This is a test plugin'
Chris@1295 121 version '0.0.1'
Chris@1295 122 settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings'
Chris@1295 123 end
Chris@1295 124 Redmine::Plugin.register :bar do
Chris@1295 125 end
Chris@1295 126
Chris@1295 127 get :plugins
Chris@1295 128 assert_response :success
Chris@1295 129 assert_template 'plugins'
Chris@1295 130
Chris@1295 131 assert_tag :td, :child => { :tag => 'span', :content => 'Foo plugin' }
Chris@1295 132 assert_tag :td, :child => { :tag => 'span', :content => 'Bar' }
Chris@1295 133 end
Chris@1295 134
Chris@1295 135 def test_info
Chris@1295 136 get :info
Chris@1295 137 assert_response :success
Chris@1295 138 assert_template 'info'
Chris@1295 139 end
Chris@1295 140
Chris@1295 141 def test_admin_menu_plugin_extension
Chris@1295 142 Redmine::MenuManager.map :admin_menu do |menu|
Chris@1295 143 menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test'
Chris@1295 144 end
Chris@1295 145
Chris@1295 146 get :index
Chris@1295 147 assert_response :success
Chris@1295 148 assert_tag :a, :attributes => { :href => '/foo/bar' },
Chris@1295 149 :content => 'Test'
Chris@1295 150
Chris@1295 151 Redmine::MenuManager.map :admin_menu do |menu|
Chris@1295 152 menu.delete :test_admin_menu_plugin_extension
Chris@1295 153 end
Chris@1295 154 end
Chris@1295 155
Chris@1295 156 private
Chris@1295 157
Chris@1295 158 def delete_configuration_data
Chris@1295 159 Role.delete_all('builtin = 0')
Chris@1295 160 Tracker.delete_all
Chris@1295 161 IssueStatus.delete_all
Chris@1295 162 Enumeration.delete_all
Chris@1295 163 end
Chris@1295 164 end