annotate test/functional/admin_controller_test.rb @ 8:0c83d98252d9 yuya

* Add custom repo prefix and proper auth realm, remove auth cache (seems like an unwise feature), pass DB handle around, various other bits of tidying
author Chris Cannam
date Thu, 12 Aug 2010 15:31:37 +0100
parents 513646585e45
children af80e5618e9b
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006-2007 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@0 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@0 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@0 18 require File.dirname(__FILE__) + '/../test_helper'
Chris@0 19 require 'admin_controller'
Chris@0 20
Chris@0 21 # Re-raise errors caught by the controller.
Chris@0 22 class AdminController; def rescue_action(e) raise e end; end
Chris@0 23
Chris@0 24 class AdminControllerTest < ActionController::TestCase
Chris@0 25 fixtures :projects, :users, :roles
Chris@0 26
Chris@0 27 def setup
Chris@0 28 @controller = AdminController.new
Chris@0 29 @request = ActionController::TestRequest.new
Chris@0 30 @response = ActionController::TestResponse.new
Chris@0 31 User.current = nil
Chris@0 32 @request.session[:user_id] = 1 # admin
Chris@0 33 end
Chris@0 34
Chris@0 35 def test_index
Chris@0 36 get :index
Chris@0 37 assert_no_tag :tag => 'div',
Chris@0 38 :attributes => { :class => /nodata/ }
Chris@0 39 end
Chris@0 40
Chris@0 41 def test_index_with_no_configuration_data
Chris@0 42 delete_configuration_data
Chris@0 43 get :index
Chris@0 44 assert_tag :tag => 'div',
Chris@0 45 :attributes => { :class => /nodata/ }
Chris@0 46 end
Chris@0 47
Chris@0 48 def test_projects
Chris@0 49 get :projects
Chris@0 50 assert_response :success
Chris@0 51 assert_template 'projects'
Chris@0 52 assert_not_nil assigns(:projects)
Chris@0 53 # active projects only
Chris@0 54 assert_nil assigns(:projects).detect {|u| !u.active?}
Chris@0 55 end
Chris@0 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@0 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@0 74
Chris@0 75 def test_test_email
Chris@0 76 get :test_email
Chris@0 77 assert_redirected_to '/settings/edit?tab=notifications'
Chris@0 78 mail = ActionMailer::Base.deliveries.last
Chris@0 79 assert_kind_of TMail::Mail, mail
Chris@0 80 user = User.find(1)
Chris@0 81 assert_equal [user.mail], mail.bcc
Chris@0 82 end
Chris@0 83
Chris@0 84 def test_no_plugins
Chris@0 85 Redmine::Plugin.clear
Chris@0 86
Chris@0 87 get :plugins
Chris@0 88 assert_response :success
Chris@0 89 assert_template 'plugins'
Chris@0 90 end
Chris@0 91
Chris@0 92 def test_plugins
Chris@0 93 # Register a few plugins
Chris@0 94 Redmine::Plugin.register :foo do
Chris@0 95 name 'Foo plugin'
Chris@0 96 author 'John Smith'
Chris@0 97 description 'This is a test plugin'
Chris@0 98 version '0.0.1'
Chris@0 99 settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings'
Chris@0 100 end
Chris@0 101 Redmine::Plugin.register :bar do
Chris@0 102 end
Chris@0 103
Chris@0 104 get :plugins
Chris@0 105 assert_response :success
Chris@0 106 assert_template 'plugins'
Chris@0 107
Chris@0 108 assert_tag :td, :child => { :tag => 'span', :content => 'Foo plugin' }
Chris@0 109 assert_tag :td, :child => { :tag => 'span', :content => 'Bar' }
Chris@0 110 end
Chris@0 111
Chris@0 112 def test_info
Chris@0 113 get :info
Chris@0 114 assert_response :success
Chris@0 115 assert_template 'info'
Chris@0 116 end
Chris@0 117
Chris@0 118 def test_admin_menu_plugin_extension
Chris@0 119 Redmine::MenuManager.map :admin_menu do |menu|
Chris@0 120 menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test'
Chris@0 121 end
Chris@0 122
Chris@0 123 get :index
Chris@0 124 assert_response :success
Chris@0 125 assert_tag :a, :attributes => { :href => '/foo/bar' },
Chris@0 126 :content => 'Test'
Chris@0 127
Chris@0 128 Redmine::MenuManager.map :admin_menu do |menu|
Chris@0 129 menu.delete :test_admin_menu_plugin_extension
Chris@0 130 end
Chris@0 131 end
Chris@0 132
Chris@0 133 private
Chris@0 134
Chris@0 135 def delete_configuration_data
Chris@0 136 Role.delete_all('builtin = 0')
Chris@0 137 Tracker.delete_all
Chris@0 138 IssueStatus.delete_all
Chris@0 139 Enumeration.delete_all
Chris@0 140 end
Chris@0 141 end