@@ -1,501 +1,501 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 | require 'projects_controller' |
|
19 | require 'projects_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class ProjectsController; def rescue_action(e) raise e end; end |
|
22 | class ProjectsController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class ProjectsControllerTest < Test::Unit::TestCase |
|
24 | class ProjectsControllerTest < Test::Unit::TestCase | |
25 | fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details, |
|
25 | fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details, | |
26 | :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages, |
|
26 | :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages, | |
27 | :attachments |
|
27 | :attachments | |
28 |
|
28 | |||
29 | def setup |
|
29 | def setup | |
30 | @controller = ProjectsController.new |
|
30 | @controller = ProjectsController.new | |
31 | @request = ActionController::TestRequest.new |
|
31 | @request = ActionController::TestRequest.new | |
32 | @response = ActionController::TestResponse.new |
|
32 | @response = ActionController::TestResponse.new | |
33 | @request.session[:user_id] = nil |
|
33 | @request.session[:user_id] = nil | |
34 | Setting.default_language = 'en' |
|
34 | Setting.default_language = 'en' | |
35 | end |
|
35 | end | |
36 |
|
36 | |||
37 | def test_index_routing |
|
37 | def test_index_routing | |
38 | assert_routing( |
|
38 | assert_routing( | |
39 | {:method => :get, :path => '/projects'}, |
|
39 | {:method => :get, :path => '/projects'}, | |
40 | :controller => 'projects', :action => 'index' |
|
40 | :controller => 'projects', :action => 'index' | |
41 | ) |
|
41 | ) | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | def test_index |
|
44 | def test_index | |
45 | get :index |
|
45 | get :index | |
46 | assert_response :success |
|
46 | assert_response :success | |
47 | assert_template 'index' |
|
47 | assert_template 'index' | |
48 | assert_not_nil assigns(:projects) |
|
48 | assert_not_nil assigns(:projects) | |
49 |
|
49 | |||
50 | assert_tag :ul, :child => {:tag => 'li', |
|
50 | assert_tag :ul, :child => {:tag => 'li', | |
51 | :descendant => {:tag => 'a', :content => 'eCookbook'}, |
|
51 | :descendant => {:tag => 'a', :content => 'eCookbook'}, | |
52 | :child => { :tag => 'ul', |
|
52 | :child => { :tag => 'ul', | |
53 | :descendant => { :tag => 'a', |
|
53 | :descendant => { :tag => 'a', | |
54 | :content => 'Child of private child' |
|
54 | :content => 'Child of private child' | |
55 | } |
|
55 | } | |
56 | } |
|
56 | } | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | assert_no_tag :a, :content => /Private child of eCookbook/ |
|
59 | assert_no_tag :a, :content => /Private child of eCookbook/ | |
60 | end |
|
60 | end | |
61 |
|
61 | |||
62 | def test_index_atom_routing |
|
62 | def test_index_atom_routing | |
63 | assert_routing( |
|
63 | assert_routing( | |
64 | {:method => :get, :path => '/projects.atom'}, |
|
64 | {:method => :get, :path => '/projects.atom'}, | |
65 | :controller => 'projects', :action => 'index', :format => 'atom' |
|
65 | :controller => 'projects', :action => 'index', :format => 'atom' | |
66 | ) |
|
66 | ) | |
67 | end |
|
67 | end | |
68 |
|
68 | |||
69 | def test_index_atom |
|
69 | def test_index_atom | |
70 | get :index, :format => 'atom' |
|
70 | get :index, :format => 'atom' | |
71 | assert_response :success |
|
71 | assert_response :success | |
72 | assert_template 'common/feed.atom.rxml' |
|
72 | assert_template 'common/feed.atom.rxml' | |
73 | assert_select 'feed>title', :text => 'Redmine: Latest projects' |
|
73 | assert_select 'feed>title', :text => 'Redmine: Latest projects' | |
74 | assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_by(User.current)) |
|
74 | assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_by(User.current)) | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | def test_add_routing |
|
77 | def test_add_routing | |
78 | assert_routing( |
|
78 | assert_routing( | |
79 | {:method => :get, :path => '/projects/new'}, |
|
79 | {:method => :get, :path => '/projects/new'}, | |
80 | :controller => 'projects', :action => 'add' |
|
80 | :controller => 'projects', :action => 'add' | |
81 | ) |
|
81 | ) | |
82 | assert_recognizes( |
|
82 | assert_recognizes( | |
83 | {:controller => 'projects', :action => 'add'}, |
|
83 | {:controller => 'projects', :action => 'add'}, | |
84 | {:method => :post, :path => '/projects/new'} |
|
84 | {:method => :post, :path => '/projects/new'} | |
85 | ) |
|
85 | ) | |
86 | assert_recognizes( |
|
86 | assert_recognizes( | |
87 | {:controller => 'projects', :action => 'add'}, |
|
87 | {:controller => 'projects', :action => 'add'}, | |
88 | {:method => :post, :path => '/projects'} |
|
88 | {:method => :post, :path => '/projects'} | |
89 | ) |
|
89 | ) | |
90 | end |
|
90 | end | |
91 |
|
91 | |||
92 | def test_show_routing |
|
92 | def test_show_routing | |
93 | assert_routing( |
|
93 | assert_routing( | |
94 | {:method => :get, :path => '/projects/test'}, |
|
94 | {:method => :get, :path => '/projects/test'}, | |
95 | :controller => 'projects', :action => 'show', :id => 'test' |
|
95 | :controller => 'projects', :action => 'show', :id => 'test' | |
96 | ) |
|
96 | ) | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
99 | def test_show_by_id |
|
99 | def test_show_by_id | |
100 | get :show, :id => 1 |
|
100 | get :show, :id => 1 | |
101 | assert_response :success |
|
101 | assert_response :success | |
102 | assert_template 'show' |
|
102 | assert_template 'show' | |
103 | assert_not_nil assigns(:project) |
|
103 | assert_not_nil assigns(:project) | |
104 | end |
|
104 | end | |
105 |
|
105 | |||
106 | def test_show_by_identifier |
|
106 | def test_show_by_identifier | |
107 | get :show, :id => 'ecookbook' |
|
107 | get :show, :id => 'ecookbook' | |
108 | assert_response :success |
|
108 | assert_response :success | |
109 | assert_template 'show' |
|
109 | assert_template 'show' | |
110 | assert_not_nil assigns(:project) |
|
110 | assert_not_nil assigns(:project) | |
111 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) |
|
111 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) | |
112 | end |
|
112 | end | |
113 |
|
113 | |||
114 | def test_private_subprojects_hidden |
|
114 | def test_private_subprojects_hidden | |
115 | get :show, :id => 'ecookbook' |
|
115 | get :show, :id => 'ecookbook' | |
116 | assert_response :success |
|
116 | assert_response :success | |
117 | assert_template 'show' |
|
117 | assert_template 'show' | |
118 | assert_no_tag :tag => 'a', :content => /Private child/ |
|
118 | assert_no_tag :tag => 'a', :content => /Private child/ | |
119 | end |
|
119 | end | |
120 |
|
120 | |||
121 | def test_private_subprojects_visible |
|
121 | def test_private_subprojects_visible | |
122 | @request.session[:user_id] = 2 # manager who is a member of the private subproject |
|
122 | @request.session[:user_id] = 2 # manager who is a member of the private subproject | |
123 | get :show, :id => 'ecookbook' |
|
123 | get :show, :id => 'ecookbook' | |
124 | assert_response :success |
|
124 | assert_response :success | |
125 | assert_template 'show' |
|
125 | assert_template 'show' | |
126 | assert_tag :tag => 'a', :content => /Private child/ |
|
126 | assert_tag :tag => 'a', :content => /Private child/ | |
127 | end |
|
127 | end | |
128 |
|
128 | |||
129 | def test_settings_routing |
|
129 | def test_settings_routing | |
130 | assert_routing( |
|
130 | assert_routing( | |
131 | {:method => :get, :path => '/projects/4223/settings'}, |
|
131 | {:method => :get, :path => '/projects/4223/settings'}, | |
132 | :controller => 'projects', :action => 'settings', :id => '4223' |
|
132 | :controller => 'projects', :action => 'settings', :id => '4223' | |
133 | ) |
|
133 | ) | |
134 | assert_routing( |
|
134 | assert_routing( | |
135 | {:method => :get, :path => '/projects/4223/settings/members'}, |
|
135 | {:method => :get, :path => '/projects/4223/settings/members'}, | |
136 | :controller => 'projects', :action => 'settings', :id => '4223', :tab => 'members' |
|
136 | :controller => 'projects', :action => 'settings', :id => '4223', :tab => 'members' | |
137 | ) |
|
137 | ) | |
138 | end |
|
138 | end | |
139 |
|
139 | |||
140 | def test_settings |
|
140 | def test_settings | |
141 | @request.session[:user_id] = 2 # manager |
|
141 | @request.session[:user_id] = 2 # manager | |
142 | get :settings, :id => 1 |
|
142 | get :settings, :id => 1 | |
143 | assert_response :success |
|
143 | assert_response :success | |
144 | assert_template 'settings' |
|
144 | assert_template 'settings' | |
145 | end |
|
145 | end | |
146 |
|
146 | |||
147 | def test_edit |
|
147 | def test_edit | |
148 | @request.session[:user_id] = 2 # manager |
|
148 | @request.session[:user_id] = 2 # manager | |
149 | post :edit, :id => 1, :project => {:name => 'Test changed name', |
|
149 | post :edit, :id => 1, :project => {:name => 'Test changed name', | |
150 | :issue_custom_field_ids => ['']} |
|
150 | :issue_custom_field_ids => ['']} | |
151 | assert_redirected_to 'projects/ecookbook/settings' |
|
151 | assert_redirected_to 'projects/ecookbook/settings' | |
152 | project = Project.find(1) |
|
152 | project = Project.find(1) | |
153 | assert_equal 'Test changed name', project.name |
|
153 | assert_equal 'Test changed name', project.name | |
154 | end |
|
154 | end | |
155 |
|
155 | |||
156 | def test_add_version_routing |
|
156 | def test_add_version_routing | |
157 | assert_routing( |
|
157 | assert_routing( | |
158 | {:method => :get, :path => 'projects/64/versions/new'}, |
|
158 | {:method => :get, :path => 'projects/64/versions/new'}, | |
159 | :controller => 'projects', :action => 'add_version', :id => '64' |
|
159 | :controller => 'projects', :action => 'add_version', :id => '64' | |
160 | ) |
|
160 | ) | |
161 | assert_routing( |
|
161 | assert_routing( | |
162 | #TODO: use PUT |
|
162 | #TODO: use PUT | |
163 | {:method => :post, :path => 'projects/64/versions/new'}, |
|
163 | {:method => :post, :path => 'projects/64/versions/new'}, | |
164 | :controller => 'projects', :action => 'add_version', :id => '64' |
|
164 | :controller => 'projects', :action => 'add_version', :id => '64' | |
165 | ) |
|
165 | ) | |
166 | end |
|
166 | end | |
167 |
|
167 | |||
168 | def test_add_issue_category_routing |
|
168 | def test_add_issue_category_routing | |
169 | assert_routing( |
|
169 | assert_routing( | |
170 | {:method => :get, :path => 'projects/test/categories/new'}, |
|
170 | {:method => :get, :path => 'projects/test/categories/new'}, | |
171 | :controller => 'projects', :action => 'add_issue_category', :id => 'test' |
|
171 | :controller => 'projects', :action => 'add_issue_category', :id => 'test' | |
172 | ) |
|
172 | ) | |
173 | assert_routing( |
|
173 | assert_routing( | |
174 | #TODO: use PUT and update form |
|
174 | #TODO: use PUT and update form | |
175 | {:method => :post, :path => 'projects/64/categories/new'}, |
|
175 | {:method => :post, :path => 'projects/64/categories/new'}, | |
176 | :controller => 'projects', :action => 'add_issue_category', :id => '64' |
|
176 | :controller => 'projects', :action => 'add_issue_category', :id => '64' | |
177 | ) |
|
177 | ) | |
178 | end |
|
178 | end | |
179 |
|
179 | |||
180 | def test_destroy_routing |
|
180 | def test_destroy_routing | |
181 | assert_routing( |
|
181 | assert_routing( | |
182 | {:method => :get, :path => '/projects/567/destroy'}, |
|
182 | {:method => :get, :path => '/projects/567/destroy'}, | |
183 | :controller => 'projects', :action => 'destroy', :id => '567' |
|
183 | :controller => 'projects', :action => 'destroy', :id => '567' | |
184 | ) |
|
184 | ) | |
185 | assert_routing( |
|
185 | assert_routing( | |
186 | #TODO: use DELETE and update form |
|
186 | #TODO: use DELETE and update form | |
187 | {:method => :post, :path => 'projects/64/destroy'}, |
|
187 | {:method => :post, :path => 'projects/64/destroy'}, | |
188 | :controller => 'projects', :action => 'destroy', :id => '64' |
|
188 | :controller => 'projects', :action => 'destroy', :id => '64' | |
189 | ) |
|
189 | ) | |
190 | end |
|
190 | end | |
191 |
|
191 | |||
192 | def test_get_destroy |
|
192 | def test_get_destroy | |
193 | @request.session[:user_id] = 1 # admin |
|
193 | @request.session[:user_id] = 1 # admin | |
194 | get :destroy, :id => 1 |
|
194 | get :destroy, :id => 1 | |
195 | assert_response :success |
|
195 | assert_response :success | |
196 | assert_template 'destroy' |
|
196 | assert_template 'destroy' | |
197 | assert_not_nil Project.find_by_id(1) |
|
197 | assert_not_nil Project.find_by_id(1) | |
198 | end |
|
198 | end | |
199 |
|
199 | |||
200 | def test_post_destroy |
|
200 | def test_post_destroy | |
201 | @request.session[:user_id] = 1 # admin |
|
201 | @request.session[:user_id] = 1 # admin | |
202 | post :destroy, :id => 1, :confirm => 1 |
|
202 | post :destroy, :id => 1, :confirm => 1 | |
203 | assert_redirected_to 'admin/projects' |
|
203 | assert_redirected_to 'admin/projects' | |
204 | assert_nil Project.find_by_id(1) |
|
204 | assert_nil Project.find_by_id(1) | |
205 | end |
|
205 | end | |
206 |
|
206 | |||
207 | def test_add_file |
|
207 | def test_add_file | |
208 | set_tmp_attachments_directory |
|
208 | set_tmp_attachments_directory | |
209 | @request.session[:user_id] = 2 |
|
209 | @request.session[:user_id] = 2 | |
210 | Setting.notified_events = ['file_added'] |
|
210 | Setting.notified_events = ['file_added'] | |
211 | ActionMailer::Base.deliveries.clear |
|
211 | ActionMailer::Base.deliveries.clear | |
212 |
|
212 | |||
213 | assert_difference 'Attachment.count' do |
|
213 | assert_difference 'Attachment.count' do | |
214 | post :add_file, :id => 1, :version_id => '', |
|
214 | post :add_file, :id => 1, :version_id => '', | |
215 | :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}} |
|
215 | :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}} | |
216 | end |
|
216 | end | |
217 | assert_redirected_to 'projects/ecookbook/files' |
|
217 | assert_redirected_to 'projects/ecookbook/files' | |
218 | a = Attachment.find(:first, :order => 'created_on DESC') |
|
218 | a = Attachment.find(:first, :order => 'created_on DESC') | |
219 | assert_equal 'testfile.txt', a.filename |
|
219 | assert_equal 'testfile.txt', a.filename | |
220 | assert_equal Project.find(1), a.container |
|
220 | assert_equal Project.find(1), a.container | |
221 |
|
221 | |||
222 | mail = ActionMailer::Base.deliveries.last |
|
222 | mail = ActionMailer::Base.deliveries.last | |
223 | assert_kind_of TMail::Mail, mail |
|
223 | assert_kind_of TMail::Mail, mail | |
224 | assert_equal "[eCookbook] New file", mail.subject |
|
224 | assert_equal "[eCookbook] New file", mail.subject | |
225 | assert mail.body.include?('testfile.txt') |
|
225 | assert mail.body.include?('testfile.txt') | |
226 | end |
|
226 | end | |
227 |
|
227 | |||
228 | def test_add_file_routing |
|
228 | def test_add_file_routing | |
229 | assert_routing( |
|
229 | assert_routing( | |
230 | {:method => :get, :path => '/projects/33/files/new'}, |
|
230 | {:method => :get, :path => '/projects/33/files/new'}, | |
231 | :controller => 'projects', :action => 'add_file', :id => '33' |
|
231 | :controller => 'projects', :action => 'add_file', :id => '33' | |
232 | ) |
|
232 | ) | |
233 | assert_routing( |
|
233 | assert_routing( | |
234 | {:method => :post, :path => '/projects/33/files/new'}, |
|
234 | {:method => :post, :path => '/projects/33/files/new'}, | |
235 | :controller => 'projects', :action => 'add_file', :id => '33' |
|
235 | :controller => 'projects', :action => 'add_file', :id => '33' | |
236 | ) |
|
236 | ) | |
237 | end |
|
237 | end | |
238 |
|
238 | |||
239 | def test_add_version_file |
|
239 | def test_add_version_file | |
240 | set_tmp_attachments_directory |
|
240 | set_tmp_attachments_directory | |
241 | @request.session[:user_id] = 2 |
|
241 | @request.session[:user_id] = 2 | |
242 | Setting.notified_events = ['file_added'] |
|
242 | Setting.notified_events = ['file_added'] | |
243 |
|
243 | |||
244 | assert_difference 'Attachment.count' do |
|
244 | assert_difference 'Attachment.count' do | |
245 | post :add_file, :id => 1, :version_id => '2', |
|
245 | post :add_file, :id => 1, :version_id => '2', | |
246 | :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}} |
|
246 | :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}} | |
247 | end |
|
247 | end | |
248 | assert_redirected_to 'projects/ecookbook/files' |
|
248 | assert_redirected_to 'projects/ecookbook/files' | |
249 | a = Attachment.find(:first, :order => 'created_on DESC') |
|
249 | a = Attachment.find(:first, :order => 'created_on DESC') | |
250 | assert_equal 'testfile.txt', a.filename |
|
250 | assert_equal 'testfile.txt', a.filename | |
251 | assert_equal Version.find(2), a.container |
|
251 | assert_equal Version.find(2), a.container | |
252 | end |
|
252 | end | |
253 |
|
253 | |||
254 | def test_list_files |
|
254 | def test_list_files | |
255 | get :list_files, :id => 1 |
|
255 | get :list_files, :id => 1 | |
256 | assert_response :success |
|
256 | assert_response :success | |
257 | assert_template 'list_files' |
|
257 | assert_template 'list_files' | |
258 | assert_not_nil assigns(:containers) |
|
258 | assert_not_nil assigns(:containers) | |
259 |
|
259 | |||
260 | # file attached to the project |
|
260 | # file attached to the project | |
261 | assert_tag :a, :content => 'project_file.zip', |
|
261 | assert_tag :a, :content => 'project_file.zip', | |
262 | :attributes => { :href => '/attachments/download/8/project_file.zip' } |
|
262 | :attributes => { :href => '/attachments/download/8/project_file.zip' } | |
263 |
|
263 | |||
264 | # file attached to a project's version |
|
264 | # file attached to a project's version | |
265 | assert_tag :a, :content => 'version_file.zip', |
|
265 | assert_tag :a, :content => 'version_file.zip', | |
266 | :attributes => { :href => '/attachments/download/9/version_file.zip' } |
|
266 | :attributes => { :href => '/attachments/download/9/version_file.zip' } | |
267 | end |
|
267 | end | |
268 |
|
268 | |||
269 | def test_list_files_routing |
|
269 | def test_list_files_routing | |
270 | assert_routing( |
|
270 | assert_routing( | |
271 | {:method => :get, :path => '/projects/33/files'}, |
|
271 | {:method => :get, :path => '/projects/33/files'}, | |
272 | :controller => 'projects', :action => 'list_files', :id => '33' |
|
272 | :controller => 'projects', :action => 'list_files', :id => '33' | |
273 | ) |
|
273 | ) | |
274 | end |
|
274 | end | |
275 |
|
275 | |||
276 | def test_changelog_routing |
|
276 | def test_changelog_routing | |
277 | assert_routing( |
|
277 | assert_routing( | |
278 | {:method => :get, :path => '/projects/44/changelog'}, |
|
278 | {:method => :get, :path => '/projects/44/changelog'}, | |
279 | :controller => 'projects', :action => 'changelog', :id => '44' |
|
279 | :controller => 'projects', :action => 'changelog', :id => '44' | |
280 | ) |
|
280 | ) | |
281 | end |
|
281 | end | |
282 |
|
282 | |||
283 | def test_changelog |
|
283 | def test_changelog | |
284 | get :changelog, :id => 1 |
|
284 | get :changelog, :id => 1 | |
285 | assert_response :success |
|
285 | assert_response :success | |
286 | assert_template 'changelog' |
|
286 | assert_template 'changelog' | |
287 | assert_not_nil assigns(:versions) |
|
287 | assert_not_nil assigns(:versions) | |
288 | end |
|
288 | end | |
289 |
|
289 | |||
290 | def test_roadmap_routing |
|
290 | def test_roadmap_routing | |
291 | assert_routing( |
|
291 | assert_routing( | |
292 | {:method => :get, :path => 'projects/33/roadmap'}, |
|
292 | {:method => :get, :path => 'projects/33/roadmap'}, | |
293 | :controller => 'projects', :action => 'roadmap', :id => '33' |
|
293 | :controller => 'projects', :action => 'roadmap', :id => '33' | |
294 | ) |
|
294 | ) | |
295 | end |
|
295 | end | |
296 |
|
296 | |||
297 | def test_roadmap |
|
297 | def test_roadmap | |
298 | get :roadmap, :id => 1 |
|
298 | get :roadmap, :id => 1 | |
299 | assert_response :success |
|
299 | assert_response :success | |
300 | assert_template 'roadmap' |
|
300 | assert_template 'roadmap' | |
301 | assert_not_nil assigns(:versions) |
|
301 | assert_not_nil assigns(:versions) | |
302 | # Version with no date set appears |
|
302 | # Version with no date set appears | |
303 | assert assigns(:versions).include?(Version.find(3)) |
|
303 | assert assigns(:versions).include?(Version.find(3)) | |
304 | # Completed version doesn't appear |
|
304 | # Completed version doesn't appear | |
305 | assert !assigns(:versions).include?(Version.find(1)) |
|
305 | assert !assigns(:versions).include?(Version.find(1)) | |
306 | end |
|
306 | end | |
307 |
|
307 | |||
308 | def test_roadmap_with_completed_versions |
|
308 | def test_roadmap_with_completed_versions | |
309 | get :roadmap, :id => 1, :completed => 1 |
|
309 | get :roadmap, :id => 1, :completed => 1 | |
310 | assert_response :success |
|
310 | assert_response :success | |
311 | assert_template 'roadmap' |
|
311 | assert_template 'roadmap' | |
312 | assert_not_nil assigns(:versions) |
|
312 | assert_not_nil assigns(:versions) | |
313 | # Version with no date set appears |
|
313 | # Version with no date set appears | |
314 | assert assigns(:versions).include?(Version.find(3)) |
|
314 | assert assigns(:versions).include?(Version.find(3)) | |
315 | # Completed version appears |
|
315 | # Completed version appears | |
316 | assert assigns(:versions).include?(Version.find(1)) |
|
316 | assert assigns(:versions).include?(Version.find(1)) | |
317 | end |
|
317 | end | |
318 |
|
318 | |||
319 | def test_project_activity_routing |
|
319 | def test_project_activity_routing | |
320 | assert_routing( |
|
320 | assert_routing( | |
321 | {:method => :get, :path => '/projects/1/activity'}, |
|
321 | {:method => :get, :path => '/projects/1/activity'}, | |
322 | :controller => 'projects', :action => 'activity', :id => '1' |
|
322 | :controller => 'projects', :action => 'activity', :id => '1' | |
323 | ) |
|
323 | ) | |
324 | end |
|
324 | end | |
325 |
|
325 | |||
326 | def test_project_activity_atom_routing |
|
326 | def test_project_activity_atom_routing | |
327 | assert_routing( |
|
327 | assert_routing( | |
328 | {:method => :get, :path => '/projects/1/activity.atom'}, |
|
328 | {:method => :get, :path => '/projects/1/activity.atom'}, | |
329 | :controller => 'projects', :action => 'activity', :id => '1', :format => 'atom' |
|
329 | :controller => 'projects', :action => 'activity', :id => '1', :format => 'atom' | |
330 | ) |
|
330 | ) | |
331 | end |
|
331 | end | |
332 |
|
332 | |||
333 | def test_project_activity |
|
333 | def test_project_activity | |
334 | get :activity, :id => 1, :with_subprojects => 0 |
|
334 | get :activity, :id => 1, :with_subprojects => 0 | |
335 | assert_response :success |
|
335 | assert_response :success | |
336 | assert_template 'activity' |
|
336 | assert_template 'activity' | |
337 | assert_not_nil assigns(:events_by_day) |
|
337 | assert_not_nil assigns(:events_by_day) | |
338 |
|
338 | |||
339 | assert_tag :tag => "h3", |
|
339 | assert_tag :tag => "h3", | |
340 | :content => /#{2.days.ago.to_date.day}/, |
|
340 | :content => /#{2.days.ago.to_date.day}/, | |
341 | :sibling => { :tag => "dl", |
|
341 | :sibling => { :tag => "dl", | |
342 | :child => { :tag => "dt", |
|
342 | :child => { :tag => "dt", | |
343 | :attributes => { :class => /issue-edit/ }, |
|
343 | :attributes => { :class => /issue-edit/ }, | |
344 | :child => { :tag => "a", |
|
344 | :child => { :tag => "a", | |
345 | :content => /(#{IssueStatus.find(2).name})/, |
|
345 | :content => /(#{IssueStatus.find(2).name})/, | |
346 | } |
|
346 | } | |
347 | } |
|
347 | } | |
348 | } |
|
348 | } | |
349 | end |
|
349 | end | |
350 |
|
350 | |||
351 | def test_previous_project_activity |
|
351 | def test_previous_project_activity | |
352 | get :activity, :id => 1, :from => 3.days.ago.to_date |
|
352 | get :activity, :id => 1, :from => 3.days.ago.to_date | |
353 | assert_response :success |
|
353 | assert_response :success | |
354 | assert_template 'activity' |
|
354 | assert_template 'activity' | |
355 | assert_not_nil assigns(:events_by_day) |
|
355 | assert_not_nil assigns(:events_by_day) | |
356 |
|
356 | |||
357 | assert_tag :tag => "h3", |
|
357 | assert_tag :tag => "h3", | |
358 | :content => /#{3.day.ago.to_date.day}/, |
|
358 | :content => /#{3.day.ago.to_date.day}/, | |
359 | :sibling => { :tag => "dl", |
|
359 | :sibling => { :tag => "dl", | |
360 | :child => { :tag => "dt", |
|
360 | :child => { :tag => "dt", | |
361 | :attributes => { :class => /issue/ }, |
|
361 | :attributes => { :class => /issue/ }, | |
362 | :child => { :tag => "a", |
|
362 | :child => { :tag => "a", | |
363 | :content => /#{Issue.find(1).subject}/, |
|
363 | :content => /#{Issue.find(1).subject}/, | |
364 | } |
|
364 | } | |
365 | } |
|
365 | } | |
366 | } |
|
366 | } | |
367 | end |
|
367 | end | |
368 |
|
368 | |||
369 | def test_global_activity_routing |
|
369 | def test_global_activity_routing | |
370 | assert_routing({:method => :get, :path => '/activity'}, :controller => 'projects', :action => 'activity') |
|
370 | assert_routing({:method => :get, :path => '/activity'}, :controller => 'projects', :action => 'activity', :id => nil) | |
371 | end |
|
371 | end | |
372 |
|
372 | |||
373 | def test_global_activity |
|
373 | def test_global_activity | |
374 | get :activity |
|
374 | get :activity | |
375 | assert_response :success |
|
375 | assert_response :success | |
376 | assert_template 'activity' |
|
376 | assert_template 'activity' | |
377 | assert_not_nil assigns(:events_by_day) |
|
377 | assert_not_nil assigns(:events_by_day) | |
378 |
|
378 | |||
379 | assert_tag :tag => "h3", |
|
379 | assert_tag :tag => "h3", | |
380 | :content => /#{5.day.ago.to_date.day}/, |
|
380 | :content => /#{5.day.ago.to_date.day}/, | |
381 | :sibling => { :tag => "dl", |
|
381 | :sibling => { :tag => "dl", | |
382 | :child => { :tag => "dt", |
|
382 | :child => { :tag => "dt", | |
383 | :attributes => { :class => /issue/ }, |
|
383 | :attributes => { :class => /issue/ }, | |
384 | :child => { :tag => "a", |
|
384 | :child => { :tag => "a", | |
385 | :content => /#{Issue.find(5).subject}/, |
|
385 | :content => /#{Issue.find(5).subject}/, | |
386 | } |
|
386 | } | |
387 | } |
|
387 | } | |
388 | } |
|
388 | } | |
389 | end |
|
389 | end | |
390 |
|
390 | |||
391 | def test_user_activity |
|
391 | def test_user_activity | |
392 | get :activity, :user_id => 2 |
|
392 | get :activity, :user_id => 2 | |
393 | assert_response :success |
|
393 | assert_response :success | |
394 | assert_template 'activity' |
|
394 | assert_template 'activity' | |
395 | assert_not_nil assigns(:events_by_day) |
|
395 | assert_not_nil assigns(:events_by_day) | |
396 |
|
396 | |||
397 | assert_tag :tag => "h3", |
|
397 | assert_tag :tag => "h3", | |
398 | :content => /#{3.day.ago.to_date.day}/, |
|
398 | :content => /#{3.day.ago.to_date.day}/, | |
399 | :sibling => { :tag => "dl", |
|
399 | :sibling => { :tag => "dl", | |
400 | :child => { :tag => "dt", |
|
400 | :child => { :tag => "dt", | |
401 | :attributes => { :class => /issue/ }, |
|
401 | :attributes => { :class => /issue/ }, | |
402 | :child => { :tag => "a", |
|
402 | :child => { :tag => "a", | |
403 | :content => /#{Issue.find(1).subject}/, |
|
403 | :content => /#{Issue.find(1).subject}/, | |
404 | } |
|
404 | } | |
405 | } |
|
405 | } | |
406 | } |
|
406 | } | |
407 | end |
|
407 | end | |
408 |
|
408 | |||
409 | def test_global_activity_atom_routing |
|
409 | def test_global_activity_atom_routing | |
410 | assert_routing({:method => :get, :path => '/activity.atom'}, :controller => 'projects', :action => 'activity', :format => 'atom') |
|
410 | assert_routing({:method => :get, :path => '/activity.atom'}, :controller => 'projects', :action => 'activity', :id => nil, :format => 'atom') | |
411 | end |
|
411 | end | |
412 |
|
412 | |||
413 | def test_activity_atom_feed |
|
413 | def test_activity_atom_feed | |
414 | get :activity, :format => 'atom' |
|
414 | get :activity, :format => 'atom' | |
415 | assert_response :success |
|
415 | assert_response :success | |
416 | assert_template 'common/feed.atom.rxml' |
|
416 | assert_template 'common/feed.atom.rxml' | |
417 | end |
|
417 | end | |
418 |
|
418 | |||
419 | def test_archive_routing |
|
419 | def test_archive_routing | |
420 | assert_routing( |
|
420 | assert_routing( | |
421 | #TODO: use PUT to project path and modify form |
|
421 | #TODO: use PUT to project path and modify form | |
422 | {:method => :post, :path => 'projects/64/archive'}, |
|
422 | {:method => :post, :path => 'projects/64/archive'}, | |
423 | :controller => 'projects', :action => 'archive', :id => '64' |
|
423 | :controller => 'projects', :action => 'archive', :id => '64' | |
424 | ) |
|
424 | ) | |
425 | end |
|
425 | end | |
426 |
|
426 | |||
427 | def test_archive |
|
427 | def test_archive | |
428 | @request.session[:user_id] = 1 # admin |
|
428 | @request.session[:user_id] = 1 # admin | |
429 | post :archive, :id => 1 |
|
429 | post :archive, :id => 1 | |
430 | assert_redirected_to 'admin/projects' |
|
430 | assert_redirected_to 'admin/projects' | |
431 | assert !Project.find(1).active? |
|
431 | assert !Project.find(1).active? | |
432 | end |
|
432 | end | |
433 |
|
433 | |||
434 | def test_unarchive_routing |
|
434 | def test_unarchive_routing | |
435 | assert_routing( |
|
435 | assert_routing( | |
436 | #TODO: use PUT to project path and modify form |
|
436 | #TODO: use PUT to project path and modify form | |
437 | {:method => :post, :path => '/projects/567/unarchive'}, |
|
437 | {:method => :post, :path => '/projects/567/unarchive'}, | |
438 | :controller => 'projects', :action => 'unarchive', :id => '567' |
|
438 | :controller => 'projects', :action => 'unarchive', :id => '567' | |
439 | ) |
|
439 | ) | |
440 | end |
|
440 | end | |
441 |
|
441 | |||
442 | def test_unarchive |
|
442 | def test_unarchive | |
443 | @request.session[:user_id] = 1 # admin |
|
443 | @request.session[:user_id] = 1 # admin | |
444 | Project.find(1).archive |
|
444 | Project.find(1).archive | |
445 | post :unarchive, :id => 1 |
|
445 | post :unarchive, :id => 1 | |
446 | assert_redirected_to 'admin/projects' |
|
446 | assert_redirected_to 'admin/projects' | |
447 | assert Project.find(1).active? |
|
447 | assert Project.find(1).active? | |
448 | end |
|
448 | end | |
449 |
|
449 | |||
450 | def test_project_breadcrumbs_should_be_limited_to_3_ancestors |
|
450 | def test_project_breadcrumbs_should_be_limited_to_3_ancestors | |
451 | CustomField.delete_all |
|
451 | CustomField.delete_all | |
452 | parent = nil |
|
452 | parent = nil | |
453 | 6.times do |i| |
|
453 | 6.times do |i| | |
454 | p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}") |
|
454 | p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}") | |
455 | p.set_parent!(parent) |
|
455 | p.set_parent!(parent) | |
456 |
|
456 | |||
457 | get :show, :id => p |
|
457 | get :show, :id => p | |
458 | assert_tag :h1, :parent => { :attributes => {:id => 'header'}}, |
|
458 | assert_tag :h1, :parent => { :attributes => {:id => 'header'}}, | |
459 | :children => { :count => [i, 3].min, |
|
459 | :children => { :count => [i, 3].min, | |
460 | :only => { :tag => 'a' } } |
|
460 | :only => { :tag => 'a' } } | |
461 |
|
461 | |||
462 | parent = p |
|
462 | parent = p | |
463 | end |
|
463 | end | |
464 | end |
|
464 | end | |
465 |
|
465 | |||
466 | def test_jump_should_redirect_to_active_tab |
|
466 | def test_jump_should_redirect_to_active_tab | |
467 | get :show, :id => 1, :jump => 'issues' |
|
467 | get :show, :id => 1, :jump => 'issues' | |
468 | assert_redirected_to 'projects/ecookbook/issues' |
|
468 | assert_redirected_to 'projects/ecookbook/issues' | |
469 | end |
|
469 | end | |
470 |
|
470 | |||
471 | def test_jump_should_not_redirect_to_inactive_tab |
|
471 | def test_jump_should_not_redirect_to_inactive_tab | |
472 | get :show, :id => 3, :jump => 'documents' |
|
472 | get :show, :id => 3, :jump => 'documents' | |
473 | assert_response :success |
|
473 | assert_response :success | |
474 | assert_template 'show' |
|
474 | assert_template 'show' | |
475 | end |
|
475 | end | |
476 |
|
476 | |||
477 | def test_jump_should_not_redirect_to_unknown_tab |
|
477 | def test_jump_should_not_redirect_to_unknown_tab | |
478 | get :show, :id => 3, :jump => 'foobar' |
|
478 | get :show, :id => 3, :jump => 'foobar' | |
479 | assert_response :success |
|
479 | assert_response :success | |
480 | assert_template 'show' |
|
480 | assert_template 'show' | |
481 | end |
|
481 | end | |
482 |
|
482 | |||
483 | # A hook that is manually registered later |
|
483 | # A hook that is manually registered later | |
484 | class ProjectBasedTemplate < Redmine::Hook::ViewListener |
|
484 | class ProjectBasedTemplate < Redmine::Hook::ViewListener | |
485 | def view_layouts_base_html_head(context) |
|
485 | def view_layouts_base_html_head(context) | |
486 | # Adds a project stylesheet |
|
486 | # Adds a project stylesheet | |
487 | stylesheet_link_tag(context[:project].identifier) if context[:project] |
|
487 | stylesheet_link_tag(context[:project].identifier) if context[:project] | |
488 | end |
|
488 | end | |
489 | end |
|
489 | end | |
490 | # Don't use this hook now |
|
490 | # Don't use this hook now | |
491 | Redmine::Hook.clear_listeners |
|
491 | Redmine::Hook.clear_listeners | |
492 |
|
492 | |||
493 | def test_hook_response |
|
493 | def test_hook_response | |
494 | Redmine::Hook.add_listener(ProjectBasedTemplate) |
|
494 | Redmine::Hook.add_listener(ProjectBasedTemplate) | |
495 | get :show, :id => 1 |
|
495 | get :show, :id => 1 | |
496 | assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'}, |
|
496 | assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'}, | |
497 | :parent => {:tag => 'head'} |
|
497 | :parent => {:tag => 'head'} | |
498 |
|
498 | |||
499 | Redmine::Hook.clear_listeners |
|
499 | Redmine::Hook.clear_listeners | |
500 | end |
|
500 | end | |
501 | end |
|
501 | end |
General Comments 0
You need to be logged in to leave comments.
Login now