annotate .svn/pristine/3b/3bcd85a0da76d9d004854a6074056d5f89671907.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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