@@ -1,240 +1,242 | |||||
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, :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations |
|
25 | fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details, :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = ProjectsController.new |
|
28 | @controller = ProjectsController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | def test_index |
|
33 | def test_index | |
34 | get :index |
|
34 | get :index | |
35 | assert_response :success |
|
35 | assert_response :success | |
36 | assert_template 'list' |
|
36 | assert_template 'list' | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
39 | def test_list |
|
39 | def test_list | |
40 | get :list |
|
40 | get :list | |
41 | assert_response :success |
|
41 | assert_response :success | |
42 | assert_template 'list' |
|
42 | assert_template 'list' | |
43 | assert_not_nil assigns(:project_tree) |
|
43 | assert_not_nil assigns(:project_tree) | |
44 | # Root project as hash key |
|
44 | # Root project as hash key | |
45 | assert assigns(:project_tree).has_key?(Project.find(1)) |
|
45 | assert assigns(:project_tree).has_key?(Project.find(1)) | |
46 | # Subproject in corresponding value |
|
46 | # Subproject in corresponding value | |
47 | assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3)) |
|
47 | assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3)) | |
48 | end |
|
48 | end | |
49 |
|
49 | |||
50 | def test_show_by_id |
|
50 | def test_show_by_id | |
51 | get :show, :id => 1 |
|
51 | get :show, :id => 1 | |
52 | assert_response :success |
|
52 | assert_response :success | |
53 | assert_template 'show' |
|
53 | assert_template 'show' | |
54 | assert_not_nil assigns(:project) |
|
54 | assert_not_nil assigns(:project) | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | def test_show_by_identifier |
|
57 | def test_show_by_identifier | |
58 | get :show, :id => 'ecookbook' |
|
58 | get :show, :id => 'ecookbook' | |
59 | assert_response :success |
|
59 | assert_response :success | |
60 | assert_template 'show' |
|
60 | assert_template 'show' | |
61 | assert_not_nil assigns(:project) |
|
61 | assert_not_nil assigns(:project) | |
62 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) |
|
62 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) | |
63 | end |
|
63 | end | |
64 |
|
64 | |||
65 | def test_settings |
|
65 | def test_settings | |
66 | @request.session[:user_id] = 2 # manager |
|
66 | @request.session[:user_id] = 2 # manager | |
67 | get :settings, :id => 1 |
|
67 | get :settings, :id => 1 | |
68 | assert_response :success |
|
68 | assert_response :success | |
69 | assert_template 'settings' |
|
69 | assert_template 'settings' | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | def test_edit |
|
72 | def test_edit | |
73 | @request.session[:user_id] = 2 # manager |
|
73 | @request.session[:user_id] = 2 # manager | |
74 | post :edit, :id => 1, :project => {:name => 'Test changed name', |
|
74 | post :edit, :id => 1, :project => {:name => 'Test changed name', | |
75 | :custom_field_ids => ['']} |
|
75 | :custom_field_ids => ['']} | |
76 | assert_redirected_to 'projects/settings/ecookbook' |
|
76 | assert_redirected_to 'projects/settings/ecookbook' | |
77 | project = Project.find(1) |
|
77 | project = Project.find(1) | |
78 | assert_equal 'Test changed name', project.name |
|
78 | assert_equal 'Test changed name', project.name | |
79 | end |
|
79 | end | |
80 |
|
80 | |||
81 | def test_get_destroy |
|
81 | def test_get_destroy | |
82 | @request.session[:user_id] = 1 # admin |
|
82 | @request.session[:user_id] = 1 # admin | |
83 | get :destroy, :id => 1 |
|
83 | get :destroy, :id => 1 | |
84 | assert_response :success |
|
84 | assert_response :success | |
85 | assert_template 'destroy' |
|
85 | assert_template 'destroy' | |
86 | assert_not_nil Project.find_by_id(1) |
|
86 | assert_not_nil Project.find_by_id(1) | |
87 | end |
|
87 | end | |
88 |
|
88 | |||
89 | def test_post_destroy |
|
89 | def test_post_destroy | |
90 | @request.session[:user_id] = 1 # admin |
|
90 | @request.session[:user_id] = 1 # admin | |
91 | post :destroy, :id => 1, :confirm => 1 |
|
91 | post :destroy, :id => 1, :confirm => 1 | |
92 | assert_redirected_to 'admin/projects' |
|
92 | assert_redirected_to 'admin/projects' | |
93 | assert_nil Project.find_by_id(1) |
|
93 | assert_nil Project.find_by_id(1) | |
94 | end |
|
94 | end | |
95 |
|
95 | |||
96 | def test_bulk_edit_issues |
|
96 | def test_bulk_edit_issues | |
97 | @request.session[:user_id] = 2 |
|
97 | @request.session[:user_id] = 2 | |
98 | # update issues priority |
|
98 | # update issues priority | |
99 | post :bulk_edit_issues, :id => 1, :issue_ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => '' |
|
99 | post :bulk_edit_issues, :id => 1, :issue_ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => '' | |
100 | assert_response 302 |
|
100 | assert_response 302 | |
101 | # check that the issues were updated |
|
101 | # check that the issues were updated | |
102 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} |
|
102 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} | |
103 | assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes |
|
103 | assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes | |
104 | end |
|
104 | end | |
105 |
|
105 | |||
106 | def test_move_issues_to_another_project |
|
106 | def test_move_issues_to_another_project | |
107 | @request.session[:user_id] = 1 |
|
107 | @request.session[:user_id] = 1 | |
108 | post :move_issues, :id => 1, :issue_ids => [1, 2], :new_project_id => 2 |
|
108 | post :move_issues, :id => 1, :issue_ids => [1, 2], :new_project_id => 2 | |
109 | assert_redirected_to 'projects/ecookbook/issues' |
|
109 | assert_redirected_to 'projects/ecookbook/issues' | |
110 | assert_equal 2, Issue.find(1).project_id |
|
110 | assert_equal 2, Issue.find(1).project_id | |
111 | assert_equal 2, Issue.find(2).project_id |
|
111 | assert_equal 2, Issue.find(2).project_id | |
112 | end |
|
112 | end | |
113 |
|
113 | |||
114 | def test_move_issues_to_another_tracker |
|
114 | def test_move_issues_to_another_tracker | |
115 | @request.session[:user_id] = 1 |
|
115 | @request.session[:user_id] = 1 | |
116 | post :move_issues, :id => 1, :issue_ids => [1, 2], :new_tracker_id => 2 |
|
116 | post :move_issues, :id => 1, :issue_ids => [1, 2], :new_tracker_id => 2 | |
117 | assert_redirected_to 'projects/ecookbook/issues' |
|
117 | assert_redirected_to 'projects/ecookbook/issues' | |
118 | assert_equal 2, Issue.find(1).tracker_id |
|
118 | assert_equal 2, Issue.find(1).tracker_id | |
119 | assert_equal 2, Issue.find(2).tracker_id |
|
119 | assert_equal 2, Issue.find(2).tracker_id | |
120 | end |
|
120 | end | |
121 |
|
121 | |||
122 | def test_list_files |
|
122 | def test_list_files | |
123 | get :list_files, :id => 1 |
|
123 | get :list_files, :id => 1 | |
124 | assert_response :success |
|
124 | assert_response :success | |
125 | assert_template 'list_files' |
|
125 | assert_template 'list_files' | |
126 | assert_not_nil assigns(:versions) |
|
126 | assert_not_nil assigns(:versions) | |
127 | end |
|
127 | end | |
128 |
|
128 | |||
129 | def test_changelog |
|
129 | def test_changelog | |
130 | get :changelog, :id => 1 |
|
130 | get :changelog, :id => 1 | |
131 | assert_response :success |
|
131 | assert_response :success | |
132 | assert_template 'changelog' |
|
132 | assert_template 'changelog' | |
133 | assert_not_nil assigns(:versions) |
|
133 | assert_not_nil assigns(:versions) | |
134 | end |
|
134 | end | |
135 |
|
135 | |||
136 | def test_roadmap |
|
136 | def test_roadmap | |
137 | get :roadmap, :id => 1 |
|
137 | get :roadmap, :id => 1 | |
138 | assert_response :success |
|
138 | assert_response :success | |
139 | assert_template 'roadmap' |
|
139 | assert_template 'roadmap' | |
140 | assert_not_nil assigns(:versions) |
|
140 | assert_not_nil assigns(:versions) | |
141 | # Version with no date set appears |
|
141 | # Version with no date set appears | |
142 | assert assigns(:versions).include?(Version.find(3)) |
|
142 | assert assigns(:versions).include?(Version.find(3)) | |
143 | # Completed version doesn't appear |
|
143 | # Completed version doesn't appear | |
144 | assert !assigns(:versions).include?(Version.find(1)) |
|
144 | assert !assigns(:versions).include?(Version.find(1)) | |
145 | end |
|
145 | end | |
146 |
|
146 | |||
147 | def test_roadmap_with_completed_versions |
|
147 | def test_roadmap_with_completed_versions | |
148 | get :roadmap, :id => 1, :completed => 1 |
|
148 | get :roadmap, :id => 1, :completed => 1 | |
149 | assert_response :success |
|
149 | assert_response :success | |
150 | assert_template 'roadmap' |
|
150 | assert_template 'roadmap' | |
151 | assert_not_nil assigns(:versions) |
|
151 | assert_not_nil assigns(:versions) | |
152 | # Version with no date set appears |
|
152 | # Version with no date set appears | |
153 | assert assigns(:versions).include?(Version.find(3)) |
|
153 | assert assigns(:versions).include?(Version.find(3)) | |
154 | # Completed version appears |
|
154 | # Completed version appears | |
155 | assert assigns(:versions).include?(Version.find(1)) |
|
155 | assert assigns(:versions).include?(Version.find(1)) | |
156 | end |
|
156 | end | |
157 |
|
157 | |||
158 | def test_activity |
|
158 | def test_activity | |
159 | get :activity, :id => 1, :year => 2.days.ago.to_date.year, :month => 2.days.ago.to_date.month |
|
159 | get :activity, :id => 1, :year => 2.days.ago.to_date.year, :month => 2.days.ago.to_date.month | |
160 | assert_response :success |
|
160 | assert_response :success | |
161 | assert_template 'activity' |
|
161 | assert_template 'activity' | |
162 | assert_not_nil assigns(:events_by_day) |
|
162 | assert_not_nil assigns(:events_by_day) | |
163 |
|
163 | |||
164 | assert_tag :tag => "h3", |
|
164 | assert_tag :tag => "h3", | |
165 | :content => /#{2.days.ago.to_date.day}/, |
|
165 | :content => /#{2.days.ago.to_date.day}/, | |
166 |
:sibling => { :tag => " |
|
166 | :sibling => { :tag => "dl", | |
167 |
:child => { :tag => " |
|
167 | :child => { :tag => "dt", | |
168 |
: |
|
168 | :attributes => { :class => 'journal' }, | |
|
169 | :child => { :tag => "a", | |||
169 | :content => /(#{IssueStatus.find(2).name})/, |
|
170 | :content => /(#{IssueStatus.find(2).name})/, | |
170 | } |
|
171 | } | |
171 | } |
|
172 | } | |
172 | } |
|
173 | } | |
173 |
|
174 | |||
174 | get :activity, :id => 1, :year => 3.days.ago.to_date.year, :month => 3.days.ago.to_date.month |
|
175 | get :activity, :id => 1, :year => 3.days.ago.to_date.year, :month => 3.days.ago.to_date.month | |
175 | assert_response :success |
|
176 | assert_response :success | |
176 | assert_template 'activity' |
|
177 | assert_template 'activity' | |
177 | assert_not_nil assigns(:events_by_day) |
|
178 | assert_not_nil assigns(:events_by_day) | |
178 |
|
179 | |||
179 | assert_tag :tag => "h3", |
|
180 | assert_tag :tag => "h3", | |
180 | :content => /#{3.day.ago.to_date.day}/, |
|
181 | :content => /#{3.day.ago.to_date.day}/, | |
181 |
:sibling => { :tag => " |
|
182 | :sibling => { :tag => "dl", | |
182 |
:child => { :tag => " |
|
183 | :child => { :tag => "dt", | |
183 |
: |
|
184 | :attributes => { :class => 'issue' }, | |
|
185 | :child => { :tag => "a", | |||
184 | :content => /#{Issue.find(1).subject}/, |
|
186 | :content => /#{Issue.find(1).subject}/, | |
185 | } |
|
187 | } | |
186 | } |
|
188 | } | |
187 | } |
|
189 | } | |
188 | end |
|
190 | end | |
189 |
|
191 | |||
190 | def test_calendar |
|
192 | def test_calendar | |
191 | get :calendar, :id => 1 |
|
193 | get :calendar, :id => 1 | |
192 | assert_response :success |
|
194 | assert_response :success | |
193 | assert_template 'calendar' |
|
195 | assert_template 'calendar' | |
194 | assert_not_nil assigns(:calendar) |
|
196 | assert_not_nil assigns(:calendar) | |
195 | end |
|
197 | end | |
196 |
|
198 | |||
197 | def test_calendar_with_subprojects |
|
199 | def test_calendar_with_subprojects | |
198 | get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2] |
|
200 | get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2] | |
199 | assert_response :success |
|
201 | assert_response :success | |
200 | assert_template 'calendar' |
|
202 | assert_template 'calendar' | |
201 | assert_not_nil assigns(:calendar) |
|
203 | assert_not_nil assigns(:calendar) | |
202 | end |
|
204 | end | |
203 |
|
205 | |||
204 | def test_gantt |
|
206 | def test_gantt | |
205 | get :gantt, :id => 1 |
|
207 | get :gantt, :id => 1 | |
206 | assert_response :success |
|
208 | assert_response :success | |
207 | assert_template 'gantt.rhtml' |
|
209 | assert_template 'gantt.rhtml' | |
208 | assert_not_nil assigns(:events) |
|
210 | assert_not_nil assigns(:events) | |
209 | end |
|
211 | end | |
210 |
|
212 | |||
211 | def test_gantt_with_subprojects |
|
213 | def test_gantt_with_subprojects | |
212 | get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2] |
|
214 | get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2] | |
213 | assert_response :success |
|
215 | assert_response :success | |
214 | assert_template 'gantt.rhtml' |
|
216 | assert_template 'gantt.rhtml' | |
215 | assert_not_nil assigns(:events) |
|
217 | assert_not_nil assigns(:events) | |
216 | end |
|
218 | end | |
217 |
|
219 | |||
218 | def test_gantt_export_to_pdf |
|
220 | def test_gantt_export_to_pdf | |
219 | get :gantt, :id => 1, :format => 'pdf' |
|
221 | get :gantt, :id => 1, :format => 'pdf' | |
220 | assert_response :success |
|
222 | assert_response :success | |
221 | assert_template 'gantt.rfpdf' |
|
223 | assert_template 'gantt.rfpdf' | |
222 | assert_equal 'application/pdf', @response.content_type |
|
224 | assert_equal 'application/pdf', @response.content_type | |
223 | assert_not_nil assigns(:events) |
|
225 | assert_not_nil assigns(:events) | |
224 | end |
|
226 | end | |
225 |
|
227 | |||
226 | def test_archive |
|
228 | def test_archive | |
227 | @request.session[:user_id] = 1 # admin |
|
229 | @request.session[:user_id] = 1 # admin | |
228 | post :archive, :id => 1 |
|
230 | post :archive, :id => 1 | |
229 | assert_redirected_to 'admin/projects' |
|
231 | assert_redirected_to 'admin/projects' | |
230 | assert !Project.find(1).active? |
|
232 | assert !Project.find(1).active? | |
231 | end |
|
233 | end | |
232 |
|
234 | |||
233 | def test_unarchive |
|
235 | def test_unarchive | |
234 | @request.session[:user_id] = 1 # admin |
|
236 | @request.session[:user_id] = 1 # admin | |
235 | Project.find(1).archive |
|
237 | Project.find(1).archive | |
236 | post :unarchive, :id => 1 |
|
238 | post :unarchive, :id => 1 | |
237 | assert_redirected_to 'admin/projects' |
|
239 | assert_redirected_to 'admin/projects' | |
238 | assert Project.find(1).active? |
|
240 | assert Project.find(1).active? | |
239 | end |
|
241 | end | |
240 | end |
|
242 | end |
General Comments 0
You need to be logged in to leave comments.
Login now