##// END OF EJS Templates
Fixed: selected modules are not activated when copying a project (#8244)....
Jean-Philippe Lang -
r5461:fab9aca747d8
parent child
Show More
@@ -1,269 +1,268
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 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 class ProjectsController < ApplicationController
19 19 menu_item :overview
20 20 menu_item :roadmap, :only => :roadmap
21 21 menu_item :settings, :only => :settings
22 22
23 23 before_filter :find_project, :except => [ :index, :list, :new, :create, :copy ]
24 24 before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy]
25 25 before_filter :authorize_global, :only => [:new, :create]
26 26 before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
27 27 accept_key_auth :index, :show, :create, :update, :destroy
28 28
29 29 after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller|
30 30 if controller.request.post?
31 31 controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt'
32 32 end
33 33 end
34 34
35 35 helper :sort
36 36 include SortHelper
37 37 helper :custom_fields
38 38 include CustomFieldsHelper
39 39 helper :issues
40 40 helper :queries
41 41 include QueriesHelper
42 42 helper :repositories
43 43 include RepositoriesHelper
44 44 include ProjectsHelper
45 45
46 46 # Lists visible projects
47 47 def index
48 48 respond_to do |format|
49 49 format.html {
50 50 @projects = Project.visible.find(:all, :order => 'lft')
51 51 }
52 52 format.api {
53 53 @offset, @limit = api_offset_and_limit
54 54 @project_count = Project.visible.count
55 55 @projects = Project.visible.all(:offset => @offset, :limit => @limit, :order => 'lft')
56 56 }
57 57 format.atom {
58 58 projects = Project.visible.find(:all, :order => 'created_on DESC',
59 59 :limit => Setting.feeds_limit.to_i)
60 60 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
61 61 }
62 62 end
63 63 end
64 64
65 65 def new
66 66 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
67 67 @trackers = Tracker.all
68 68 @project = Project.new(params[:project])
69 69 end
70 70
71 71 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
72 72 def create
73 73 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
74 74 @trackers = Tracker.all
75 75 @project = Project.new
76 76 @project.safe_attributes = params[:project]
77 77
78 78 if validate_parent_id && @project.save
79 79 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
80 80 # Add current user as a project member if he is not admin
81 81 unless User.current.admin?
82 82 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
83 83 m = Member.new(:user => User.current, :roles => [r])
84 84 @project.members << m
85 85 end
86 86 respond_to do |format|
87 87 format.html {
88 88 flash[:notice] = l(:notice_successful_create)
89 89 redirect_to :controller => 'projects', :action => 'settings', :id => @project
90 90 }
91 91 format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
92 92 end
93 93 else
94 94 respond_to do |format|
95 95 format.html { render :action => 'new' }
96 96 format.api { render_validation_errors(@project) }
97 97 end
98 98 end
99 99
100 100 end
101 101
102 102 def copy
103 103 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
104 104 @trackers = Tracker.all
105 105 @root_projects = Project.find(:all,
106 106 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
107 107 :order => 'name')
108 108 @source_project = Project.find(params[:id])
109 109 if request.get?
110 110 @project = Project.copy_from(@source_project)
111 111 if @project
112 112 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
113 113 else
114 114 redirect_to :controller => 'admin', :action => 'projects'
115 115 end
116 116 else
117 117 Mailer.with_deliveries(params[:notifications] == '1') do
118 118 @project = Project.new
119 119 @project.safe_attributes = params[:project]
120 @project.enabled_module_names = params[:enabled_modules]
121 120 if validate_parent_id && @project.copy(@source_project, :only => params[:only])
122 121 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
123 122 flash[:notice] = l(:notice_successful_create)
124 123 redirect_to :controller => 'projects', :action => 'settings', :id => @project
125 124 elsif !@project.new_record?
126 125 # Project was created
127 126 # But some objects were not copied due to validation failures
128 127 # (eg. issues from disabled trackers)
129 128 # TODO: inform about that
130 129 redirect_to :controller => 'projects', :action => 'settings', :id => @project
131 130 end
132 131 end
133 132 end
134 133 rescue ActiveRecord::RecordNotFound
135 134 redirect_to :controller => 'admin', :action => 'projects'
136 135 end
137 136
138 137 # Show @project
139 138 def show
140 139 if params[:jump]
141 140 # try to redirect to the requested menu item
142 141 redirect_to_project_menu_item(@project, params[:jump]) && return
143 142 end
144 143
145 144 @users_by_role = @project.users_by_role
146 145 @subprojects = @project.children.visible.all
147 146 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
148 147 @trackers = @project.rolled_up_trackers
149 148
150 149 cond = @project.project_condition(Setting.display_subprojects_issues?)
151 150
152 151 @open_issues_by_tracker = Issue.visible.count(:group => :tracker,
153 152 :include => [:project, :status, :tracker],
154 153 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
155 154 @total_issues_by_tracker = Issue.visible.count(:group => :tracker,
156 155 :include => [:project, :status, :tracker],
157 156 :conditions => cond)
158 157
159 158 if User.current.allowed_to?(:view_time_entries, @project)
160 159 @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f
161 160 end
162 161
163 162 @key = User.current.rss_key
164 163
165 164 respond_to do |format|
166 165 format.html
167 166 format.api
168 167 end
169 168 end
170 169
171 170 def settings
172 171 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
173 172 @issue_category ||= IssueCategory.new
174 173 @member ||= @project.members.new
175 174 @trackers = Tracker.all
176 175 @repository ||= @project.repository
177 176 @wiki ||= @project.wiki
178 177 end
179 178
180 179 def edit
181 180 end
182 181
183 182 # TODO: convert to PUT only
184 183 verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
185 184 def update
186 185 @project.safe_attributes = params[:project]
187 186 if validate_parent_id && @project.save
188 187 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
189 188 respond_to do |format|
190 189 format.html {
191 190 flash[:notice] = l(:notice_successful_update)
192 191 redirect_to :action => 'settings', :id => @project
193 192 }
194 193 format.api { head :ok }
195 194 end
196 195 else
197 196 respond_to do |format|
198 197 format.html {
199 198 settings
200 199 render :action => 'settings'
201 200 }
202 201 format.api { render_validation_errors(@project) }
203 202 end
204 203 end
205 204 end
206 205
207 206 verify :method => :post, :only => :modules, :render => {:nothing => true, :status => :method_not_allowed }
208 207 def modules
209 208 @project.enabled_module_names = params[:enabled_module_names]
210 209 flash[:notice] = l(:notice_successful_update)
211 210 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
212 211 end
213 212
214 213 def archive
215 214 if request.post?
216 215 unless @project.archive
217 216 flash[:error] = l(:error_can_not_archive_project)
218 217 end
219 218 end
220 219 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
221 220 end
222 221
223 222 def unarchive
224 223 @project.unarchive if request.post? && !@project.active?
225 224 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
226 225 end
227 226
228 227 # Delete @project
229 228 def destroy
230 229 @project_to_destroy = @project
231 230 if request.get?
232 231 # display confirmation view
233 232 else
234 233 if api_request? || params[:confirm]
235 234 @project_to_destroy.destroy
236 235 respond_to do |format|
237 236 format.html { redirect_to :controller => 'admin', :action => 'projects' }
238 237 format.api { head :ok }
239 238 end
240 239 end
241 240 end
242 241 # hide project in layout
243 242 @project = nil
244 243 end
245 244
246 245 private
247 246 def find_optional_project
248 247 return true unless params[:id]
249 248 @project = Project.find(params[:id])
250 249 authorize
251 250 rescue ActiveRecord::RecordNotFound
252 251 render_404
253 252 end
254 253
255 254 # Validates parent_id param according to user's permissions
256 255 # TODO: move it to Project model in a validation that depends on User.current
257 256 def validate_parent_id
258 257 return true if User.current.admin?
259 258 parent_id = params[:project] && params[:project][:parent_id]
260 259 if parent_id || @project.new_record?
261 260 parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i)
262 261 unless @project.allowed_parents.include?(parent)
263 262 @project.errors.add :parent_id, :invalid
264 263 return false
265 264 end
266 265 end
267 266 true
268 267 end
269 268 end
@@ -1,533 +1,538
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2008 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.expand_path('../../test_helper', __FILE__)
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 < ActionController::TestCase
25 25 fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
26 26 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
27 27 :attachments, :custom_fields, :custom_values, :time_entries
28 28
29 29 def setup
30 30 @controller = ProjectsController.new
31 31 @request = ActionController::TestRequest.new
32 32 @response = ActionController::TestResponse.new
33 33 @request.session[:user_id] = nil
34 34 Setting.default_language = 'en'
35 35 end
36 36
37 37 def test_index
38 38 get :index
39 39 assert_response :success
40 40 assert_template 'index'
41 41 assert_not_nil assigns(:projects)
42 42
43 43 assert_tag :ul, :child => {:tag => 'li',
44 44 :descendant => {:tag => 'a', :content => 'eCookbook'},
45 45 :child => { :tag => 'ul',
46 46 :descendant => { :tag => 'a',
47 47 :content => 'Child of private child'
48 48 }
49 49 }
50 50 }
51 51
52 52 assert_no_tag :a, :content => /Private child of eCookbook/
53 53 end
54 54
55 55 def test_index_atom
56 56 get :index, :format => 'atom'
57 57 assert_response :success
58 58 assert_template 'common/feed.atom.rxml'
59 59 assert_select 'feed>title', :text => 'Redmine: Latest projects'
60 60 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_condition(User.current))
61 61 end
62 62
63 63 context "#index" do
64 64 context "by non-admin user with view_time_entries permission" do
65 65 setup do
66 66 @request.session[:user_id] = 3
67 67 end
68 68 should "show overall spent time link" do
69 69 get :index
70 70 assert_template 'index'
71 71 assert_tag :a, :attributes => {:href => '/time_entries'}
72 72 end
73 73 end
74 74
75 75 context "by non-admin user without view_time_entries permission" do
76 76 setup do
77 77 Role.find(2).remove_permission! :view_time_entries
78 78 Role.non_member.remove_permission! :view_time_entries
79 79 Role.anonymous.remove_permission! :view_time_entries
80 80 @request.session[:user_id] = 3
81 81 end
82 82 should "not show overall spent time link" do
83 83 get :index
84 84 assert_template 'index'
85 85 assert_no_tag :a, :attributes => {:href => '/time_entries'}
86 86 end
87 87 end
88 88 end
89 89
90 90 context "#new" do
91 91 context "by admin user" do
92 92 setup do
93 93 @request.session[:user_id] = 1
94 94 end
95 95
96 96 should "accept get" do
97 97 get :new
98 98 assert_response :success
99 99 assert_template 'new'
100 100 end
101 101
102 102 end
103 103
104 104 context "by non-admin user with add_project permission" do
105 105 setup do
106 106 Role.non_member.add_permission! :add_project
107 107 @request.session[:user_id] = 9
108 108 end
109 109
110 110 should "accept get" do
111 111 get :new
112 112 assert_response :success
113 113 assert_template 'new'
114 114 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}
115 115 end
116 116 end
117 117
118 118 context "by non-admin user with add_subprojects permission" do
119 119 setup do
120 120 Role.find(1).remove_permission! :add_project
121 121 Role.find(1).add_permission! :add_subprojects
122 122 @request.session[:user_id] = 2
123 123 end
124 124
125 125 should "accept get" do
126 126 get :new, :parent_id => 'ecookbook'
127 127 assert_response :success
128 128 assert_template 'new'
129 129 # parent project selected
130 130 assert_tag :select, :attributes => {:name => 'project[parent_id]'},
131 131 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}}
132 132 # no empty value
133 133 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'},
134 134 :child => {:tag => 'option', :attributes => {:value => ''}}
135 135 end
136 136 end
137 137
138 138 end
139 139
140 140 context "POST :create" do
141 141 context "by admin user" do
142 142 setup do
143 143 @request.session[:user_id] = 1
144 144 end
145 145
146 146 should "create a new project" do
147 147 post :create,
148 148 :project => {
149 149 :name => "blog",
150 150 :description => "weblog",
151 151 :homepage => 'http://weblog',
152 152 :identifier => "blog",
153 153 :is_public => 1,
154 154 :custom_field_values => { '3' => 'Beta' },
155 155 :tracker_ids => ['1', '3'],
156 156 # an issue custom field that is not for all project
157 157 :issue_custom_field_ids => ['9'],
158 158 :enabled_module_names => ['issue_tracking', 'news', 'repository']
159 159 }
160 160 assert_redirected_to '/projects/blog/settings'
161 161
162 162 project = Project.find_by_name('blog')
163 163 assert_kind_of Project, project
164 164 assert project.active?
165 165 assert_equal 'weblog', project.description
166 166 assert_equal 'http://weblog', project.homepage
167 167 assert_equal true, project.is_public?
168 168 assert_nil project.parent
169 169 assert_equal 'Beta', project.custom_value_for(3).value
170 170 assert_equal [1, 3], project.trackers.map(&:id).sort
171 171 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort
172 172 assert project.issue_custom_fields.include?(IssueCustomField.find(9))
173 173 end
174 174
175 175 should "create a new subproject" do
176 176 post :create, :project => { :name => "blog",
177 177 :description => "weblog",
178 178 :identifier => "blog",
179 179 :is_public => 1,
180 180 :custom_field_values => { '3' => 'Beta' },
181 181 :parent_id => 1
182 182 }
183 183 assert_redirected_to '/projects/blog/settings'
184 184
185 185 project = Project.find_by_name('blog')
186 186 assert_kind_of Project, project
187 187 assert_equal Project.find(1), project.parent
188 188 end
189 189 end
190 190
191 191 context "by non-admin user with add_project permission" do
192 192 setup do
193 193 Role.non_member.add_permission! :add_project
194 194 @request.session[:user_id] = 9
195 195 end
196 196
197 197 should "accept create a Project" do
198 198 post :create, :project => { :name => "blog",
199 199 :description => "weblog",
200 200 :identifier => "blog",
201 201 :is_public => 1,
202 202 :custom_field_values => { '3' => 'Beta' },
203 203 :tracker_ids => ['1', '3'],
204 204 :enabled_module_names => ['issue_tracking', 'news', 'repository']
205 205 }
206 206
207 207 assert_redirected_to '/projects/blog/settings'
208 208
209 209 project = Project.find_by_name('blog')
210 210 assert_kind_of Project, project
211 211 assert_equal 'weblog', project.description
212 212 assert_equal true, project.is_public?
213 213 assert_equal [1, 3], project.trackers.map(&:id).sort
214 214 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort
215 215
216 216 # User should be added as a project member
217 217 assert User.find(9).member_of?(project)
218 218 assert_equal 1, project.members.size
219 219 end
220 220
221 221 should "fail with parent_id" do
222 222 assert_no_difference 'Project.count' do
223 223 post :create, :project => { :name => "blog",
224 224 :description => "weblog",
225 225 :identifier => "blog",
226 226 :is_public => 1,
227 227 :custom_field_values => { '3' => 'Beta' },
228 228 :parent_id => 1
229 229 }
230 230 end
231 231 assert_response :success
232 232 project = assigns(:project)
233 233 assert_kind_of Project, project
234 234 assert_not_nil project.errors.on(:parent_id)
235 235 end
236 236 end
237 237
238 238 context "by non-admin user with add_subprojects permission" do
239 239 setup do
240 240 Role.find(1).remove_permission! :add_project
241 241 Role.find(1).add_permission! :add_subprojects
242 242 @request.session[:user_id] = 2
243 243 end
244 244
245 245 should "create a project with a parent_id" do
246 246 post :create, :project => { :name => "blog",
247 247 :description => "weblog",
248 248 :identifier => "blog",
249 249 :is_public => 1,
250 250 :custom_field_values => { '3' => 'Beta' },
251 251 :parent_id => 1
252 252 }
253 253 assert_redirected_to '/projects/blog/settings'
254 254 project = Project.find_by_name('blog')
255 255 end
256 256
257 257 should "fail without parent_id" do
258 258 assert_no_difference 'Project.count' do
259 259 post :create, :project => { :name => "blog",
260 260 :description => "weblog",
261 261 :identifier => "blog",
262 262 :is_public => 1,
263 263 :custom_field_values => { '3' => 'Beta' }
264 264 }
265 265 end
266 266 assert_response :success
267 267 project = assigns(:project)
268 268 assert_kind_of Project, project
269 269 assert_not_nil project.errors.on(:parent_id)
270 270 end
271 271
272 272 should "fail with unauthorized parent_id" do
273 273 assert !User.find(2).member_of?(Project.find(6))
274 274 assert_no_difference 'Project.count' do
275 275 post :create, :project => { :name => "blog",
276 276 :description => "weblog",
277 277 :identifier => "blog",
278 278 :is_public => 1,
279 279 :custom_field_values => { '3' => 'Beta' },
280 280 :parent_id => 6
281 281 }
282 282 end
283 283 assert_response :success
284 284 project = assigns(:project)
285 285 assert_kind_of Project, project
286 286 assert_not_nil project.errors.on(:parent_id)
287 287 end
288 288 end
289 289 end
290 290
291 291 def test_create_should_preserve_modules_on_validation_failure
292 292 with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
293 293 @request.session[:user_id] = 1
294 294 assert_no_difference 'Project.count' do
295 295 post :create, :project => {
296 296 :name => "blog",
297 297 :identifier => "",
298 298 :enabled_module_names => %w(issue_tracking news)
299 299 }
300 300 end
301 301 assert_response :success
302 302 project = assigns(:project)
303 303 assert_equal %w(issue_tracking news), project.enabled_module_names.sort
304 304 end
305 305 end
306 306
307 307 def test_create_should_not_accept_get
308 308 @request.session[:user_id] = 1
309 309 get :create
310 310 assert_response :method_not_allowed
311 311 end
312 312
313 313 def test_show_by_id
314 314 get :show, :id => 1
315 315 assert_response :success
316 316 assert_template 'show'
317 317 assert_not_nil assigns(:project)
318 318 end
319 319
320 320 def test_show_by_identifier
321 321 get :show, :id => 'ecookbook'
322 322 assert_response :success
323 323 assert_template 'show'
324 324 assert_not_nil assigns(:project)
325 325 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
326 326
327 327 assert_tag 'li', :content => /Development status/
328 328 end
329 329
330 330 def test_show_should_not_display_hidden_custom_fields
331 331 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
332 332 get :show, :id => 'ecookbook'
333 333 assert_response :success
334 334 assert_template 'show'
335 335 assert_not_nil assigns(:project)
336 336
337 337 assert_no_tag 'li', :content => /Development status/
338 338 end
339 339
340 340 def test_show_should_not_fail_when_custom_values_are_nil
341 341 project = Project.find_by_identifier('ecookbook')
342 342 project.custom_values.first.update_attribute(:value, nil)
343 343 get :show, :id => 'ecookbook'
344 344 assert_response :success
345 345 assert_template 'show'
346 346 assert_not_nil assigns(:project)
347 347 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
348 348 end
349 349
350 350 def show_archived_project_should_be_denied
351 351 project = Project.find_by_identifier('ecookbook')
352 352 project.archive!
353 353
354 354 get :show, :id => 'ecookbook'
355 355 assert_response 403
356 356 assert_nil assigns(:project)
357 357 assert_tag :tag => 'p', :content => /archived/
358 358 end
359 359
360 360 def test_private_subprojects_hidden
361 361 get :show, :id => 'ecookbook'
362 362 assert_response :success
363 363 assert_template 'show'
364 364 assert_no_tag :tag => 'a', :content => /Private child/
365 365 end
366 366
367 367 def test_private_subprojects_visible
368 368 @request.session[:user_id] = 2 # manager who is a member of the private subproject
369 369 get :show, :id => 'ecookbook'
370 370 assert_response :success
371 371 assert_template 'show'
372 372 assert_tag :tag => 'a', :content => /Private child/
373 373 end
374 374
375 375 def test_settings
376 376 @request.session[:user_id] = 2 # manager
377 377 get :settings, :id => 1
378 378 assert_response :success
379 379 assert_template 'settings'
380 380 end
381 381
382 382 def test_update
383 383 @request.session[:user_id] = 2 # manager
384 384 post :update, :id => 1, :project => {:name => 'Test changed name',
385 385 :issue_custom_field_ids => ['']}
386 386 assert_redirected_to '/projects/ecookbook/settings'
387 387 project = Project.find(1)
388 388 assert_equal 'Test changed name', project.name
389 389 end
390 390
391 391 def test_modules
392 392 @request.session[:user_id] = 2
393 393 Project.find(1).enabled_module_names = ['issue_tracking', 'news']
394 394
395 395 post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents']
396 396 assert_redirected_to '/projects/ecookbook/settings/modules'
397 397 assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort
398 398 end
399 399
400 400 def test_modules_should_not_allow_get
401 401 @request.session[:user_id] = 1
402 402 get :modules, :id => 1
403 403 assert_response :method_not_allowed
404 404 end
405 405
406 406 def test_get_destroy
407 407 @request.session[:user_id] = 1 # admin
408 408 get :destroy, :id => 1
409 409 assert_response :success
410 410 assert_template 'destroy'
411 411 assert_not_nil Project.find_by_id(1)
412 412 end
413 413
414 414 def test_post_destroy
415 415 @request.session[:user_id] = 1 # admin
416 416 post :destroy, :id => 1, :confirm => 1
417 417 assert_redirected_to '/admin/projects'
418 418 assert_nil Project.find_by_id(1)
419 419 end
420 420
421 421 def test_archive
422 422 @request.session[:user_id] = 1 # admin
423 423 post :archive, :id => 1
424 424 assert_redirected_to '/admin/projects'
425 425 assert !Project.find(1).active?
426 426 end
427 427
428 428 def test_unarchive
429 429 @request.session[:user_id] = 1 # admin
430 430 Project.find(1).archive
431 431 post :unarchive, :id => 1
432 432 assert_redirected_to '/admin/projects'
433 433 assert Project.find(1).active?
434 434 end
435 435
436 436 def test_project_breadcrumbs_should_be_limited_to_3_ancestors
437 437 CustomField.delete_all
438 438 parent = nil
439 439 6.times do |i|
440 440 p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}")
441 441 p.set_parent!(parent)
442 442 get :show, :id => p
443 443 assert_tag :h1, :parent => { :attributes => {:id => 'header'}},
444 444 :children => { :count => [i, 3].min,
445 445 :only => { :tag => 'a' } }
446 446
447 447 parent = p
448 448 end
449 449 end
450 450
451 def test_copy_with_project
451 def test_get_copy
452 452 @request.session[:user_id] = 1 # admin
453 453 get :copy, :id => 1
454 454 assert_response :success
455 455 assert_template 'copy'
456 456 assert assigns(:project)
457 457 assert_equal Project.find(1).description, assigns(:project).description
458 458 assert_nil assigns(:project).id
459
460 assert_tag :tag => 'input',
461 :attributes => {:name => 'project[enabled_module_names][]', :value => 'issue_tracking'}
459 462 end
460 463
461 def test_copy_without_project
464 def test_get_copy_without_project
462 465 @request.session[:user_id] = 1 # admin
463 466 get :copy
464 467 assert_response :redirect
465 468 assert_redirected_to :controller => 'admin', :action => 'projects'
466 469 end
467 470
468 471 def test_post_copy_should_copy_requested_items
469 472 @request.session[:user_id] = 1 # admin
470 473 CustomField.delete_all
471 474
472 475 assert_difference 'Project.count' do
473 476 post :copy, :id => 1,
474 477 :project => {
475 478 :name => 'Copy',
476 479 :identifier => 'unique-copy',
477 480 :tracker_ids => ['1', '2', '3', ''],
478 :enabled_modules => %w(issue_tracking time_tracking)
481 :enabled_module_names => %w(issue_tracking time_tracking)
479 482 },
480 483 :only => %w(issues versions)
481 484 end
482 485 project = Project.find('unique-copy')
483 486 source = Project.find(1)
487 assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort
488
484 489 assert_equal source.versions.count, project.versions.count, "All versions were not copied"
485 490 # issues assigned to a closed version won't be copied
486 491 assert_equal source.issues.select {|i| i.fixed_version.nil? || i.fixed_version.open?}.size,
487 492 project.issues.count, "All issues were not copied"
488 493 assert_equal 0, project.members.count
489 494 end
490 495
491 496 def test_post_copy_should_redirect_to_settings_when_successful
492 497 @request.session[:user_id] = 1 # admin
493 498 post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'}
494 499 assert_response :redirect
495 500 assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy'
496 501 end
497 502
498 503 def test_jump_should_redirect_to_active_tab
499 504 get :show, :id => 1, :jump => 'issues'
500 505 assert_redirected_to '/projects/ecookbook/issues'
501 506 end
502 507
503 508 def test_jump_should_not_redirect_to_inactive_tab
504 509 get :show, :id => 3, :jump => 'documents'
505 510 assert_response :success
506 511 assert_template 'show'
507 512 end
508 513
509 514 def test_jump_should_not_redirect_to_unknown_tab
510 515 get :show, :id => 3, :jump => 'foobar'
511 516 assert_response :success
512 517 assert_template 'show'
513 518 end
514 519
515 520 # A hook that is manually registered later
516 521 class ProjectBasedTemplate < Redmine::Hook::ViewListener
517 522 def view_layouts_base_html_head(context)
518 523 # Adds a project stylesheet
519 524 stylesheet_link_tag(context[:project].identifier) if context[:project]
520 525 end
521 526 end
522 527 # Don't use this hook now
523 528 Redmine::Hook.clear_listeners
524 529
525 530 def test_hook_response
526 531 Redmine::Hook.add_listener(ProjectBasedTemplate)
527 532 get :show, :id => 1
528 533 assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'},
529 534 :parent => {:tag => 'head'}
530 535
531 536 Redmine::Hook.clear_listeners
532 537 end
533 538 end
General Comments 0
You need to be logged in to leave comments. Login now