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