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