##// END OF EJS Templates
Fixes test broken by r1578....
Jean-Philippe Lang -
r1567:8474d05e9994
parent child
Show More
@@ -1,307 +1,307
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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
27
28 def setup
28 def setup
29 @controller = ProjectsController.new
29 @controller = ProjectsController.new
30 @request = ActionController::TestRequest.new
30 @request = ActionController::TestRequest.new
31 @response = ActionController::TestResponse.new
31 @response = ActionController::TestResponse.new
32 @request.session[:user_id] = nil
32 @request.session[:user_id] = nil
33 end
33 end
34
34
35 def test_index
35 def test_index
36 get :index
36 get :index
37 assert_response :success
37 assert_response :success
38 assert_template 'index'
38 assert_template 'index'
39 assert_not_nil assigns(:project_tree)
39 assert_not_nil assigns(:project_tree)
40 # Root project as hash key
40 # Root project as hash key
41 assert assigns(:project_tree).has_key?(Project.find(1))
41 assert assigns(:project_tree).has_key?(Project.find(1))
42 # Subproject in corresponding value
42 # Subproject in corresponding value
43 assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
43 assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
44 end
44 end
45
45
46 def test_show_by_id
46 def test_show_by_id
47 get :show, :id => 1
47 get :show, :id => 1
48 assert_response :success
48 assert_response :success
49 assert_template 'show'
49 assert_template 'show'
50 assert_not_nil assigns(:project)
50 assert_not_nil assigns(:project)
51 end
51 end
52
52
53 def test_show_by_identifier
53 def test_show_by_identifier
54 get :show, :id => 'ecookbook'
54 get :show, :id => 'ecookbook'
55 assert_response :success
55 assert_response :success
56 assert_template 'show'
56 assert_template 'show'
57 assert_not_nil assigns(:project)
57 assert_not_nil assigns(:project)
58 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
58 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
59 end
59 end
60
60
61 def test_private_subprojects_hidden
61 def test_private_subprojects_hidden
62 get :show, :id => 'ecookbook'
62 get :show, :id => 'ecookbook'
63 assert_response :success
63 assert_response :success
64 assert_template 'show'
64 assert_template 'show'
65 assert_no_tag :tag => 'a', :content => /Private child/
65 assert_no_tag :tag => 'a', :content => /Private child/
66 end
66 end
67
67
68 def test_private_subprojects_visible
68 def test_private_subprojects_visible
69 @request.session[:user_id] = 2 # manager who is a member of the private subproject
69 @request.session[:user_id] = 2 # manager who is a member of the private subproject
70 get :show, :id => 'ecookbook'
70 get :show, :id => 'ecookbook'
71 assert_response :success
71 assert_response :success
72 assert_template 'show'
72 assert_template 'show'
73 assert_tag :tag => 'a', :content => /Private child/
73 assert_tag :tag => 'a', :content => /Private child/
74 end
74 end
75
75
76 def test_settings
76 def test_settings
77 @request.session[:user_id] = 2 # manager
77 @request.session[:user_id] = 2 # manager
78 get :settings, :id => 1
78 get :settings, :id => 1
79 assert_response :success
79 assert_response :success
80 assert_template 'settings'
80 assert_template 'settings'
81 end
81 end
82
82
83 def test_edit
83 def test_edit
84 @request.session[:user_id] = 2 # manager
84 @request.session[:user_id] = 2 # manager
85 post :edit, :id => 1, :project => {:name => 'Test changed name',
85 post :edit, :id => 1, :project => {:name => 'Test changed name',
86 :custom_field_ids => ['']}
86 :custom_field_ids => ['']}
87 assert_redirected_to 'projects/settings/ecookbook'
87 assert_redirected_to 'projects/settings/ecookbook'
88 project = Project.find(1)
88 project = Project.find(1)
89 assert_equal 'Test changed name', project.name
89 assert_equal 'Test changed name', project.name
90 end
90 end
91
91
92 def test_get_destroy
92 def test_get_destroy
93 @request.session[:user_id] = 1 # admin
93 @request.session[:user_id] = 1 # admin
94 get :destroy, :id => 1
94 get :destroy, :id => 1
95 assert_response :success
95 assert_response :success
96 assert_template 'destroy'
96 assert_template 'destroy'
97 assert_not_nil Project.find_by_id(1)
97 assert_not_nil Project.find_by_id(1)
98 end
98 end
99
99
100 def test_post_destroy
100 def test_post_destroy
101 @request.session[:user_id] = 1 # admin
101 @request.session[:user_id] = 1 # admin
102 post :destroy, :id => 1, :confirm => 1
102 post :destroy, :id => 1, :confirm => 1
103 assert_redirected_to 'admin/projects'
103 assert_redirected_to 'admin/projects'
104 assert_nil Project.find_by_id(1)
104 assert_nil Project.find_by_id(1)
105 end
105 end
106
106
107 def test_list_files
107 def test_list_files
108 get :list_files, :id => 1
108 get :list_files, :id => 1
109 assert_response :success
109 assert_response :success
110 assert_template 'list_files'
110 assert_template 'list_files'
111 assert_not_nil assigns(:versions)
111 assert_not_nil assigns(:versions)
112 end
112 end
113
113
114 def test_changelog
114 def test_changelog
115 get :changelog, :id => 1
115 get :changelog, :id => 1
116 assert_response :success
116 assert_response :success
117 assert_template 'changelog'
117 assert_template 'changelog'
118 assert_not_nil assigns(:versions)
118 assert_not_nil assigns(:versions)
119 end
119 end
120
120
121 def test_roadmap
121 def test_roadmap
122 get :roadmap, :id => 1
122 get :roadmap, :id => 1
123 assert_response :success
123 assert_response :success
124 assert_template 'roadmap'
124 assert_template 'roadmap'
125 assert_not_nil assigns(:versions)
125 assert_not_nil assigns(:versions)
126 # Version with no date set appears
126 # Version with no date set appears
127 assert assigns(:versions).include?(Version.find(3))
127 assert assigns(:versions).include?(Version.find(3))
128 # Completed version doesn't appear
128 # Completed version doesn't appear
129 assert !assigns(:versions).include?(Version.find(1))
129 assert !assigns(:versions).include?(Version.find(1))
130 end
130 end
131
131
132 def test_roadmap_with_completed_versions
132 def test_roadmap_with_completed_versions
133 get :roadmap, :id => 1, :completed => 1
133 get :roadmap, :id => 1, :completed => 1
134 assert_response :success
134 assert_response :success
135 assert_template 'roadmap'
135 assert_template 'roadmap'
136 assert_not_nil assigns(:versions)
136 assert_not_nil assigns(:versions)
137 # Version with no date set appears
137 # Version with no date set appears
138 assert assigns(:versions).include?(Version.find(3))
138 assert assigns(:versions).include?(Version.find(3))
139 # Completed version appears
139 # Completed version appears
140 assert assigns(:versions).include?(Version.find(1))
140 assert assigns(:versions).include?(Version.find(1))
141 end
141 end
142
142
143 def test_project_activity
143 def test_project_activity
144 get :activity, :id => 1, :with_subprojects => 0
144 get :activity, :id => 1, :with_subprojects => 0
145 assert_response :success
145 assert_response :success
146 assert_template 'activity'
146 assert_template 'activity'
147 assert_not_nil assigns(:events_by_day)
147 assert_not_nil assigns(:events_by_day)
148 assert_not_nil assigns(:events)
148 assert_not_nil assigns(:events)
149
149
150 # subproject issue not included by default
150 # subproject issue not included by default
151 assert !assigns(:events).include?(Issue.find(5))
151 assert !assigns(:events).include?(Issue.find(5))
152
152
153 assert_tag :tag => "h3",
153 assert_tag :tag => "h3",
154 :content => /#{2.days.ago.to_date.day}/,
154 :content => /#{2.days.ago.to_date.day}/,
155 :sibling => { :tag => "dl",
155 :sibling => { :tag => "dl",
156 :child => { :tag => "dt",
156 :child => { :tag => "dt",
157 :attributes => { :class => 'issue-edit' },
157 :attributes => { :class => /issue-edit/ },
158 :child => { :tag => "a",
158 :child => { :tag => "a",
159 :content => /(#{IssueStatus.find(2).name})/,
159 :content => /(#{IssueStatus.find(2).name})/,
160 }
160 }
161 }
161 }
162 }
162 }
163
163
164 get :activity, :id => 1, :from => 3.days.ago.to_date
164 get :activity, :id => 1, :from => 3.days.ago.to_date
165 assert_response :success
165 assert_response :success
166 assert_template 'activity'
166 assert_template 'activity'
167 assert_not_nil assigns(:events_by_day)
167 assert_not_nil assigns(:events_by_day)
168
168
169 assert_tag :tag => "h3",
169 assert_tag :tag => "h3",
170 :content => /#{3.day.ago.to_date.day}/,
170 :content => /#{3.day.ago.to_date.day}/,
171 :sibling => { :tag => "dl",
171 :sibling => { :tag => "dl",
172 :child => { :tag => "dt",
172 :child => { :tag => "dt",
173 :attributes => { :class => 'issue' },
173 :attributes => { :class => /issue/ },
174 :child => { :tag => "a",
174 :child => { :tag => "a",
175 :content => /#{Issue.find(1).subject}/,
175 :content => /#{Issue.find(1).subject}/,
176 }
176 }
177 }
177 }
178 }
178 }
179 end
179 end
180
180
181 def test_activity_with_subprojects
181 def test_activity_with_subprojects
182 get :activity, :id => 1, :with_subprojects => 1
182 get :activity, :id => 1, :with_subprojects => 1
183 assert_response :success
183 assert_response :success
184 assert_template 'activity'
184 assert_template 'activity'
185 assert_not_nil assigns(:events)
185 assert_not_nil assigns(:events)
186
186
187 assert assigns(:events).include?(Issue.find(1))
187 assert assigns(:events).include?(Issue.find(1))
188 assert !assigns(:events).include?(Issue.find(4))
188 assert !assigns(:events).include?(Issue.find(4))
189 # subproject issue
189 # subproject issue
190 assert assigns(:events).include?(Issue.find(5))
190 assert assigns(:events).include?(Issue.find(5))
191 end
191 end
192
192
193 def test_global_activity_anonymous
193 def test_global_activity_anonymous
194 get :activity
194 get :activity
195 assert_response :success
195 assert_response :success
196 assert_template 'activity'
196 assert_template 'activity'
197 assert_not_nil assigns(:events)
197 assert_not_nil assigns(:events)
198
198
199 assert assigns(:events).include?(Issue.find(1))
199 assert assigns(:events).include?(Issue.find(1))
200 # Issue of a private project
200 # Issue of a private project
201 assert !assigns(:events).include?(Issue.find(4))
201 assert !assigns(:events).include?(Issue.find(4))
202 end
202 end
203
203
204 def test_global_activity_logged_user
204 def test_global_activity_logged_user
205 @request.session[:user_id] = 2 # manager
205 @request.session[:user_id] = 2 # manager
206 get :activity
206 get :activity
207 assert_response :success
207 assert_response :success
208 assert_template 'activity'
208 assert_template 'activity'
209 assert_not_nil assigns(:events)
209 assert_not_nil assigns(:events)
210
210
211 assert assigns(:events).include?(Issue.find(1))
211 assert assigns(:events).include?(Issue.find(1))
212 # Issue of a private project the user belongs to
212 # Issue of a private project the user belongs to
213 assert assigns(:events).include?(Issue.find(4))
213 assert assigns(:events).include?(Issue.find(4))
214 end
214 end
215
215
216
216
217 def test_global_activity_with_all_types
217 def test_global_activity_with_all_types
218 get :activity, :show_issues => 1, :show_news => 1, :show_files => 1, :show_documents => 1, :show_changesets => 1, :show_wiki_pages => 1, :show_messages => 1
218 get :activity, :show_issues => 1, :show_news => 1, :show_files => 1, :show_documents => 1, :show_changesets => 1, :show_wiki_pages => 1, :show_messages => 1
219 assert_response :success
219 assert_response :success
220 assert_template 'activity'
220 assert_template 'activity'
221 assert_not_nil assigns(:events)
221 assert_not_nil assigns(:events)
222
222
223 assert assigns(:events).include?(Issue.find(1))
223 assert assigns(:events).include?(Issue.find(1))
224 assert !assigns(:events).include?(Issue.find(4))
224 assert !assigns(:events).include?(Issue.find(4))
225 assert assigns(:events).include?(Message.find(5))
225 assert assigns(:events).include?(Message.find(5))
226 end
226 end
227
227
228 def test_calendar
228 def test_calendar
229 get :calendar, :id => 1
229 get :calendar, :id => 1
230 assert_response :success
230 assert_response :success
231 assert_template 'calendar'
231 assert_template 'calendar'
232 assert_not_nil assigns(:calendar)
232 assert_not_nil assigns(:calendar)
233 end
233 end
234
234
235 def test_calendar_with_subprojects_should_not_show_private_subprojects
235 def test_calendar_with_subprojects_should_not_show_private_subprojects
236 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
236 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
237 assert_response :success
237 assert_response :success
238 assert_template 'calendar'
238 assert_template 'calendar'
239 assert_not_nil assigns(:calendar)
239 assert_not_nil assigns(:calendar)
240 assert_no_tag :tag => 'a', :content => /#6/
240 assert_no_tag :tag => 'a', :content => /#6/
241 end
241 end
242
242
243 def test_calendar_with_subprojects_should_show_private_subprojects
243 def test_calendar_with_subprojects_should_show_private_subprojects
244 @request.session[:user_id] = 2
244 @request.session[:user_id] = 2
245 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
245 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
246 assert_response :success
246 assert_response :success
247 assert_template 'calendar'
247 assert_template 'calendar'
248 assert_not_nil assigns(:calendar)
248 assert_not_nil assigns(:calendar)
249 assert_tag :tag => 'a', :content => /#6/
249 assert_tag :tag => 'a', :content => /#6/
250 end
250 end
251
251
252 def test_gantt
252 def test_gantt
253 get :gantt, :id => 1
253 get :gantt, :id => 1
254 assert_response :success
254 assert_response :success
255 assert_template 'gantt.rhtml'
255 assert_template 'gantt.rhtml'
256 events = assigns(:events)
256 events = assigns(:events)
257 assert_not_nil events
257 assert_not_nil events
258 # Issue with start and due dates
258 # Issue with start and due dates
259 i = Issue.find(1)
259 i = Issue.find(1)
260 assert_not_nil i.due_date
260 assert_not_nil i.due_date
261 assert events.include?(Issue.find(1))
261 assert events.include?(Issue.find(1))
262 # Issue with without due date but targeted to a version with date
262 # Issue with without due date but targeted to a version with date
263 i = Issue.find(2)
263 i = Issue.find(2)
264 assert_nil i.due_date
264 assert_nil i.due_date
265 assert events.include?(i)
265 assert events.include?(i)
266 end
266 end
267
267
268 def test_gantt_with_subprojects_should_not_show_private_subprojects
268 def test_gantt_with_subprojects_should_not_show_private_subprojects
269 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
269 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
270 assert_response :success
270 assert_response :success
271 assert_template 'gantt.rhtml'
271 assert_template 'gantt.rhtml'
272 assert_not_nil assigns(:events)
272 assert_not_nil assigns(:events)
273 assert_no_tag :tag => 'a', :content => /#6/
273 assert_no_tag :tag => 'a', :content => /#6/
274 end
274 end
275
275
276 def test_gantt_with_subprojects_should_show_private_subprojects
276 def test_gantt_with_subprojects_should_show_private_subprojects
277 @request.session[:user_id] = 2
277 @request.session[:user_id] = 2
278 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
278 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
279 assert_response :success
279 assert_response :success
280 assert_template 'gantt.rhtml'
280 assert_template 'gantt.rhtml'
281 assert_not_nil assigns(:events)
281 assert_not_nil assigns(:events)
282 assert_tag :tag => 'a', :content => /#6/
282 assert_tag :tag => 'a', :content => /#6/
283 end
283 end
284
284
285 def test_gantt_export_to_pdf
285 def test_gantt_export_to_pdf
286 get :gantt, :id => 1, :format => 'pdf'
286 get :gantt, :id => 1, :format => 'pdf'
287 assert_response :success
287 assert_response :success
288 assert_template 'gantt.rfpdf'
288 assert_template 'gantt.rfpdf'
289 assert_equal 'application/pdf', @response.content_type
289 assert_equal 'application/pdf', @response.content_type
290 assert_not_nil assigns(:events)
290 assert_not_nil assigns(:events)
291 end
291 end
292
292
293 def test_archive
293 def test_archive
294 @request.session[:user_id] = 1 # admin
294 @request.session[:user_id] = 1 # admin
295 post :archive, :id => 1
295 post :archive, :id => 1
296 assert_redirected_to 'admin/projects'
296 assert_redirected_to 'admin/projects'
297 assert !Project.find(1).active?
297 assert !Project.find(1).active?
298 end
298 end
299
299
300 def test_unarchive
300 def test_unarchive
301 @request.session[:user_id] = 1 # admin
301 @request.session[:user_id] = 1 # admin
302 Project.find(1).archive
302 Project.find(1).archive
303 post :unarchive, :id => 1
303 post :unarchive, :id => 1
304 assert_redirected_to 'admin/projects'
304 assert_redirected_to 'admin/projects'
305 assert Project.find(1).active?
305 assert Project.find(1).active?
306 end
306 end
307 end
307 end
General Comments 0
You need to be logged in to leave comments. Login now