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