##// END OF EJS Templates
Adds test for test email failure....
Jean-Philippe Lang -
r7936:1337fcb3d99c
parent child
Show More
@@ -1,141 +1,148
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'
19 require 'admin_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class AdminController; def rescue_action(e) raise e end; end
22 class AdminController; def rescue_action(e) raise e end; end
23
23
24 class AdminControllerTest < ActionController::TestCase
24 class AdminControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles
25 fixtures :projects, :users, :roles
26
26
27 def setup
27 def setup
28 @controller = AdminController.new
28 @controller = AdminController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 @request.session[:user_id] = 1 # admin
32 @request.session[:user_id] = 1 # admin
33 end
33 end
34
34
35 def test_index
35 def test_index
36 get :index
36 get :index
37 assert_no_tag :tag => 'div',
37 assert_no_tag :tag => 'div',
38 :attributes => { :class => /nodata/ }
38 :attributes => { :class => /nodata/ }
39 end
39 end
40
40
41 def test_index_with_no_configuration_data
41 def test_index_with_no_configuration_data
42 delete_configuration_data
42 delete_configuration_data
43 get :index
43 get :index
44 assert_tag :tag => 'div',
44 assert_tag :tag => 'div',
45 :attributes => { :class => /nodata/ }
45 :attributes => { :class => /nodata/ }
46 end
46 end
47
47
48 def test_projects
48 def test_projects
49 get :projects
49 get :projects
50 assert_response :success
50 assert_response :success
51 assert_template 'projects'
51 assert_template 'projects'
52 assert_not_nil assigns(:projects)
52 assert_not_nil assigns(:projects)
53 # active projects only
53 # active projects only
54 assert_nil assigns(:projects).detect {|u| !u.active?}
54 assert_nil assigns(:projects).detect {|u| !u.active?}
55 end
55 end
56
56
57 def test_projects_with_name_filter
57 def test_projects_with_name_filter
58 get :projects, :name => 'store', :status => ''
58 get :projects, :name => 'store', :status => ''
59 assert_response :success
59 assert_response :success
60 assert_template 'projects'
60 assert_template 'projects'
61 projects = assigns(:projects)
61 projects = assigns(:projects)
62 assert_not_nil projects
62 assert_not_nil projects
63 assert_equal 1, projects.size
63 assert_equal 1, projects.size
64 assert_equal 'OnlineStore', projects.first.name
64 assert_equal 'OnlineStore', projects.first.name
65 end
65 end
66
66
67 def test_load_default_configuration_data
67 def test_load_default_configuration_data
68 delete_configuration_data
68 delete_configuration_data
69 post :default_configuration, :lang => 'fr'
69 post :default_configuration, :lang => 'fr'
70 assert_response :redirect
70 assert_response :redirect
71 assert_nil flash[:error]
71 assert_nil flash[:error]
72 assert IssueStatus.find_by_name('Nouveau')
72 assert IssueStatus.find_by_name('Nouveau')
73 end
73 end
74
74
75 def test_test_email
75 def test_test_email
76 get :test_email
76 get :test_email
77 assert_redirected_to '/settings/edit?tab=notifications'
77 assert_redirected_to '/settings/edit?tab=notifications'
78 mail = ActionMailer::Base.deliveries.last
78 mail = ActionMailer::Base.deliveries.last
79 assert_kind_of TMail::Mail, mail
79 assert_kind_of TMail::Mail, mail
80 user = User.find(1)
80 user = User.find(1)
81 assert_equal [user.mail], mail.bcc
81 assert_equal [user.mail], mail.bcc
82 end
82 end
83
83
84 def test_test_email_failure_should_display_the_error
85 Mailer.stubs(:deliver_test).raises(Exception, 'Some error message')
86 get :test_email
87 assert_redirected_to '/settings/edit?tab=notifications'
88 assert_match /Some error message/, flash[:error]
89 end
90
84 def test_no_plugins
91 def test_no_plugins
85 Redmine::Plugin.clear
92 Redmine::Plugin.clear
86
93
87 get :plugins
94 get :plugins
88 assert_response :success
95 assert_response :success
89 assert_template 'plugins'
96 assert_template 'plugins'
90 end
97 end
91
98
92 def test_plugins
99 def test_plugins
93 # Register a few plugins
100 # Register a few plugins
94 Redmine::Plugin.register :foo do
101 Redmine::Plugin.register :foo do
95 name 'Foo plugin'
102 name 'Foo plugin'
96 author 'John Smith'
103 author 'John Smith'
97 description 'This is a test plugin'
104 description 'This is a test plugin'
98 version '0.0.1'
105 version '0.0.1'
99 settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings'
106 settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings'
100 end
107 end
101 Redmine::Plugin.register :bar do
108 Redmine::Plugin.register :bar do
102 end
109 end
103
110
104 get :plugins
111 get :plugins
105 assert_response :success
112 assert_response :success
106 assert_template 'plugins'
113 assert_template 'plugins'
107
114
108 assert_tag :td, :child => { :tag => 'span', :content => 'Foo plugin' }
115 assert_tag :td, :child => { :tag => 'span', :content => 'Foo plugin' }
109 assert_tag :td, :child => { :tag => 'span', :content => 'Bar' }
116 assert_tag :td, :child => { :tag => 'span', :content => 'Bar' }
110 end
117 end
111
118
112 def test_info
119 def test_info
113 get :info
120 get :info
114 assert_response :success
121 assert_response :success
115 assert_template 'info'
122 assert_template 'info'
116 end
123 end
117
124
118 def test_admin_menu_plugin_extension
125 def test_admin_menu_plugin_extension
119 Redmine::MenuManager.map :admin_menu do |menu|
126 Redmine::MenuManager.map :admin_menu do |menu|
120 menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test'
127 menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test'
121 end
128 end
122
129
123 get :index
130 get :index
124 assert_response :success
131 assert_response :success
125 assert_tag :a, :attributes => { :href => '/foo/bar' },
132 assert_tag :a, :attributes => { :href => '/foo/bar' },
126 :content => 'Test'
133 :content => 'Test'
127
134
128 Redmine::MenuManager.map :admin_menu do |menu|
135 Redmine::MenuManager.map :admin_menu do |menu|
129 menu.delete :test_admin_menu_plugin_extension
136 menu.delete :test_admin_menu_plugin_extension
130 end
137 end
131 end
138 end
132
139
133 private
140 private
134
141
135 def delete_configuration_data
142 def delete_configuration_data
136 Role.delete_all('builtin = 0')
143 Role.delete_all('builtin = 0')
137 Tracker.delete_all
144 Tracker.delete_all
138 IssueStatus.delete_all
145 IssueStatus.delete_all
139 Enumeration.delete_all
146 Enumeration.delete_all
140 end
147 end
141 end
148 end
General Comments 0
You need to be logged in to leave comments. Login now