##// END OF EJS Templates
Merged r4185 from trunk....
Eric Davis -
r4089:98eaff414f12
parent child
Show More
@@ -1,271 +1,271
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2009 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
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 # TODO: convert to PUT only
36 36 verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
37 37
38 38 helper :sort
39 39 include SortHelper
40 40 helper :custom_fields
41 41 include CustomFieldsHelper
42 42 helper :issues
43 43 helper :queries
44 44 include QueriesHelper
45 45 helper :repositories
46 46 include RepositoriesHelper
47 47 include ProjectsHelper
48 48
49 49 # Lists visible projects
50 50 def index
51 51 respond_to do |format|
52 52 format.html {
53 53 @projects = Project.visible.find(:all, :order => 'lft')
54 54 }
55 55 format.xml {
56 56 @projects = Project.visible.find(:all, :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
71 71 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
72 72 @project.trackers = Tracker.all
73 73 @project.is_public = Setting.default_projects_public?
74 74 @project.enabled_module_names = Setting.default_projects_modules
75 75 end
76 76
77 77 def create
78 78 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
79 79 @trackers = Tracker.all
80 80 @project = Project.new(params[:project])
81 81
82 82 @project.enabled_module_names = params[:enabled_modules]
83 83 if validate_parent_id && @project.save
84 84 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
85 85 # Add current user as a project member if he is not admin
86 86 unless User.current.admin?
87 87 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
88 88 m = Member.new(:user => User.current, :roles => [r])
89 89 @project.members << m
90 90 end
91 91 respond_to do |format|
92 92 format.html {
93 93 flash[:notice] = l(:notice_successful_create)
94 94 redirect_to :controller => 'projects', :action => 'settings', :id => @project
95 95 }
96 96 format.xml { head :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
97 97 end
98 98 else
99 99 respond_to do |format|
100 100 format.html { render :action => 'new' }
101 101 format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
102 102 end
103 103 end
104 104
105 105 end
106 106
107 107 def copy
108 108 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
109 109 @trackers = Tracker.all
110 110 @root_projects = Project.find(:all,
111 111 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
112 112 :order => 'name')
113 113 @source_project = Project.find(params[:id])
114 114 if request.get?
115 115 @project = Project.copy_from(@source_project)
116 116 if @project
117 117 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
118 118 else
119 119 redirect_to :controller => 'admin', :action => 'projects'
120 120 end
121 121 else
122 122 Mailer.with_deliveries(params[:notifications] == '1') do
123 123 @project = Project.new(params[:project])
124 124 @project.enabled_module_names = params[:enabled_modules]
125 125 if validate_parent_id && @project.copy(@source_project, :only => params[:only])
126 126 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
127 127 flash[:notice] = l(:notice_successful_create)
128 redirect_to :controller => 'admin', :action => 'projects'
128 redirect_to :controller => 'projects', :action => 'settings'
129 129 elsif !@project.new_record?
130 130 # Project was created
131 131 # But some objects were not copied due to validation failures
132 132 # (eg. issues from disabled trackers)
133 133 # TODO: inform about that
134 redirect_to :controller => 'admin', :action => 'projects'
134 redirect_to :controller => 'projects', :action => 'settings'
135 135 end
136 136 end
137 137 end
138 138 rescue ActiveRecord::RecordNotFound
139 139 redirect_to :controller => 'admin', :action => 'projects'
140 140 end
141 141
142 142 # Show @project
143 143 def show
144 144 if params[:jump]
145 145 # try to redirect to the requested menu item
146 146 redirect_to_project_menu_item(@project, params[:jump]) && return
147 147 end
148 148
149 149 @users_by_role = @project.users_by_role
150 150 @subprojects = @project.children.visible
151 151 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
152 152 @trackers = @project.rolled_up_trackers
153 153
154 154 cond = @project.project_condition(Setting.display_subprojects_issues?)
155 155
156 156 @open_issues_by_tracker = Issue.visible.count(:group => :tracker,
157 157 :include => [:project, :status, :tracker],
158 158 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
159 159 @total_issues_by_tracker = Issue.visible.count(:group => :tracker,
160 160 :include => [:project, :status, :tracker],
161 161 :conditions => cond)
162 162
163 163 TimeEntry.visible_by(User.current) do
164 164 @total_hours = TimeEntry.sum(:hours,
165 165 :include => :project,
166 166 :conditions => cond).to_f
167 167 end
168 168 @key = User.current.rss_key
169 169
170 170 respond_to do |format|
171 171 format.html
172 172 format.xml
173 173 end
174 174 end
175 175
176 176 def settings
177 177 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
178 178 @issue_category ||= IssueCategory.new
179 179 @member ||= @project.members.new
180 180 @trackers = Tracker.all
181 181 @repository ||= @project.repository
182 182 @wiki ||= @project.wiki
183 183 end
184 184
185 185 def edit
186 186 end
187 187
188 188 def update
189 189 @project.attributes = params[:project]
190 190 if validate_parent_id && @project.save
191 191 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
192 192 respond_to do |format|
193 193 format.html {
194 194 flash[:notice] = l(:notice_successful_update)
195 195 redirect_to :action => 'settings', :id => @project
196 196 }
197 197 format.xml { head :ok }
198 198 end
199 199 else
200 200 respond_to do |format|
201 201 format.html {
202 202 settings
203 203 render :action => 'settings'
204 204 }
205 205 format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
206 206 end
207 207 end
208 208 end
209 209
210 210 def modules
211 211 @project.enabled_module_names = params[:enabled_modules]
212 212 flash[:notice] = l(:notice_successful_update)
213 213 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
214 214 end
215 215
216 216 def archive
217 217 if request.post?
218 218 unless @project.archive
219 219 flash[:error] = l(:error_can_not_archive_project)
220 220 end
221 221 end
222 222 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
223 223 end
224 224
225 225 def unarchive
226 226 @project.unarchive if request.post? && !@project.active?
227 227 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
228 228 end
229 229
230 230 # Delete @project
231 231 def destroy
232 232 @project_to_destroy = @project
233 233 if request.get?
234 234 # display confirmation view
235 235 else
236 236 if params[:format] == 'xml' || params[:confirm]
237 237 @project_to_destroy.destroy
238 238 respond_to do |format|
239 239 format.html { redirect_to :controller => 'admin', :action => 'projects' }
240 240 format.xml { head :ok }
241 241 end
242 242 end
243 243 end
244 244 # hide project in layout
245 245 @project = nil
246 246 end
247 247
248 248 private
249 249 def find_optional_project
250 250 return true unless params[:id]
251 251 @project = Project.find(params[:id])
252 252 authorize
253 253 rescue ActiveRecord::RecordNotFound
254 254 render_404
255 255 end
256 256
257 257 # Validates parent_id param according to user's permissions
258 258 # TODO: move it to Project model in a validation that depends on User.current
259 259 def validate_parent_id
260 260 return true if User.current.admin?
261 261 parent_id = params[:project] && params[:project][:parent_id]
262 262 if parent_id || @project.new_record?
263 263 parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i)
264 264 unless @project.allowed_parents.include?(parent)
265 265 @project.errors.add :parent_id, :invalid
266 266 return false
267 267 end
268 268 end
269 269 true
270 270 end
271 271 end
@@ -1,427 +1,438
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.dirname(__FILE__) + '/../test_helper'
19 19 require 'projects_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class ProjectsController; def rescue_action(e) raise e end; end
23 23
24 24 class ProjectsControllerTest < 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_by(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, :project => { :name => "blog",
148 148 :description => "weblog",
149 149 :identifier => "blog",
150 150 :is_public => 1,
151 151 :custom_field_values => { '3' => 'Beta' }
152 152 }
153 153 assert_redirected_to '/projects/blog/settings'
154 154
155 155 project = Project.find_by_name('blog')
156 156 assert_kind_of Project, project
157 157 assert_equal 'weblog', project.description
158 158 assert_equal true, project.is_public?
159 159 assert_nil project.parent
160 160 end
161 161
162 162 should "create a new subproject" do
163 163 post :create, :project => { :name => "blog",
164 164 :description => "weblog",
165 165 :identifier => "blog",
166 166 :is_public => 1,
167 167 :custom_field_values => { '3' => 'Beta' },
168 168 :parent_id => 1
169 169 }
170 170 assert_redirected_to '/projects/blog/settings'
171 171
172 172 project = Project.find_by_name('blog')
173 173 assert_kind_of Project, project
174 174 assert_equal Project.find(1), project.parent
175 175 end
176 176 end
177 177
178 178 context "by non-admin user with add_project permission" do
179 179 setup do
180 180 Role.non_member.add_permission! :add_project
181 181 @request.session[:user_id] = 9
182 182 end
183 183
184 184 should "accept create a Project" do
185 185 post :create, :project => { :name => "blog",
186 186 :description => "weblog",
187 187 :identifier => "blog",
188 188 :is_public => 1,
189 189 :custom_field_values => { '3' => 'Beta' }
190 190 }
191 191
192 192 assert_redirected_to '/projects/blog/settings'
193 193
194 194 project = Project.find_by_name('blog')
195 195 assert_kind_of Project, project
196 196 assert_equal 'weblog', project.description
197 197 assert_equal true, project.is_public?
198 198
199 199 # User should be added as a project member
200 200 assert User.find(9).member_of?(project)
201 201 assert_equal 1, project.members.size
202 202 end
203 203
204 204 should "fail with parent_id" do
205 205 assert_no_difference 'Project.count' do
206 206 post :create, :project => { :name => "blog",
207 207 :description => "weblog",
208 208 :identifier => "blog",
209 209 :is_public => 1,
210 210 :custom_field_values => { '3' => 'Beta' },
211 211 :parent_id => 1
212 212 }
213 213 end
214 214 assert_response :success
215 215 project = assigns(:project)
216 216 assert_kind_of Project, project
217 217 assert_not_nil project.errors.on(:parent_id)
218 218 end
219 219 end
220 220
221 221 context "by non-admin user with add_subprojects permission" do
222 222 setup do
223 223 Role.find(1).remove_permission! :add_project
224 224 Role.find(1).add_permission! :add_subprojects
225 225 @request.session[:user_id] = 2
226 226 end
227 227
228 228 should "create a project with a parent_id" do
229 229 post :create, :project => { :name => "blog",
230 230 :description => "weblog",
231 231 :identifier => "blog",
232 232 :is_public => 1,
233 233 :custom_field_values => { '3' => 'Beta' },
234 234 :parent_id => 1
235 235 }
236 236 assert_redirected_to '/projects/blog/settings'
237 237 project = Project.find_by_name('blog')
238 238 end
239 239
240 240 should "fail without parent_id" do
241 241 assert_no_difference 'Project.count' do
242 242 post :create, :project => { :name => "blog",
243 243 :description => "weblog",
244 244 :identifier => "blog",
245 245 :is_public => 1,
246 246 :custom_field_values => { '3' => 'Beta' }
247 247 }
248 248 end
249 249 assert_response :success
250 250 project = assigns(:project)
251 251 assert_kind_of Project, project
252 252 assert_not_nil project.errors.on(:parent_id)
253 253 end
254 254
255 255 should "fail with unauthorized parent_id" do
256 256 assert !User.find(2).member_of?(Project.find(6))
257 257 assert_no_difference 'Project.count' do
258 258 post :create, :project => { :name => "blog",
259 259 :description => "weblog",
260 260 :identifier => "blog",
261 261 :is_public => 1,
262 262 :custom_field_values => { '3' => 'Beta' },
263 263 :parent_id => 6
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 end
272 272 end
273 273
274 274 def test_show_by_id
275 275 get :show, :id => 1
276 276 assert_response :success
277 277 assert_template 'show'
278 278 assert_not_nil assigns(:project)
279 279 end
280 280
281 281 def test_show_by_identifier
282 282 get :show, :id => 'ecookbook'
283 283 assert_response :success
284 284 assert_template 'show'
285 285 assert_not_nil assigns(:project)
286 286 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
287 287 end
288 288
289 289 def test_show_should_not_fail_when_custom_values_are_nil
290 290 project = Project.find_by_identifier('ecookbook')
291 291 project.custom_values.first.update_attribute(:value, nil)
292 292 get :show, :id => 'ecookbook'
293 293 assert_response :success
294 294 assert_template 'show'
295 295 assert_not_nil assigns(:project)
296 296 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
297 297 end
298 298
299 299 def test_private_subprojects_hidden
300 300 get :show, :id => 'ecookbook'
301 301 assert_response :success
302 302 assert_template 'show'
303 303 assert_no_tag :tag => 'a', :content => /Private child/
304 304 end
305 305
306 306 def test_private_subprojects_visible
307 307 @request.session[:user_id] = 2 # manager who is a member of the private subproject
308 308 get :show, :id => 'ecookbook'
309 309 assert_response :success
310 310 assert_template 'show'
311 311 assert_tag :tag => 'a', :content => /Private child/
312 312 end
313 313
314 314 def test_settings
315 315 @request.session[:user_id] = 2 # manager
316 316 get :settings, :id => 1
317 317 assert_response :success
318 318 assert_template 'settings'
319 319 end
320 320
321 321 def test_update
322 322 @request.session[:user_id] = 2 # manager
323 323 post :update, :id => 1, :project => {:name => 'Test changed name',
324 324 :issue_custom_field_ids => ['']}
325 325 assert_redirected_to 'projects/ecookbook/settings'
326 326 project = Project.find(1)
327 327 assert_equal 'Test changed name', project.name
328 328 end
329 329
330 330 def test_get_destroy
331 331 @request.session[:user_id] = 1 # admin
332 332 get :destroy, :id => 1
333 333 assert_response :success
334 334 assert_template 'destroy'
335 335 assert_not_nil Project.find_by_id(1)
336 336 end
337 337
338 338 def test_post_destroy
339 339 @request.session[:user_id] = 1 # admin
340 340 post :destroy, :id => 1, :confirm => 1
341 341 assert_redirected_to 'admin/projects'
342 342 assert_nil Project.find_by_id(1)
343 343 end
344 344
345 345 def test_archive
346 346 @request.session[:user_id] = 1 # admin
347 347 post :archive, :id => 1
348 348 assert_redirected_to 'admin/projects'
349 349 assert !Project.find(1).active?
350 350 end
351 351
352 352 def test_unarchive
353 353 @request.session[:user_id] = 1 # admin
354 354 Project.find(1).archive
355 355 post :unarchive, :id => 1
356 356 assert_redirected_to 'admin/projects'
357 357 assert Project.find(1).active?
358 358 end
359 359
360 360 def test_project_breadcrumbs_should_be_limited_to_3_ancestors
361 361 CustomField.delete_all
362 362 parent = nil
363 363 6.times do |i|
364 364 p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}")
365 365 p.set_parent!(parent)
366 366 get :show, :id => p
367 367 assert_tag :h1, :parent => { :attributes => {:id => 'header'}},
368 368 :children => { :count => [i, 3].min,
369 369 :only => { :tag => 'a' } }
370 370
371 371 parent = p
372 372 end
373 373 end
374 374
375 375 def test_copy_with_project
376 376 @request.session[:user_id] = 1 # admin
377 377 get :copy, :id => 1
378 378 assert_response :success
379 379 assert_template 'copy'
380 380 assert assigns(:project)
381 381 assert_equal Project.find(1).description, assigns(:project).description
382 382 assert_nil assigns(:project).id
383 383 end
384 384
385 385 def test_copy_without_project
386 386 @request.session[:user_id] = 1 # admin
387 387 get :copy
388 388 assert_response :redirect
389 389 assert_redirected_to :controller => 'admin', :action => 'projects'
390 390 end
391 391
392 context "POST :copy" do
393 should "TODO: test the rest of the method"
394
395 should "redirect to the project settings when successful" do
396 @request.session[:user_id] = 1 # admin
397 post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'}
398 assert_response :redirect
399 assert_redirected_to :controller => 'projects', :action => 'settings'
400 end
401 end
402
392 403 def test_jump_should_redirect_to_active_tab
393 404 get :show, :id => 1, :jump => 'issues'
394 405 assert_redirected_to 'projects/ecookbook/issues'
395 406 end
396 407
397 408 def test_jump_should_not_redirect_to_inactive_tab
398 409 get :show, :id => 3, :jump => 'documents'
399 410 assert_response :success
400 411 assert_template 'show'
401 412 end
402 413
403 414 def test_jump_should_not_redirect_to_unknown_tab
404 415 get :show, :id => 3, :jump => 'foobar'
405 416 assert_response :success
406 417 assert_template 'show'
407 418 end
408 419
409 420 # A hook that is manually registered later
410 421 class ProjectBasedTemplate < Redmine::Hook::ViewListener
411 422 def view_layouts_base_html_head(context)
412 423 # Adds a project stylesheet
413 424 stylesheet_link_tag(context[:project].identifier) if context[:project]
414 425 end
415 426 end
416 427 # Don't use this hook now
417 428 Redmine::Hook.clear_listeners
418 429
419 430 def test_hook_response
420 431 Redmine::Hook.add_listener(ProjectBasedTemplate)
421 432 get :show, :id => 1
422 433 assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'},
423 434 :parent => {:tag => 'head'}
424 435
425 436 Redmine::Hook.clear_listeners
426 437 end
427 438 end
General Comments 0
You need to be logged in to leave comments. Login now