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