Mercurial > hg > soundsoftware-site
comparison test/functional/projects_controller_test.rb @ 1526:404aa68d4227
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 11 Sep 2014 12:46:20 +0100 |
parents | dffacf8a6908 |
children |
comparison
equal
deleted
inserted
replaced
1493:a5f2bdf3b486 | 1526:404aa68d4227 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2014 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. |
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 require 'projects_controller' | |
20 | |
21 # Re-raise errors caught by the controller. | |
22 class ProjectsController; def rescue_action(e) raise e end; end | |
23 | 19 |
24 class ProjectsControllerTest < ActionController::TestCase | 20 class ProjectsControllerTest < ActionController::TestCase |
25 fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details, | 21 fixtures :projects, :versions, :users, :roles, :members, |
26 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages, | 22 :member_roles, :issues, :journals, :journal_details, |
23 :trackers, :projects_trackers, :issue_statuses, | |
24 :enabled_modules, :enumerations, :boards, :messages, | |
27 :attachments, :custom_fields, :custom_values, :time_entries | 25 :attachments, :custom_fields, :custom_values, :time_entries |
28 | 26 |
29 def setup | 27 def setup |
30 @controller = ProjectsController.new | |
31 @request = ActionController::TestRequest.new | |
32 @response = ActionController::TestResponse.new | |
33 @request.session[:user_id] = nil | 28 @request.session[:user_id] = nil |
34 Setting.default_language = 'en' | 29 Setting.default_language = 'en' |
35 end | 30 end |
36 | 31 |
37 def test_index | 32 def test_index_by_anonymous_should_not_show_private_projects |
38 get :index | 33 get :index |
39 assert_response :success | 34 assert_response :success |
40 assert_template 'index' | 35 assert_template 'index' |
41 assert_not_nil assigns(:projects) | 36 projects = assigns(:projects) |
42 | 37 assert_not_nil projects |
43 assert_tag :ul, :child => {:tag => 'li', | 38 assert projects.all?(&:is_public?) |
44 :descendant => {:tag => 'a', :content => 'eCookbook'}, | 39 |
45 :child => { :tag => 'ul', | 40 assert_select 'ul' do |
46 :descendant => { :tag => 'a', | 41 assert_select 'li' do |
47 :content => 'Child of private child' | 42 assert_select 'a', :text => 'eCookbook' |
48 } | 43 assert_select 'ul' do |
49 } | 44 assert_select 'a', :text => 'Child of private child' |
50 } | 45 end |
51 | 46 end |
52 assert_no_tag :a, :content => /Private child of eCookbook/ | 47 end |
48 assert_select 'a', :text => /Private child of eCookbook/, :count => 0 | |
53 end | 49 end |
54 | 50 |
55 def test_index_atom | 51 def test_index_atom |
56 get :index, :format => 'atom' | 52 get :index, :format => 'atom' |
57 assert_response :success | 53 assert_response :success |
58 assert_template 'common/feed' | 54 assert_template 'common/feed' |
59 assert_select 'feed>title', :text => 'Redmine: Latest projects' | 55 assert_select 'feed>title', :text => 'Redmine: Latest projects' |
60 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_condition(User.current)) | 56 assert_select 'feed>entry', :count => Project.visible(User.current).count |
61 end | 57 end |
62 | 58 |
63 context "#index" do | 59 test "#index by non-admin user with view_time_entries permission should show overall spent time link" do |
64 context "by non-admin user with view_time_entries permission" do | 60 @request.session[:user_id] = 3 |
65 setup do | 61 get :index |
66 @request.session[:user_id] = 3 | 62 assert_template 'index' |
67 end | 63 assert_select 'a[href=?]', '/time_entries' |
68 should "show overall spent time link" do | 64 end |
69 get :index | 65 |
70 assert_template 'index' | 66 test "#index by non-admin user without view_time_entries permission should not show overall spent time link" do |
71 assert_tag :a, :attributes => {:href => '/time_entries'} | 67 Role.find(2).remove_permission! :view_time_entries |
72 end | 68 Role.non_member.remove_permission! :view_time_entries |
73 end | 69 Role.anonymous.remove_permission! :view_time_entries |
74 | 70 @request.session[:user_id] = 3 |
75 context "by non-admin user without view_time_entries permission" do | 71 |
76 setup do | 72 get :index |
77 Role.find(2).remove_permission! :view_time_entries | 73 assert_template 'index' |
78 Role.non_member.remove_permission! :view_time_entries | 74 assert_select 'a[href=?]', '/time_entries', 0 |
79 Role.anonymous.remove_permission! :view_time_entries | 75 end |
80 @request.session[:user_id] = 3 | 76 |
81 end | 77 test "#new by admin user should accept get" do |
82 should "not show overall spent time link" do | 78 @request.session[:user_id] = 1 |
83 get :index | 79 |
84 assert_template 'index' | 80 get :new |
85 assert_no_tag :a, :attributes => {:href => '/time_entries'} | 81 assert_response :success |
86 end | 82 assert_template 'new' |
87 end | 83 end |
88 end | 84 |
89 | 85 test "#new by non-admin user with add_project permission should accept get" do |
90 context "#new" do | 86 Role.non_member.add_permission! :add_project |
91 context "by admin user" do | 87 @request.session[:user_id] = 9 |
92 setup do | 88 |
93 @request.session[:user_id] = 1 | 89 get :new |
94 end | 90 assert_response :success |
95 | 91 assert_template 'new' |
96 should "accept get" do | 92 assert_select 'select[name=?]', 'project[parent_id]', 0 |
97 get :new | 93 end |
98 assert_response :success | 94 |
99 assert_template 'new' | 95 test "#new by non-admin user with add_subprojects permission should accept get" do |
100 end | 96 Role.find(1).remove_permission! :add_project |
101 | 97 Role.find(1).add_permission! :add_subprojects |
102 end | 98 @request.session[:user_id] = 2 |
103 | 99 |
104 context "by non-admin user with add_project permission" do | 100 get :new, :parent_id => 'ecookbook' |
105 setup do | 101 assert_response :success |
106 Role.non_member.add_permission! :add_project | 102 assert_template 'new' |
107 @request.session[:user_id] = 9 | 103 |
108 end | 104 assert_select 'select[name=?]', 'project[parent_id]' do |
109 | 105 # parent project selected |
110 should "accept get" do | 106 assert_select 'option[value=1][selected=selected]' |
111 get :new | 107 # no empty value |
112 assert_response :success | 108 assert_select 'option[value=]', 0 |
113 assert_template 'new' | 109 end |
114 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'} | 110 end |
115 end | 111 |
116 end | 112 test "#create by admin user should create a new project" do |
117 | 113 @request.session[:user_id] = 1 |
118 context "by non-admin user with add_subprojects permission" do | 114 |
119 setup do | 115 post :create, |
120 Role.find(1).remove_permission! :add_project | 116 :project => { |
121 Role.find(1).add_permission! :add_subprojects | 117 :name => "blog", |
122 @request.session[:user_id] = 2 | 118 :description => "weblog", |
123 end | 119 :homepage => 'http://weblog', |
124 | 120 :identifier => "blog", |
125 should "accept get" do | 121 :is_public => 1, |
126 get :new, :parent_id => 'ecookbook' | 122 :custom_field_values => { '3' => 'Beta' }, |
127 assert_response :success | 123 :tracker_ids => ['1', '3'], |
128 assert_template 'new' | 124 # an issue custom field that is not for all project |
129 # parent project selected | 125 :issue_custom_field_ids => ['9'], |
130 assert_tag :select, :attributes => {:name => 'project[parent_id]'}, | 126 :enabled_module_names => ['issue_tracking', 'news', 'repository'] |
131 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}} | 127 } |
132 # no empty value | 128 assert_redirected_to '/projects/blog/settings' |
133 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}, | 129 |
134 :child => {:tag => 'option', :attributes => {:value => ''}} | 130 project = Project.find_by_name('blog') |
135 end | 131 assert_kind_of Project, project |
136 end | 132 assert project.active? |
137 | 133 assert_equal 'weblog', project.description |
138 end | 134 assert_equal 'http://weblog', project.homepage |
139 | 135 assert_equal true, project.is_public? |
140 context "POST :create" do | 136 assert_nil project.parent |
141 context "by admin user" do | 137 assert_equal 'Beta', project.custom_value_for(3).value |
142 setup do | 138 assert_equal [1, 3], project.trackers.map(&:id).sort |
143 @request.session[:user_id] = 1 | 139 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort |
144 end | 140 assert project.issue_custom_fields.include?(IssueCustomField.find(9)) |
145 | 141 end |
146 should "create a new project" do | 142 |
147 post :create, | 143 test "#create by admin user should create a new subproject" do |
148 :project => { | 144 @request.session[:user_id] = 1 |
149 :name => "blog", | 145 |
150 :description => "weblog", | 146 assert_difference 'Project.count' do |
151 :homepage => 'http://weblog', | 147 post :create, :project => { :name => "blog", |
152 :identifier => "blog", | 148 :description => "weblog", |
153 :is_public => 1, | 149 :identifier => "blog", |
154 :custom_field_values => { '3' => 'Beta' }, | 150 :is_public => 1, |
155 :tracker_ids => ['1', '3'], | 151 :custom_field_values => { '3' => 'Beta' }, |
156 # an issue custom field that is not for all project | 152 :parent_id => 1 |
157 :issue_custom_field_ids => ['9'], | 153 } |
158 :enabled_module_names => ['issue_tracking', 'news', 'repository'] | 154 assert_redirected_to '/projects/blog/settings' |
159 } | 155 end |
160 assert_redirected_to '/projects/blog/settings' | 156 |
161 | 157 project = Project.find_by_name('blog') |
162 project = Project.find_by_name('blog') | 158 assert_kind_of Project, project |
163 assert_kind_of Project, project | 159 assert_equal Project.find(1), project.parent |
164 assert project.active? | 160 end |
165 assert_equal 'weblog', project.description | 161 |
166 assert_equal 'http://weblog', project.homepage | 162 test "#create by admin user should continue" do |
167 assert_equal true, project.is_public? | 163 @request.session[:user_id] = 1 |
168 assert_nil project.parent | 164 |
169 assert_equal 'Beta', project.custom_value_for(3).value | 165 assert_difference 'Project.count' do |
170 assert_equal [1, 3], project.trackers.map(&:id).sort | 166 post :create, :project => {:name => "blog", :identifier => "blog"}, :continue => 'Create and continue' |
171 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort | 167 end |
172 assert project.issue_custom_fields.include?(IssueCustomField.find(9)) | 168 assert_redirected_to '/projects/new' |
173 end | 169 end |
174 | 170 |
175 should "create a new subproject" do | 171 test "#create by non-admin user with add_project permission should create a new project" do |
176 post :create, :project => { :name => "blog", | 172 Role.non_member.add_permission! :add_project |
177 :description => "weblog", | 173 @request.session[:user_id] = 9 |
178 :identifier => "blog", | 174 |
179 :is_public => 1, | 175 post :create, :project => { :name => "blog", |
180 :custom_field_values => { '3' => 'Beta' }, | 176 :description => "weblog", |
181 :parent_id => 1 | 177 :identifier => "blog", |
182 } | 178 :is_public => 1, |
183 assert_redirected_to '/projects/blog/settings' | 179 :custom_field_values => { '3' => 'Beta' }, |
184 | 180 :tracker_ids => ['1', '3'], |
185 project = Project.find_by_name('blog') | 181 :enabled_module_names => ['issue_tracking', 'news', 'repository'] |
186 assert_kind_of Project, project | 182 } |
187 assert_equal Project.find(1), project.parent | 183 |
188 end | 184 assert_redirected_to '/projects/blog/settings' |
189 | 185 |
190 should "continue" do | 186 project = Project.find_by_name('blog') |
191 assert_difference 'Project.count' do | 187 assert_kind_of Project, project |
192 post :create, :project => {:name => "blog", :identifier => "blog"}, :continue => 'Create and continue' | 188 assert_equal 'weblog', project.description |
193 end | 189 assert_equal true, project.is_public? |
194 assert_redirected_to '/projects/new?' | 190 assert_equal [1, 3], project.trackers.map(&:id).sort |
195 end | 191 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort |
196 end | 192 |
197 | 193 # User should be added as a project member |
198 context "by non-admin user with add_project permission" do | 194 assert User.find(9).member_of?(project) |
199 setup do | 195 assert_equal 1, project.members.size |
200 Role.non_member.add_permission! :add_project | 196 end |
201 @request.session[:user_id] = 9 | 197 |
202 end | 198 test "#create by non-admin user with add_project permission should fail with parent_id" do |
203 | 199 Role.non_member.add_permission! :add_project |
204 should "accept create a Project" do | 200 @request.session[:user_id] = 9 |
205 post :create, :project => { :name => "blog", | 201 |
206 :description => "weblog", | 202 assert_no_difference 'Project.count' do |
207 :identifier => "blog", | 203 post :create, :project => { :name => "blog", |
208 :is_public => 1, | 204 :description => "weblog", |
209 :custom_field_values => { '3' => 'Beta' }, | 205 :identifier => "blog", |
210 :tracker_ids => ['1', '3'], | 206 :is_public => 1, |
211 :enabled_module_names => ['issue_tracking', 'news', 'repository'] | 207 :custom_field_values => { '3' => 'Beta' }, |
212 } | 208 :parent_id => 1 |
213 | 209 } |
214 assert_redirected_to '/projects/blog/settings' | 210 end |
215 | 211 assert_response :success |
216 project = Project.find_by_name('blog') | 212 project = assigns(:project) |
217 assert_kind_of Project, project | 213 assert_kind_of Project, project |
218 assert_equal 'weblog', project.description | 214 assert_not_equal [], project.errors[:parent_id] |
219 assert_equal true, project.is_public? | 215 end |
220 assert_equal [1, 3], project.trackers.map(&:id).sort | 216 |
221 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort | 217 test "#create by non-admin user with add_subprojects permission should create a project with a parent_id" do |
222 | 218 Role.find(1).remove_permission! :add_project |
223 # User should be added as a project member | 219 Role.find(1).add_permission! :add_subprojects |
224 assert User.find(9).member_of?(project) | 220 @request.session[:user_id] = 2 |
225 assert_equal 1, project.members.size | 221 |
226 end | 222 post :create, :project => { :name => "blog", |
227 | 223 :description => "weblog", |
228 should "fail with parent_id" do | 224 :identifier => "blog", |
229 assert_no_difference 'Project.count' do | 225 :is_public => 1, |
230 post :create, :project => { :name => "blog", | 226 :custom_field_values => { '3' => 'Beta' }, |
231 :description => "weblog", | 227 :parent_id => 1 |
232 :identifier => "blog", | 228 } |
233 :is_public => 1, | 229 assert_redirected_to '/projects/blog/settings' |
234 :custom_field_values => { '3' => 'Beta' }, | 230 project = Project.find_by_name('blog') |
235 :parent_id => 1 | 231 end |
236 } | 232 |
237 end | 233 test "#create by non-admin user with add_subprojects permission should fail without parent_id" do |
238 assert_response :success | 234 Role.find(1).remove_permission! :add_project |
239 project = assigns(:project) | 235 Role.find(1).add_permission! :add_subprojects |
240 assert_kind_of Project, project | 236 @request.session[:user_id] = 2 |
241 assert_not_nil project.errors[:parent_id] | 237 |
242 end | 238 assert_no_difference 'Project.count' do |
243 end | 239 post :create, :project => { :name => "blog", |
244 | 240 :description => "weblog", |
245 context "by non-admin user with add_subprojects permission" do | 241 :identifier => "blog", |
246 setup do | 242 :is_public => 1, |
247 Role.find(1).remove_permission! :add_project | 243 :custom_field_values => { '3' => 'Beta' } |
248 Role.find(1).add_permission! :add_subprojects | 244 } |
249 @request.session[:user_id] = 2 | 245 end |
250 end | 246 assert_response :success |
251 | 247 project = assigns(:project) |
252 should "create a project with a parent_id" do | 248 assert_kind_of Project, project |
253 post :create, :project => { :name => "blog", | 249 assert_not_equal [], project.errors[:parent_id] |
254 :description => "weblog", | 250 end |
255 :identifier => "blog", | 251 |
256 :is_public => 1, | 252 test "#create by non-admin user with add_subprojects permission should fail with unauthorized parent_id" do |
257 :custom_field_values => { '3' => 'Beta' }, | 253 Role.find(1).remove_permission! :add_project |
258 :parent_id => 1 | 254 Role.find(1).add_permission! :add_subprojects |
259 } | 255 @request.session[:user_id] = 2 |
260 assert_redirected_to '/projects/blog/settings' | 256 |
261 project = Project.find_by_name('blog') | 257 assert !User.find(2).member_of?(Project.find(6)) |
262 end | 258 assert_no_difference 'Project.count' do |
263 | 259 post :create, :project => { :name => "blog", |
264 should "fail without parent_id" do | 260 :description => "weblog", |
265 assert_no_difference 'Project.count' do | 261 :identifier => "blog", |
266 post :create, :project => { :name => "blog", | 262 :is_public => 1, |
267 :description => "weblog", | 263 :custom_field_values => { '3' => 'Beta' }, |
268 :identifier => "blog", | 264 :parent_id => 6 |
269 :is_public => 1, | 265 } |
270 :custom_field_values => { '3' => 'Beta' } | 266 end |
271 } | 267 assert_response :success |
272 end | 268 project = assigns(:project) |
273 assert_response :success | 269 assert_kind_of Project, project |
274 project = assigns(:project) | 270 assert_not_equal [], project.errors[:parent_id] |
275 assert_kind_of Project, project | 271 end |
276 assert_not_nil project.errors[:parent_id] | 272 |
277 end | 273 def test_create_subproject_with_inherit_members_should_inherit_members |
278 | 274 Role.find_by_name('Manager').add_permission! :add_subprojects |
279 should "fail with unauthorized parent_id" do | 275 parent = Project.find(1) |
280 assert !User.find(2).member_of?(Project.find(6)) | 276 @request.session[:user_id] = 2 |
281 assert_no_difference 'Project.count' do | 277 |
282 post :create, :project => { :name => "blog", | 278 assert_difference 'Project.count' do |
283 :description => "weblog", | 279 post :create, :project => { |
284 :identifier => "blog", | 280 :name => 'inherited', :identifier => 'inherited', :parent_id => parent.id, :inherit_members => '1' |
285 :is_public => 1, | 281 } |
286 :custom_field_values => { '3' => 'Beta' }, | 282 assert_response 302 |
287 :parent_id => 6 | 283 end |
288 } | 284 |
289 end | 285 project = Project.order('id desc').first |
290 assert_response :success | 286 assert_equal 'inherited', project.name |
291 project = assigns(:project) | 287 assert_equal parent, project.parent |
292 assert_kind_of Project, project | 288 assert project.memberships.count > 0 |
293 assert_not_nil project.errors[:parent_id] | 289 assert_equal parent.memberships.count, project.memberships.count |
294 end | |
295 end | |
296 end | 290 end |
297 | 291 |
298 def test_create_should_preserve_modules_on_validation_failure | 292 def test_create_should_preserve_modules_on_validation_failure |
299 with_settings :default_projects_modules => ['issue_tracking', 'repository'] do | 293 with_settings :default_projects_modules => ['issue_tracking', 'repository'] do |
300 @request.session[:user_id] = 1 | 294 @request.session[:user_id] = 1 |
323 assert_response :success | 317 assert_response :success |
324 assert_template 'show' | 318 assert_template 'show' |
325 assert_not_nil assigns(:project) | 319 assert_not_nil assigns(:project) |
326 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) | 320 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) |
327 | 321 |
328 assert_tag 'li', :content => /Development status/ | 322 assert_select 'li', :text => /Development status/ |
323 end | |
324 | |
325 def test_show_should_not_display_empty_sidebar | |
326 p = Project.find(1) | |
327 p.enabled_module_names = [] | |
328 p.save! | |
329 | |
330 get :show, :id => 'ecookbook' | |
331 assert_response :success | |
332 assert_select '#main.nosidebar' | |
329 end | 333 end |
330 | 334 |
331 def test_show_should_not_display_hidden_custom_fields | 335 def test_show_should_not_display_hidden_custom_fields |
332 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false | 336 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false |
333 get :show, :id => 'ecookbook' | 337 get :show, :id => 'ecookbook' |
334 assert_response :success | 338 assert_response :success |
335 assert_template 'show' | 339 assert_template 'show' |
336 assert_not_nil assigns(:project) | 340 assert_not_nil assigns(:project) |
337 | 341 |
338 assert_no_tag 'li', :content => /Development status/ | 342 assert_select 'li', :text => /Development status/, :count => 0 |
339 end | 343 end |
340 | 344 |
341 def test_show_should_not_fail_when_custom_values_are_nil | 345 def test_show_should_not_fail_when_custom_values_are_nil |
342 project = Project.find_by_identifier('ecookbook') | 346 project = Project.find_by_identifier('ecookbook') |
343 project.custom_values.first.update_attribute(:value, nil) | 347 project.custom_values.first.update_attribute(:value, nil) |
353 project.archive! | 357 project.archive! |
354 | 358 |
355 get :show, :id => 'ecookbook' | 359 get :show, :id => 'ecookbook' |
356 assert_response 403 | 360 assert_response 403 |
357 assert_nil assigns(:project) | 361 assert_nil assigns(:project) |
358 assert_tag :tag => 'p', :content => /archived/ | 362 assert_select 'p', :text => /archived/ |
359 end | 363 end |
360 | 364 |
361 def test_private_subprojects_hidden | 365 def test_show_should_not_show_private_subprojects_that_are_not_visible |
362 get :show, :id => 'ecookbook' | 366 get :show, :id => 'ecookbook' |
363 assert_response :success | 367 assert_response :success |
364 assert_template 'show' | 368 assert_template 'show' |
365 assert_no_tag :tag => 'a', :content => /Private child/ | 369 assert_select 'a', :text => /Private child/, :count => 0 |
366 end | 370 end |
367 | 371 |
368 def test_private_subprojects_visible | 372 def test_show_should_show_private_subprojects_that_are_visible |
369 @request.session[:user_id] = 2 # manager who is a member of the private subproject | 373 @request.session[:user_id] = 2 # manager who is a member of the private subproject |
370 get :show, :id => 'ecookbook' | 374 get :show, :id => 'ecookbook' |
371 assert_response :success | 375 assert_response :success |
372 assert_template 'show' | 376 assert_template 'show' |
373 assert_tag :tag => 'a', :content => /Private child/ | 377 assert_select 'a', :text => /Private child/ |
374 end | 378 end |
375 | 379 |
376 def test_settings | 380 def test_settings |
377 @request.session[:user_id] = 2 # manager | 381 @request.session[:user_id] = 2 # manager |
378 get :settings, :id => 1 | 382 get :settings, :id => 1 |
379 assert_response :success | 383 assert_response :success |
380 assert_template 'settings' | 384 assert_template 'settings' |
385 end | |
386 | |
387 def test_settings_of_subproject | |
388 @request.session[:user_id] = 2 | |
389 get :settings, :id => 'private-child' | |
390 assert_response :success | |
391 assert_template 'settings' | |
392 | |
393 assert_select 'input[type=checkbox][name=?]', 'project[inherit_members]' | |
381 end | 394 end |
382 | 395 |
383 def test_settings_should_be_denied_for_member_on_closed_project | 396 def test_settings_should_be_denied_for_member_on_closed_project |
384 Project.find(1).close | 397 Project.find(1).close |
385 @request.session[:user_id] = 2 # manager | 398 @request.session[:user_id] = 2 # manager |
407 def test_update_with_failure | 420 def test_update_with_failure |
408 @request.session[:user_id] = 2 # manager | 421 @request.session[:user_id] = 2 # manager |
409 post :update, :id => 1, :project => {:name => ''} | 422 post :update, :id => 1, :project => {:name => ''} |
410 assert_response :success | 423 assert_response :success |
411 assert_template 'settings' | 424 assert_template 'settings' |
412 assert_error_tag :content => /name can't be blank/i | 425 assert_error_tag :content => /name #{ESCAPED_CANT} be blank/i |
413 end | 426 end |
414 | 427 |
415 def test_update_should_be_denied_for_member_on_closed_project | 428 def test_update_should_be_denied_for_member_on_closed_project |
416 Project.find(1).close | 429 Project.find(1).close |
417 @request.session[:user_id] = 2 # manager | 430 @request.session[:user_id] = 2 # manager |
436 post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents'] | 449 post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents'] |
437 assert_redirected_to '/projects/ecookbook/settings/modules' | 450 assert_redirected_to '/projects/ecookbook/settings/modules' |
438 assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort | 451 assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort |
439 end | 452 end |
440 | 453 |
441 def test_destroy_without_confirmation | 454 def test_destroy_leaf_project_without_confirmation_should_show_confirmation |
442 @request.session[:user_id] = 1 # admin | 455 @request.session[:user_id] = 1 # admin |
443 delete :destroy, :id => 1 | 456 |
444 assert_response :success | 457 assert_no_difference 'Project.count' do |
445 assert_template 'destroy' | 458 delete :destroy, :id => 2 |
446 assert_not_nil Project.find_by_id(1) | 459 assert_response :success |
447 assert_tag :tag => 'strong', | 460 assert_template 'destroy' |
448 :content => ['Private child of eCookbook', | 461 end |
462 end | |
463 | |
464 def test_destroy_without_confirmation_should_show_confirmation_with_subprojects | |
465 @request.session[:user_id] = 1 # admin | |
466 | |
467 assert_no_difference 'Project.count' do | |
468 delete :destroy, :id => 1 | |
469 assert_response :success | |
470 assert_template 'destroy' | |
471 end | |
472 assert_select 'strong', | |
473 :text => ['Private child of eCookbook', | |
449 'Child of private child, eCookbook Subproject 1', | 474 'Child of private child, eCookbook Subproject 1', |
450 'eCookbook Subproject 2'].join(', ') | 475 'eCookbook Subproject 2'].join(', ') |
451 end | 476 end |
452 | 477 |
453 def test_destroy | 478 def test_destroy_with_confirmation_should_destroy_the_project_and_subprojects |
454 @request.session[:user_id] = 1 # admin | 479 @request.session[:user_id] = 1 # admin |
455 delete :destroy, :id => 1, :confirm => 1 | 480 |
456 assert_redirected_to '/admin/projects' | 481 assert_difference 'Project.count', -5 do |
482 delete :destroy, :id => 1, :confirm => 1 | |
483 assert_redirected_to '/admin/projects' | |
484 end | |
457 assert_nil Project.find_by_id(1) | 485 assert_nil Project.find_by_id(1) |
458 end | 486 end |
459 | 487 |
460 def test_archive | 488 def test_archive |
461 @request.session[:user_id] = 1 # admin | 489 @request.session[:user_id] = 1 # admin |
497 | 525 |
498 def test_project_breadcrumbs_should_be_limited_to_3_ancestors | 526 def test_project_breadcrumbs_should_be_limited_to_3_ancestors |
499 CustomField.delete_all | 527 CustomField.delete_all |
500 parent = nil | 528 parent = nil |
501 6.times do |i| | 529 6.times do |i| |
502 p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}") | 530 p = Project.generate_with_parent!(parent) |
503 p.set_parent!(parent) | |
504 get :show, :id => p | 531 get :show, :id => p |
505 assert_tag :h1, :parent => { :attributes => {:id => 'header'}}, | 532 assert_select '#header h1' do |
506 :children => { :count => [i, 3].min, | 533 assert_select 'a', :count => [i, 3].min |
507 :only => { :tag => 'a' } } | 534 end |
508 | 535 |
509 parent = p | 536 parent = p |
510 end | 537 end |
511 end | 538 end |
512 | 539 |
517 assert_template 'copy' | 544 assert_template 'copy' |
518 assert assigns(:project) | 545 assert assigns(:project) |
519 assert_equal Project.find(1).description, assigns(:project).description | 546 assert_equal Project.find(1).description, assigns(:project).description |
520 assert_nil assigns(:project).id | 547 assert_nil assigns(:project).id |
521 | 548 |
522 assert_tag :tag => 'input', | 549 assert_select 'input[name=?][value=?]', 'project[enabled_module_names][]', 'issue_tracking', 1 |
523 :attributes => {:name => 'project[enabled_module_names][]', :value => 'issue_tracking'} | |
524 end | 550 end |
525 | 551 |
526 def test_get_copy_with_invalid_source_should_respond_with_404 | 552 def test_get_copy_with_invalid_source_should_respond_with_404 |
527 @request.session[:user_id] = 1 | 553 @request.session[:user_id] = 1 |
528 get :copy, :id => 99 | 554 get :copy, :id => 99 |
573 def test_jump_should_not_redirect_to_unknown_tab | 599 def test_jump_should_not_redirect_to_unknown_tab |
574 get :show, :id => 3, :jump => 'foobar' | 600 get :show, :id => 3, :jump => 'foobar' |
575 assert_response :success | 601 assert_response :success |
576 assert_template 'show' | 602 assert_template 'show' |
577 end | 603 end |
604 | |
605 def test_body_should_have_project_css_class | |
606 get :show, :id => 1 | |
607 assert_select 'body.project-ecookbook' | |
608 end | |
578 end | 609 end |