@@ -1,164 +1,178 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 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 |
|
19 | |||
20 | class AdminControllerTest < ActionController::TestCase |
|
20 | class AdminControllerTest < ActionController::TestCase | |
21 | fixtures :projects, :users, :roles |
|
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 | def setup |
|
32 | def setup | |
24 | User.current = nil |
|
33 | User.current = nil | |
25 | @request.session[:user_id] = 1 # admin |
|
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 | end |
|
40 | end | |
27 |
|
41 | |||
28 | def test_index |
|
42 | def test_index | |
29 | get :index |
|
43 | get :index | |
30 | assert_no_tag :tag => 'div', |
|
44 | assert_no_tag :tag => 'div', | |
31 | :attributes => { :class => /nodata/ } |
|
45 | :attributes => { :class => /nodata/ } | |
32 | end |
|
46 | end | |
33 |
|
47 | |||
34 | def test_index_with_no_configuration_data |
|
48 | def test_index_with_no_configuration_data | |
35 | delete_configuration_data |
|
49 | delete_configuration_data | |
36 | get :index |
|
50 | get :index | |
37 | assert_tag :tag => 'div', |
|
51 | assert_tag :tag => 'div', | |
38 | :attributes => { :class => /nodata/ } |
|
52 | :attributes => { :class => /nodata/ } | |
39 | end |
|
53 | end | |
40 |
|
54 | |||
41 | def test_projects |
|
55 | def test_projects | |
42 | get :projects |
|
56 | get :projects | |
43 | assert_response :success |
|
57 | assert_response :success | |
44 | assert_template 'projects' |
|
58 | assert_template 'projects' | |
45 | assert_not_nil assigns(:projects) |
|
59 | assert_not_nil assigns(:projects) | |
46 | # active projects only |
|
60 | # active projects only | |
47 | assert_nil assigns(:projects).detect {|u| !u.active?} |
|
61 | assert_nil assigns(:projects).detect {|u| !u.active?} | |
48 | end |
|
62 | end | |
49 |
|
63 | |||
50 | def test_projects_with_status_filter |
|
64 | def test_projects_with_status_filter | |
51 | get :projects, :status => 1 |
|
65 | get :projects, :status => 1 | |
52 | assert_response :success |
|
66 | assert_response :success | |
53 | assert_template 'projects' |
|
67 | assert_template 'projects' | |
54 | assert_not_nil assigns(:projects) |
|
68 | assert_not_nil assigns(:projects) | |
55 | # active projects only |
|
69 | # active projects only | |
56 | assert_nil assigns(:projects).detect {|u| !u.active?} |
|
70 | assert_nil assigns(:projects).detect {|u| !u.active?} | |
57 | end |
|
71 | end | |
58 |
|
72 | |||
59 | def test_projects_with_name_filter |
|
73 | def test_projects_with_name_filter | |
60 | get :projects, :name => 'store', :status => '' |
|
74 | get :projects, :name => 'store', :status => '' | |
61 | assert_response :success |
|
75 | assert_response :success | |
62 | assert_template 'projects' |
|
76 | assert_template 'projects' | |
63 | projects = assigns(:projects) |
|
77 | projects = assigns(:projects) | |
64 | assert_not_nil projects |
|
78 | assert_not_nil projects | |
65 | assert_equal 1, projects.size |
|
79 | assert_equal 1, projects.size | |
66 | assert_equal 'OnlineStore', projects.first.name |
|
80 | assert_equal 'OnlineStore', projects.first.name | |
67 | end |
|
81 | end | |
68 |
|
82 | |||
69 | def test_load_default_configuration_data |
|
83 | def test_load_default_configuration_data | |
70 | delete_configuration_data |
|
84 | delete_configuration_data | |
71 | post :default_configuration, :lang => 'fr' |
|
85 | post :default_configuration, :lang => 'fr' | |
72 | assert_response :redirect |
|
86 | assert_response :redirect | |
73 | assert_nil flash[:error] |
|
87 | assert_nil flash[:error] | |
74 | assert IssueStatus.find_by_name('Nouveau') |
|
88 | assert IssueStatus.find_by_name('Nouveau') | |
75 | end |
|
89 | end | |
76 |
|
90 | |||
77 | def test_load_default_configuration_data_should_rescue_error |
|
91 | def test_load_default_configuration_data_should_rescue_error | |
78 | delete_configuration_data |
|
92 | delete_configuration_data | |
79 | Redmine::DefaultData::Loader.stubs(:load).raises(Exception.new("Something went wrong")) |
|
93 | Redmine::DefaultData::Loader.stubs(:load).raises(Exception.new("Something went wrong")) | |
80 | post :default_configuration, :lang => 'fr' |
|
94 | post :default_configuration, :lang => 'fr' | |
81 | assert_response :redirect |
|
95 | assert_response :redirect | |
82 | assert_not_nil flash[:error] |
|
96 | assert_not_nil flash[:error] | |
83 | assert_match /Something went wrong/, flash[:error] |
|
97 | assert_match /Something went wrong/, flash[:error] | |
84 | end |
|
98 | end | |
85 |
|
99 | |||
86 | def test_test_email |
|
100 | def test_test_email | |
87 | user = User.find(1) |
|
101 | user = User.find(1) | |
88 | user.pref[:no_self_notified] = '1' |
|
102 | user.pref[:no_self_notified] = '1' | |
89 | user.pref.save! |
|
103 | user.pref.save! | |
90 | ActionMailer::Base.deliveries.clear |
|
104 | ActionMailer::Base.deliveries.clear | |
91 |
|
105 | |||
92 | get :test_email |
|
106 | get :test_email | |
93 | assert_redirected_to '/settings/edit?tab=notifications' |
|
107 | assert_redirected_to '/settings/edit?tab=notifications' | |
94 | mail = ActionMailer::Base.deliveries.last |
|
108 | mail = ActionMailer::Base.deliveries.last | |
95 | assert_not_nil mail |
|
109 | assert_not_nil mail | |
96 | user = User.find(1) |
|
110 | user = User.find(1) | |
97 | assert_equal [user.mail], mail.bcc |
|
111 | assert_equal [user.mail], mail.bcc | |
98 | end |
|
112 | end | |
99 |
|
113 | |||
100 | def test_test_email_failure_should_display_the_error |
|
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 | get :test_email |
|
116 | get :test_email | |
103 | assert_redirected_to '/settings/edit?tab=notifications' |
|
117 | assert_redirected_to '/settings/edit?tab=notifications' | |
104 | assert_match /Some error message/, flash[:error] |
|
118 | assert_match /Some error message/, flash[:error] | |
105 | end |
|
119 | end | |
106 |
|
120 | |||
107 | def test_no_plugins |
|
121 | def test_no_plugins | |
108 | Redmine::Plugin.clear |
|
122 | Redmine::Plugin.clear | |
109 |
|
123 | |||
110 | get :plugins |
|
124 | get :plugins | |
111 | assert_response :success |
|
125 | assert_response :success | |
112 | assert_template 'plugins' |
|
126 | assert_template 'plugins' | |
113 | end |
|
127 | end | |
114 |
|
128 | |||
115 | def test_plugins |
|
129 | def test_plugins | |
116 | # Register a few plugins |
|
130 | # Register a few plugins | |
117 | Redmine::Plugin.register :foo do |
|
131 | Redmine::Plugin.register :foo do | |
118 | name 'Foo plugin' |
|
132 | name 'Foo plugin' | |
119 | author 'John Smith' |
|
133 | author 'John Smith' | |
120 | description 'This is a test plugin' |
|
134 | description 'This is a test plugin' | |
121 | version '0.0.1' |
|
135 | version '0.0.1' | |
122 | settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings' |
|
136 | settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings' | |
123 | end |
|
137 | end | |
124 | Redmine::Plugin.register :bar do |
|
138 | Redmine::Plugin.register :bar do | |
125 | end |
|
139 | end | |
126 |
|
140 | |||
127 | get :plugins |
|
141 | get :plugins | |
128 | assert_response :success |
|
142 | assert_response :success | |
129 | assert_template 'plugins' |
|
143 | assert_template 'plugins' | |
130 |
|
144 | |||
131 | assert_tag :td, :child => { :tag => 'span', :content => 'Foo plugin' } |
|
145 | assert_tag :td, :child => { :tag => 'span', :content => 'Foo plugin' } | |
132 | assert_tag :td, :child => { :tag => 'span', :content => 'Bar' } |
|
146 | assert_tag :td, :child => { :tag => 'span', :content => 'Bar' } | |
133 | end |
|
147 | end | |
134 |
|
148 | |||
135 | def test_info |
|
149 | def test_info | |
136 | get :info |
|
150 | get :info | |
137 | assert_response :success |
|
151 | assert_response :success | |
138 | assert_template 'info' |
|
152 | assert_template 'info' | |
139 | end |
|
153 | end | |
140 |
|
154 | |||
141 | def test_admin_menu_plugin_extension |
|
155 | def test_admin_menu_plugin_extension | |
142 | Redmine::MenuManager.map :admin_menu do |menu| |
|
156 | Redmine::MenuManager.map :admin_menu do |menu| | |
143 | menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test' |
|
157 | menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test' | |
144 | end |
|
158 | end | |
145 |
|
159 | |||
146 | get :index |
|
160 | get :index | |
147 | assert_response :success |
|
161 | assert_response :success | |
148 | assert_tag :a, :attributes => { :href => '/foo/bar' }, |
|
162 | assert_tag :a, :attributes => { :href => '/foo/bar' }, | |
149 | :content => 'Test' |
|
163 | :content => 'Test' | |
150 |
|
164 | |||
151 | Redmine::MenuManager.map :admin_menu do |menu| |
|
165 | Redmine::MenuManager.map :admin_menu do |menu| | |
152 | menu.delete :test_admin_menu_plugin_extension |
|
166 | menu.delete :test_admin_menu_plugin_extension | |
153 | end |
|
167 | end | |
154 | end |
|
168 | end | |
155 |
|
169 | |||
156 | private |
|
170 | private | |
157 |
|
171 | |||
158 | def delete_configuration_data |
|
172 | def delete_configuration_data | |
159 | Role.delete_all('builtin = 0') |
|
173 | Role.delete_all('builtin = 0') | |
160 | Tracker.delete_all |
|
174 | Tracker.delete_all | |
161 | IssueStatus.delete_all |
|
175 | IssueStatus.delete_all | |
162 | Enumeration.delete_all |
|
176 | Enumeration.delete_all | |
163 | end |
|
177 | end | |
164 | end |
|
178 | end |
General Comments 0
You need to be logged in to leave comments.
Login now