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