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