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