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