##// END OF EJS Templates
Default target version for new issues (#1828)....
Jean-Philippe Lang -
r14404:9178d4748f19
parent child
Show More
@@ -0,0 +1,12
1 class AddProjectsDefaultVersionId < ActiveRecord::Migration
2 def self.up
3 # Don't try to add the column if redmine_default_version plugin was used
4 unless column_exists?(:projects, :default_version_id, :integer)
5 add_column :projects, :default_version_id, :integer, :default => nil
6 end
7 end
8
9 def self.down
10 remove_column :projects, :default_version_id
11 end
12 end
@@ -1,115 +1,123
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2015 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 module ProjectsHelper
21 21 def project_settings_tabs
22 22 tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural},
23 23 {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural},
24 24 {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural},
25 25 {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural},
26 26 {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
27 27 {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
28 28 {:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository_plural},
29 29 {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
30 30 {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities}
31 31 ]
32 32 tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
33 33 end
34 34
35 35 def parent_project_select_tag(project)
36 36 selected = project.parent
37 37 # retrieve the requested parent project
38 38 parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id]
39 39 if parent_id
40 40 selected = (parent_id.blank? ? nil : Project.find(parent_id))
41 41 end
42 42
43 43 options = ''
44 44 options << "<option value=''>&nbsp;</option>" if project.allowed_parents.include?(nil)
45 45 options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected)
46 46 content_tag('select', options.html_safe, :name => 'project[parent_id]', :id => 'project_parent_id')
47 47 end
48 48
49 49 def render_project_action_links
50 50 links = []
51 51 if User.current.allowed_to?(:add_project, nil, :global => true)
52 52 links << link_to(l(:label_project_new), new_project_path, :class => 'icon icon-add')
53 53 end
54 54 if User.current.allowed_to?(:view_issues, nil, :global => true)
55 55 links << link_to(l(:label_issue_view_all), issues_path)
56 56 end
57 57 if User.current.allowed_to?(:view_time_entries, nil, :global => true)
58 58 links << link_to(l(:label_overall_spent_time), time_entries_path)
59 59 end
60 60 links << link_to(l(:label_overall_activity), activity_path)
61 61 links.join(" | ").html_safe
62 62 end
63 63
64 64 # Renders the projects index
65 65 def render_project_hierarchy(projects)
66 66 render_project_nested_lists(projects) do |project|
67 67 s = link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'my-project' : nil}")
68 68 if project.description.present?
69 69 s << content_tag('div', textilizable(project.short_description, :project => project), :class => 'wiki description')
70 70 end
71 71 s
72 72 end
73 73 end
74 74
75 75 # Returns a set of options for a select field, grouped by project.
76 76 def version_options_for_select(versions, selected=nil)
77 77 grouped = Hash.new {|h,k| h[k] = []}
78 78 versions.each do |version|
79 79 grouped[version.project.name] << [version.name, version.id]
80 80 end
81 81
82 82 selected = selected.is_a?(Version) ? selected.id : selected
83 83 if grouped.keys.size > 1
84 84 grouped_options_for_select(grouped, selected)
85 85 else
86 86 options_for_select((grouped.values.first || []), selected)
87 87 end
88 88 end
89 89
90 def project_default_version_options(project)
91 versions = project.shared_versions.open.to_a
92 if project.default_version && !versions.include?(project.default_version)
93 versions << project.default_version
94 end
95 version_options_for_select(versions, project.default_version)
96 end
97
90 98 def format_version_sharing(sharing)
91 99 sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
92 100 l("label_version_sharing_#{sharing}")
93 101 end
94 102
95 103 def render_api_includes(project, api)
96 104 api.array :trackers do
97 105 project.trackers.each do |tracker|
98 106 api.tracker(:id => tracker.id, :name => tracker.name)
99 107 end
100 108 end if include_in_api_response?('trackers')
101 109
102 110 api.array :issue_categories do
103 111 project.issue_categories.each do |category|
104 112 api.issue_category(:id => category.id, :name => category.name)
105 113 end
106 114 end if include_in_api_response?('issue_categories')
107 115
108 116 api.array :enabled_modules do
109 117 project.enabled_modules.each do |enabled_module|
110 118 api.enabled_module(:id => enabled_module.id, :name => enabled_module.name)
111 119 end
112 120 end if include_in_api_response?('enabled_modules')
113 121
114 122 end
115 123 end
@@ -1,1680 +1,1689
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2015 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 Issue < ActiveRecord::Base
19 19 include Redmine::SafeAttributes
20 20 include Redmine::Utils::DateCalculation
21 21 include Redmine::I18n
22 22 before_save :set_parent_id
23 23 include Redmine::NestedSet::IssueNestedSet
24 24
25 25 belongs_to :project
26 26 belongs_to :tracker
27 27 belongs_to :status, :class_name => 'IssueStatus'
28 28 belongs_to :author, :class_name => 'User'
29 29 belongs_to :assigned_to, :class_name => 'Principal'
30 30 belongs_to :fixed_version, :class_name => 'Version'
31 31 belongs_to :priority, :class_name => 'IssuePriority'
32 32 belongs_to :category, :class_name => 'IssueCategory'
33 33
34 34 has_many :journals, :as => :journalized, :dependent => :destroy, :inverse_of => :journalized
35 35 has_many :visible_journals,
36 36 lambda {where(["(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(User.current, :view_private_notes)}))", false])},
37 37 :class_name => 'Journal',
38 38 :as => :journalized
39 39
40 40 has_many :time_entries, :dependent => :destroy
41 41 has_and_belongs_to_many :changesets, lambda {order("#{Changeset.table_name}.committed_on ASC, #{Changeset.table_name}.id ASC")}
42 42
43 43 has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all
44 44 has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
45 45
46 46 acts_as_attachable :after_add => :attachment_added, :after_remove => :attachment_removed
47 47 acts_as_customizable
48 48 acts_as_watchable
49 49 acts_as_searchable :columns => ['subject', "#{table_name}.description"],
50 50 :preload => [:project, :status, :tracker],
51 51 :scope => lambda {|options| options[:open_issues] ? self.open : self.all}
52 52
53 53 acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id} (#{o.status}): #{o.subject}"},
54 54 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}},
55 55 :type => Proc.new {|o| 'issue' + (o.closed? ? ' closed' : '') }
56 56
57 57 acts_as_activity_provider :scope => preload(:project, :author, :tracker),
58 58 :author_key => :author_id
59 59
60 60 DONE_RATIO_OPTIONS = %w(issue_field issue_status)
61 61
62 62 attr_reader :current_journal
63 63 delegate :notes, :notes=, :private_notes, :private_notes=, :to => :current_journal, :allow_nil => true
64 64
65 65 validates_presence_of :subject, :project, :tracker
66 66 validates_presence_of :priority, :if => Proc.new {|issue| issue.new_record? || issue.priority_id_changed?}
67 67 validates_presence_of :status, :if => Proc.new {|issue| issue.new_record? || issue.status_id_changed?}
68 68 validates_presence_of :author, :if => Proc.new {|issue| issue.new_record? || issue.author_id_changed?}
69 69
70 70 validates_length_of :subject, :maximum => 255
71 71 validates_inclusion_of :done_ratio, :in => 0..100
72 72 validates :estimated_hours, :numericality => {:greater_than_or_equal_to => 0, :allow_nil => true, :message => :invalid}
73 73 validates :start_date, :date => true
74 74 validates :due_date, :date => true
75 75 validate :validate_issue, :validate_required_fields
76 76 attr_protected :id
77 77
78 78 scope :visible, lambda {|*args|
79 79 joins(:project).
80 80 where(Issue.visible_condition(args.shift || User.current, *args))
81 81 }
82 82
83 83 scope :open, lambda {|*args|
84 84 is_closed = args.size > 0 ? !args.first : false
85 85 joins(:status).
86 86 where("#{IssueStatus.table_name}.is_closed = ?", is_closed)
87 87 }
88 88
89 89 scope :recently_updated, lambda { order("#{Issue.table_name}.updated_on DESC") }
90 90 scope :on_active_project, lambda {
91 91 joins(:project).
92 92 where("#{Project.table_name}.status = ?", Project::STATUS_ACTIVE)
93 93 }
94 94 scope :fixed_version, lambda {|versions|
95 95 ids = [versions].flatten.compact.map {|v| v.is_a?(Version) ? v.id : v}
96 96 ids.any? ? where(:fixed_version_id => ids) : where('1=0')
97 97 }
98 98 scope :assigned_to, lambda {|arg|
99 99 arg = Array(arg).uniq
100 100 ids = arg.map {|p| p.is_a?(Principal) ? p.id : p}
101 101 ids += arg.select {|p| p.is_a?(User)}.map(&:group_ids).flatten.uniq
102 102 ids.compact!
103 103 ids.any? ? where(:assigned_to_id => ids) : none
104 104 }
105 105
106 106 before_validation :clear_disabled_fields
107 107 before_create :default_assign
108 108 before_save :close_duplicates, :update_done_ratio_from_issue_status,
109 109 :force_updated_on_change, :update_closed_on, :set_assigned_to_was
110 110 after_save {|issue| issue.send :after_project_change if !issue.id_changed? && issue.project_id_changed?}
111 111 after_save :reschedule_following_issues, :update_nested_set_attributes,
112 112 :update_parent_attributes, :create_journal
113 113 # Should be after_create but would be called before previous after_save callbacks
114 114 after_save :after_create_from_copy
115 115 after_destroy :update_parent_attributes
116 116 after_create :send_notification
117 117 # Keep it at the end of after_save callbacks
118 118 after_save :clear_assigned_to_was
119 119
120 120 # Returns a SQL conditions string used to find all issues visible by the specified user
121 121 def self.visible_condition(user, options={})
122 122 Project.allowed_to_condition(user, :view_issues, options) do |role, user|
123 123 if user.id && user.logged?
124 124 case role.issues_visibility
125 125 when 'all'
126 126 nil
127 127 when 'default'
128 128 user_ids = [user.id] + user.groups.map(&:id).compact
129 129 "(#{table_name}.is_private = #{connection.quoted_false} OR #{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
130 130 when 'own'
131 131 user_ids = [user.id] + user.groups.map(&:id).compact
132 132 "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
133 133 else
134 134 '1=0'
135 135 end
136 136 else
137 137 "(#{table_name}.is_private = #{connection.quoted_false})"
138 138 end
139 139 end
140 140 end
141 141
142 142 # Returns true if usr or current user is allowed to view the issue
143 143 def visible?(usr=nil)
144 144 (usr || User.current).allowed_to?(:view_issues, self.project) do |role, user|
145 145 if user.logged?
146 146 case role.issues_visibility
147 147 when 'all'
148 148 true
149 149 when 'default'
150 150 !self.is_private? || (self.author == user || user.is_or_belongs_to?(assigned_to))
151 151 when 'own'
152 152 self.author == user || user.is_or_belongs_to?(assigned_to)
153 153 else
154 154 false
155 155 end
156 156 else
157 157 !self.is_private?
158 158 end
159 159 end
160 160 end
161 161
162 162 # Returns true if user or current user is allowed to edit or add a note to the issue
163 163 def editable?(user=User.current)
164 164 attributes_editable?(user) || user.allowed_to?(:add_issue_notes, project)
165 165 end
166 166
167 167 # Returns true if user or current user is allowed to edit the issue
168 168 def attributes_editable?(user=User.current)
169 169 user.allowed_to?(:edit_issues, project)
170 170 end
171 171
172 172 def initialize(attributes=nil, *args)
173 173 super
174 174 if new_record?
175 175 # set default values for new records only
176 176 self.priority ||= IssuePriority.default
177 177 self.watcher_user_ids = []
178 178 end
179 179 end
180 180
181 181 def create_or_update
182 182 super
183 183 ensure
184 184 @status_was = nil
185 185 end
186 186 private :create_or_update
187 187
188 188 # AR#Persistence#destroy would raise and RecordNotFound exception
189 189 # if the issue was already deleted or updated (non matching lock_version).
190 190 # This is a problem when bulk deleting issues or deleting a project
191 191 # (because an issue may already be deleted if its parent was deleted
192 192 # first).
193 193 # The issue is reloaded by the nested_set before being deleted so
194 194 # the lock_version condition should not be an issue but we handle it.
195 195 def destroy
196 196 super
197 197 rescue ActiveRecord::StaleObjectError, ActiveRecord::RecordNotFound
198 198 # Stale or already deleted
199 199 begin
200 200 reload
201 201 rescue ActiveRecord::RecordNotFound
202 202 # The issue was actually already deleted
203 203 @destroyed = true
204 204 return freeze
205 205 end
206 206 # The issue was stale, retry to destroy
207 207 super
208 208 end
209 209
210 210 alias :base_reload :reload
211 211 def reload(*args)
212 212 @workflow_rule_by_attribute = nil
213 213 @assignable_versions = nil
214 214 @relations = nil
215 215 @spent_hours = nil
216 216 @total_spent_hours = nil
217 217 @total_estimated_hours = nil
218 218 base_reload(*args)
219 219 end
220 220
221 221 # Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields
222 222 def available_custom_fields
223 223 (project && tracker) ? (project.all_issue_custom_fields & tracker.custom_fields) : []
224 224 end
225 225
226 226 def visible_custom_field_values(user=nil)
227 227 user_real = user || User.current
228 228 custom_field_values.select do |value|
229 229 value.custom_field.visible_by?(project, user_real)
230 230 end
231 231 end
232 232
233 233 # Copies attributes from another issue, arg can be an id or an Issue
234 234 def copy_from(arg, options={})
235 235 issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
236 236 self.attributes = issue.attributes.dup.except("id", "root_id", "parent_id", "lft", "rgt", "created_on", "updated_on")
237 237 self.custom_field_values = issue.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
238 238 self.status = issue.status
239 239 self.author = User.current
240 240 unless options[:attachments] == false
241 241 self.attachments = issue.attachments.map do |attachement|
242 242 attachement.copy(:container => self)
243 243 end
244 244 end
245 245 @copied_from = issue
246 246 @copy_options = options
247 247 self
248 248 end
249 249
250 250 # Returns an unsaved copy of the issue
251 251 def copy(attributes=nil, copy_options={})
252 252 copy = self.class.new.copy_from(self, copy_options)
253 253 copy.attributes = attributes if attributes
254 254 copy
255 255 end
256 256
257 257 # Returns true if the issue is a copy
258 258 def copy?
259 259 @copied_from.present?
260 260 end
261 261
262 262 def status_id=(status_id)
263 263 if status_id.to_s != self.status_id.to_s
264 264 self.status = (status_id.present? ? IssueStatus.find_by_id(status_id) : nil)
265 265 end
266 266 self.status_id
267 267 end
268 268
269 269 # Sets the status.
270 270 def status=(status)
271 271 if status != self.status
272 272 @workflow_rule_by_attribute = nil
273 273 end
274 274 association(:status).writer(status)
275 275 end
276 276
277 277 def priority_id=(pid)
278 278 self.priority = nil
279 279 write_attribute(:priority_id, pid)
280 280 end
281 281
282 282 def category_id=(cid)
283 283 self.category = nil
284 284 write_attribute(:category_id, cid)
285 285 end
286 286
287 287 def fixed_version_id=(vid)
288 288 self.fixed_version = nil
289 289 write_attribute(:fixed_version_id, vid)
290 290 end
291 291
292 292 def tracker_id=(tracker_id)
293 293 if tracker_id.to_s != self.tracker_id.to_s
294 294 self.tracker = (tracker_id.present? ? Tracker.find_by_id(tracker_id) : nil)
295 295 end
296 296 self.tracker_id
297 297 end
298 298
299 299 # Sets the tracker.
300 300 # This will set the status to the default status of the new tracker if:
301 301 # * the status was the default for the previous tracker
302 302 # * or if the status was not part of the new tracker statuses
303 303 # * or the status was nil
304 304 def tracker=(tracker)
305 305 if tracker != self.tracker
306 306 if status == default_status
307 307 self.status = nil
308 308 elsif status && tracker && !tracker.issue_status_ids.include?(status.id)
309 309 self.status = nil
310 310 end
311 311 @custom_field_values = nil
312 312 @workflow_rule_by_attribute = nil
313 313 end
314 314 association(:tracker).writer(tracker)
315 315 self.status ||= default_status
316 316 self.tracker
317 317 end
318 318
319 319 def project_id=(project_id)
320 320 if project_id.to_s != self.project_id.to_s
321 321 self.project = (project_id.present? ? Project.find_by_id(project_id) : nil)
322 322 end
323 323 self.project_id
324 324 end
325 325
326 326 # Sets the project.
327 327 # Unless keep_tracker argument is set to true, this will change the tracker
328 328 # to the first tracker of the new project if the previous tracker is not part
329 329 # of the new project trackers.
330 # This will clear the fixed_version is it's no longer valid for the new project.
331 # This will clear the parent issue if it's no longer valid for the new project.
332 # This will set the category to the category with the same name in the new
330 # This will:
331 # * clear the fixed_version is it's no longer valid for the new project.
332 # * clear the parent issue if it's no longer valid for the new project.
333 # * set the category to the category with the same name in the new
333 334 # project if it exists, or clear it if it doesn't.
335 # * for new issue, set the fixed_version to the project default version
336 # if it's a valid fixed_version.
334 337 def project=(project, keep_tracker=false)
335 338 project_was = self.project
336 339 association(:project).writer(project)
337 340 if project_was && project && project_was != project
338 341 @assignable_versions = nil
339 342
340 343 unless keep_tracker || project.trackers.include?(tracker)
341 344 self.tracker = project.trackers.first
342 345 end
343 346 # Reassign to the category with same name if any
344 347 if category
345 348 self.category = project.issue_categories.find_by_name(category.name)
346 349 end
347 350 # Keep the fixed_version if it's still valid in the new_project
348 351 if fixed_version && fixed_version.project != project && !project.shared_versions.include?(fixed_version)
349 352 self.fixed_version = nil
350 353 end
351 354 # Clear the parent task if it's no longer valid
352 355 unless valid_parent_project?
353 356 self.parent_issue_id = nil
354 357 end
355 358 @custom_field_values = nil
356 359 @workflow_rule_by_attribute = nil
357 360 end
361 # Set fixed_version to the project default version if it's valid
362 if new_record? && fixed_version.nil? && project && project.default_version_id?
363 if project.shared_versions.open.exists?(project.default_version_id)
364 self.fixed_version_id = project.default_version_id
365 end
366 end
358 367 self.project
359 368 end
360 369
361 370 def description=(arg)
362 371 if arg.is_a?(String)
363 372 arg = arg.gsub(/(\r\n|\n|\r)/, "\r\n")
364 373 end
365 374 write_attribute(:description, arg)
366 375 end
367 376
368 377 # Overrides assign_attributes so that project and tracker get assigned first
369 378 def assign_attributes_with_project_and_tracker_first(new_attributes, *args)
370 379 return if new_attributes.nil?
371 380 attrs = new_attributes.dup
372 381 attrs.stringify_keys!
373 382
374 383 %w(project project_id tracker tracker_id).each do |attr|
375 384 if attrs.has_key?(attr)
376 385 send "#{attr}=", attrs.delete(attr)
377 386 end
378 387 end
379 388 send :assign_attributes_without_project_and_tracker_first, attrs, *args
380 389 end
381 390 # Do not redefine alias chain on reload (see #4838)
382 391 alias_method_chain(:assign_attributes, :project_and_tracker_first) unless method_defined?(:assign_attributes_without_project_and_tracker_first)
383 392
384 393 def attributes=(new_attributes)
385 394 assign_attributes new_attributes
386 395 end
387 396
388 397 def estimated_hours=(h)
389 398 write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)
390 399 end
391 400
392 401 safe_attributes 'project_id',
393 402 'tracker_id',
394 403 'status_id',
395 404 'category_id',
396 405 'assigned_to_id',
397 406 'priority_id',
398 407 'fixed_version_id',
399 408 'subject',
400 409 'description',
401 410 'start_date',
402 411 'due_date',
403 412 'done_ratio',
404 413 'estimated_hours',
405 414 'custom_field_values',
406 415 'custom_fields',
407 416 'lock_version',
408 417 'notes',
409 418 :if => lambda {|issue, user| issue.new_record? || user.allowed_to?(:edit_issues, issue.project) }
410 419
411 420 safe_attributes 'notes',
412 421 :if => lambda {|issue, user| user.allowed_to?(:add_issue_notes, issue.project)}
413 422
414 423 safe_attributes 'private_notes',
415 424 :if => lambda {|issue, user| !issue.new_record? && user.allowed_to?(:set_notes_private, issue.project)}
416 425
417 426 safe_attributes 'watcher_user_ids',
418 427 :if => lambda {|issue, user| issue.new_record? && user.allowed_to?(:add_issue_watchers, issue.project)}
419 428
420 429 safe_attributes 'is_private',
421 430 :if => lambda {|issue, user|
422 431 user.allowed_to?(:set_issues_private, issue.project) ||
423 432 (issue.author_id == user.id && user.allowed_to?(:set_own_issues_private, issue.project))
424 433 }
425 434
426 435 safe_attributes 'parent_issue_id',
427 436 :if => lambda {|issue, user| (issue.new_record? || user.allowed_to?(:edit_issues, issue.project)) &&
428 437 user.allowed_to?(:manage_subtasks, issue.project)}
429 438
430 439 def safe_attribute_names(user=nil)
431 440 names = super
432 441 names -= disabled_core_fields
433 442 names -= read_only_attribute_names(user)
434 443 if new_record?
435 444 # Make sure that project_id can always be set for new issues
436 445 names |= %w(project_id)
437 446 end
438 447 if dates_derived?
439 448 names -= %w(start_date due_date)
440 449 end
441 450 if priority_derived?
442 451 names -= %w(priority_id)
443 452 end
444 453 if done_ratio_derived?
445 454 names -= %w(done_ratio)
446 455 end
447 456 names
448 457 end
449 458
450 459 # Safely sets attributes
451 460 # Should be called from controllers instead of #attributes=
452 461 # attr_accessible is too rough because we still want things like
453 462 # Issue.new(:project => foo) to work
454 463 def safe_attributes=(attrs, user=User.current)
455 464 return unless attrs.is_a?(Hash)
456 465
457 466 attrs = attrs.deep_dup
458 467
459 468 # Project and Tracker must be set before since new_statuses_allowed_to depends on it.
460 469 if (p = attrs.delete('project_id')) && safe_attribute?('project_id')
461 470 if allowed_target_projects(user).where(:id => p.to_i).exists?
462 471 self.project_id = p
463 472 end
464 473
465 474 if project_id_changed? && attrs['category_id'].to_s == category_id_was.to_s
466 475 # Discard submitted category on previous project
467 476 attrs.delete('category_id')
468 477 end
469 478 end
470 479
471 480 if (t = attrs.delete('tracker_id')) && safe_attribute?('tracker_id')
472 481 self.tracker_id = t
473 482 end
474 483 if project
475 484 # Set the default tracker to accept custom field values
476 485 # even if tracker is not specified
477 486 self.tracker ||= project.trackers.first
478 487 end
479 488
480 489 statuses_allowed = new_statuses_allowed_to(user)
481 490 if (s = attrs.delete('status_id')) && safe_attribute?('status_id')
482 491 if statuses_allowed.collect(&:id).include?(s.to_i)
483 492 self.status_id = s
484 493 end
485 494 end
486 495 if new_record? && !statuses_allowed.include?(status)
487 496 self.status = statuses_allowed.first || default_status
488 497 end
489 498
490 499 attrs = delete_unsafe_attributes(attrs, user)
491 500 return if attrs.empty?
492 501
493 502 if attrs['parent_issue_id'].present?
494 503 s = attrs['parent_issue_id'].to_s
495 504 unless (m = s.match(%r{\A#?(\d+)\z})) && (m[1] == parent_id.to_s || Issue.visible(user).exists?(m[1]))
496 505 @invalid_parent_issue_id = attrs.delete('parent_issue_id')
497 506 end
498 507 end
499 508
500 509 if attrs['custom_field_values'].present?
501 510 editable_custom_field_ids = editable_custom_field_values(user).map {|v| v.custom_field_id.to_s}
502 511 attrs['custom_field_values'].select! {|k, v| editable_custom_field_ids.include?(k.to_s)}
503 512 end
504 513
505 514 if attrs['custom_fields'].present?
506 515 editable_custom_field_ids = editable_custom_field_values(user).map {|v| v.custom_field_id.to_s}
507 516 attrs['custom_fields'].select! {|c| editable_custom_field_ids.include?(c['id'].to_s)}
508 517 end
509 518
510 519 # mass-assignment security bypass
511 520 assign_attributes attrs, :without_protection => true
512 521 end
513 522
514 523 def disabled_core_fields
515 524 tracker ? tracker.disabled_core_fields : []
516 525 end
517 526
518 527 # Returns the custom_field_values that can be edited by the given user
519 528 def editable_custom_field_values(user=nil)
520 529 visible_custom_field_values(user).reject do |value|
521 530 read_only_attribute_names(user).include?(value.custom_field_id.to_s)
522 531 end
523 532 end
524 533
525 534 # Returns the custom fields that can be edited by the given user
526 535 def editable_custom_fields(user=nil)
527 536 editable_custom_field_values(user).map(&:custom_field).uniq
528 537 end
529 538
530 539 # Returns the names of attributes that are read-only for user or the current user
531 540 # For users with multiple roles, the read-only fields are the intersection of
532 541 # read-only fields of each role
533 542 # The result is an array of strings where sustom fields are represented with their ids
534 543 #
535 544 # Examples:
536 545 # issue.read_only_attribute_names # => ['due_date', '2']
537 546 # issue.read_only_attribute_names(user) # => []
538 547 def read_only_attribute_names(user=nil)
539 548 workflow_rule_by_attribute(user).reject {|attr, rule| rule != 'readonly'}.keys
540 549 end
541 550
542 551 # Returns the names of required attributes for user or the current user
543 552 # For users with multiple roles, the required fields are the intersection of
544 553 # required fields of each role
545 554 # The result is an array of strings where sustom fields are represented with their ids
546 555 #
547 556 # Examples:
548 557 # issue.required_attribute_names # => ['due_date', '2']
549 558 # issue.required_attribute_names(user) # => []
550 559 def required_attribute_names(user=nil)
551 560 workflow_rule_by_attribute(user).reject {|attr, rule| rule != 'required'}.keys
552 561 end
553 562
554 563 # Returns true if the attribute is required for user
555 564 def required_attribute?(name, user=nil)
556 565 required_attribute_names(user).include?(name.to_s)
557 566 end
558 567
559 568 # Returns a hash of the workflow rule by attribute for the given user
560 569 #
561 570 # Examples:
562 571 # issue.workflow_rule_by_attribute # => {'due_date' => 'required', 'start_date' => 'readonly'}
563 572 def workflow_rule_by_attribute(user=nil)
564 573 return @workflow_rule_by_attribute if @workflow_rule_by_attribute && user.nil?
565 574
566 575 user_real = user || User.current
567 576 roles = user_real.admin ? Role.all.to_a : user_real.roles_for_project(project)
568 577 roles = roles.select(&:consider_workflow?)
569 578 return {} if roles.empty?
570 579
571 580 result = {}
572 581 workflow_permissions = WorkflowPermission.where(:tracker_id => tracker_id, :old_status_id => status_id, :role_id => roles.map(&:id)).to_a
573 582 if workflow_permissions.any?
574 583 workflow_rules = workflow_permissions.inject({}) do |h, wp|
575 584 h[wp.field_name] ||= {}
576 585 h[wp.field_name][wp.role_id] = wp.rule
577 586 h
578 587 end
579 588 fields_with_roles = {}
580 589 IssueCustomField.where(:visible => false).joins(:roles).pluck(:id, "role_id").each do |field_id, role_id|
581 590 fields_with_roles[field_id] ||= []
582 591 fields_with_roles[field_id] << role_id
583 592 end
584 593 roles.each do |role|
585 594 fields_with_roles.each do |field_id, role_ids|
586 595 unless role_ids.include?(role.id)
587 596 field_name = field_id.to_s
588 597 workflow_rules[field_name] ||= {}
589 598 workflow_rules[field_name][role.id] = 'readonly'
590 599 end
591 600 end
592 601 end
593 602 workflow_rules.each do |attr, rules|
594 603 next if rules.size < roles.size
595 604 uniq_rules = rules.values.uniq
596 605 if uniq_rules.size == 1
597 606 result[attr] = uniq_rules.first
598 607 else
599 608 result[attr] = 'required'
600 609 end
601 610 end
602 611 end
603 612 @workflow_rule_by_attribute = result if user.nil?
604 613 result
605 614 end
606 615 private :workflow_rule_by_attribute
607 616
608 617 def done_ratio
609 618 if Issue.use_status_for_done_ratio? && status && status.default_done_ratio
610 619 status.default_done_ratio
611 620 else
612 621 read_attribute(:done_ratio)
613 622 end
614 623 end
615 624
616 625 def self.use_status_for_done_ratio?
617 626 Setting.issue_done_ratio == 'issue_status'
618 627 end
619 628
620 629 def self.use_field_for_done_ratio?
621 630 Setting.issue_done_ratio == 'issue_field'
622 631 end
623 632
624 633 def validate_issue
625 634 if due_date && start_date && (start_date_changed? || due_date_changed?) && due_date < start_date
626 635 errors.add :due_date, :greater_than_start_date
627 636 end
628 637
629 638 if start_date && start_date_changed? && soonest_start && start_date < soonest_start
630 639 errors.add :start_date, :earlier_than_minimum_start_date, :date => format_date(soonest_start)
631 640 end
632 641
633 642 if fixed_version
634 643 if !assignable_versions.include?(fixed_version)
635 644 errors.add :fixed_version_id, :inclusion
636 645 elsif reopening? && fixed_version.closed?
637 646 errors.add :base, I18n.t(:error_can_not_reopen_issue_on_closed_version)
638 647 end
639 648 end
640 649
641 650 # Checks that the issue can not be added/moved to a disabled tracker
642 651 if project && (tracker_id_changed? || project_id_changed?)
643 652 unless project.trackers.include?(tracker)
644 653 errors.add :tracker_id, :inclusion
645 654 end
646 655 end
647 656
648 657 # Checks parent issue assignment
649 658 if @invalid_parent_issue_id.present?
650 659 errors.add :parent_issue_id, :invalid
651 660 elsif @parent_issue
652 661 if !valid_parent_project?(@parent_issue)
653 662 errors.add :parent_issue_id, :invalid
654 663 elsif (@parent_issue != parent) && (all_dependent_issues.include?(@parent_issue) || @parent_issue.all_dependent_issues.include?(self))
655 664 errors.add :parent_issue_id, :invalid
656 665 elsif !new_record?
657 666 # moving an existing issue
658 667 if move_possible?(@parent_issue)
659 668 # move accepted
660 669 else
661 670 errors.add :parent_issue_id, :invalid
662 671 end
663 672 end
664 673 end
665 674 end
666 675
667 676 # Validates the issue against additional workflow requirements
668 677 def validate_required_fields
669 678 user = new_record? ? author : current_journal.try(:user)
670 679
671 680 required_attribute_names(user).each do |attribute|
672 681 if attribute =~ /^\d+$/
673 682 attribute = attribute.to_i
674 683 v = custom_field_values.detect {|v| v.custom_field_id == attribute }
675 684 if v && Array(v.value).detect(&:present?).nil?
676 685 errors.add :base, v.custom_field.name + ' ' + l('activerecord.errors.messages.blank')
677 686 end
678 687 else
679 688 if respond_to?(attribute) && send(attribute).blank? && !disabled_core_fields.include?(attribute)
680 689 next if attribute == 'category_id' && project.try(:issue_categories).blank?
681 690 next if attribute == 'fixed_version_id' && assignable_versions.blank?
682 691 errors.add attribute, :blank
683 692 end
684 693 end
685 694 end
686 695 end
687 696
688 697 # Overrides Redmine::Acts::Customizable::InstanceMethods#validate_custom_field_values
689 698 # so that custom values that are not editable are not validated (eg. a custom field that
690 699 # is marked as required should not trigger a validation error if the user is not allowed
691 700 # to edit this field).
692 701 def validate_custom_field_values
693 702 user = new_record? ? author : current_journal.try(:user)
694 703 if new_record? || custom_field_values_changed?
695 704 editable_custom_field_values(user).each(&:validate_value)
696 705 end
697 706 end
698 707
699 708 # Set the done_ratio using the status if that setting is set. This will keep the done_ratios
700 709 # even if the user turns off the setting later
701 710 def update_done_ratio_from_issue_status
702 711 if Issue.use_status_for_done_ratio? && status && status.default_done_ratio
703 712 self.done_ratio = status.default_done_ratio
704 713 end
705 714 end
706 715
707 716 def init_journal(user, notes = "")
708 717 @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes)
709 718 end
710 719
711 720 # Returns the current journal or nil if it's not initialized
712 721 def current_journal
713 722 @current_journal
714 723 end
715 724
716 725 # Returns the names of attributes that are journalized when updating the issue
717 726 def journalized_attribute_names
718 727 names = Issue.column_names - %w(id root_id lft rgt lock_version created_on updated_on closed_on)
719 728 if tracker
720 729 names -= tracker.disabled_core_fields
721 730 end
722 731 names
723 732 end
724 733
725 734 # Returns the id of the last journal or nil
726 735 def last_journal_id
727 736 if new_record?
728 737 nil
729 738 else
730 739 journals.maximum(:id)
731 740 end
732 741 end
733 742
734 743 # Returns a scope for journals that have an id greater than journal_id
735 744 def journals_after(journal_id)
736 745 scope = journals.reorder("#{Journal.table_name}.id ASC")
737 746 if journal_id.present?
738 747 scope = scope.where("#{Journal.table_name}.id > ?", journal_id.to_i)
739 748 end
740 749 scope
741 750 end
742 751
743 752 # Returns the initial status of the issue
744 753 # Returns nil for a new issue
745 754 def status_was
746 755 if status_id_changed?
747 756 if status_id_was.to_i > 0
748 757 @status_was ||= IssueStatus.find_by_id(status_id_was)
749 758 end
750 759 else
751 760 @status_was ||= status
752 761 end
753 762 end
754 763
755 764 # Return true if the issue is closed, otherwise false
756 765 def closed?
757 766 status.present? && status.is_closed?
758 767 end
759 768
760 769 # Returns true if the issue was closed when loaded
761 770 def was_closed?
762 771 status_was.present? && status_was.is_closed?
763 772 end
764 773
765 774 # Return true if the issue is being reopened
766 775 def reopening?
767 776 if new_record?
768 777 false
769 778 else
770 779 status_id_changed? && !closed? && was_closed?
771 780 end
772 781 end
773 782 alias :reopened? :reopening?
774 783
775 784 # Return true if the issue is being closed
776 785 def closing?
777 786 if new_record?
778 787 closed?
779 788 else
780 789 status_id_changed? && closed? && !was_closed?
781 790 end
782 791 end
783 792
784 793 # Returns true if the issue is overdue
785 794 def overdue?
786 795 due_date.present? && (due_date < Date.today) && !closed?
787 796 end
788 797
789 798 # Is the amount of work done less than it should for the due date
790 799 def behind_schedule?
791 800 return false if start_date.nil? || due_date.nil?
792 801 done_date = start_date + ((due_date - start_date + 1) * done_ratio / 100).floor
793 802 return done_date <= Date.today
794 803 end
795 804
796 805 # Does this issue have children?
797 806 def children?
798 807 !leaf?
799 808 end
800 809
801 810 # Users the issue can be assigned to
802 811 def assignable_users
803 812 users = project.assignable_users.to_a
804 813 users << author if author
805 814 users << assigned_to if assigned_to
806 815 users.uniq.sort
807 816 end
808 817
809 818 # Versions that the issue can be assigned to
810 819 def assignable_versions
811 820 return @assignable_versions if @assignable_versions
812 821
813 822 versions = project.shared_versions.open.to_a
814 823 if fixed_version
815 824 if fixed_version_id_changed?
816 825 # nothing to do
817 826 elsif project_id_changed?
818 827 if project.shared_versions.include?(fixed_version)
819 828 versions << fixed_version
820 829 end
821 830 else
822 831 versions << fixed_version
823 832 end
824 833 end
825 834 @assignable_versions = versions.uniq.sort
826 835 end
827 836
828 837 # Returns true if this issue is blocked by another issue that is still open
829 838 def blocked?
830 839 !relations_to.detect {|ir| ir.relation_type == 'blocks' && !ir.issue_from.closed?}.nil?
831 840 end
832 841
833 842 # Returns the default status of the issue based on its tracker
834 843 # Returns nil if tracker is nil
835 844 def default_status
836 845 tracker.try(:default_status)
837 846 end
838 847
839 848 # Returns an array of statuses that user is able to apply
840 849 def new_statuses_allowed_to(user=User.current, include_default=false)
841 850 if new_record? && @copied_from
842 851 [default_status, @copied_from.status].compact.uniq.sort
843 852 else
844 853 initial_status = nil
845 854 if new_record?
846 855 # nop
847 856 elsif tracker_id_changed?
848 857 if Tracker.where(:id => tracker_id_was, :default_status_id => status_id_was).any?
849 858 initial_status = default_status
850 859 elsif tracker.issue_status_ids.include?(status_id_was)
851 860 initial_status = IssueStatus.find_by_id(status_id_was)
852 861 else
853 862 initial_status = default_status
854 863 end
855 864 else
856 865 initial_status = status_was
857 866 end
858 867
859 868 initial_assigned_to_id = assigned_to_id_changed? ? assigned_to_id_was : assigned_to_id
860 869 assignee_transitions_allowed = initial_assigned_to_id.present? &&
861 870 (user.id == initial_assigned_to_id || user.group_ids.include?(initial_assigned_to_id))
862 871
863 872 statuses = []
864 873 statuses += IssueStatus.new_statuses_allowed(
865 874 initial_status,
866 875 user.admin ? Role.all.to_a : user.roles_for_project(project),
867 876 tracker,
868 877 author == user,
869 878 assignee_transitions_allowed
870 879 )
871 880 statuses << initial_status unless statuses.empty?
872 881 statuses << default_status if include_default || (new_record? && statuses.empty?)
873 882 statuses = statuses.compact.uniq.sort
874 883 if blocked?
875 884 statuses.reject!(&:is_closed?)
876 885 end
877 886 statuses
878 887 end
879 888 end
880 889
881 890 # Returns the previous assignee (user or group) if changed
882 891 def assigned_to_was
883 892 # assigned_to_id_was is reset before after_save callbacks
884 893 user_id = @previous_assigned_to_id || assigned_to_id_was
885 894 if user_id && user_id != assigned_to_id
886 895 @assigned_to_was ||= Principal.find_by_id(user_id)
887 896 end
888 897 end
889 898
890 899 # Returns the original tracker
891 900 def tracker_was
892 901 Tracker.find_by_id(tracker_id_was)
893 902 end
894 903
895 904 # Returns the users that should be notified
896 905 def notified_users
897 906 notified = []
898 907 # Author and assignee are always notified unless they have been
899 908 # locked or don't want to be notified
900 909 notified << author if author
901 910 if assigned_to
902 911 notified += (assigned_to.is_a?(Group) ? assigned_to.users : [assigned_to])
903 912 end
904 913 if assigned_to_was
905 914 notified += (assigned_to_was.is_a?(Group) ? assigned_to_was.users : [assigned_to_was])
906 915 end
907 916 notified = notified.select {|u| u.active? && u.notify_about?(self)}
908 917
909 918 notified += project.notified_users
910 919 notified.uniq!
911 920 # Remove users that can not view the issue
912 921 notified.reject! {|user| !visible?(user)}
913 922 notified
914 923 end
915 924
916 925 # Returns the email addresses that should be notified
917 926 def recipients
918 927 notified_users.collect(&:mail)
919 928 end
920 929
921 930 def each_notification(users, &block)
922 931 if users.any?
923 932 if custom_field_values.detect {|value| !value.custom_field.visible?}
924 933 users_by_custom_field_visibility = users.group_by do |user|
925 934 visible_custom_field_values(user).map(&:custom_field_id).sort
926 935 end
927 936 users_by_custom_field_visibility.values.each do |users|
928 937 yield(users)
929 938 end
930 939 else
931 940 yield(users)
932 941 end
933 942 end
934 943 end
935 944
936 945 def notify?
937 946 @notify != false
938 947 end
939 948
940 949 def notify=(arg)
941 950 @notify = arg
942 951 end
943 952
944 953 # Returns the number of hours spent on this issue
945 954 def spent_hours
946 955 @spent_hours ||= time_entries.sum(:hours) || 0
947 956 end
948 957
949 958 # Returns the total number of hours spent on this issue and its descendants
950 959 def total_spent_hours
951 960 @total_spent_hours ||= if leaf?
952 961 spent_hours
953 962 else
954 963 self_and_descendants.joins(:time_entries).sum("#{TimeEntry.table_name}.hours").to_f || 0.0
955 964 end
956 965 end
957 966
958 967 def total_estimated_hours
959 968 if leaf?
960 969 estimated_hours
961 970 else
962 971 @total_estimated_hours ||= self_and_descendants.sum(:estimated_hours)
963 972 end
964 973 end
965 974
966 975 def relations
967 976 @relations ||= IssueRelation::Relations.new(self, (relations_from + relations_to).sort)
968 977 end
969 978
970 979 # Preloads relations for a collection of issues
971 980 def self.load_relations(issues)
972 981 if issues.any?
973 982 relations = IssueRelation.where("issue_from_id IN (:ids) OR issue_to_id IN (:ids)", :ids => issues.map(&:id)).all
974 983 issues.each do |issue|
975 984 issue.instance_variable_set "@relations", relations.select {|r| r.issue_from_id == issue.id || r.issue_to_id == issue.id}
976 985 end
977 986 end
978 987 end
979 988
980 989 # Preloads visible spent time for a collection of issues
981 990 def self.load_visible_spent_hours(issues, user=User.current)
982 991 if issues.any?
983 992 hours_by_issue_id = TimeEntry.visible(user).where(:issue_id => issues.map(&:id)).group(:issue_id).sum(:hours)
984 993 issues.each do |issue|
985 994 issue.instance_variable_set "@spent_hours", (hours_by_issue_id[issue.id] || 0)
986 995 end
987 996 end
988 997 end
989 998
990 999 # Preloads visible total spent time for a collection of issues
991 1000 def self.load_visible_total_spent_hours(issues, user=User.current)
992 1001 if issues.any?
993 1002 hours_by_issue_id = TimeEntry.visible(user).joins(:issue).
994 1003 joins("JOIN #{Issue.table_name} parent ON parent.root_id = #{Issue.table_name}.root_id" +
995 1004 " AND parent.lft <= #{Issue.table_name}.lft AND parent.rgt >= #{Issue.table_name}.rgt").
996 1005 where("parent.id IN (?)", issues.map(&:id)).group("parent.id").sum(:hours)
997 1006 issues.each do |issue|
998 1007 issue.instance_variable_set "@total_spent_hours", (hours_by_issue_id[issue.id] || 0)
999 1008 end
1000 1009 end
1001 1010 end
1002 1011
1003 1012 # Preloads visible relations for a collection of issues
1004 1013 def self.load_visible_relations(issues, user=User.current)
1005 1014 if issues.any?
1006 1015 issue_ids = issues.map(&:id)
1007 1016 # Relations with issue_from in given issues and visible issue_to
1008 1017 relations_from = IssueRelation.joins(:issue_to => :project).
1009 1018 where(visible_condition(user)).where(:issue_from_id => issue_ids).to_a
1010 1019 # Relations with issue_to in given issues and visible issue_from
1011 1020 relations_to = IssueRelation.joins(:issue_from => :project).
1012 1021 where(visible_condition(user)).
1013 1022 where(:issue_to_id => issue_ids).to_a
1014 1023 issues.each do |issue|
1015 1024 relations =
1016 1025 relations_from.select {|relation| relation.issue_from_id == issue.id} +
1017 1026 relations_to.select {|relation| relation.issue_to_id == issue.id}
1018 1027
1019 1028 issue.instance_variable_set "@relations", IssueRelation::Relations.new(issue, relations.sort)
1020 1029 end
1021 1030 end
1022 1031 end
1023 1032
1024 1033 # Finds an issue relation given its id.
1025 1034 def find_relation(relation_id)
1026 1035 IssueRelation.where("issue_to_id = ? OR issue_from_id = ?", id, id).find(relation_id)
1027 1036 end
1028 1037
1029 1038 # Returns all the other issues that depend on the issue
1030 1039 # The algorithm is a modified breadth first search (bfs)
1031 1040 def all_dependent_issues(except=[])
1032 1041 # The found dependencies
1033 1042 dependencies = []
1034 1043
1035 1044 # The visited flag for every node (issue) used by the breadth first search
1036 1045 eNOT_DISCOVERED = 0 # The issue is "new" to the algorithm, it has not seen it before.
1037 1046
1038 1047 ePROCESS_ALL = 1 # The issue is added to the queue. Process both children and relations of
1039 1048 # the issue when it is processed.
1040 1049
1041 1050 ePROCESS_RELATIONS_ONLY = 2 # The issue was added to the queue and will be output as dependent issue,
1042 1051 # but its children will not be added to the queue when it is processed.
1043 1052
1044 1053 eRELATIONS_PROCESSED = 3 # The related issues, the parent issue and the issue itself have been added to
1045 1054 # the queue, but its children have not been added.
1046 1055
1047 1056 ePROCESS_CHILDREN_ONLY = 4 # The relations and the parent of the issue have been added to the queue, but
1048 1057 # the children still need to be processed.
1049 1058
1050 1059 eALL_PROCESSED = 5 # The issue and all its children, its parent and its related issues have been
1051 1060 # added as dependent issues. It needs no further processing.
1052 1061
1053 1062 issue_status = Hash.new(eNOT_DISCOVERED)
1054 1063
1055 1064 # The queue
1056 1065 queue = []
1057 1066
1058 1067 # Initialize the bfs, add start node (self) to the queue
1059 1068 queue << self
1060 1069 issue_status[self] = ePROCESS_ALL
1061 1070
1062 1071 while (!queue.empty?) do
1063 1072 current_issue = queue.shift
1064 1073 current_issue_status = issue_status[current_issue]
1065 1074 dependencies << current_issue
1066 1075
1067 1076 # Add parent to queue, if not already in it.
1068 1077 parent = current_issue.parent
1069 1078 parent_status = issue_status[parent]
1070 1079
1071 1080 if parent && (parent_status == eNOT_DISCOVERED) && !except.include?(parent)
1072 1081 queue << parent
1073 1082 issue_status[parent] = ePROCESS_RELATIONS_ONLY
1074 1083 end
1075 1084
1076 1085 # Add children to queue, but only if they are not already in it and
1077 1086 # the children of the current node need to be processed.
1078 1087 if (current_issue_status == ePROCESS_CHILDREN_ONLY || current_issue_status == ePROCESS_ALL)
1079 1088 current_issue.children.each do |child|
1080 1089 next if except.include?(child)
1081 1090
1082 1091 if (issue_status[child] == eNOT_DISCOVERED)
1083 1092 queue << child
1084 1093 issue_status[child] = ePROCESS_ALL
1085 1094 elsif (issue_status[child] == eRELATIONS_PROCESSED)
1086 1095 queue << child
1087 1096 issue_status[child] = ePROCESS_CHILDREN_ONLY
1088 1097 elsif (issue_status[child] == ePROCESS_RELATIONS_ONLY)
1089 1098 queue << child
1090 1099 issue_status[child] = ePROCESS_ALL
1091 1100 end
1092 1101 end
1093 1102 end
1094 1103
1095 1104 # Add related issues to the queue, if they are not already in it.
1096 1105 current_issue.relations_from.map(&:issue_to).each do |related_issue|
1097 1106 next if except.include?(related_issue)
1098 1107
1099 1108 if (issue_status[related_issue] == eNOT_DISCOVERED)
1100 1109 queue << related_issue
1101 1110 issue_status[related_issue] = ePROCESS_ALL
1102 1111 elsif (issue_status[related_issue] == eRELATIONS_PROCESSED)
1103 1112 queue << related_issue
1104 1113 issue_status[related_issue] = ePROCESS_CHILDREN_ONLY
1105 1114 elsif (issue_status[related_issue] == ePROCESS_RELATIONS_ONLY)
1106 1115 queue << related_issue
1107 1116 issue_status[related_issue] = ePROCESS_ALL
1108 1117 end
1109 1118 end
1110 1119
1111 1120 # Set new status for current issue
1112 1121 if (current_issue_status == ePROCESS_ALL) || (current_issue_status == ePROCESS_CHILDREN_ONLY)
1113 1122 issue_status[current_issue] = eALL_PROCESSED
1114 1123 elsif (current_issue_status == ePROCESS_RELATIONS_ONLY)
1115 1124 issue_status[current_issue] = eRELATIONS_PROCESSED
1116 1125 end
1117 1126 end # while
1118 1127
1119 1128 # Remove the issues from the "except" parameter from the result array
1120 1129 dependencies -= except
1121 1130 dependencies.delete(self)
1122 1131
1123 1132 dependencies
1124 1133 end
1125 1134
1126 1135 # Returns an array of issues that duplicate this one
1127 1136 def duplicates
1128 1137 relations_to.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.issue_from}
1129 1138 end
1130 1139
1131 1140 # Returns the due date or the target due date if any
1132 1141 # Used on gantt chart
1133 1142 def due_before
1134 1143 due_date || (fixed_version ? fixed_version.effective_date : nil)
1135 1144 end
1136 1145
1137 1146 # Returns the time scheduled for this issue.
1138 1147 #
1139 1148 # Example:
1140 1149 # Start Date: 2/26/09, End Date: 3/04/09
1141 1150 # duration => 6
1142 1151 def duration
1143 1152 (start_date && due_date) ? due_date - start_date : 0
1144 1153 end
1145 1154
1146 1155 # Returns the duration in working days
1147 1156 def working_duration
1148 1157 (start_date && due_date) ? working_days(start_date, due_date) : 0
1149 1158 end
1150 1159
1151 1160 def soonest_start(reload=false)
1152 1161 if @soonest_start.nil? || reload
1153 1162 dates = relations_to(reload).collect{|relation| relation.successor_soonest_start}
1154 1163 p = @parent_issue || parent
1155 1164 if p && Setting.parent_issue_dates == 'derived'
1156 1165 dates << p.soonest_start
1157 1166 end
1158 1167 @soonest_start = dates.compact.max
1159 1168 end
1160 1169 @soonest_start
1161 1170 end
1162 1171
1163 1172 # Sets start_date on the given date or the next working day
1164 1173 # and changes due_date to keep the same working duration.
1165 1174 def reschedule_on(date)
1166 1175 wd = working_duration
1167 1176 date = next_working_date(date)
1168 1177 self.start_date = date
1169 1178 self.due_date = add_working_days(date, wd)
1170 1179 end
1171 1180
1172 1181 # Reschedules the issue on the given date or the next working day and saves the record.
1173 1182 # If the issue is a parent task, this is done by rescheduling its subtasks.
1174 1183 def reschedule_on!(date)
1175 1184 return if date.nil?
1176 1185 if leaf? || !dates_derived?
1177 1186 if start_date.nil? || start_date != date
1178 1187 if start_date && start_date > date
1179 1188 # Issue can not be moved earlier than its soonest start date
1180 1189 date = [soonest_start(true), date].compact.max
1181 1190 end
1182 1191 reschedule_on(date)
1183 1192 begin
1184 1193 save
1185 1194 rescue ActiveRecord::StaleObjectError
1186 1195 reload
1187 1196 reschedule_on(date)
1188 1197 save
1189 1198 end
1190 1199 end
1191 1200 else
1192 1201 leaves.each do |leaf|
1193 1202 if leaf.start_date
1194 1203 # Only move subtask if it starts at the same date as the parent
1195 1204 # or if it starts before the given date
1196 1205 if start_date == leaf.start_date || date > leaf.start_date
1197 1206 leaf.reschedule_on!(date)
1198 1207 end
1199 1208 else
1200 1209 leaf.reschedule_on!(date)
1201 1210 end
1202 1211 end
1203 1212 end
1204 1213 end
1205 1214
1206 1215 def dates_derived?
1207 1216 !leaf? && Setting.parent_issue_dates == 'derived'
1208 1217 end
1209 1218
1210 1219 def priority_derived?
1211 1220 !leaf? && Setting.parent_issue_priority == 'derived'
1212 1221 end
1213 1222
1214 1223 def done_ratio_derived?
1215 1224 !leaf? && Setting.parent_issue_done_ratio == 'derived'
1216 1225 end
1217 1226
1218 1227 def <=>(issue)
1219 1228 if issue.nil?
1220 1229 -1
1221 1230 elsif root_id != issue.root_id
1222 1231 (root_id || 0) <=> (issue.root_id || 0)
1223 1232 else
1224 1233 (lft || 0) <=> (issue.lft || 0)
1225 1234 end
1226 1235 end
1227 1236
1228 1237 def to_s
1229 1238 "#{tracker} ##{id}: #{subject}"
1230 1239 end
1231 1240
1232 1241 # Returns a string of css classes that apply to the issue
1233 1242 def css_classes(user=User.current)
1234 1243 s = "issue tracker-#{tracker_id} status-#{status_id} #{priority.try(:css_classes)}"
1235 1244 s << ' closed' if closed?
1236 1245 s << ' overdue' if overdue?
1237 1246 s << ' child' if child?
1238 1247 s << ' parent' unless leaf?
1239 1248 s << ' private' if is_private?
1240 1249 if user.logged?
1241 1250 s << ' created-by-me' if author_id == user.id
1242 1251 s << ' assigned-to-me' if assigned_to_id == user.id
1243 1252 s << ' assigned-to-my-group' if user.groups.any? {|g| g.id == assigned_to_id}
1244 1253 end
1245 1254 s
1246 1255 end
1247 1256
1248 1257 # Unassigns issues from +version+ if it's no longer shared with issue's project
1249 1258 def self.update_versions_from_sharing_change(version)
1250 1259 # Update issues assigned to the version
1251 1260 update_versions(["#{Issue.table_name}.fixed_version_id = ?", version.id])
1252 1261 end
1253 1262
1254 1263 # Unassigns issues from versions that are no longer shared
1255 1264 # after +project+ was moved
1256 1265 def self.update_versions_from_hierarchy_change(project)
1257 1266 moved_project_ids = project.self_and_descendants.reload.collect(&:id)
1258 1267 # Update issues of the moved projects and issues assigned to a version of a moved project
1259 1268 Issue.update_versions(
1260 1269 ["#{Version.table_name}.project_id IN (?) OR #{Issue.table_name}.project_id IN (?)",
1261 1270 moved_project_ids, moved_project_ids]
1262 1271 )
1263 1272 end
1264 1273
1265 1274 def parent_issue_id=(arg)
1266 1275 s = arg.to_s.strip.presence
1267 1276 if s && (m = s.match(%r{\A#?(\d+)\z})) && (@parent_issue = Issue.find_by_id(m[1]))
1268 1277 @invalid_parent_issue_id = nil
1269 1278 elsif s.blank?
1270 1279 @parent_issue = nil
1271 1280 @invalid_parent_issue_id = nil
1272 1281 else
1273 1282 @parent_issue = nil
1274 1283 @invalid_parent_issue_id = arg
1275 1284 end
1276 1285 end
1277 1286
1278 1287 def parent_issue_id
1279 1288 if @invalid_parent_issue_id
1280 1289 @invalid_parent_issue_id
1281 1290 elsif instance_variable_defined? :@parent_issue
1282 1291 @parent_issue.nil? ? nil : @parent_issue.id
1283 1292 else
1284 1293 parent_id
1285 1294 end
1286 1295 end
1287 1296
1288 1297 def set_parent_id
1289 1298 self.parent_id = parent_issue_id
1290 1299 end
1291 1300
1292 1301 # Returns true if issue's project is a valid
1293 1302 # parent issue project
1294 1303 def valid_parent_project?(issue=parent)
1295 1304 return true if issue.nil? || issue.project_id == project_id
1296 1305
1297 1306 case Setting.cross_project_subtasks
1298 1307 when 'system'
1299 1308 true
1300 1309 when 'tree'
1301 1310 issue.project.root == project.root
1302 1311 when 'hierarchy'
1303 1312 issue.project.is_or_is_ancestor_of?(project) || issue.project.is_descendant_of?(project)
1304 1313 when 'descendants'
1305 1314 issue.project.is_or_is_ancestor_of?(project)
1306 1315 else
1307 1316 false
1308 1317 end
1309 1318 end
1310 1319
1311 1320 # Returns an issue scope based on project and scope
1312 1321 def self.cross_project_scope(project, scope=nil)
1313 1322 if project.nil?
1314 1323 return Issue
1315 1324 end
1316 1325 case scope
1317 1326 when 'all', 'system'
1318 1327 Issue
1319 1328 when 'tree'
1320 1329 Issue.joins(:project).where("(#{Project.table_name}.lft >= :lft AND #{Project.table_name}.rgt <= :rgt)",
1321 1330 :lft => project.root.lft, :rgt => project.root.rgt)
1322 1331 when 'hierarchy'
1323 1332 Issue.joins(:project).where("(#{Project.table_name}.lft >= :lft AND #{Project.table_name}.rgt <= :rgt) OR (#{Project.table_name}.lft < :lft AND #{Project.table_name}.rgt > :rgt)",
1324 1333 :lft => project.lft, :rgt => project.rgt)
1325 1334 when 'descendants'
1326 1335 Issue.joins(:project).where("(#{Project.table_name}.lft >= :lft AND #{Project.table_name}.rgt <= :rgt)",
1327 1336 :lft => project.lft, :rgt => project.rgt)
1328 1337 else
1329 1338 Issue.where(:project_id => project.id)
1330 1339 end
1331 1340 end
1332 1341
1333 1342 def self.by_tracker(project)
1334 1343 count_and_group_by(:project => project, :association => :tracker)
1335 1344 end
1336 1345
1337 1346 def self.by_version(project)
1338 1347 count_and_group_by(:project => project, :association => :fixed_version)
1339 1348 end
1340 1349
1341 1350 def self.by_priority(project)
1342 1351 count_and_group_by(:project => project, :association => :priority)
1343 1352 end
1344 1353
1345 1354 def self.by_category(project)
1346 1355 count_and_group_by(:project => project, :association => :category)
1347 1356 end
1348 1357
1349 1358 def self.by_assigned_to(project)
1350 1359 count_and_group_by(:project => project, :association => :assigned_to)
1351 1360 end
1352 1361
1353 1362 def self.by_author(project)
1354 1363 count_and_group_by(:project => project, :association => :author)
1355 1364 end
1356 1365
1357 1366 def self.by_subproject(project)
1358 1367 r = count_and_group_by(:project => project, :with_subprojects => true, :association => :project)
1359 1368 r.reject {|r| r["project_id"] == project.id.to_s}
1360 1369 end
1361 1370
1362 1371 # Query generator for selecting groups of issue counts for a project
1363 1372 # based on specific criteria
1364 1373 #
1365 1374 # Options
1366 1375 # * project - Project to search in.
1367 1376 # * with_subprojects - Includes subprojects issues if set to true.
1368 1377 # * association - Symbol. Association for grouping.
1369 1378 def self.count_and_group_by(options)
1370 1379 assoc = reflect_on_association(options[:association])
1371 1380 select_field = assoc.foreign_key
1372 1381
1373 1382 Issue.
1374 1383 visible(User.current, :project => options[:project], :with_subprojects => options[:with_subprojects]).
1375 1384 joins(:status, assoc.name).
1376 1385 group(:status_id, :is_closed, select_field).
1377 1386 count.
1378 1387 map do |columns, total|
1379 1388 status_id, is_closed, field_value = columns
1380 1389 is_closed = ['t', 'true', '1'].include?(is_closed.to_s)
1381 1390 {
1382 1391 "status_id" => status_id.to_s,
1383 1392 "closed" => is_closed,
1384 1393 select_field => field_value.to_s,
1385 1394 "total" => total.to_s
1386 1395 }
1387 1396 end
1388 1397 end
1389 1398
1390 1399 # Returns a scope of projects that user can assign the issue to
1391 1400 def allowed_target_projects(user=User.current)
1392 1401 current_project = new_record? ? nil : project
1393 1402 self.class.allowed_target_projects(user, current_project)
1394 1403 end
1395 1404
1396 1405 # Returns a scope of projects that user can assign issues to
1397 1406 # If current_project is given, it will be included in the scope
1398 1407 def self.allowed_target_projects(user=User.current, current_project=nil)
1399 1408 condition = Project.allowed_to_condition(user, :add_issues)
1400 1409 if current_project
1401 1410 condition = ["(#{condition}) OR #{Project.table_name}.id = ?", current_project.id]
1402 1411 end
1403 1412 Project.where(condition).having_trackers
1404 1413 end
1405 1414
1406 1415 private
1407 1416
1408 1417 def after_project_change
1409 1418 # Update project_id on related time entries
1410 1419 TimeEntry.where({:issue_id => id}).update_all(["project_id = ?", project_id])
1411 1420
1412 1421 # Delete issue relations
1413 1422 unless Setting.cross_project_issue_relations?
1414 1423 relations_from.clear
1415 1424 relations_to.clear
1416 1425 end
1417 1426
1418 1427 # Move subtasks that were in the same project
1419 1428 children.each do |child|
1420 1429 next unless child.project_id == project_id_was
1421 1430 # Change project and keep project
1422 1431 child.send :project=, project, true
1423 1432 unless child.save
1424 1433 raise ActiveRecord::Rollback
1425 1434 end
1426 1435 end
1427 1436 end
1428 1437
1429 1438 # Callback for after the creation of an issue by copy
1430 1439 # * adds a "copied to" relation with the copied issue
1431 1440 # * copies subtasks from the copied issue
1432 1441 def after_create_from_copy
1433 1442 return unless copy? && !@after_create_from_copy_handled
1434 1443
1435 1444 if (@copied_from.project_id == project_id || Setting.cross_project_issue_relations?) && @copy_options[:link] != false
1436 1445 if @current_journal
1437 1446 @copied_from.init_journal(@current_journal.user)
1438 1447 end
1439 1448 relation = IssueRelation.new(:issue_from => @copied_from, :issue_to => self, :relation_type => IssueRelation::TYPE_COPIED_TO)
1440 1449 unless relation.save
1441 1450 logger.error "Could not create relation while copying ##{@copied_from.id} to ##{id} due to validation errors: #{relation.errors.full_messages.join(', ')}" if logger
1442 1451 end
1443 1452 end
1444 1453
1445 1454 unless @copied_from.leaf? || @copy_options[:subtasks] == false
1446 1455 copy_options = (@copy_options || {}).merge(:subtasks => false)
1447 1456 copied_issue_ids = {@copied_from.id => self.id}
1448 1457 @copied_from.reload.descendants.reorder("#{Issue.table_name}.lft").each do |child|
1449 1458 # Do not copy self when copying an issue as a descendant of the copied issue
1450 1459 next if child == self
1451 1460 # Do not copy subtasks of issues that were not copied
1452 1461 next unless copied_issue_ids[child.parent_id]
1453 1462 # Do not copy subtasks that are not visible to avoid potential disclosure of private data
1454 1463 unless child.visible?
1455 1464 logger.error "Subtask ##{child.id} was not copied during ##{@copied_from.id} copy because it is not visible to the current user" if logger
1456 1465 next
1457 1466 end
1458 1467 copy = Issue.new.copy_from(child, copy_options)
1459 1468 if @current_journal
1460 1469 copy.init_journal(@current_journal.user)
1461 1470 end
1462 1471 copy.author = author
1463 1472 copy.project = project
1464 1473 copy.parent_issue_id = copied_issue_ids[child.parent_id]
1465 1474 unless copy.save
1466 1475 logger.error "Could not copy subtask ##{child.id} while copying ##{@copied_from.id} to ##{id} due to validation errors: #{copy.errors.full_messages.join(', ')}" if logger
1467 1476 next
1468 1477 end
1469 1478 copied_issue_ids[child.id] = copy.id
1470 1479 end
1471 1480 end
1472 1481 @after_create_from_copy_handled = true
1473 1482 end
1474 1483
1475 1484 def update_nested_set_attributes
1476 1485 if parent_id_changed?
1477 1486 update_nested_set_attributes_on_parent_change
1478 1487 end
1479 1488 remove_instance_variable(:@parent_issue) if instance_variable_defined?(:@parent_issue)
1480 1489 end
1481 1490
1482 1491 # Updates the nested set for when an existing issue is moved
1483 1492 def update_nested_set_attributes_on_parent_change
1484 1493 former_parent_id = parent_id_was
1485 1494 # delete invalid relations of all descendants
1486 1495 self_and_descendants.each do |issue|
1487 1496 issue.relations.each do |relation|
1488 1497 relation.destroy unless relation.valid?
1489 1498 end
1490 1499 end
1491 1500 # update former parent
1492 1501 recalculate_attributes_for(former_parent_id) if former_parent_id
1493 1502 end
1494 1503
1495 1504 def update_parent_attributes
1496 1505 if parent_id
1497 1506 recalculate_attributes_for(parent_id)
1498 1507 association(:parent).reset
1499 1508 end
1500 1509 end
1501 1510
1502 1511 def recalculate_attributes_for(issue_id)
1503 1512 if issue_id && p = Issue.find_by_id(issue_id)
1504 1513 if p.priority_derived?
1505 1514 # priority = highest priority of children
1506 1515 if priority_position = p.children.joins(:priority).maximum("#{IssuePriority.table_name}.position")
1507 1516 p.priority = IssuePriority.find_by_position(priority_position)
1508 1517 end
1509 1518 end
1510 1519
1511 1520 if p.dates_derived?
1512 1521 # start/due dates = lowest/highest dates of children
1513 1522 p.start_date = p.children.minimum(:start_date)
1514 1523 p.due_date = p.children.maximum(:due_date)
1515 1524 if p.start_date && p.due_date && p.due_date < p.start_date
1516 1525 p.start_date, p.due_date = p.due_date, p.start_date
1517 1526 end
1518 1527 end
1519 1528
1520 1529 if p.done_ratio_derived?
1521 1530 # done ratio = weighted average ratio of leaves
1522 1531 unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio
1523 1532 leaves_count = p.leaves.count
1524 1533 if leaves_count > 0
1525 1534 average = p.leaves.where("estimated_hours > 0").average(:estimated_hours).to_f
1526 1535 if average == 0
1527 1536 average = 1
1528 1537 end
1529 1538 done = p.leaves.joins(:status).
1530 1539 sum("COALESCE(CASE WHEN estimated_hours > 0 THEN estimated_hours ELSE NULL END, #{average}) " +
1531 1540 "* (CASE WHEN is_closed = #{self.class.connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)").to_f
1532 1541 progress = done / (average * leaves_count)
1533 1542 p.done_ratio = progress.round
1534 1543 end
1535 1544 end
1536 1545 end
1537 1546
1538 1547 # ancestors will be recursively updated
1539 1548 p.save(:validate => false)
1540 1549 end
1541 1550 end
1542 1551
1543 1552 # Update issues so their versions are not pointing to a
1544 1553 # fixed_version that is not shared with the issue's project
1545 1554 def self.update_versions(conditions=nil)
1546 1555 # Only need to update issues with a fixed_version from
1547 1556 # a different project and that is not systemwide shared
1548 1557 Issue.joins(:project, :fixed_version).
1549 1558 where("#{Issue.table_name}.fixed_version_id IS NOT NULL" +
1550 1559 " AND #{Issue.table_name}.project_id <> #{Version.table_name}.project_id" +
1551 1560 " AND #{Version.table_name}.sharing <> 'system'").
1552 1561 where(conditions).each do |issue|
1553 1562 next if issue.project.nil? || issue.fixed_version.nil?
1554 1563 unless issue.project.shared_versions.include?(issue.fixed_version)
1555 1564 issue.init_journal(User.current)
1556 1565 issue.fixed_version = nil
1557 1566 issue.save
1558 1567 end
1559 1568 end
1560 1569 end
1561 1570
1562 1571 # Callback on file attachment
1563 1572 def attachment_added(attachment)
1564 1573 if current_journal && !attachment.new_record?
1565 1574 current_journal.journalize_attachment(attachment, :added)
1566 1575 end
1567 1576 end
1568 1577
1569 1578 # Callback on attachment deletion
1570 1579 def attachment_removed(attachment)
1571 1580 if current_journal && !attachment.new_record?
1572 1581 current_journal.journalize_attachment(attachment, :removed)
1573 1582 current_journal.save
1574 1583 end
1575 1584 end
1576 1585
1577 1586 # Called after a relation is added
1578 1587 def relation_added(relation)
1579 1588 if current_journal
1580 1589 current_journal.journalize_relation(relation, :added)
1581 1590 current_journal.save
1582 1591 end
1583 1592 end
1584 1593
1585 1594 # Called after a relation is removed
1586 1595 def relation_removed(relation)
1587 1596 if current_journal
1588 1597 current_journal.journalize_relation(relation, :removed)
1589 1598 current_journal.save
1590 1599 end
1591 1600 end
1592 1601
1593 1602 # Default assignment based on category
1594 1603 def default_assign
1595 1604 if assigned_to.nil? && category && category.assigned_to
1596 1605 self.assigned_to = category.assigned_to
1597 1606 end
1598 1607 end
1599 1608
1600 1609 # Updates start/due dates of following issues
1601 1610 def reschedule_following_issues
1602 1611 if start_date_changed? || due_date_changed?
1603 1612 relations_from.each do |relation|
1604 1613 relation.set_issue_to_dates
1605 1614 end
1606 1615 end
1607 1616 end
1608 1617
1609 1618 # Closes duplicates if the issue is being closed
1610 1619 def close_duplicates
1611 1620 if closing?
1612 1621 duplicates.each do |duplicate|
1613 1622 # Reload is needed in case the duplicate was updated by a previous duplicate
1614 1623 duplicate.reload
1615 1624 # Don't re-close it if it's already closed
1616 1625 next if duplicate.closed?
1617 1626 # Same user and notes
1618 1627 if @current_journal
1619 1628 duplicate.init_journal(@current_journal.user, @current_journal.notes)
1620 1629 end
1621 1630 duplicate.update_attribute :status, self.status
1622 1631 end
1623 1632 end
1624 1633 end
1625 1634
1626 1635 # Make sure updated_on is updated when adding a note and set updated_on now
1627 1636 # so we can set closed_on with the same value on closing
1628 1637 def force_updated_on_change
1629 1638 if @current_journal || changed?
1630 1639 self.updated_on = current_time_from_proper_timezone
1631 1640 if new_record?
1632 1641 self.created_on = updated_on
1633 1642 end
1634 1643 end
1635 1644 end
1636 1645
1637 1646 # Callback for setting closed_on when the issue is closed.
1638 1647 # The closed_on attribute stores the time of the last closing
1639 1648 # and is preserved when the issue is reopened.
1640 1649 def update_closed_on
1641 1650 if closing?
1642 1651 self.closed_on = updated_on
1643 1652 end
1644 1653 end
1645 1654
1646 1655 # Saves the changes in a Journal
1647 1656 # Called after_save
1648 1657 def create_journal
1649 1658 if current_journal
1650 1659 current_journal.save
1651 1660 end
1652 1661 end
1653 1662
1654 1663 def send_notification
1655 1664 if notify? && Setting.notified_events.include?('issue_added')
1656 1665 Mailer.deliver_issue_add(self)
1657 1666 end
1658 1667 end
1659 1668
1660 1669 # Stores the previous assignee so we can still have access
1661 1670 # to it during after_save callbacks (assigned_to_id_was is reset)
1662 1671 def set_assigned_to_was
1663 1672 @previous_assigned_to_id = assigned_to_id_was
1664 1673 end
1665 1674
1666 1675 # Clears the previous assignee at the end of after_save callbacks
1667 1676 def clear_assigned_to_was
1668 1677 @assigned_to_was = nil
1669 1678 @previous_assigned_to_id = nil
1670 1679 end
1671 1680
1672 1681 def clear_disabled_fields
1673 1682 if tracker
1674 1683 tracker.disabled_core_fields.each do |attribute|
1675 1684 send "#{attribute}=", nil
1676 1685 end
1677 1686 self.done_ratio ||= 0
1678 1687 end
1679 1688 end
1680 1689 end
@@ -1,1042 +1,1044
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2015 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 Project < ActiveRecord::Base
19 19 include Redmine::SafeAttributes
20 20 include Redmine::NestedSet::ProjectNestedSet
21 21
22 22 # Project statuses
23 23 STATUS_ACTIVE = 1
24 24 STATUS_CLOSED = 5
25 25 STATUS_ARCHIVED = 9
26 26
27 27 # Maximum length for project identifiers
28 28 IDENTIFIER_MAX_LENGTH = 100
29 29
30 30 # Specific overridden Activities
31 31 has_many :time_entry_activities
32 32 has_many :memberships, :class_name => 'Member', :inverse_of => :project
33 33 # Memberships of active users only
34 34 has_many :members,
35 35 lambda { joins(:principal).where(:users => {:type => 'User', :status => Principal::STATUS_ACTIVE}) }
36 36 has_many :enabled_modules, :dependent => :delete_all
37 37 has_and_belongs_to_many :trackers, lambda {order(:position)}
38 38 has_many :issues, :dependent => :destroy
39 39 has_many :issue_changes, :through => :issues, :source => :journals
40 40 has_many :versions, lambda {order("#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC")}, :dependent => :destroy
41 belongs_to :default_version, :class_name => 'Version'
41 42 has_many :time_entries, :dependent => :destroy
42 43 has_many :queries, :class_name => 'IssueQuery', :dependent => :delete_all
43 44 has_many :documents, :dependent => :destroy
44 45 has_many :news, lambda {includes(:author)}, :dependent => :destroy
45 46 has_many :issue_categories, lambda {order("#{IssueCategory.table_name}.name")}, :dependent => :delete_all
46 47 has_many :boards, lambda {order("position ASC")}, :dependent => :destroy
47 48 has_one :repository, lambda {where(["is_default = ?", true])}
48 49 has_many :repositories, :dependent => :destroy
49 50 has_many :changesets, :through => :repository
50 51 has_one :wiki, :dependent => :destroy
51 52 # Custom field for the project issues
52 53 has_and_belongs_to_many :issue_custom_fields,
53 54 lambda {order("#{CustomField.table_name}.position")},
54 55 :class_name => 'IssueCustomField',
55 56 :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
56 57 :association_foreign_key => 'custom_field_id'
57 58
58 59 acts_as_attachable :view_permission => :view_files,
59 60 :edit_permission => :manage_files,
60 61 :delete_permission => :manage_files
61 62
62 63 acts_as_customizable
63 64 acts_as_searchable :columns => ['name', 'identifier', 'description'], :project_key => "#{Project.table_name}.id", :permission => nil
64 65 acts_as_event :title => Proc.new {|o| "#{l(:label_project)}: #{o.name}"},
65 66 :url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o}},
66 67 :author => nil
67 68
68 69 attr_protected :status
69 70
70 71 validates_presence_of :name, :identifier
71 72 validates_uniqueness_of :identifier, :if => Proc.new {|p| p.identifier_changed?}
72 73 validates_length_of :name, :maximum => 255
73 74 validates_length_of :homepage, :maximum => 255
74 75 validates_length_of :identifier, :in => 1..IDENTIFIER_MAX_LENGTH
75 76 # downcase letters, digits, dashes but not digits only
76 77 validates_format_of :identifier, :with => /\A(?!\d+$)[a-z0-9\-_]*\z/, :if => Proc.new { |p| p.identifier_changed? }
77 78 # reserved words
78 79 validates_exclusion_of :identifier, :in => %w( new )
79 80 validate :validate_parent
80 81
81 82 after_save :update_inherited_members, :if => Proc.new {|project| project.inherit_members_changed?}
82 83 after_save :remove_inherited_member_roles, :add_inherited_member_roles, :if => Proc.new {|project| project.parent_id_changed?}
83 84 after_update :update_versions_from_hierarchy_change, :if => Proc.new {|project| project.parent_id_changed?}
84 85 before_destroy :delete_all_members
85 86
86 87 scope :has_module, lambda {|mod|
87 88 where("#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s)
88 89 }
89 90 scope :active, lambda { where(:status => STATUS_ACTIVE) }
90 91 scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) }
91 92 scope :all_public, lambda { where(:is_public => true) }
92 93 scope :visible, lambda {|*args| where(Project.visible_condition(args.shift || User.current, *args)) }
93 94 scope :allowed_to, lambda {|*args|
94 95 user = User.current
95 96 permission = nil
96 97 if args.first.is_a?(Symbol)
97 98 permission = args.shift
98 99 else
99 100 user = args.shift
100 101 permission = args.shift
101 102 end
102 103 where(Project.allowed_to_condition(user, permission, *args))
103 104 }
104 105 scope :like, lambda {|arg|
105 106 if arg.blank?
106 107 where(nil)
107 108 else
108 109 pattern = "%#{arg.to_s.strip.downcase}%"
109 110 where("LOWER(identifier) LIKE :p OR LOWER(name) LIKE :p", :p => pattern)
110 111 end
111 112 }
112 113 scope :sorted, lambda {order(:lft)}
113 114 scope :having_trackers, lambda {
114 115 where("#{Project.table_name}.id IN (SELECT DISTINCT project_id FROM #{table_name_prefix}projects_trackers#{table_name_suffix})")
115 116 }
116 117
117 118 def initialize(attributes=nil, *args)
118 119 super
119 120
120 121 initialized = (attributes || {}).stringify_keys
121 122 if !initialized.key?('identifier') && Setting.sequential_project_identifiers?
122 123 self.identifier = Project.next_identifier
123 124 end
124 125 if !initialized.key?('is_public')
125 126 self.is_public = Setting.default_projects_public?
126 127 end
127 128 if !initialized.key?('enabled_module_names')
128 129 self.enabled_module_names = Setting.default_projects_modules
129 130 end
130 131 if !initialized.key?('trackers') && !initialized.key?('tracker_ids')
131 132 default = Setting.default_projects_tracker_ids
132 133 if default.is_a?(Array)
133 134 self.trackers = Tracker.where(:id => default.map(&:to_i)).sorted.to_a
134 135 else
135 136 self.trackers = Tracker.sorted.to_a
136 137 end
137 138 end
138 139 end
139 140
140 141 def identifier=(identifier)
141 142 super unless identifier_frozen?
142 143 end
143 144
144 145 def identifier_frozen?
145 146 errors[:identifier].blank? && !(new_record? || identifier.blank?)
146 147 end
147 148
148 149 # returns latest created projects
149 150 # non public projects will be returned only if user is a member of those
150 151 def self.latest(user=nil, count=5)
151 152 visible(user).limit(count).order("created_on DESC").to_a
152 153 end
153 154
154 155 # Returns true if the project is visible to +user+ or to the current user.
155 156 def visible?(user=User.current)
156 157 user.allowed_to?(:view_project, self)
157 158 end
158 159
159 160 # Returns a SQL conditions string used to find all projects visible by the specified user.
160 161 #
161 162 # Examples:
162 163 # Project.visible_condition(admin) => "projects.status = 1"
163 164 # Project.visible_condition(normal_user) => "((projects.status = 1) AND (projects.is_public = 1 OR projects.id IN (1,3,4)))"
164 165 # Project.visible_condition(anonymous) => "((projects.status = 1) AND (projects.is_public = 1))"
165 166 def self.visible_condition(user, options={})
166 167 allowed_to_condition(user, :view_project, options)
167 168 end
168 169
169 170 # Returns a SQL conditions string used to find all projects for which +user+ has the given +permission+
170 171 #
171 172 # Valid options:
172 173 # * :project => limit the condition to project
173 174 # * :with_subprojects => limit the condition to project and its subprojects
174 175 # * :member => limit the condition to the user projects
175 176 def self.allowed_to_condition(user, permission, options={})
176 177 perm = Redmine::AccessControl.permission(permission)
177 178 base_statement = (perm && perm.read? ? "#{Project.table_name}.status <> #{Project::STATUS_ARCHIVED}" : "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}")
178 179 if perm && perm.project_module
179 180 # If the permission belongs to a project module, make sure the module is enabled
180 181 base_statement << " AND #{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.project_module}')"
181 182 end
182 183 if project = options[:project]
183 184 project_statement = project.project_condition(options[:with_subprojects])
184 185 base_statement = "(#{project_statement}) AND (#{base_statement})"
185 186 end
186 187
187 188 if user.admin?
188 189 base_statement
189 190 else
190 191 statement_by_role = {}
191 192 unless options[:member]
192 193 role = user.builtin_role
193 194 if role.allowed_to?(permission)
194 195 s = "#{Project.table_name}.is_public = #{connection.quoted_true}"
195 196 if user.id
196 197 s = "(#{s} AND #{Project.table_name}.id NOT IN (SELECT project_id FROM #{Member.table_name} WHERE user_id = #{user.id}))"
197 198 end
198 199 statement_by_role[role] = s
199 200 end
200 201 end
201 202 user.projects_by_role.each do |role, projects|
202 203 if role.allowed_to?(permission) && projects.any?
203 204 statement_by_role[role] = "#{Project.table_name}.id IN (#{projects.collect(&:id).join(',')})"
204 205 end
205 206 end
206 207 if statement_by_role.empty?
207 208 "1=0"
208 209 else
209 210 if block_given?
210 211 statement_by_role.each do |role, statement|
211 212 if s = yield(role, user)
212 213 statement_by_role[role] = "(#{statement} AND (#{s}))"
213 214 end
214 215 end
215 216 end
216 217 "((#{base_statement}) AND (#{statement_by_role.values.join(' OR ')}))"
217 218 end
218 219 end
219 220 end
220 221
221 222 def override_roles(role)
222 223 @override_members ||= memberships.
223 224 joins(:principal).
224 225 where(:users => {:type => ['GroupAnonymous', 'GroupNonMember']}).to_a
225 226
226 227 group_class = role.anonymous? ? GroupAnonymous : GroupNonMember
227 228 member = @override_members.detect {|m| m.principal.is_a? group_class}
228 229 member ? member.roles.to_a : [role]
229 230 end
230 231
231 232 def principals
232 233 @principals ||= Principal.active.joins(:members).where("#{Member.table_name}.project_id = ?", id).uniq
233 234 end
234 235
235 236 def users
236 237 @users ||= User.active.joins(:members).where("#{Member.table_name}.project_id = ?", id).uniq
237 238 end
238 239
239 240 # Returns the Systemwide and project specific activities
240 241 def activities(include_inactive=false)
241 242 t = TimeEntryActivity.table_name
242 243 scope = TimeEntryActivity.where("#{t}.project_id IS NULL OR #{t}.project_id = ?", id)
243 244
244 245 overridden_activity_ids = self.time_entry_activities.pluck(:parent_id).compact
245 246 if overridden_activity_ids.any?
246 247 scope = scope.where("#{t}.id NOT IN (?)", overridden_activity_ids)
247 248 end
248 249 unless include_inactive
249 250 scope = scope.active
250 251 end
251 252 scope
252 253 end
253 254
254 255 # Will create a new Project specific Activity or update an existing one
255 256 #
256 257 # This will raise a ActiveRecord::Rollback if the TimeEntryActivity
257 258 # does not successfully save.
258 259 def update_or_create_time_entry_activity(id, activity_hash)
259 260 if activity_hash.respond_to?(:has_key?) && activity_hash.has_key?('parent_id')
260 261 self.create_time_entry_activity_if_needed(activity_hash)
261 262 else
262 263 activity = project.time_entry_activities.find_by_id(id.to_i)
263 264 activity.update_attributes(activity_hash) if activity
264 265 end
265 266 end
266 267
267 268 # Create a new TimeEntryActivity if it overrides a system TimeEntryActivity
268 269 #
269 270 # This will raise a ActiveRecord::Rollback if the TimeEntryActivity
270 271 # does not successfully save.
271 272 def create_time_entry_activity_if_needed(activity)
272 273 if activity['parent_id']
273 274 parent_activity = TimeEntryActivity.find(activity['parent_id'])
274 275 activity['name'] = parent_activity.name
275 276 activity['position'] = parent_activity.position
276 277 if Enumeration.overriding_change?(activity, parent_activity)
277 278 project_activity = self.time_entry_activities.create(activity)
278 279 if project_activity.new_record?
279 280 raise ActiveRecord::Rollback, "Overriding TimeEntryActivity was not successfully saved"
280 281 else
281 282 self.time_entries.
282 283 where(:activity_id => parent_activity.id).
283 284 update_all(:activity_id => project_activity.id)
284 285 end
285 286 end
286 287 end
287 288 end
288 289
289 290 # Returns a :conditions SQL string that can be used to find the issues associated with this project.
290 291 #
291 292 # Examples:
292 293 # project.project_condition(true) => "(projects.id = 1 OR (projects.lft > 1 AND projects.rgt < 10))"
293 294 # project.project_condition(false) => "projects.id = 1"
294 295 def project_condition(with_subprojects)
295 296 cond = "#{Project.table_name}.id = #{id}"
296 297 cond = "(#{cond} OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt}))" if with_subprojects
297 298 cond
298 299 end
299 300
300 301 def self.find(*args)
301 302 if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/)
302 303 project = find_by_identifier(*args)
303 304 raise ActiveRecord::RecordNotFound, "Couldn't find Project with identifier=#{args.first}" if project.nil?
304 305 project
305 306 else
306 307 super
307 308 end
308 309 end
309 310
310 311 def self.find_by_param(*args)
311 312 self.find(*args)
312 313 end
313 314
314 315 alias :base_reload :reload
315 316 def reload(*args)
316 317 @principals = nil
317 318 @users = nil
318 319 @shared_versions = nil
319 320 @rolled_up_versions = nil
320 321 @rolled_up_trackers = nil
321 322 @all_issue_custom_fields = nil
322 323 @all_time_entry_custom_fields = nil
323 324 @to_param = nil
324 325 @allowed_parents = nil
325 326 @allowed_permissions = nil
326 327 @actions_allowed = nil
327 328 @start_date = nil
328 329 @due_date = nil
329 330 @override_members = nil
330 331 @assignable_users = nil
331 332 base_reload(*args)
332 333 end
333 334
334 335 def to_param
335 336 if new_record?
336 337 nil
337 338 else
338 339 # id is used for projects with a numeric identifier (compatibility)
339 340 @to_param ||= (identifier.to_s =~ %r{^\d*$} ? id.to_s : identifier)
340 341 end
341 342 end
342 343
343 344 def active?
344 345 self.status == STATUS_ACTIVE
345 346 end
346 347
347 348 def archived?
348 349 self.status == STATUS_ARCHIVED
349 350 end
350 351
351 352 # Archives the project and its descendants
352 353 def archive
353 354 # Check that there is no issue of a non descendant project that is assigned
354 355 # to one of the project or descendant versions
355 356 version_ids = self_and_descendants.joins(:versions).pluck("#{Version.table_name}.id")
356 357
357 358 if version_ids.any? &&
358 359 Issue.
359 360 includes(:project).
360 361 where("#{Project.table_name}.lft < ? OR #{Project.table_name}.rgt > ?", lft, rgt).
361 362 where(:fixed_version_id => version_ids).
362 363 exists?
363 364 return false
364 365 end
365 366 Project.transaction do
366 367 archive!
367 368 end
368 369 true
369 370 end
370 371
371 372 # Unarchives the project
372 373 # All its ancestors must be active
373 374 def unarchive
374 375 return false if ancestors.detect {|a| !a.active?}
375 376 update_attribute :status, STATUS_ACTIVE
376 377 end
377 378
378 379 def close
379 380 self_and_descendants.status(STATUS_ACTIVE).update_all :status => STATUS_CLOSED
380 381 end
381 382
382 383 def reopen
383 384 self_and_descendants.status(STATUS_CLOSED).update_all :status => STATUS_ACTIVE
384 385 end
385 386
386 387 # Returns an array of projects the project can be moved to
387 388 # by the current user
388 389 def allowed_parents(user=User.current)
389 390 return @allowed_parents if @allowed_parents
390 391 @allowed_parents = Project.allowed_to(user, :add_subprojects).to_a
391 392 @allowed_parents = @allowed_parents - self_and_descendants
392 393 if user.allowed_to?(:add_project, nil, :global => true) || (!new_record? && parent.nil?)
393 394 @allowed_parents << nil
394 395 end
395 396 unless parent.nil? || @allowed_parents.empty? || @allowed_parents.include?(parent)
396 397 @allowed_parents << parent
397 398 end
398 399 @allowed_parents
399 400 end
400 401
401 402 # Sets the parent of the project with authorization check
402 403 def set_allowed_parent!(p)
403 404 ActiveSupport::Deprecation.warn "Project#set_allowed_parent! is deprecated and will be removed in Redmine 4, use #safe_attributes= instead."
404 405 p = p.id if p.is_a?(Project)
405 406 send :safe_attributes, {:project_id => p}
406 407 save
407 408 end
408 409
409 410 # Sets the parent of the project and saves the project
410 411 # Argument can be either a Project, a String, a Fixnum or nil
411 412 def set_parent!(p)
412 413 if p.is_a?(Project)
413 414 self.parent = p
414 415 else
415 416 self.parent_id = p
416 417 end
417 418 save
418 419 end
419 420
420 421 # Returns an array of the trackers used by the project and its active sub projects
421 422 def rolled_up_trackers
422 423 @rolled_up_trackers ||=
423 424 Tracker.
424 425 joins(:projects).
425 426 joins("JOIN #{EnabledModule.table_name} ON #{EnabledModule.table_name}.project_id = #{Project.table_name}.id AND #{EnabledModule.table_name}.name = 'issue_tracking'").
426 427 where("#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status <> ?", lft, rgt, STATUS_ARCHIVED).
427 428 uniq.
428 429 sorted.
429 430 to_a
430 431 end
431 432
432 433 # Closes open and locked project versions that are completed
433 434 def close_completed_versions
434 435 Version.transaction do
435 436 versions.where(:status => %w(open locked)).each do |version|
436 437 if version.completed?
437 438 version.update_attribute(:status, 'closed')
438 439 end
439 440 end
440 441 end
441 442 end
442 443
443 444 # Returns a scope of the Versions on subprojects
444 445 def rolled_up_versions
445 446 @rolled_up_versions ||=
446 447 Version.
447 448 joins(:project).
448 449 where("#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status <> ?", lft, rgt, STATUS_ARCHIVED)
449 450 end
450 451
451 452 # Returns a scope of the Versions used by the project
452 453 def shared_versions
453 454 if new_record?
454 455 Version.
455 456 joins(:project).
456 457 preload(:project).
457 458 where("#{Project.table_name}.status <> ? AND #{Version.table_name}.sharing = 'system'", STATUS_ARCHIVED)
458 459 else
459 460 @shared_versions ||= begin
460 461 r = root? ? self : root
461 462 Version.
462 463 joins(:project).
463 464 preload(:project).
464 465 where("#{Project.table_name}.id = #{id}" +
465 466 " OR (#{Project.table_name}.status <> #{Project::STATUS_ARCHIVED} AND (" +
466 467 " #{Version.table_name}.sharing = 'system'" +
467 468 " OR (#{Project.table_name}.lft >= #{r.lft} AND #{Project.table_name}.rgt <= #{r.rgt} AND #{Version.table_name}.sharing = 'tree')" +
468 469 " OR (#{Project.table_name}.lft < #{lft} AND #{Project.table_name}.rgt > #{rgt} AND #{Version.table_name}.sharing IN ('hierarchy', 'descendants'))" +
469 470 " OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt} AND #{Version.table_name}.sharing = 'hierarchy')" +
470 471 "))")
471 472 end
472 473 end
473 474 end
474 475
475 476 # Returns a hash of project users grouped by role
476 477 def users_by_role
477 478 members.includes(:user, :roles).inject({}) do |h, m|
478 479 m.roles.each do |r|
479 480 h[r] ||= []
480 481 h[r] << m.user
481 482 end
482 483 h
483 484 end
484 485 end
485 486
486 487 # Adds user as a project member with the default role
487 488 # Used for when a non-admin user creates a project
488 489 def add_default_member(user)
489 490 role = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
490 491 member = Member.new(:project => self, :principal => user, :roles => [role])
491 492 self.members << member
492 493 member
493 494 end
494 495
495 496 # Deletes all project's members
496 497 def delete_all_members
497 498 me, mr = Member.table_name, MemberRole.table_name
498 499 self.class.connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.project_id = #{id})")
499 500 Member.delete_all(['project_id = ?', id])
500 501 end
501 502
502 503 # Return a Principal scope of users/groups issues can be assigned to
503 504 def assignable_users
504 505 types = ['User']
505 506 types << 'Group' if Setting.issue_group_assignment?
506 507
507 508 @assignable_users ||= Principal.
508 509 active.
509 510 joins(:members => :roles).
510 511 where(:type => types, :members => {:project_id => id}, :roles => {:assignable => true}).
511 512 uniq.
512 513 sorted
513 514 end
514 515
515 516 # Returns the mail addresses of users that should be always notified on project events
516 517 def recipients
517 518 notified_users.collect {|user| user.mail}
518 519 end
519 520
520 521 # Returns the users that should be notified on project events
521 522 def notified_users
522 523 # TODO: User part should be extracted to User#notify_about?
523 524 members.select {|m| m.principal.present? && (m.mail_notification? || m.principal.mail_notification == 'all')}.collect {|m| m.principal}
524 525 end
525 526
526 527 # Returns a scope of all custom fields enabled for project issues
527 528 # (explicitly associated custom fields and custom fields enabled for all projects)
528 529 def all_issue_custom_fields
529 530 if new_record?
530 531 @all_issue_custom_fields ||= IssueCustomField.
531 532 sorted.
532 533 where("is_for_all = ? OR id IN (?)", true, issue_custom_field_ids)
533 534 else
534 535 @all_issue_custom_fields ||= IssueCustomField.
535 536 sorted.
536 537 where("is_for_all = ? OR id IN (SELECT DISTINCT cfp.custom_field_id" +
537 538 " FROM #{table_name_prefix}custom_fields_projects#{table_name_suffix} cfp" +
538 539 " WHERE cfp.project_id = ?)", true, id)
539 540 end
540 541 end
541 542
542 543 def project
543 544 self
544 545 end
545 546
546 547 def <=>(project)
547 548 name.casecmp(project.name)
548 549 end
549 550
550 551 def to_s
551 552 name
552 553 end
553 554
554 555 # Returns a short description of the projects (first lines)
555 556 def short_description(length = 255)
556 557 description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
557 558 end
558 559
559 560 def css_classes
560 561 s = 'project'
561 562 s << ' root' if root?
562 563 s << ' child' if child?
563 564 s << (leaf? ? ' leaf' : ' parent')
564 565 unless active?
565 566 if archived?
566 567 s << ' archived'
567 568 else
568 569 s << ' closed'
569 570 end
570 571 end
571 572 s
572 573 end
573 574
574 575 # The earliest start date of a project, based on it's issues and versions
575 576 def start_date
576 577 @start_date ||= [
577 578 issues.minimum('start_date'),
578 579 shared_versions.minimum('effective_date'),
579 580 Issue.fixed_version(shared_versions).minimum('start_date')
580 581 ].compact.min
581 582 end
582 583
583 584 # The latest due date of an issue or version
584 585 def due_date
585 586 @due_date ||= [
586 587 issues.maximum('due_date'),
587 588 shared_versions.maximum('effective_date'),
588 589 Issue.fixed_version(shared_versions).maximum('due_date')
589 590 ].compact.max
590 591 end
591 592
592 593 def overdue?
593 594 active? && !due_date.nil? && (due_date < Date.today)
594 595 end
595 596
596 597 # Returns the percent completed for this project, based on the
597 598 # progress on it's versions.
598 599 def completed_percent(options={:include_subprojects => false})
599 600 if options.delete(:include_subprojects)
600 601 total = self_and_descendants.collect(&:completed_percent).sum
601 602
602 603 total / self_and_descendants.count
603 604 else
604 605 if versions.count > 0
605 606 total = versions.collect(&:completed_percent).sum
606 607
607 608 total / versions.count
608 609 else
609 610 100
610 611 end
611 612 end
612 613 end
613 614
614 615 # Return true if this project allows to do the specified action.
615 616 # action can be:
616 617 # * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit')
617 618 # * a permission Symbol (eg. :edit_project)
618 619 def allows_to?(action)
619 620 if archived?
620 621 # No action allowed on archived projects
621 622 return false
622 623 end
623 624 unless active? || Redmine::AccessControl.read_action?(action)
624 625 # No write action allowed on closed projects
625 626 return false
626 627 end
627 628 # No action allowed on disabled modules
628 629 if action.is_a? Hash
629 630 allowed_actions.include? "#{action[:controller]}/#{action[:action]}"
630 631 else
631 632 allowed_permissions.include? action
632 633 end
633 634 end
634 635
635 636 # Return the enabled module with the given name
636 637 # or nil if the module is not enabled for the project
637 638 def enabled_module(name)
638 639 name = name.to_s
639 640 enabled_modules.detect {|m| m.name == name}
640 641 end
641 642
642 643 # Return true if the module with the given name is enabled
643 644 def module_enabled?(name)
644 645 enabled_module(name).present?
645 646 end
646 647
647 648 def enabled_module_names=(module_names)
648 649 if module_names && module_names.is_a?(Array)
649 650 module_names = module_names.collect(&:to_s).reject(&:blank?)
650 651 self.enabled_modules = module_names.collect {|name| enabled_modules.detect {|mod| mod.name == name} || EnabledModule.new(:name => name)}
651 652 else
652 653 enabled_modules.clear
653 654 end
654 655 end
655 656
656 657 # Returns an array of the enabled modules names
657 658 def enabled_module_names
658 659 enabled_modules.collect(&:name)
659 660 end
660 661
661 662 # Enable a specific module
662 663 #
663 664 # Examples:
664 665 # project.enable_module!(:issue_tracking)
665 666 # project.enable_module!("issue_tracking")
666 667 def enable_module!(name)
667 668 enabled_modules << EnabledModule.new(:name => name.to_s) unless module_enabled?(name)
668 669 end
669 670
670 671 # Disable a module if it exists
671 672 #
672 673 # Examples:
673 674 # project.disable_module!(:issue_tracking)
674 675 # project.disable_module!("issue_tracking")
675 676 # project.disable_module!(project.enabled_modules.first)
676 677 def disable_module!(target)
677 678 target = enabled_modules.detect{|mod| target.to_s == mod.name} unless enabled_modules.include?(target)
678 679 target.destroy unless target.blank?
679 680 end
680 681
681 682 safe_attributes 'name',
682 683 'description',
683 684 'homepage',
684 685 'is_public',
685 686 'identifier',
686 687 'custom_field_values',
687 688 'custom_fields',
688 689 'tracker_ids',
689 690 'issue_custom_field_ids',
690 'parent_id'
691 'parent_id',
692 'default_version_id'
691 693
692 694 safe_attributes 'enabled_module_names',
693 695 :if => lambda {|project, user| project.new_record? || user.allowed_to?(:select_project_modules, project) }
694 696
695 697 safe_attributes 'inherit_members',
696 698 :if => lambda {|project, user| project.parent.nil? || project.parent.visible?(user)}
697 699
698 700 def safe_attributes=(attrs, user=User.current)
699 701 return unless attrs.is_a?(Hash)
700 702 attrs = attrs.deep_dup
701 703
702 704 @unallowed_parent_id = nil
703 705 if new_record? || attrs.key?('parent_id')
704 706 parent_id_param = attrs['parent_id'].to_s
705 707 if new_record? || parent_id_param != parent_id.to_s
706 708 p = parent_id_param.present? ? Project.find_by_id(parent_id_param) : nil
707 709 unless allowed_parents(user).include?(p)
708 710 attrs.delete('parent_id')
709 711 @unallowed_parent_id = true
710 712 end
711 713 end
712 714 end
713 715
714 716 super(attrs, user)
715 717 end
716 718
717 719 # Returns an auto-generated project identifier based on the last identifier used
718 720 def self.next_identifier
719 721 p = Project.order('id DESC').first
720 722 p.nil? ? nil : p.identifier.to_s.succ
721 723 end
722 724
723 725 # Copies and saves the Project instance based on the +project+.
724 726 # Duplicates the source project's:
725 727 # * Wiki
726 728 # * Versions
727 729 # * Categories
728 730 # * Issues
729 731 # * Members
730 732 # * Queries
731 733 #
732 734 # Accepts an +options+ argument to specify what to copy
733 735 #
734 736 # Examples:
735 737 # project.copy(1) # => copies everything
736 738 # project.copy(1, :only => 'members') # => copies members only
737 739 # project.copy(1, :only => ['members', 'versions']) # => copies members and versions
738 740 def copy(project, options={})
739 741 project = project.is_a?(Project) ? project : Project.find(project)
740 742
741 743 to_be_copied = %w(wiki versions issue_categories issues members queries boards)
742 744 to_be_copied = to_be_copied & Array.wrap(options[:only]) unless options[:only].nil?
743 745
744 746 Project.transaction do
745 747 if save
746 748 reload
747 749 to_be_copied.each do |name|
748 750 send "copy_#{name}", project
749 751 end
750 752 Redmine::Hook.call_hook(:model_project_copy_before_save, :source_project => project, :destination_project => self)
751 753 save
752 754 else
753 755 false
754 756 end
755 757 end
756 758 end
757 759
758 760 def member_principals
759 761 ActiveSupport::Deprecation.warn "Project#member_principals is deprecated and will be removed in Redmine 4.0. Use #memberships.active instead."
760 762 memberships.active
761 763 end
762 764
763 765 # Returns a new unsaved Project instance with attributes copied from +project+
764 766 def self.copy_from(project)
765 767 project = project.is_a?(Project) ? project : Project.find(project)
766 768 # clear unique attributes
767 769 attributes = project.attributes.dup.except('id', 'name', 'identifier', 'status', 'parent_id', 'lft', 'rgt')
768 770 copy = Project.new(attributes)
769 771 copy.enabled_module_names = project.enabled_module_names
770 772 copy.trackers = project.trackers
771 773 copy.custom_values = project.custom_values.collect {|v| v.clone}
772 774 copy.issue_custom_fields = project.issue_custom_fields
773 775 copy
774 776 end
775 777
776 778 # Yields the given block for each project with its level in the tree
777 779 def self.project_tree(projects, &block)
778 780 ancestors = []
779 781 projects.sort_by(&:lft).each do |project|
780 782 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
781 783 ancestors.pop
782 784 end
783 785 yield project, ancestors.size
784 786 ancestors << project
785 787 end
786 788 end
787 789
788 790 private
789 791
790 792 def update_inherited_members
791 793 if parent
792 794 if inherit_members? && !inherit_members_was
793 795 remove_inherited_member_roles
794 796 add_inherited_member_roles
795 797 elsif !inherit_members? && inherit_members_was
796 798 remove_inherited_member_roles
797 799 end
798 800 end
799 801 end
800 802
801 803 def remove_inherited_member_roles
802 804 member_roles = memberships.map(&:member_roles).flatten
803 805 member_role_ids = member_roles.map(&:id)
804 806 member_roles.each do |member_role|
805 807 if member_role.inherited_from && !member_role_ids.include?(member_role.inherited_from)
806 808 member_role.destroy
807 809 end
808 810 end
809 811 end
810 812
811 813 def add_inherited_member_roles
812 814 if inherit_members? && parent
813 815 parent.memberships.each do |parent_member|
814 816 member = Member.find_or_new(self.id, parent_member.user_id)
815 817 parent_member.member_roles.each do |parent_member_role|
816 818 member.member_roles << MemberRole.new(:role => parent_member_role.role, :inherited_from => parent_member_role.id)
817 819 end
818 820 member.save!
819 821 end
820 822 memberships.reset
821 823 end
822 824 end
823 825
824 826 def update_versions_from_hierarchy_change
825 827 Issue.update_versions_from_hierarchy_change(self)
826 828 end
827 829
828 830 def validate_parent
829 831 if @unallowed_parent_id
830 832 errors.add(:parent_id, :invalid)
831 833 elsif parent_id_changed?
832 834 unless parent.nil? || (parent.active? && move_possible?(parent))
833 835 errors.add(:parent_id, :invalid)
834 836 end
835 837 end
836 838 end
837 839
838 840 # Copies wiki from +project+
839 841 def copy_wiki(project)
840 842 # Check that the source project has a wiki first
841 843 unless project.wiki.nil?
842 844 wiki = self.wiki || Wiki.new
843 845 wiki.attributes = project.wiki.attributes.dup.except("id", "project_id")
844 846 wiki_pages_map = {}
845 847 project.wiki.pages.each do |page|
846 848 # Skip pages without content
847 849 next if page.content.nil?
848 850 new_wiki_content = WikiContent.new(page.content.attributes.dup.except("id", "page_id", "updated_on"))
849 851 new_wiki_page = WikiPage.new(page.attributes.dup.except("id", "wiki_id", "created_on", "parent_id"))
850 852 new_wiki_page.content = new_wiki_content
851 853 wiki.pages << new_wiki_page
852 854 wiki_pages_map[page.id] = new_wiki_page
853 855 end
854 856
855 857 self.wiki = wiki
856 858 wiki.save
857 859 # Reproduce page hierarchy
858 860 project.wiki.pages.each do |page|
859 861 if page.parent_id && wiki_pages_map[page.id]
860 862 wiki_pages_map[page.id].parent = wiki_pages_map[page.parent_id]
861 863 wiki_pages_map[page.id].save
862 864 end
863 865 end
864 866 end
865 867 end
866 868
867 869 # Copies versions from +project+
868 870 def copy_versions(project)
869 871 project.versions.each do |version|
870 872 new_version = Version.new
871 873 new_version.attributes = version.attributes.dup.except("id", "project_id", "created_on", "updated_on")
872 874 self.versions << new_version
873 875 end
874 876 end
875 877
876 878 # Copies issue categories from +project+
877 879 def copy_issue_categories(project)
878 880 project.issue_categories.each do |issue_category|
879 881 new_issue_category = IssueCategory.new
880 882 new_issue_category.attributes = issue_category.attributes.dup.except("id", "project_id")
881 883 self.issue_categories << new_issue_category
882 884 end
883 885 end
884 886
885 887 # Copies issues from +project+
886 888 def copy_issues(project)
887 889 # Stores the source issue id as a key and the copied issues as the
888 890 # value. Used to map the two together for issue relations.
889 891 issues_map = {}
890 892
891 893 # Store status and reopen locked/closed versions
892 894 version_statuses = versions.reject(&:open?).map {|version| [version, version.status]}
893 895 version_statuses.each do |version, status|
894 896 version.update_attribute :status, 'open'
895 897 end
896 898
897 899 # Get issues sorted by root_id, lft so that parent issues
898 900 # get copied before their children
899 901 project.issues.reorder('root_id, lft').each do |issue|
900 902 new_issue = Issue.new
901 903 new_issue.copy_from(issue, :subtasks => false, :link => false)
902 904 new_issue.project = self
903 905 # Changing project resets the custom field values
904 906 # TODO: handle this in Issue#project=
905 907 new_issue.custom_field_values = issue.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
906 908 # Reassign fixed_versions by name, since names are unique per project
907 909 if issue.fixed_version && issue.fixed_version.project == project
908 910 new_issue.fixed_version = self.versions.detect {|v| v.name == issue.fixed_version.name}
909 911 end
910 912 # Reassign version custom field values
911 913 new_issue.custom_field_values.each do |custom_value|
912 914 if custom_value.custom_field.field_format == 'version' && custom_value.value.present?
913 915 versions = Version.where(:id => custom_value.value).to_a
914 916 new_value = versions.map do |version|
915 917 if version.project == project
916 918 self.versions.detect {|v| v.name == version.name}.try(:id)
917 919 else
918 920 version.id
919 921 end
920 922 end
921 923 new_value.compact!
922 924 new_value = new_value.first unless custom_value.custom_field.multiple?
923 925 custom_value.value = new_value
924 926 end
925 927 end
926 928 # Reassign the category by name, since names are unique per project
927 929 if issue.category
928 930 new_issue.category = self.issue_categories.detect {|c| c.name == issue.category.name}
929 931 end
930 932 # Parent issue
931 933 if issue.parent_id
932 934 if copied_parent = issues_map[issue.parent_id]
933 935 new_issue.parent_issue_id = copied_parent.id
934 936 end
935 937 end
936 938
937 939 self.issues << new_issue
938 940 if new_issue.new_record?
939 941 logger.info "Project#copy_issues: issue ##{issue.id} could not be copied: #{new_issue.errors.full_messages}" if logger && logger.info?
940 942 else
941 943 issues_map[issue.id] = new_issue unless new_issue.new_record?
942 944 end
943 945 end
944 946
945 947 # Restore locked/closed version statuses
946 948 version_statuses.each do |version, status|
947 949 version.update_attribute :status, status
948 950 end
949 951
950 952 # Relations after in case issues related each other
951 953 project.issues.each do |issue|
952 954 new_issue = issues_map[issue.id]
953 955 unless new_issue
954 956 # Issue was not copied
955 957 next
956 958 end
957 959
958 960 # Relations
959 961 issue.relations_from.each do |source_relation|
960 962 new_issue_relation = IssueRelation.new
961 963 new_issue_relation.attributes = source_relation.attributes.dup.except("id", "issue_from_id", "issue_to_id")
962 964 new_issue_relation.issue_to = issues_map[source_relation.issue_to_id]
963 965 if new_issue_relation.issue_to.nil? && Setting.cross_project_issue_relations?
964 966 new_issue_relation.issue_to = source_relation.issue_to
965 967 end
966 968 new_issue.relations_from << new_issue_relation
967 969 end
968 970
969 971 issue.relations_to.each do |source_relation|
970 972 new_issue_relation = IssueRelation.new
971 973 new_issue_relation.attributes = source_relation.attributes.dup.except("id", "issue_from_id", "issue_to_id")
972 974 new_issue_relation.issue_from = issues_map[source_relation.issue_from_id]
973 975 if new_issue_relation.issue_from.nil? && Setting.cross_project_issue_relations?
974 976 new_issue_relation.issue_from = source_relation.issue_from
975 977 end
976 978 new_issue.relations_to << new_issue_relation
977 979 end
978 980 end
979 981 end
980 982
981 983 # Copies members from +project+
982 984 def copy_members(project)
983 985 # Copy users first, then groups to handle members with inherited and given roles
984 986 members_to_copy = []
985 987 members_to_copy += project.memberships.select {|m| m.principal.is_a?(User)}
986 988 members_to_copy += project.memberships.select {|m| !m.principal.is_a?(User)}
987 989
988 990 members_to_copy.each do |member|
989 991 new_member = Member.new
990 992 new_member.attributes = member.attributes.dup.except("id", "project_id", "created_on")
991 993 # only copy non inherited roles
992 994 # inherited roles will be added when copying the group membership
993 995 role_ids = member.member_roles.reject(&:inherited?).collect(&:role_id)
994 996 next if role_ids.empty?
995 997 new_member.role_ids = role_ids
996 998 new_member.project = self
997 999 self.members << new_member
998 1000 end
999 1001 end
1000 1002
1001 1003 # Copies queries from +project+
1002 1004 def copy_queries(project)
1003 1005 project.queries.each do |query|
1004 1006 new_query = IssueQuery.new
1005 1007 new_query.attributes = query.attributes.dup.except("id", "project_id", "sort_criteria", "user_id", "type")
1006 1008 new_query.sort_criteria = query.sort_criteria if query.sort_criteria
1007 1009 new_query.project = self
1008 1010 new_query.user_id = query.user_id
1009 1011 new_query.role_ids = query.role_ids if query.visibility == IssueQuery::VISIBILITY_ROLES
1010 1012 self.queries << new_query
1011 1013 end
1012 1014 end
1013 1015
1014 1016 # Copies boards from +project+
1015 1017 def copy_boards(project)
1016 1018 project.boards.each do |board|
1017 1019 new_board = Board.new
1018 1020 new_board.attributes = board.attributes.dup.except("id", "project_id", "topics_count", "messages_count", "last_message_id")
1019 1021 new_board.project = self
1020 1022 self.boards << new_board
1021 1023 end
1022 1024 end
1023 1025
1024 1026 def allowed_permissions
1025 1027 @allowed_permissions ||= begin
1026 1028 module_names = enabled_modules.loaded? ? enabled_modules.map(&:name) : enabled_modules.pluck(:name)
1027 1029 Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name}
1028 1030 end
1029 1031 end
1030 1032
1031 1033 def allowed_actions
1032 1034 @actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten
1033 1035 end
1034 1036
1035 1037 # Archives subprojects recursively
1036 1038 def archive!
1037 1039 children.each do |subproject|
1038 1040 subproject.send :archive!
1039 1041 end
1040 1042 update_attribute :status, STATUS_ARCHIVED
1041 1043 end
1042 1044 end
@@ -1,300 +1,307
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2015 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 Version < ActiveRecord::Base
19 19 include Redmine::SafeAttributes
20
20 21 after_update :update_issues_from_sharing_change
22 before_destroy :nullify_projects_default_version
23
21 24 belongs_to :project
22 25 has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id', :dependent => :nullify
23 26 acts_as_customizable
24 27 acts_as_attachable :view_permission => :view_files,
25 28 :edit_permission => :manage_files,
26 29 :delete_permission => :manage_files
27 30
28 31 VERSION_STATUSES = %w(open locked closed)
29 32 VERSION_SHARINGS = %w(none descendants hierarchy tree system)
30 33
31 34 validates_presence_of :name
32 35 validates_uniqueness_of :name, :scope => [:project_id]
33 36 validates_length_of :name, :maximum => 60
34 37 validates_length_of :description, :maximum => 255
35 38 validates :effective_date, :date => true
36 39 validates_inclusion_of :status, :in => VERSION_STATUSES
37 40 validates_inclusion_of :sharing, :in => VERSION_SHARINGS
38 41 attr_protected :id
39 42
40 43 scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
41 44 scope :open, lambda { where(:status => 'open') }
42 45 scope :visible, lambda {|*args|
43 46 joins(:project).
44 47 where(Project.allowed_to_condition(args.first || User.current, :view_issues))
45 48 }
46 49
47 50 safe_attributes 'name',
48 51 'description',
49 52 'effective_date',
50 53 'due_date',
51 54 'wiki_page_title',
52 55 'status',
53 56 'sharing',
54 57 'custom_field_values',
55 58 'custom_fields'
56 59
57 60 # Returns true if +user+ or current user is allowed to view the version
58 61 def visible?(user=User.current)
59 62 user.allowed_to?(:view_issues, self.project)
60 63 end
61 64
62 65 # Version files have same visibility as project files
63 66 def attachments_visible?(*args)
64 67 project.present? && project.attachments_visible?(*args)
65 68 end
66 69
67 70 def attachments_deletable?(usr=User.current)
68 71 project.present? && project.attachments_deletable?(usr)
69 72 end
70 73
71 74 def start_date
72 75 @start_date ||= fixed_issues.minimum('start_date')
73 76 end
74 77
75 78 def due_date
76 79 effective_date
77 80 end
78 81
79 82 def due_date=(arg)
80 83 self.effective_date=(arg)
81 84 end
82 85
83 86 # Returns the total estimated time for this version
84 87 # (sum of leaves estimated_hours)
85 88 def estimated_hours
86 89 @estimated_hours ||= fixed_issues.sum(:estimated_hours).to_f
87 90 end
88 91
89 92 # Returns the total reported time for this version
90 93 def spent_hours
91 94 @spent_hours ||= TimeEntry.joins(:issue).where("#{Issue.table_name}.fixed_version_id = ?", id).sum(:hours).to_f
92 95 end
93 96
94 97 def closed?
95 98 status == 'closed'
96 99 end
97 100
98 101 def open?
99 102 status == 'open'
100 103 end
101 104
102 105 # Returns true if the version is completed: due date reached and no open issues
103 106 def completed?
104 107 effective_date && (effective_date < Date.today) && (open_issues_count == 0)
105 108 end
106 109
107 110 def behind_schedule?
108 111 if completed_percent == 100
109 112 return false
110 113 elsif due_date && start_date
111 114 done_date = start_date + ((due_date - start_date+1)* completed_percent/100).floor
112 115 return done_date <= Date.today
113 116 else
114 117 false # No issues so it's not late
115 118 end
116 119 end
117 120
118 121 # Returns the completion percentage of this version based on the amount of open/closed issues
119 122 # and the time spent on the open issues.
120 123 def completed_percent
121 124 if issues_count == 0
122 125 0
123 126 elsif open_issues_count == 0
124 127 100
125 128 else
126 129 issues_progress(false) + issues_progress(true)
127 130 end
128 131 end
129 132
130 133 # Returns the percentage of issues that have been marked as 'closed'.
131 134 def closed_percent
132 135 if issues_count == 0
133 136 0
134 137 else
135 138 issues_progress(false)
136 139 end
137 140 end
138 141
139 142 # Returns true if the version is overdue: due date reached and some open issues
140 143 def overdue?
141 144 effective_date && (effective_date < Date.today) && (open_issues_count > 0)
142 145 end
143 146
144 147 # Returns assigned issues count
145 148 def issues_count
146 149 load_issue_counts
147 150 @issue_count
148 151 end
149 152
150 153 # Returns the total amount of open issues for this version.
151 154 def open_issues_count
152 155 load_issue_counts
153 156 @open_issues_count
154 157 end
155 158
156 159 # Returns the total amount of closed issues for this version.
157 160 def closed_issues_count
158 161 load_issue_counts
159 162 @closed_issues_count
160 163 end
161 164
162 165 def wiki_page
163 166 if project.wiki && !wiki_page_title.blank?
164 167 @wiki_page ||= project.wiki.find_page(wiki_page_title)
165 168 end
166 169 @wiki_page
167 170 end
168 171
169 172 def to_s; name end
170 173
171 174 def to_s_with_project
172 175 "#{project} - #{name}"
173 176 end
174 177
175 178 # Versions are sorted by effective_date and name
176 179 # Those with no effective_date are at the end, sorted by name
177 180 def <=>(version)
178 181 if self.effective_date
179 182 if version.effective_date
180 183 if self.effective_date == version.effective_date
181 184 name == version.name ? id <=> version.id : name <=> version.name
182 185 else
183 186 self.effective_date <=> version.effective_date
184 187 end
185 188 else
186 189 -1
187 190 end
188 191 else
189 192 if version.effective_date
190 193 1
191 194 else
192 195 name == version.name ? id <=> version.id : name <=> version.name
193 196 end
194 197 end
195 198 end
196 199
197 200 def self.fields_for_order_statement(table=nil)
198 201 table ||= table_name
199 202 ["(CASE WHEN #{table}.effective_date IS NULL THEN 1 ELSE 0 END)", "#{table}.effective_date", "#{table}.name", "#{table}.id"]
200 203 end
201 204
202 205 scope :sorted, lambda { order(fields_for_order_statement) }
203 206
204 207 # Returns the sharings that +user+ can set the version to
205 208 def allowed_sharings(user = User.current)
206 209 VERSION_SHARINGS.select do |s|
207 210 if sharing == s
208 211 true
209 212 else
210 213 case s
211 214 when 'system'
212 215 # Only admin users can set a systemwide sharing
213 216 user.admin?
214 217 when 'hierarchy', 'tree'
215 218 # Only users allowed to manage versions of the root project can
216 219 # set sharing to hierarchy or tree
217 220 project.nil? || user.allowed_to?(:manage_versions, project.root)
218 221 else
219 222 true
220 223 end
221 224 end
222 225 end
223 226 end
224 227
225 228 # Returns true if the version is shared, otherwise false
226 229 def shared?
227 230 sharing != 'none'
228 231 end
229 232
230 233 def deletable?
231 234 fixed_issues.empty? && !referenced_by_a_custom_field?
232 235 end
233 236
234 237 private
235 238
236 239 def load_issue_counts
237 240 unless @issue_count
238 241 @open_issues_count = 0
239 242 @closed_issues_count = 0
240 243 fixed_issues.group(:status).count.each do |status, count|
241 244 if status.is_closed?
242 245 @closed_issues_count += count
243 246 else
244 247 @open_issues_count += count
245 248 end
246 249 end
247 250 @issue_count = @open_issues_count + @closed_issues_count
248 251 end
249 252 end
250 253
251 254 # Update the issue's fixed versions. Used if a version's sharing changes.
252 255 def update_issues_from_sharing_change
253 256 if sharing_changed?
254 257 if VERSION_SHARINGS.index(sharing_was).nil? ||
255 258 VERSION_SHARINGS.index(sharing).nil? ||
256 259 VERSION_SHARINGS.index(sharing_was) > VERSION_SHARINGS.index(sharing)
257 260 Issue.update_versions_from_sharing_change self
258 261 end
259 262 end
260 263 end
261 264
262 265 # Returns the average estimated time of assigned issues
263 266 # or 1 if no issue has an estimated time
264 267 # Used to weight unestimated issues in progress calculation
265 268 def estimated_average
266 269 if @estimated_average.nil?
267 270 average = fixed_issues.average(:estimated_hours).to_f
268 271 if average == 0
269 272 average = 1
270 273 end
271 274 @estimated_average = average
272 275 end
273 276 @estimated_average
274 277 end
275 278
276 279 # Returns the total progress of open or closed issues. The returned percentage takes into account
277 280 # the amount of estimated time set for this version.
278 281 #
279 282 # Examples:
280 283 # issues_progress(true) => returns the progress percentage for open issues.
281 284 # issues_progress(false) => returns the progress percentage for closed issues.
282 285 def issues_progress(open)
283 286 @issues_progress ||= {}
284 287 @issues_progress[open] ||= begin
285 288 progress = 0
286 289 if issues_count > 0
287 290 ratio = open ? 'done_ratio' : 100
288 291
289 292 done = fixed_issues.open(open).sum("COALESCE(estimated_hours, #{estimated_average}) * #{ratio}").to_f
290 293 progress = done / (estimated_average * issues_count)
291 294 end
292 295 progress
293 296 end
294 297 end
295 298
296 299 def referenced_by_a_custom_field?
297 300 CustomValue.joins(:custom_field).
298 301 where(:value => id.to_s, :custom_fields => {:field_format => 'version'}).any?
299 302 end
303
304 def nullify_projects_default_version
305 Project.where(:default_version_id => id).update_all(:default_version_id => nil)
306 end
300 307 end
@@ -1,102 +1,106
1 1 <%= error_messages_for 'project' %>
2 2
3 3 <div class="box tabular">
4 4 <!--[form:project]-->
5 5 <p><%= f.text_field :name, :required => true, :size => 60 %></p>
6 6
7 7 <p><%= f.text_area :description, :rows => 8, :class => 'wiki-edit' %></p>
8 8 <p><%= f.text_field :identifier, :required => true, :size => 60, :disabled => @project.identifier_frozen?, :maxlength => Project::IDENTIFIER_MAX_LENGTH %>
9 9 <% unless @project.identifier_frozen? %>
10 10 <em class="info"><%= l(:text_length_between, :min => 1, :max => Project::IDENTIFIER_MAX_LENGTH) %> <%= l(:text_project_identifier_info).html_safe %></em>
11 11 <% end %></p>
12 12 <p><%= f.text_field :homepage, :size => 60 %></p>
13 13 <p><%= f.check_box :is_public %></p>
14 14
15 15 <% unless @project.allowed_parents.compact.empty? %>
16 16 <p><%= label(:project, :parent_id, l(:field_parent)) %><%= parent_project_select_tag(@project) %></p>
17 17 <% end %>
18 18
19 19 <% if @project.safe_attribute? 'inherit_members' %>
20 20 <p><%= f.check_box :inherit_members %></p>
21 21 <% end %>
22 22
23 <% if @project.safe_attribute?('default_version_id') && (default_version_options = project_default_version_options(@project)).present? %>
24 <p><%= f.select :default_version_id, project_default_version_options(@project), :include_blank => true %></p>
25 <% end %>
26
23 27 <%= wikitoolbar_for 'project_description' %>
24 28
25 29 <% @project.custom_field_values.each do |value| %>
26 30 <p><%= custom_field_tag_with_label :project, value %></p>
27 31 <% end %>
28 32 <%= call_hook(:view_projects_form, :project => @project, :form => f) %>
29 33 </div>
30 34
31 35 <% if @project.new_record? %>
32 36 <fieldset class="box tabular"><legend><%= l(:label_module_plural) %></legend>
33 37 <% Redmine::AccessControl.available_project_modules.each do |m| %>
34 38 <label class="floating">
35 39 <%= check_box_tag 'project[enabled_module_names][]', m, @project.module_enabled?(m), :id => "project_enabled_module_names_#{m}" %>
36 40 <%= l_or_humanize(m, :prefix => "project_module_") %>
37 41 </label>
38 42 <% end %>
39 43 <%= hidden_field_tag 'project[enabled_module_names][]', '' %>
40 44 </fieldset>
41 45 <% end %>
42 46
43 47 <% if @project.new_record? || @project.module_enabled?('issue_tracking') %>
44 48 <% unless @trackers.empty? %>
45 49 <fieldset class="box tabular" id="project_trackers"><legend><%=l(:label_tracker_plural)%></legend>
46 50 <% @trackers.each do |tracker| %>
47 51 <label class="floating">
48 52 <%= check_box_tag 'project[tracker_ids][]', tracker.id, @project.trackers.to_a.include?(tracker), :id => nil %>
49 53 <%= tracker %>
50 54 </label>
51 55 <% end %>
52 56 <%= hidden_field_tag 'project[tracker_ids][]', '' %>
53 57 </fieldset>
54 58 <% end %>
55 59
56 60 <% unless @issue_custom_fields.empty? %>
57 61 <fieldset class="box tabular" id="project_issue_custom_fields"><legend><%=l(:label_custom_field_plural)%></legend>
58 62 <% @issue_custom_fields.each do |custom_field| %>
59 63 <label class="floating">
60 64 <%= check_box_tag 'project[issue_custom_field_ids][]', custom_field.id, (@project.all_issue_custom_fields.include? custom_field),
61 65 :disabled => (custom_field.is_for_all? ? "disabled" : nil),
62 66 :id => nil %>
63 67 <%= custom_field_name_tag(custom_field) %>
64 68 </label>
65 69 <% end %>
66 70 <%= hidden_field_tag 'project[issue_custom_field_ids][]', '' %>
67 71 </fieldset>
68 72 <% end %>
69 73 <% end %>
70 74 <!--[eoform:project]-->
71 75
72 76 <% unless @project.identifier_frozen? %>
73 77 <% content_for :header_tags do %>
74 78 <%= javascript_include_tag 'project_identifier' %>
75 79 <% end %>
76 80 <% end %>
77 81
78 82 <% if !User.current.admin? && @project.inherit_members? && @project.parent && User.current.member_of?(@project.parent) %>
79 83 <%= javascript_tag do %>
80 84 $(document).ready(function() {
81 85 $("#project_inherit_members").change(function(){
82 86 if (!$(this).is(':checked')) {
83 87 if (!confirm("<%= escape_javascript(l(:text_own_membership_delete_confirmation)) %>")) {
84 88 $("#project_inherit_members").attr("checked", true);
85 89 }
86 90 }
87 91 });
88 92 });
89 93 <% end %>
90 94 <% end %>
91 95
92 96 <%= javascript_tag do %>
93 97 $(document).ready(function() {
94 98 $('#project_enabled_module_names_issue_tracking').on('change', function(){
95 99 if ($(this).prop('checked')){
96 100 $('#project_trackers, #project_issue_custom_fields').show();
97 101 } else {
98 102 $('#project_trackers, #project_issue_custom_fields').hide();
99 103 }
100 104 }).trigger('change');
101 105 });
102 106 <% end %>
@@ -1,1167 +1,1168
1 1 en:
2 2 # Text direction: Left-to-Right (ltr) or Right-to-Left (rtl)
3 3 direction: ltr
4 4 date:
5 5 formats:
6 6 # Use the strftime parameters for formats.
7 7 # When no format has been given, it uses default.
8 8 # You can provide other formats here if you like!
9 9 default: "%m/%d/%Y"
10 10 short: "%b %d"
11 11 long: "%B %d, %Y"
12 12
13 13 day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
14 14 abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
15 15
16 16 # Don't forget the nil at the beginning; there's no such thing as a 0th month
17 17 month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
18 18 abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
19 19 # Used in date_select and datime_select.
20 20 order:
21 21 - :year
22 22 - :month
23 23 - :day
24 24
25 25 time:
26 26 formats:
27 27 default: "%m/%d/%Y %I:%M %p"
28 28 time: "%I:%M %p"
29 29 short: "%d %b %H:%M"
30 30 long: "%B %d, %Y %H:%M"
31 31 am: "am"
32 32 pm: "pm"
33 33
34 34 datetime:
35 35 distance_in_words:
36 36 half_a_minute: "half a minute"
37 37 less_than_x_seconds:
38 38 one: "less than 1 second"
39 39 other: "less than %{count} seconds"
40 40 x_seconds:
41 41 one: "1 second"
42 42 other: "%{count} seconds"
43 43 less_than_x_minutes:
44 44 one: "less than a minute"
45 45 other: "less than %{count} minutes"
46 46 x_minutes:
47 47 one: "1 minute"
48 48 other: "%{count} minutes"
49 49 about_x_hours:
50 50 one: "about 1 hour"
51 51 other: "about %{count} hours"
52 52 x_hours:
53 53 one: "1 hour"
54 54 other: "%{count} hours"
55 55 x_days:
56 56 one: "1 day"
57 57 other: "%{count} days"
58 58 about_x_months:
59 59 one: "about 1 month"
60 60 other: "about %{count} months"
61 61 x_months:
62 62 one: "1 month"
63 63 other: "%{count} months"
64 64 about_x_years:
65 65 one: "about 1 year"
66 66 other: "about %{count} years"
67 67 over_x_years:
68 68 one: "over 1 year"
69 69 other: "over %{count} years"
70 70 almost_x_years:
71 71 one: "almost 1 year"
72 72 other: "almost %{count} years"
73 73
74 74 number:
75 75 format:
76 76 separator: "."
77 77 delimiter: ""
78 78 precision: 3
79 79
80 80 human:
81 81 format:
82 82 delimiter: ""
83 83 precision: 3
84 84 storage_units:
85 85 format: "%n %u"
86 86 units:
87 87 byte:
88 88 one: "Byte"
89 89 other: "Bytes"
90 90 kb: "KB"
91 91 mb: "MB"
92 92 gb: "GB"
93 93 tb: "TB"
94 94
95 95 # Used in array.to_sentence.
96 96 support:
97 97 array:
98 98 sentence_connector: "and"
99 99 skip_last_comma: false
100 100
101 101 activerecord:
102 102 errors:
103 103 template:
104 104 header:
105 105 one: "1 error prohibited this %{model} from being saved"
106 106 other: "%{count} errors prohibited this %{model} from being saved"
107 107 messages:
108 108 inclusion: "is not included in the list"
109 109 exclusion: "is reserved"
110 110 invalid: "is invalid"
111 111 confirmation: "doesn't match confirmation"
112 112 accepted: "must be accepted"
113 113 empty: "cannot be empty"
114 114 blank: "cannot be blank"
115 115 too_long: "is too long (maximum is %{count} characters)"
116 116 too_short: "is too short (minimum is %{count} characters)"
117 117 wrong_length: "is the wrong length (should be %{count} characters)"
118 118 taken: "has already been taken"
119 119 not_a_number: "is not a number"
120 120 not_a_date: "is not a valid date"
121 121 greater_than: "must be greater than %{count}"
122 122 greater_than_or_equal_to: "must be greater than or equal to %{count}"
123 123 equal_to: "must be equal to %{count}"
124 124 less_than: "must be less than %{count}"
125 125 less_than_or_equal_to: "must be less than or equal to %{count}"
126 126 odd: "must be odd"
127 127 even: "must be even"
128 128 greater_than_start_date: "must be greater than start date"
129 129 not_same_project: "doesn't belong to the same project"
130 130 circular_dependency: "This relation would create a circular dependency"
131 131 cant_link_an_issue_with_a_descendant: "An issue cannot be linked to one of its subtasks"
132 132 earlier_than_minimum_start_date: "cannot be earlier than %{date} because of preceding issues"
133 133
134 134 actionview_instancetag_blank_option: Please select
135 135
136 136 general_text_No: 'No'
137 137 general_text_Yes: 'Yes'
138 138 general_text_no: 'no'
139 139 general_text_yes: 'yes'
140 140 general_lang_name: 'English'
141 141 general_csv_separator: ','
142 142 general_csv_decimal_separator: '.'
143 143 general_csv_encoding: ISO-8859-1
144 144 general_pdf_fontname: freesans
145 145 general_first_day_of_week: '7'
146 146
147 147 notice_account_updated: Account was successfully updated.
148 148 notice_account_invalid_creditentials: Invalid user or password
149 149 notice_account_password_updated: Password was successfully updated.
150 150 notice_account_wrong_password: Wrong password
151 151 notice_account_register_done: Account was successfully created. An email containing the instructions to activate your account was sent to %{email}.
152 152 notice_account_unknown_email: Unknown user.
153 153 notice_account_not_activated_yet: You haven't activated your account yet. If you want to receive a new activation email, please <a href="%{url}">click this link</a>.
154 154 notice_account_locked: Your account is locked.
155 155 notice_can_t_change_password: This account uses an external authentication source. Impossible to change the password.
156 156 notice_account_lost_email_sent: An email with instructions to choose a new password has been sent to you.
157 157 notice_account_activated: Your account has been activated. You can now log in.
158 158 notice_successful_create: Successful creation.
159 159 notice_successful_update: Successful update.
160 160 notice_successful_delete: Successful deletion.
161 161 notice_successful_connection: Successful connection.
162 162 notice_file_not_found: The page you were trying to access doesn't exist or has been removed.
163 163 notice_locking_conflict: Data has been updated by another user.
164 164 notice_not_authorized: You are not authorized to access this page.
165 165 notice_not_authorized_archived_project: The project you're trying to access has been archived.
166 166 notice_email_sent: "An email was sent to %{value}"
167 167 notice_email_error: "An error occurred while sending mail (%{value})"
168 168 notice_feeds_access_key_reseted: Your Atom access key was reset.
169 169 notice_api_access_key_reseted: Your API access key was reset.
170 170 notice_failed_to_save_issues: "Failed to save %{count} issue(s) on %{total} selected: %{ids}."
171 171 notice_failed_to_save_time_entries: "Failed to save %{count} time entrie(s) on %{total} selected: %{ids}."
172 172 notice_failed_to_save_members: "Failed to save member(s): %{errors}."
173 173 notice_no_issue_selected: "No issue is selected! Please, check the issues you want to edit."
174 174 notice_account_pending: "Your account was created and is now pending administrator approval."
175 175 notice_default_data_loaded: Default configuration successfully loaded.
176 176 notice_unable_delete_version: Unable to delete version.
177 177 notice_unable_delete_time_entry: Unable to delete time log entry.
178 178 notice_issue_done_ratios_updated: Issue done ratios updated.
179 179 notice_gantt_chart_truncated: "The chart was truncated because it exceeds the maximum number of items that can be displayed (%{max})"
180 180 notice_issue_successful_create: "Issue %{id} created."
181 181 notice_issue_update_conflict: "The issue has been updated by an other user while you were editing it."
182 182 notice_account_deleted: "Your account has been permanently deleted."
183 183 notice_user_successful_create: "User %{id} created."
184 184 notice_new_password_must_be_different: The new password must be different from the current password
185 185 notice_import_finished: "All %{count} items have been imported."
186 186 notice_import_finished_with_errors: "%{count} out of %{total} items could not be imported."
187 187
188 188 error_can_t_load_default_data: "Default configuration could not be loaded: %{value}"
189 189 error_scm_not_found: "The entry or revision was not found in the repository."
190 190 error_scm_command_failed: "An error occurred when trying to access the repository: %{value}"
191 191 error_scm_annotate: "The entry does not exist or cannot be annotated."
192 192 error_scm_annotate_big_text_file: "The entry cannot be annotated, as it exceeds the maximum text file size."
193 193 error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
194 194 error_no_tracker_in_project: 'No tracker is associated to this project. Please check the Project settings.'
195 195 error_no_default_issue_status: 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
196 196 error_can_not_delete_custom_field: Unable to delete custom field
197 197 error_can_not_delete_tracker: "This tracker contains issues and cannot be deleted."
198 198 error_can_not_remove_role: "This role is in use and cannot be deleted."
199 199 error_can_not_reopen_issue_on_closed_version: 'An issue assigned to a closed version cannot be reopened'
200 200 error_can_not_archive_project: This project cannot be archived
201 201 error_issue_done_ratios_not_updated: "Issue done ratios not updated."
202 202 error_workflow_copy_source: 'Please select a source tracker or role'
203 203 error_workflow_copy_target: 'Please select target tracker(s) and role(s)'
204 204 error_unable_delete_issue_status: 'Unable to delete issue status'
205 205 error_unable_to_connect: "Unable to connect (%{value})"
206 206 error_attachment_too_big: "This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size})"
207 207 error_session_expired: "Your session has expired. Please login again."
208 208 warning_attachments_not_saved: "%{count} file(s) could not be saved."
209 209 error_password_expired: "Your password has expired or the administrator requires you to change it."
210 210 error_invalid_file_encoding: "The file is not a valid %{encoding} encoded file"
211 211 error_invalid_csv_file_or_settings: "The file is not a CSV file or does not match the settings below"
212 212 error_can_not_read_import_file: "An error occurred while reading the file to import"
213 213
214 214 mail_subject_lost_password: "Your %{value} password"
215 215 mail_body_lost_password: 'To change your password, click on the following link:'
216 216 mail_subject_register: "Your %{value} account activation"
217 217 mail_body_register: 'To activate your account, click on the following link:'
218 218 mail_body_account_information_external: "You can use your %{value} account to log in."
219 219 mail_body_account_information: Your account information
220 220 mail_subject_account_activation_request: "%{value} account activation request"
221 221 mail_body_account_activation_request: "A new user (%{value}) has registered. The account is pending your approval:"
222 222 mail_subject_reminder: "%{count} issue(s) due in the next %{days} days"
223 223 mail_body_reminder: "%{count} issue(s) that are assigned to you are due in the next %{days} days:"
224 224 mail_subject_wiki_content_added: "'%{id}' wiki page has been added"
225 225 mail_body_wiki_content_added: "The '%{id}' wiki page has been added by %{author}."
226 226 mail_subject_wiki_content_updated: "'%{id}' wiki page has been updated"
227 227 mail_body_wiki_content_updated: "The '%{id}' wiki page has been updated by %{author}."
228 228
229 229 field_name: Name
230 230 field_description: Description
231 231 field_summary: Summary
232 232 field_is_required: Required
233 233 field_firstname: First name
234 234 field_lastname: Last name
235 235 field_mail: Email
236 236 field_address: Email
237 237 field_filename: File
238 238 field_filesize: Size
239 239 field_downloads: Downloads
240 240 field_author: Author
241 241 field_created_on: Created
242 242 field_updated_on: Updated
243 243 field_closed_on: Closed
244 244 field_field_format: Format
245 245 field_is_for_all: For all projects
246 246 field_possible_values: Possible values
247 247 field_regexp: Regular expression
248 248 field_min_length: Minimum length
249 249 field_max_length: Maximum length
250 250 field_value: Value
251 251 field_category: Category
252 252 field_title: Title
253 253 field_project: Project
254 254 field_issue: Issue
255 255 field_status: Status
256 256 field_notes: Notes
257 257 field_is_closed: Issue closed
258 258 field_is_default: Default value
259 259 field_tracker: Tracker
260 260 field_subject: Subject
261 261 field_due_date: Due date
262 262 field_assigned_to: Assignee
263 263 field_priority: Priority
264 264 field_fixed_version: Target version
265 265 field_user: User
266 266 field_principal: Principal
267 267 field_role: Role
268 268 field_homepage: Homepage
269 269 field_is_public: Public
270 270 field_parent: Subproject of
271 271 field_is_in_roadmap: Issues displayed in roadmap
272 272 field_login: Login
273 273 field_mail_notification: Email notifications
274 274 field_admin: Administrator
275 275 field_last_login_on: Last connection
276 276 field_language: Language
277 277 field_effective_date: Date
278 278 field_password: Password
279 279 field_new_password: New password
280 280 field_password_confirmation: Confirmation
281 281 field_version: Version
282 282 field_type: Type
283 283 field_host: Host
284 284 field_port: Port
285 285 field_account: Account
286 286 field_base_dn: Base DN
287 287 field_attr_login: Login attribute
288 288 field_attr_firstname: Firstname attribute
289 289 field_attr_lastname: Lastname attribute
290 290 field_attr_mail: Email attribute
291 291 field_onthefly: On-the-fly user creation
292 292 field_start_date: Start date
293 293 field_done_ratio: "% Done"
294 294 field_auth_source: Authentication mode
295 295 field_hide_mail: Hide my email address
296 296 field_comments: Comment
297 297 field_url: URL
298 298 field_start_page: Start page
299 299 field_subproject: Subproject
300 300 field_hours: Hours
301 301 field_activity: Activity
302 302 field_spent_on: Date
303 303 field_identifier: Identifier
304 304 field_is_filter: Used as a filter
305 305 field_issue_to: Related issue
306 306 field_delay: Delay
307 307 field_assignable: Issues can be assigned to this role
308 308 field_redirect_existing_links: Redirect existing links
309 309 field_estimated_hours: Estimated time
310 310 field_column_names: Columns
311 311 field_time_entries: Log time
312 312 field_time_zone: Time zone
313 313 field_searchable: Searchable
314 314 field_default_value: Default value
315 315 field_comments_sorting: Display comments
316 316 field_parent_title: Parent page
317 317 field_editable: Editable
318 318 field_watcher: Watcher
319 319 field_identity_url: OpenID URL
320 320 field_content: Content
321 321 field_group_by: Group results by
322 322 field_sharing: Sharing
323 323 field_parent_issue: Parent task
324 324 field_member_of_group: "Assignee's group"
325 325 field_assigned_to_role: "Assignee's role"
326 326 field_text: Text field
327 327 field_visible: Visible
328 328 field_warn_on_leaving_unsaved: "Warn me when leaving a page with unsaved text"
329 329 field_issues_visibility: Issues visibility
330 330 field_is_private: Private
331 331 field_commit_logs_encoding: Commit messages encoding
332 332 field_scm_path_encoding: Path encoding
333 333 field_path_to_repository: Path to repository
334 334 field_root_directory: Root directory
335 335 field_cvsroot: CVSROOT
336 336 field_cvs_module: Module
337 337 field_repository_is_default: Main repository
338 338 field_multiple: Multiple values
339 339 field_auth_source_ldap_filter: LDAP filter
340 340 field_core_fields: Standard fields
341 341 field_timeout: "Timeout (in seconds)"
342 342 field_board_parent: Parent forum
343 343 field_private_notes: Private notes
344 344 field_inherit_members: Inherit members
345 345 field_generate_password: Generate password
346 346 field_must_change_passwd: Must change password at next logon
347 347 field_default_status: Default status
348 348 field_users_visibility: Users visibility
349 349 field_time_entries_visibility: Time logs visibility
350 350 field_total_estimated_hours: Total estimated time
351 field_default_version: Default version
351 352
352 353 setting_app_title: Application title
353 354 setting_app_subtitle: Application subtitle
354 355 setting_welcome_text: Welcome text
355 356 setting_default_language: Default language
356 357 setting_login_required: Authentication required
357 358 setting_self_registration: Self-registration
358 359 setting_attachment_max_size: Maximum attachment size
359 360 setting_issues_export_limit: Issues export limit
360 361 setting_mail_from: Emission email address
361 362 setting_bcc_recipients: Blind carbon copy recipients (bcc)
362 363 setting_plain_text_mail: Plain text mail (no HTML)
363 364 setting_host_name: Host name and path
364 365 setting_text_formatting: Text formatting
365 366 setting_wiki_compression: Wiki history compression
366 367 setting_feeds_limit: Maximum number of items in Atom feeds
367 368 setting_default_projects_public: New projects are public by default
368 369 setting_autofetch_changesets: Fetch commits automatically
369 370 setting_sys_api_enabled: Enable WS for repository management
370 371 setting_commit_ref_keywords: Referencing keywords
371 372 setting_commit_fix_keywords: Fixing keywords
372 373 setting_autologin: Autologin
373 374 setting_date_format: Date format
374 375 setting_time_format: Time format
375 376 setting_cross_project_issue_relations: Allow cross-project issue relations
376 377 setting_cross_project_subtasks: Allow cross-project subtasks
377 378 setting_issue_list_default_columns: Default columns displayed on the issue list
378 379 setting_repositories_encodings: Attachments and repositories encodings
379 380 setting_emails_header: Email header
380 381 setting_emails_footer: Email footer
381 382 setting_protocol: Protocol
382 383 setting_per_page_options: Objects per page options
383 384 setting_user_format: Users display format
384 385 setting_activity_days_default: Days displayed on project activity
385 386 setting_display_subprojects_issues: Display subprojects issues on main projects by default
386 387 setting_enabled_scm: Enabled SCM
387 388 setting_mail_handler_body_delimiters: "Truncate emails after one of these lines"
388 389 setting_mail_handler_api_enabled: Enable WS for incoming emails
389 390 setting_mail_handler_api_key: API key
390 391 setting_sequential_project_identifiers: Generate sequential project identifiers
391 392 setting_gravatar_enabled: Use Gravatar user icons
392 393 setting_gravatar_default: Default Gravatar image
393 394 setting_diff_max_lines_displayed: Maximum number of diff lines displayed
394 395 setting_file_max_size_displayed: Maximum size of text files displayed inline
395 396 setting_repository_log_display_limit: Maximum number of revisions displayed on file log
396 397 setting_openid: Allow OpenID login and registration
397 398 setting_password_max_age: Require password change after
398 399 setting_password_min_length: Minimum password length
399 400 setting_new_project_user_role_id: Role given to a non-admin user who creates a project
400 401 setting_default_projects_modules: Default enabled modules for new projects
401 402 setting_issue_done_ratio: Calculate the issue done ratio with
402 403 setting_issue_done_ratio_issue_field: Use the issue field
403 404 setting_issue_done_ratio_issue_status: Use the issue status
404 405 setting_start_of_week: Start calendars on
405 406 setting_rest_api_enabled: Enable REST web service
406 407 setting_cache_formatted_text: Cache formatted text
407 408 setting_default_notification_option: Default notification option
408 409 setting_commit_logtime_enabled: Enable time logging
409 410 setting_commit_logtime_activity_id: Activity for logged time
410 411 setting_gantt_items_limit: Maximum number of items displayed on the gantt chart
411 412 setting_issue_group_assignment: Allow issue assignment to groups
412 413 setting_default_issue_start_date_to_creation_date: Use current date as start date for new issues
413 414 setting_commit_cross_project_ref: Allow issues of all the other projects to be referenced and fixed
414 415 setting_unsubscribe: Allow users to delete their own account
415 416 setting_session_lifetime: Session maximum lifetime
416 417 setting_session_timeout: Session inactivity timeout
417 418 setting_thumbnails_enabled: Display attachment thumbnails
418 419 setting_thumbnails_size: Thumbnails size (in pixels)
419 420 setting_non_working_week_days: Non-working days
420 421 setting_jsonp_enabled: Enable JSONP support
421 422 setting_default_projects_tracker_ids: Default trackers for new projects
422 423 setting_mail_handler_excluded_filenames: Exclude attachments by name
423 424 setting_force_default_language_for_anonymous: Force default language for anonymous users
424 425 setting_force_default_language_for_loggedin: Force default language for logged-in users
425 426 setting_link_copied_issue: Link issues on copy
426 427 setting_max_additional_emails: Maximum number of additional email addresses
427 428 setting_search_results_per_page: Search results per page
428 429
429 430 permission_add_project: Create project
430 431 permission_add_subprojects: Create subprojects
431 432 permission_edit_project: Edit project
432 433 permission_close_project: Close / reopen the project
433 434 permission_select_project_modules: Select project modules
434 435 permission_manage_members: Manage members
435 436 permission_manage_project_activities: Manage project activities
436 437 permission_manage_versions: Manage versions
437 438 permission_manage_categories: Manage issue categories
438 439 permission_view_issues: View Issues
439 440 permission_add_issues: Add issues
440 441 permission_edit_issues: Edit issues
441 442 permission_copy_issues: Copy issues
442 443 permission_manage_issue_relations: Manage issue relations
443 444 permission_set_issues_private: Set issues public or private
444 445 permission_set_own_issues_private: Set own issues public or private
445 446 permission_add_issue_notes: Add notes
446 447 permission_edit_issue_notes: Edit notes
447 448 permission_edit_own_issue_notes: Edit own notes
448 449 permission_view_private_notes: View private notes
449 450 permission_set_notes_private: Set notes as private
450 451 permission_move_issues: Move issues
451 452 permission_delete_issues: Delete issues
452 453 permission_manage_public_queries: Manage public queries
453 454 permission_save_queries: Save queries
454 455 permission_view_gantt: View gantt chart
455 456 permission_view_calendar: View calendar
456 457 permission_view_issue_watchers: View watchers list
457 458 permission_add_issue_watchers: Add watchers
458 459 permission_delete_issue_watchers: Delete watchers
459 460 permission_log_time: Log spent time
460 461 permission_view_time_entries: View spent time
461 462 permission_edit_time_entries: Edit time logs
462 463 permission_edit_own_time_entries: Edit own time logs
463 464 permission_manage_news: Manage news
464 465 permission_comment_news: Comment news
465 466 permission_view_documents: View documents
466 467 permission_add_documents: Add documents
467 468 permission_edit_documents: Edit documents
468 469 permission_delete_documents: Delete documents
469 470 permission_manage_files: Manage files
470 471 permission_view_files: View files
471 472 permission_manage_wiki: Manage wiki
472 473 permission_rename_wiki_pages: Rename wiki pages
473 474 permission_delete_wiki_pages: Delete wiki pages
474 475 permission_view_wiki_pages: View wiki
475 476 permission_view_wiki_edits: View wiki history
476 477 permission_edit_wiki_pages: Edit wiki pages
477 478 permission_delete_wiki_pages_attachments: Delete attachments
478 479 permission_protect_wiki_pages: Protect wiki pages
479 480 permission_manage_repository: Manage repository
480 481 permission_browse_repository: Browse repository
481 482 permission_view_changesets: View changesets
482 483 permission_commit_access: Commit access
483 484 permission_manage_boards: Manage forums
484 485 permission_view_messages: View messages
485 486 permission_add_messages: Post messages
486 487 permission_edit_messages: Edit messages
487 488 permission_edit_own_messages: Edit own messages
488 489 permission_delete_messages: Delete messages
489 490 permission_delete_own_messages: Delete own messages
490 491 permission_export_wiki_pages: Export wiki pages
491 492 permission_manage_subtasks: Manage subtasks
492 493 permission_manage_related_issues: Manage related issues
493 494 permission_import_issues: Import issues
494 495
495 496 project_module_issue_tracking: Issue tracking
496 497 project_module_time_tracking: Time tracking
497 498 project_module_news: News
498 499 project_module_documents: Documents
499 500 project_module_files: Files
500 501 project_module_wiki: Wiki
501 502 project_module_repository: Repository
502 503 project_module_boards: Forums
503 504 project_module_calendar: Calendar
504 505 project_module_gantt: Gantt
505 506
506 507 label_user: User
507 508 label_user_plural: Users
508 509 label_user_new: New user
509 510 label_user_anonymous: Anonymous
510 511 label_project: Project
511 512 label_project_new: New project
512 513 label_project_plural: Projects
513 514 label_x_projects:
514 515 zero: no projects
515 516 one: 1 project
516 517 other: "%{count} projects"
517 518 label_project_all: All Projects
518 519 label_project_latest: Latest projects
519 520 label_issue: Issue
520 521 label_issue_new: New issue
521 522 label_issue_plural: Issues
522 523 label_issue_view_all: View all issues
523 524 label_issues_by: "Issues by %{value}"
524 525 label_issue_added: Issue added
525 526 label_issue_updated: Issue updated
526 527 label_issue_note_added: Note added
527 528 label_issue_status_updated: Status updated
528 529 label_issue_assigned_to_updated: Assignee updated
529 530 label_issue_priority_updated: Priority updated
530 531 label_document: Document
531 532 label_document_new: New document
532 533 label_document_plural: Documents
533 534 label_document_added: Document added
534 535 label_role: Role
535 536 label_role_plural: Roles
536 537 label_role_new: New role
537 538 label_role_and_permissions: Roles and permissions
538 539 label_role_anonymous: Anonymous
539 540 label_role_non_member: Non member
540 541 label_member: Member
541 542 label_member_new: New member
542 543 label_member_plural: Members
543 544 label_tracker: Tracker
544 545 label_tracker_plural: Trackers
545 546 label_tracker_new: New tracker
546 547 label_workflow: Workflow
547 548 label_issue_status: Issue status
548 549 label_issue_status_plural: Issue statuses
549 550 label_issue_status_new: New status
550 551 label_issue_category: Issue category
551 552 label_issue_category_plural: Issue categories
552 553 label_issue_category_new: New category
553 554 label_custom_field: Custom field
554 555 label_custom_field_plural: Custom fields
555 556 label_custom_field_new: New custom field
556 557 label_enumerations: Enumerations
557 558 label_enumeration_new: New value
558 559 label_information: Information
559 560 label_information_plural: Information
560 561 label_please_login: Please log in
561 562 label_register: Register
562 563 label_login_with_open_id_option: or login with OpenID
563 564 label_password_lost: Lost password
564 565 label_password_required: Confirm your password to continue
565 566 label_home: Home
566 567 label_my_page: My page
567 568 label_my_account: My account
568 569 label_my_projects: My projects
569 570 label_my_page_block: My page block
570 571 label_administration: Administration
571 572 label_login: Sign in
572 573 label_logout: Sign out
573 574 label_help: Help
574 575 label_reported_issues: Reported issues
575 576 label_assigned_issues: Assigned issues
576 577 label_assigned_to_me_issues: Issues assigned to me
577 578 label_last_login: Last connection
578 579 label_registered_on: Registered on
579 580 label_activity: Activity
580 581 label_overall_activity: Overall activity
581 582 label_user_activity: "%{value}'s activity"
582 583 label_new: New
583 584 label_logged_as: Logged in as
584 585 label_environment: Environment
585 586 label_authentication: Authentication
586 587 label_auth_source: Authentication mode
587 588 label_auth_source_new: New authentication mode
588 589 label_auth_source_plural: Authentication modes
589 590 label_subproject_plural: Subprojects
590 591 label_subproject_new: New subproject
591 592 label_and_its_subprojects: "%{value} and its subprojects"
592 593 label_min_max_length: Min - Max length
593 594 label_list: List
594 595 label_date: Date
595 596 label_integer: Integer
596 597 label_float: Float
597 598 label_boolean: Boolean
598 599 label_string: Text
599 600 label_text: Long text
600 601 label_attribute: Attribute
601 602 label_attribute_plural: Attributes
602 603 label_no_data: No data to display
603 604 label_change_status: Change status
604 605 label_history: History
605 606 label_attachment: File
606 607 label_attachment_new: New file
607 608 label_attachment_delete: Delete file
608 609 label_attachment_plural: Files
609 610 label_file_added: File added
610 611 label_report: Report
611 612 label_report_plural: Reports
612 613 label_news: News
613 614 label_news_new: Add news
614 615 label_news_plural: News
615 616 label_news_latest: Latest news
616 617 label_news_view_all: View all news
617 618 label_news_added: News added
618 619 label_news_comment_added: Comment added to a news
619 620 label_settings: Settings
620 621 label_overview: Overview
621 622 label_version: Version
622 623 label_version_new: New version
623 624 label_version_plural: Versions
624 625 label_close_versions: Close completed versions
625 626 label_confirmation: Confirmation
626 627 label_export_to: 'Also available in:'
627 628 label_read: Read...
628 629 label_public_projects: Public projects
629 630 label_open_issues: open
630 631 label_open_issues_plural: open
631 632 label_closed_issues: closed
632 633 label_closed_issues_plural: closed
633 634 label_x_open_issues_abbr:
634 635 zero: 0 open
635 636 one: 1 open
636 637 other: "%{count} open"
637 638 label_x_closed_issues_abbr:
638 639 zero: 0 closed
639 640 one: 1 closed
640 641 other: "%{count} closed"
641 642 label_x_issues:
642 643 zero: 0 issues
643 644 one: 1 issue
644 645 other: "%{count} issues"
645 646 label_total: Total
646 647 label_total_plural: Totals
647 648 label_total_time: Total time
648 649 label_permissions: Permissions
649 650 label_current_status: Current status
650 651 label_new_statuses_allowed: New statuses allowed
651 652 label_all: all
652 653 label_any: any
653 654 label_none: none
654 655 label_nobody: nobody
655 656 label_next: Next
656 657 label_previous: Previous
657 658 label_used_by: Used by
658 659 label_details: Details
659 660 label_add_note: Add a note
660 661 label_calendar: Calendar
661 662 label_months_from: months from
662 663 label_gantt: Gantt
663 664 label_internal: Internal
664 665 label_last_changes: "last %{count} changes"
665 666 label_change_view_all: View all changes
666 667 label_personalize_page: Personalize this page
667 668 label_comment: Comment
668 669 label_comment_plural: Comments
669 670 label_x_comments:
670 671 zero: no comments
671 672 one: 1 comment
672 673 other: "%{count} comments"
673 674 label_comment_add: Add a comment
674 675 label_comment_added: Comment added
675 676 label_comment_delete: Delete comments
676 677 label_query: Custom query
677 678 label_query_plural: Custom queries
678 679 label_query_new: New query
679 680 label_my_queries: My custom queries
680 681 label_filter_add: Add filter
681 682 label_filter_plural: Filters
682 683 label_equals: is
683 684 label_not_equals: is not
684 685 label_in_less_than: in less than
685 686 label_in_more_than: in more than
686 687 label_in_the_next_days: in the next
687 688 label_in_the_past_days: in the past
688 689 label_greater_or_equal: '>='
689 690 label_less_or_equal: '<='
690 691 label_between: between
691 692 label_in: in
692 693 label_today: today
693 694 label_all_time: all time
694 695 label_yesterday: yesterday
695 696 label_this_week: this week
696 697 label_last_week: last week
697 698 label_last_n_weeks: "last %{count} weeks"
698 699 label_last_n_days: "last %{count} days"
699 700 label_this_month: this month
700 701 label_last_month: last month
701 702 label_this_year: this year
702 703 label_date_range: Date range
703 704 label_less_than_ago: less than days ago
704 705 label_more_than_ago: more than days ago
705 706 label_ago: days ago
706 707 label_contains: contains
707 708 label_not_contains: doesn't contain
708 709 label_any_issues_in_project: any issues in project
709 710 label_any_issues_not_in_project: any issues not in project
710 711 label_no_issues_in_project: no issues in project
711 712 label_day_plural: days
712 713 label_repository: Repository
713 714 label_repository_new: New repository
714 715 label_repository_plural: Repositories
715 716 label_browse: Browse
716 717 label_branch: Branch
717 718 label_tag: Tag
718 719 label_revision: Revision
719 720 label_revision_plural: Revisions
720 721 label_revision_id: "Revision %{value}"
721 722 label_associated_revisions: Associated revisions
722 723 label_added: added
723 724 label_modified: modified
724 725 label_copied: copied
725 726 label_renamed: renamed
726 727 label_deleted: deleted
727 728 label_latest_revision: Latest revision
728 729 label_latest_revision_plural: Latest revisions
729 730 label_view_revisions: View revisions
730 731 label_view_all_revisions: View all revisions
731 732 label_max_size: Maximum size
732 733 label_sort_highest: Move to top
733 734 label_sort_higher: Move up
734 735 label_sort_lower: Move down
735 736 label_sort_lowest: Move to bottom
736 737 label_roadmap: Roadmap
737 738 label_roadmap_due_in: "Due in %{value}"
738 739 label_roadmap_overdue: "%{value} late"
739 740 label_roadmap_no_issues: No issues for this version
740 741 label_search: Search
741 742 label_result_plural: Results
742 743 label_all_words: All words
743 744 label_wiki: Wiki
744 745 label_wiki_edit: Wiki edit
745 746 label_wiki_edit_plural: Wiki edits
746 747 label_wiki_page: Wiki page
747 748 label_wiki_page_plural: Wiki pages
748 749 label_index_by_title: Index by title
749 750 label_index_by_date: Index by date
750 751 label_current_version: Current version
751 752 label_preview: Preview
752 753 label_feed_plural: Feeds
753 754 label_changes_details: Details of all changes
754 755 label_issue_tracking: Issue tracking
755 756 label_spent_time: Spent time
756 757 label_total_spent_time: Total spent time
757 758 label_overall_spent_time: Overall spent time
758 759 label_f_hour: "%{value} hour"
759 760 label_f_hour_plural: "%{value} hours"
760 761 label_f_hour_short: "%{value} h"
761 762 label_time_tracking: Time tracking
762 763 label_change_plural: Changes
763 764 label_statistics: Statistics
764 765 label_commits_per_month: Commits per month
765 766 label_commits_per_author: Commits per author
766 767 label_diff: diff
767 768 label_view_diff: View differences
768 769 label_diff_inline: inline
769 770 label_diff_side_by_side: side by side
770 771 label_options: Options
771 772 label_copy_workflow_from: Copy workflow from
772 773 label_permissions_report: Permissions report
773 774 label_watched_issues: Watched issues
774 775 label_related_issues: Related issues
775 776 label_applied_status: Applied status
776 777 label_loading: Loading...
777 778 label_relation_new: New relation
778 779 label_relation_delete: Delete relation
779 780 label_relates_to: Related to
780 781 label_duplicates: Duplicates
781 782 label_duplicated_by: Duplicated by
782 783 label_blocks: Blocks
783 784 label_blocked_by: Blocked by
784 785 label_precedes: Precedes
785 786 label_follows: Follows
786 787 label_copied_to: Copied to
787 788 label_copied_from: Copied from
788 789 label_end_to_start: end to start
789 790 label_end_to_end: end to end
790 791 label_start_to_start: start to start
791 792 label_start_to_end: start to end
792 793 label_stay_logged_in: Stay logged in
793 794 label_disabled: disabled
794 795 label_show_completed_versions: Show completed versions
795 796 label_me: me
796 797 label_board: Forum
797 798 label_board_new: New forum
798 799 label_board_plural: Forums
799 800 label_board_locked: Locked
800 801 label_board_sticky: Sticky
801 802 label_topic_plural: Topics
802 803 label_message_plural: Messages
803 804 label_message_last: Last message
804 805 label_message_new: New message
805 806 label_message_posted: Message added
806 807 label_reply_plural: Replies
807 808 label_send_information: Send account information to the user
808 809 label_year: Year
809 810 label_month: Month
810 811 label_week: Week
811 812 label_date_from: From
812 813 label_date_to: To
813 814 label_language_based: Based on user's language
814 815 label_sort_by: "Sort by %{value}"
815 816 label_send_test_email: Send a test email
816 817 label_feeds_access_key: Atom access key
817 818 label_missing_feeds_access_key: Missing a Atom access key
818 819 label_feeds_access_key_created_on: "Atom access key created %{value} ago"
819 820 label_module_plural: Modules
820 821 label_added_time_by: "Added by %{author} %{age} ago"
821 822 label_updated_time_by: "Updated by %{author} %{age} ago"
822 823 label_updated_time: "Updated %{value} ago"
823 824 label_jump_to_a_project: Jump to a project...
824 825 label_file_plural: Files
825 826 label_changeset_plural: Changesets
826 827 label_default_columns: Default columns
827 828 label_no_change_option: (No change)
828 829 label_bulk_edit_selected_issues: Bulk edit selected issues
829 830 label_bulk_edit_selected_time_entries: Bulk edit selected time entries
830 831 label_theme: Theme
831 832 label_default: Default
832 833 label_search_titles_only: Search titles only
833 834 label_user_mail_option_all: "For any event on all my projects"
834 835 label_user_mail_option_selected: "For any event on the selected projects only..."
835 836 label_user_mail_option_none: "No events"
836 837 label_user_mail_option_only_my_events: "Only for things I watch or I'm involved in"
837 838 label_user_mail_option_only_assigned: "Only for things I am assigned to"
838 839 label_user_mail_option_only_owner: "Only for things I am the owner of"
839 840 label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
840 841 label_registration_activation_by_email: account activation by email
841 842 label_registration_manual_activation: manual account activation
842 843 label_registration_automatic_activation: automatic account activation
843 844 label_display_per_page: "Per page: %{value}"
844 845 label_age: Age
845 846 label_change_properties: Change properties
846 847 label_general: General
847 848 label_more: More
848 849 label_scm: SCM
849 850 label_plugins: Plugins
850 851 label_ldap_authentication: LDAP authentication
851 852 label_downloads_abbr: D/L
852 853 label_optional_description: Optional description
853 854 label_add_another_file: Add another file
854 855 label_preferences: Preferences
855 856 label_chronological_order: In chronological order
856 857 label_reverse_chronological_order: In reverse chronological order
857 858 label_planning: Planning
858 859 label_incoming_emails: Incoming emails
859 860 label_generate_key: Generate a key
860 861 label_issue_watchers: Watchers
861 862 label_example: Example
862 863 label_display: Display
863 864 label_sort: Sort
864 865 label_ascending: Ascending
865 866 label_descending: Descending
866 867 label_date_from_to: From %{start} to %{end}
867 868 label_wiki_content_added: Wiki page added
868 869 label_wiki_content_updated: Wiki page updated
869 870 label_group: Group
870 871 label_group_plural: Groups
871 872 label_group_new: New group
872 873 label_group_anonymous: Anonymous users
873 874 label_group_non_member: Non member users
874 875 label_time_entry_plural: Spent time
875 876 label_version_sharing_none: Not shared
876 877 label_version_sharing_descendants: With subprojects
877 878 label_version_sharing_hierarchy: With project hierarchy
878 879 label_version_sharing_tree: With project tree
879 880 label_version_sharing_system: With all projects
880 881 label_update_issue_done_ratios: Update issue done ratios
881 882 label_copy_source: Source
882 883 label_copy_target: Target
883 884 label_copy_same_as_target: Same as target
884 885 label_display_used_statuses_only: Only display statuses that are used by this tracker
885 886 label_api_access_key: API access key
886 887 label_missing_api_access_key: Missing an API access key
887 888 label_api_access_key_created_on: "API access key created %{value} ago"
888 889 label_profile: Profile
889 890 label_subtask_plural: Subtasks
890 891 label_project_copy_notifications: Send email notifications during the project copy
891 892 label_principal_search: "Search for user or group:"
892 893 label_user_search: "Search for user:"
893 894 label_additional_workflow_transitions_for_author: Additional transitions allowed when the user is the author
894 895 label_additional_workflow_transitions_for_assignee: Additional transitions allowed when the user is the assignee
895 896 label_issues_visibility_all: All issues
896 897 label_issues_visibility_public: All non private issues
897 898 label_issues_visibility_own: Issues created by or assigned to the user
898 899 label_git_report_last_commit: Report last commit for files and directories
899 900 label_parent_revision: Parent
900 901 label_child_revision: Child
901 902 label_export_options: "%{export_format} export options"
902 903 label_copy_attachments: Copy attachments
903 904 label_copy_subtasks: Copy subtasks
904 905 label_item_position: "%{position} of %{count}"
905 906 label_completed_versions: Completed versions
906 907 label_search_for_watchers: Search for watchers to add
907 908 label_session_expiration: Session expiration
908 909 label_show_closed_projects: View closed projects
909 910 label_status_transitions: Status transitions
910 911 label_fields_permissions: Fields permissions
911 912 label_readonly: Read-only
912 913 label_required: Required
913 914 label_hidden: Hidden
914 915 label_attribute_of_project: "Project's %{name}"
915 916 label_attribute_of_issue: "Issue's %{name}"
916 917 label_attribute_of_author: "Author's %{name}"
917 918 label_attribute_of_assigned_to: "Assignee's %{name}"
918 919 label_attribute_of_user: "User's %{name}"
919 920 label_attribute_of_fixed_version: "Target version's %{name}"
920 921 label_cross_project_descendants: With subprojects
921 922 label_cross_project_tree: With project tree
922 923 label_cross_project_hierarchy: With project hierarchy
923 924 label_cross_project_system: With all projects
924 925 label_gantt_progress_line: Progress line
925 926 label_visibility_private: to me only
926 927 label_visibility_roles: to these roles only
927 928 label_visibility_public: to any users
928 929 label_link: Link
929 930 label_only: only
930 931 label_drop_down_list: drop-down list
931 932 label_checkboxes: checkboxes
932 933 label_radio_buttons: radio buttons
933 934 label_link_values_to: Link values to URL
934 935 label_custom_field_select_type: Select the type of object to which the custom field is to be attached
935 936 label_check_for_updates: Check for updates
936 937 label_latest_compatible_version: Latest compatible version
937 938 label_unknown_plugin: Unknown plugin
938 939 label_add_projects: Add projects
939 940 label_users_visibility_all: All active users
940 941 label_users_visibility_members_of_visible_projects: Members of visible projects
941 942 label_edit_attachments: Edit attached files
942 943 label_link_copied_issue: Link copied issue
943 944 label_ask: Ask
944 945 label_search_attachments_yes: Search attachment filenames and descriptions
945 946 label_search_attachments_no: Do not search attachments
946 947 label_search_attachments_only: Search attachments only
947 948 label_search_open_issues_only: Open issues only
948 949 label_email_address_plural: Emails
949 950 label_email_address_add: Add email address
950 951 label_enable_notifications: Enable notifications
951 952 label_disable_notifications: Disable notifications
952 953 label_blank_value: blank
953 954 label_parent_task_attributes: Parent tasks attributes
954 955 label_parent_task_attributes_derived: Calculated from subtasks
955 956 label_parent_task_attributes_independent: Independent of subtasks
956 957 label_time_entries_visibility_all: All time entries
957 958 label_time_entries_visibility_own: Time entries created by the user
958 959 label_member_management: Member management
959 960 label_member_management_all_roles: All roles
960 961 label_member_management_selected_roles_only: Only these roles
961 962 label_import_issues: Import issues
962 963 label_select_file_to_import: Select the file to import
963 964 label_fields_separator: Field separator
964 965 label_fields_wrapper: Field wrapper
965 966 label_encoding: Encoding
966 967 label_comma_char: Comma
967 968 label_semi_colon_char: Semi colon
968 969 label_quote_char: Quote
969 970 label_double_quote_char: Double quote
970 971 label_fields_mapping: Fields mapping
971 972 label_file_content_preview: File content preview
972 973 label_create_missing_values: Create missing values
973 974 label_api: API
974 975 label_field_format_enumeration: Key/value list
975 976
976 977 button_login: Login
977 978 button_submit: Submit
978 979 button_save: Save
979 980 button_check_all: Check all
980 981 button_uncheck_all: Uncheck all
981 982 button_collapse_all: Collapse all
982 983 button_expand_all: Expand all
983 984 button_delete: Delete
984 985 button_create: Create
985 986 button_create_and_continue: Create and continue
986 987 button_test: Test
987 988 button_edit: Edit
988 989 button_edit_associated_wikipage: "Edit associated Wiki page: %{page_title}"
989 990 button_add: Add
990 991 button_change: Change
991 992 button_apply: Apply
992 993 button_clear: Clear
993 994 button_lock: Lock
994 995 button_unlock: Unlock
995 996 button_download: Download
996 997 button_list: List
997 998 button_view: View
998 999 button_move: Move
999 1000 button_move_and_follow: Move and follow
1000 1001 button_back: Back
1001 1002 button_cancel: Cancel
1002 1003 button_activate: Activate
1003 1004 button_sort: Sort
1004 1005 button_log_time: Log time
1005 1006 button_rollback: Rollback to this version
1006 1007 button_watch: Watch
1007 1008 button_unwatch: Unwatch
1008 1009 button_reply: Reply
1009 1010 button_archive: Archive
1010 1011 button_unarchive: Unarchive
1011 1012 button_reset: Reset
1012 1013 button_rename: Rename
1013 1014 button_change_password: Change password
1014 1015 button_copy: Copy
1015 1016 button_copy_and_follow: Copy and follow
1016 1017 button_annotate: Annotate
1017 1018 button_update: Update
1018 1019 button_configure: Configure
1019 1020 button_quote: Quote
1020 1021 button_duplicate: Duplicate
1021 1022 button_show: Show
1022 1023 button_hide: Hide
1023 1024 button_edit_section: Edit this section
1024 1025 button_export: Export
1025 1026 button_delete_my_account: Delete my account
1026 1027 button_close: Close
1027 1028 button_reopen: Reopen
1028 1029 button_import: Import
1029 1030
1030 1031 status_active: active
1031 1032 status_registered: registered
1032 1033 status_locked: locked
1033 1034
1034 1035 project_status_active: active
1035 1036 project_status_closed: closed
1036 1037 project_status_archived: archived
1037 1038
1038 1039 version_status_open: open
1039 1040 version_status_locked: locked
1040 1041 version_status_closed: closed
1041 1042
1042 1043 field_active: Active
1043 1044
1044 1045 text_select_mail_notifications: Select actions for which email notifications should be sent.
1045 1046 text_regexp_info: eg. ^[A-Z0-9]+$
1046 1047 text_min_max_length_info: 0 means no restriction
1047 1048 text_project_destroy_confirmation: Are you sure you want to delete this project and related data?
1048 1049 text_subprojects_destroy_warning: "Its subproject(s): %{value} will be also deleted."
1049 1050 text_workflow_edit: Select a role and a tracker to edit the workflow
1050 1051 text_are_you_sure: Are you sure?
1051 1052 text_journal_changed: "%{label} changed from %{old} to %{new}"
1052 1053 text_journal_changed_no_detail: "%{label} updated"
1053 1054 text_journal_set_to: "%{label} set to %{value}"
1054 1055 text_journal_deleted: "%{label} deleted (%{old})"
1055 1056 text_journal_added: "%{label} %{value} added"
1056 1057 text_tip_issue_begin_day: issue beginning this day
1057 1058 text_tip_issue_end_day: issue ending this day
1058 1059 text_tip_issue_begin_end_day: issue beginning and ending this day
1059 1060 text_project_identifier_info: 'Only lower case letters (a-z), numbers, dashes and underscores are allowed, must start with a lower case letter.<br />Once saved, the identifier cannot be changed.'
1060 1061 text_caracters_maximum: "%{count} characters maximum."
1061 1062 text_caracters_minimum: "Must be at least %{count} characters long."
1062 1063 text_length_between: "Length between %{min} and %{max} characters."
1063 1064 text_tracker_no_workflow: No workflow defined for this tracker
1064 1065 text_unallowed_characters: Unallowed characters
1065 1066 text_comma_separated: Multiple values allowed (comma separated).
1066 1067 text_line_separated: Multiple values allowed (one line for each value).
1067 1068 text_issues_ref_in_commit_messages: Referencing and fixing issues in commit messages
1068 1069 text_issue_added: "Issue %{id} has been reported by %{author}."
1069 1070 text_issue_updated: "Issue %{id} has been updated by %{author}."
1070 1071 text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content?
1071 1072 text_issue_category_destroy_question: "Some issues (%{count}) are assigned to this category. What do you want to do?"
1072 1073 text_issue_category_destroy_assignments: Remove category assignments
1073 1074 text_issue_category_reassign_to: Reassign issues to this category
1074 1075 text_user_mail_option: "For unselected projects, you will only receive notifications about things you watch or you're involved in (eg. issues you're the author or assignee)."
1075 1076 text_no_configuration_data: "Roles, trackers, issue statuses and workflow have not been configured yet.\nIt is highly recommended to load the default configuration. You will be able to modify it once loaded."
1076 1077 text_load_default_configuration: Load the default configuration
1077 1078 text_status_changed_by_changeset: "Applied in changeset %{value}."
1078 1079 text_time_logged_by_changeset: "Applied in changeset %{value}."
1079 1080 text_issues_destroy_confirmation: 'Are you sure you want to delete the selected issue(s)?'
1080 1081 text_issues_destroy_descendants_confirmation: "This will also delete %{count} subtask(s)."
1081 1082 text_time_entries_destroy_confirmation: 'Are you sure you want to delete the selected time entr(y/ies)?'
1082 1083 text_select_project_modules: 'Select modules to enable for this project:'
1083 1084 text_default_administrator_account_changed: Default administrator account changed
1084 1085 text_file_repository_writable: Attachments directory writable
1085 1086 text_plugin_assets_writable: Plugin assets directory writable
1086 1087 text_rmagick_available: RMagick available (optional)
1087 1088 text_convert_available: ImageMagick convert available (optional)
1088 1089 text_destroy_time_entries_question: "%{hours} hours were reported on the issues you are about to delete. What do you want to do?"
1089 1090 text_destroy_time_entries: Delete reported hours
1090 1091 text_assign_time_entries_to_project: Assign reported hours to the project
1091 1092 text_reassign_time_entries: 'Reassign reported hours to this issue:'
1092 1093 text_user_wrote: "%{value} wrote:"
1093 1094 text_enumeration_destroy_question: "%{count} objects are assigned to the value β€œ%{name}”."
1094 1095 text_enumeration_category_reassign_to: 'Reassign them to this value:'
1095 1096 text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/configuration.yml and restart the application to enable them."
1096 1097 text_repository_usernames_mapping: "Select or update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
1097 1098 text_diff_truncated: '... This diff was truncated because it exceeds the maximum size that can be displayed.'
1098 1099 text_custom_field_possible_values_info: 'One line for each value'
1099 1100 text_wiki_page_destroy_question: "This page has %{descendants} child page(s) and descendant(s). What do you want to do?"
1100 1101 text_wiki_page_nullify_children: "Keep child pages as root pages"
1101 1102 text_wiki_page_destroy_children: "Delete child pages and all their descendants"
1102 1103 text_wiki_page_reassign_children: "Reassign child pages to this parent page"
1103 1104 text_own_membership_delete_confirmation: "You are about to remove some or all of your permissions and may no longer be able to edit this project after that.\nAre you sure you want to continue?"
1104 1105 text_zoom_in: Zoom in
1105 1106 text_zoom_out: Zoom out
1106 1107 text_warn_on_leaving_unsaved: "The current page contains unsaved text that will be lost if you leave this page."
1107 1108 text_scm_path_encoding_note: "Default: UTF-8"
1108 1109 text_subversion_repository_note: "Examples: file:///, http://, https://, svn://, svn+[tunnelscheme]://"
1109 1110 text_git_repository_note: Repository is bare and local (e.g. /gitrepo, c:\gitrepo)
1110 1111 text_mercurial_repository_note: Local repository (e.g. /hgrepo, c:\hgrepo)
1111 1112 text_scm_command: Command
1112 1113 text_scm_command_version: Version
1113 1114 text_scm_config: You can configure your SCM commands in config/configuration.yml. Please restart the application after editing it.
1114 1115 text_scm_command_not_available: SCM command is not available. Please check settings on the administration panel.
1115 1116 text_issue_conflict_resolution_overwrite: "Apply my changes anyway (previous notes will be kept but some changes may be overwritten)"
1116 1117 text_issue_conflict_resolution_add_notes: "Add my notes and discard my other changes"
1117 1118 text_issue_conflict_resolution_cancel: "Discard all my changes and redisplay %{link}"
1118 1119 text_account_destroy_confirmation: "Are you sure you want to proceed?\nYour account will be permanently deleted, with no way to reactivate it."
1119 1120 text_session_expiration_settings: "Warning: changing these settings may expire the current sessions including yours."
1120 1121 text_project_closed: This project is closed and read-only.
1121 1122 text_turning_multiple_off: "If you disable multiple values, multiple values will be removed in order to preserve only one value per item."
1122 1123
1123 1124 default_role_manager: Manager
1124 1125 default_role_developer: Developer
1125 1126 default_role_reporter: Reporter
1126 1127 default_tracker_bug: Bug
1127 1128 default_tracker_feature: Feature
1128 1129 default_tracker_support: Support
1129 1130 default_issue_status_new: New
1130 1131 default_issue_status_in_progress: In Progress
1131 1132 default_issue_status_resolved: Resolved
1132 1133 default_issue_status_feedback: Feedback
1133 1134 default_issue_status_closed: Closed
1134 1135 default_issue_status_rejected: Rejected
1135 1136 default_doc_category_user: User documentation
1136 1137 default_doc_category_tech: Technical documentation
1137 1138 default_priority_low: Low
1138 1139 default_priority_normal: Normal
1139 1140 default_priority_high: High
1140 1141 default_priority_urgent: Urgent
1141 1142 default_priority_immediate: Immediate
1142 1143 default_activity_design: Design
1143 1144 default_activity_development: Development
1144 1145
1145 1146 enumeration_issue_priorities: Issue priorities
1146 1147 enumeration_doc_categories: Document categories
1147 1148 enumeration_activities: Activities (time tracking)
1148 1149 enumeration_system_activity: System Activity
1149 1150 description_filter: Filter
1150 1151 description_search: Searchfield
1151 1152 description_choose_project: Projects
1152 1153 description_project_scope: Search scope
1153 1154 description_notes: Notes
1154 1155 description_message_content: Message content
1155 1156 description_query_sort_criteria_attribute: Sort attribute
1156 1157 description_query_sort_criteria_direction: Sort direction
1157 1158 description_user_mail_notification: Mail notification settings
1158 1159 description_available_columns: Available Columns
1159 1160 description_selected_columns: Selected Columns
1160 1161 description_all_columns: All Columns
1161 1162 description_issue_category_reassign: Choose issue category
1162 1163 description_wiki_subpages_reassign: Choose new parent page
1163 1164 description_date_range_list: Choose range from list
1164 1165 description_date_range_interval: Choose range by selecting start and end date
1165 1166 description_date_from: Enter start date
1166 1167 description_date_to: Enter end date
1167 1168 text_repository_identifier_info: 'Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.'
@@ -1,1187 +1,1188
1 1 # French translations for Ruby on Rails
2 2 # by Christian Lescuyer (christian@flyingcoders.com)
3 3 # contributor: Sebastien Grosjean - ZenCocoon.com
4 4 # contributor: Thibaut Cuvelier - Developpez.com
5 5
6 6 fr:
7 7 direction: ltr
8 8 date:
9 9 formats:
10 10 default: "%d/%m/%Y"
11 11 short: "%e %b"
12 12 long: "%e %B %Y"
13 13 long_ordinal: "%e %B %Y"
14 14 only_day: "%e"
15 15
16 16 day_names: [dimanche, lundi, mardi, mercredi, jeudi, vendredi, samedi]
17 17 abbr_day_names: [dim, lun, mar, mer, jeu, ven, sam]
18 18
19 19 # Don't forget the nil at the beginning; there's no such thing as a 0th month
20 20 month_names: [~, janvier, fΓ©vrier, mars, avril, mai, juin, juillet, aoΓ»t, septembre, octobre, novembre, dΓ©cembre]
21 21 abbr_month_names: [~, jan., fΓ©v., mar., avr., mai, juin, juil., aoΓ»t, sept., oct., nov., dΓ©c.]
22 22 # Used in date_select and datime_select.
23 23 order:
24 24 - :day
25 25 - :month
26 26 - :year
27 27
28 28 time:
29 29 formats:
30 30 default: "%d/%m/%Y %H:%M"
31 31 time: "%H:%M"
32 32 short: "%d %b %H:%M"
33 33 long: "%A %d %B %Y %H:%M:%S %Z"
34 34 long_ordinal: "%A %d %B %Y %H:%M:%S %Z"
35 35 only_second: "%S"
36 36 am: 'am'
37 37 pm: 'pm'
38 38
39 39 datetime:
40 40 distance_in_words:
41 41 half_a_minute: "30 secondes"
42 42 less_than_x_seconds:
43 43 zero: "moins d'une seconde"
44 44 one: "moins d'uneΒ seconde"
45 45 other: "moins de %{count}Β secondes"
46 46 x_seconds:
47 47 one: "1Β seconde"
48 48 other: "%{count}Β secondes"
49 49 less_than_x_minutes:
50 50 zero: "moins d'une minute"
51 51 one: "moins d'uneΒ minute"
52 52 other: "moins de %{count}Β minutes"
53 53 x_minutes:
54 54 one: "1Β minute"
55 55 other: "%{count}Β minutes"
56 56 about_x_hours:
57 57 one: "environ une heure"
58 58 other: "environ %{count}Β heures"
59 59 x_hours:
60 60 one: "une heure"
61 61 other: "%{count}Β heures"
62 62 x_days:
63 63 one: "unΒ jour"
64 64 other: "%{count}Β jours"
65 65 about_x_months:
66 66 one: "environ un mois"
67 67 other: "environ %{count}Β mois"
68 68 x_months:
69 69 one: "unΒ mois"
70 70 other: "%{count}Β mois"
71 71 about_x_years:
72 72 one: "environ un an"
73 73 other: "environ %{count}Β ans"
74 74 over_x_years:
75 75 one: "plus d'un an"
76 76 other: "plus de %{count}Β ans"
77 77 almost_x_years:
78 78 one: "presqu'un an"
79 79 other: "presque %{count} ans"
80 80 prompts:
81 81 year: "AnnΓ©e"
82 82 month: "Mois"
83 83 day: "Jour"
84 84 hour: "Heure"
85 85 minute: "Minute"
86 86 second: "Seconde"
87 87
88 88 number:
89 89 format:
90 90 precision: 3
91 91 separator: ','
92 92 delimiter: 'Β '
93 93 currency:
94 94 format:
95 95 unit: '€'
96 96 precision: 2
97 97 format: '%nΒ %u'
98 98 human:
99 99 format:
100 100 precision: 3
101 101 storage_units:
102 102 format: "%n %u"
103 103 units:
104 104 byte:
105 105 one: "octet"
106 106 other: "octets"
107 107 kb: "ko"
108 108 mb: "Mo"
109 109 gb: "Go"
110 110 tb: "To"
111 111
112 112 support:
113 113 array:
114 114 sentence_connector: 'et'
115 115 skip_last_comma: true
116 116 word_connector: ", "
117 117 two_words_connector: " et "
118 118 last_word_connector: " et "
119 119
120 120 activerecord:
121 121 errors:
122 122 template:
123 123 header:
124 124 one: "Impossible d'enregistrer %{model} : une erreur"
125 125 other: "Impossible d'enregistrer %{model} : %{count} erreurs."
126 126 body: "Veuillez vΓ©rifier les champs suivantsΒ :"
127 127 messages:
128 128 inclusion: "n'est pas inclus(e) dans la liste"
129 129 exclusion: "n'est pas disponible"
130 130 invalid: "n'est pas valide"
131 131 confirmation: "ne concorde pas avec la confirmation"
132 132 accepted: "doit Γͺtre acceptΓ©(e)"
133 133 empty: "doit Γͺtre renseignΓ©(e)"
134 134 blank: "doit Γͺtre renseignΓ©(e)"
135 135 too_long: "est trop long (pas plus de %{count} caractères)"
136 136 too_short: "est trop court (au moins %{count} caractères)"
137 137 wrong_length: "ne fait pas la bonne longueur (doit comporter %{count} caractères)"
138 138 taken: "est dΓ©jΓ  utilisΓ©"
139 139 not_a_number: "n'est pas un nombre"
140 140 not_a_date: "n'est pas une date valide"
141 141 greater_than: "doit Γͺtre supΓ©rieur Γ  %{count}"
142 142 greater_than_or_equal_to: "doit Γͺtre supΓ©rieur ou Γ©gal Γ  %{count}"
143 143 equal_to: "doit Γͺtre Γ©gal Γ  %{count}"
144 144 less_than: "doit Γͺtre infΓ©rieur Γ  %{count}"
145 145 less_than_or_equal_to: "doit Γͺtre infΓ©rieur ou Γ©gal Γ  %{count}"
146 146 odd: "doit Γͺtre impair"
147 147 even: "doit Γͺtre pair"
148 148 greater_than_start_date: "doit Γͺtre postΓ©rieure Γ  la date de dΓ©but"
149 149 not_same_project: "n'appartient pas au mΓͺme projet"
150 150 circular_dependency: "Cette relation crΓ©erait une dΓ©pendance circulaire"
151 151 cant_link_an_issue_with_a_descendant: "Une demande ne peut pas Γͺtre liΓ©e Γ  l'une de ses sous-tΓ’ches"
152 152 earlier_than_minimum_start_date: "ne peut pas Γͺtre antΓ©rieure au %{date} Γ  cause des demandes qui prΓ©cΓ¨dent"
153 153
154 154 actionview_instancetag_blank_option: Choisir
155 155
156 156 general_text_No: 'Non'
157 157 general_text_Yes: 'Oui'
158 158 general_text_no: 'non'
159 159 general_text_yes: 'oui'
160 160 general_lang_name: 'French (FranΓ§ais)'
161 161 general_csv_separator: ';'
162 162 general_csv_decimal_separator: ','
163 163 general_csv_encoding: ISO-8859-1
164 164 general_pdf_fontname: freesans
165 165 general_first_day_of_week: '1'
166 166
167 167 notice_account_updated: Le compte a été mis à jour avec succès.
168 168 notice_account_invalid_creditentials: Identifiant ou mot de passe invalide.
169 169 notice_account_password_updated: Mot de passe mis à jour avec succès.
170 170 notice_account_wrong_password: Mot de passe incorrect
171 171 notice_account_register_done: Un message contenant les instructions pour activer votre compte vous a Γ©tΓ© envoyΓ© Γ  l'adresse %{email}.
172 172 notice_account_unknown_email: Aucun compte ne correspond Γ  cette adresse.
173 173 notice_account_not_activated_yet: Vous n'avez pas encore activΓ© votre compte. Si vous voulez recevoir un nouveau message d'activation, veuillez <a href="%{url}">cliquer sur ce lien</a>.
174 174 notice_account_locked: Votre compte est verrouillΓ©.
175 175 notice_can_t_change_password: Ce compte utilise une authentification externe. Impossible de changer le mot de passe.
176 176 notice_account_lost_email_sent: Un message contenant les instructions pour choisir un nouveau mot de passe vous a Γ©tΓ© envoyΓ©.
177 177 notice_account_activated: Votre compte a Γ©tΓ© activΓ©. Vous pouvez Γ  prΓ©sent vous connecter.
178 178 notice_successful_create: Création effectuée avec succès.
179 179 notice_successful_update: Mise à jour effectuée avec succès.
180 180 notice_successful_delete: Suppression effectuée avec succès.
181 181 notice_successful_connection: Connexion rΓ©ussie.
182 182 notice_file_not_found: "La page Γ  laquelle vous souhaitez accΓ©der n'existe pas ou a Γ©tΓ© supprimΓ©e."
183 183 notice_locking_conflict: Les donnΓ©es ont Γ©tΓ© mises Γ  jour par un autre utilisateur. Mise Γ  jour impossible.
184 184 notice_not_authorized: "Vous n'Γͺtes pas autorisΓ© Γ  accΓ©der Γ  cette page."
185 185 notice_not_authorized_archived_project: Le projet auquel vous tentez d'accΓ©der a Γ©tΓ© archivΓ©.
186 186 notice_email_sent: "Un email a Γ©tΓ© envoyΓ© Γ  %{value}"
187 187 notice_email_error: "Erreur lors de l'envoi de l'email (%{value})"
188 188 notice_feeds_access_key_reseted: "Votre clé d'accès aux flux Atom a été réinitialisée."
189 189 notice_api_access_key_reseted: Votre clé d'accès API a été réinitialisée.
190 190 notice_failed_to_save_issues: "%{count} demande(s) sur les %{total} sΓ©lectionnΓ©es n'ont pas pu Γͺtre mise(s) Γ  jour : %{ids}."
191 191 notice_failed_to_save_time_entries: "%{count} temps passΓ©(s) sur les %{total} sΓ©lectionnΓ©s n'ont pas pu Γͺtre mis Γ  jour: %{ids}."
192 192 notice_failed_to_save_members: "Erreur lors de la sauvegarde des membres: %{errors}."
193 193 notice_no_issue_selected: "Aucune demande sΓ©lectionnΓ©e ! Cochez les demandes que vous voulez mettre Γ  jour."
194 194 notice_account_pending: "Votre compte a été créé et attend l'approbation de l'administrateur."
195 195 notice_default_data_loaded: Paramétrage par défaut chargé avec succès.
196 196 notice_unable_delete_version: Impossible de supprimer cette version.
197 197 notice_unable_delete_time_entry: Impossible de supprimer le temps passΓ©.
198 198 notice_issue_done_ratios_updated: L'avancement des demandes a Γ©tΓ© mis Γ  jour.
199 199 notice_gantt_chart_truncated: "Le diagramme a Γ©tΓ© tronquΓ© car il excΓ¨de le nombre maximal d'Γ©lΓ©ments pouvant Γͺtre affichΓ©s (%{max})"
200 200 notice_issue_successful_create: "Demande %{id} créée."
201 201 notice_issue_update_conflict: "La demande a Γ©tΓ© mise Γ  jour par un autre utilisateur pendant que vous la modifiez."
202 202 notice_account_deleted: "Votre compte a Γ©tΓ© dΓ©finitivement supprimΓ©."
203 203 notice_user_successful_create: "Utilisateur %{id} créé."
204 204 notice_new_password_must_be_different: Votre nouveau mot de passe doit Γͺtre diffΓ©rent de votre mot de passe actuel
205 205 notice_import_finished: "Les %{count} Γ©lΓ©ments ont Γ©tΓ© importΓ©(s)."
206 206 notice_import_finished_with_errors: "%{count} Γ©lΓ©ment(s) sur %{total} n'ont pas pu Γͺtre importΓ©(s)."
207 207
208 208 error_can_t_load_default_data: "Une erreur s'est produite lors du chargement du paramΓ©trage : %{value}"
209 209 error_scm_not_found: "L'entrΓ©e et/ou la rΓ©vision demandΓ©e n'existe pas dans le dΓ©pΓ΄t."
210 210 error_scm_command_failed: "Une erreur s'est produite lors de l'accès au dépôt : %{value}"
211 211 error_scm_annotate: "L'entrΓ©e n'existe pas ou ne peut pas Γͺtre annotΓ©e."
212 212 error_scm_annotate_big_text_file: Cette entrΓ©e ne peut pas Γͺtre annotΓ©e car elle excΓ¨de la taille maximale.
213 213 error_issue_not_found_in_project: "La demande n'existe pas ou n'appartient pas Γ  ce projet"
214 214 error_no_tracker_in_project: "Aucun tracker n'est associΓ© Γ  ce projet. VΓ©rifier la configuration du projet."
215 215 error_no_default_issue_status: "Aucun statut de demande n'est dΓ©fini par dΓ©faut. VΓ©rifier votre configuration (Administration -> Statuts de demandes)."
216 216 error_can_not_delete_custom_field: Impossible de supprimer le champ personnalisΓ©
217 217 error_can_not_delete_tracker: Ce tracker contient des demandes et ne peut pas Γͺtre supprimΓ©.
218 218 error_can_not_remove_role: Ce rΓ΄le est utilisΓ© et ne peut pas Γͺtre supprimΓ©.
219 219 error_can_not_reopen_issue_on_closed_version: 'Une demande assignΓ©e Γ  une version fermΓ©e ne peut pas Γͺtre rΓ©ouverte'
220 220 error_can_not_archive_project: "Ce projet ne peut pas Γͺtre archivΓ©"
221 221 error_issue_done_ratios_not_updated: L'avancement des demandes n'a pas pu Γͺtre mis Γ  jour.
222 222 error_workflow_copy_source: 'Veuillez sΓ©lectionner un tracker et/ou un rΓ΄le source'
223 223 error_workflow_copy_target: 'Veuillez sΓ©lectionner les trackers et rΓ΄les cibles'
224 224 error_unable_delete_issue_status: Impossible de supprimer le statut de demande
225 225 error_unable_to_connect: Connexion impossible (%{value})
226 226 error_attachment_too_big: Ce fichier ne peut pas Γͺtre attachΓ© car il excΓ¨de la taille maximale autorisΓ©e (%{max_size})
227 227 error_session_expired: "Votre session a expirΓ©. Veuillez vous reconnecter."
228 228 warning_attachments_not_saved: "%{count} fichier(s) n'ont pas pu Γͺtre sauvegardΓ©s."
229 229 error_password_expired: "Votre mot de passe a expirΓ© ou nΓ©cessite d'Γͺtre changΓ©."
230 230 error_invalid_file_encoding: "Le fichier n'est pas un fichier %{encoding} valide"
231 231 error_invalid_csv_file_or_settings: "Le fichier n'est pas un fichier CSV ou n'est pas conforme aux paramètres sélectionnés"
232 232 error_can_not_read_import_file: "Une erreur est survenue lors de la lecture du fichier Γ  importer"
233 233
234 234 mail_subject_lost_password: "Votre mot de passe %{value}"
235 235 mail_body_lost_password: 'Pour changer votre mot de passe, cliquez sur le lien suivant :'
236 236 mail_subject_register: "Activation de votre compte %{value}"
237 237 mail_body_register: 'Pour activer votre compte, cliquez sur le lien suivant :'
238 238 mail_body_account_information_external: "Vous pouvez utiliser votre compte %{value} pour vous connecter."
239 239 mail_body_account_information: Paramètres de connexion de votre compte
240 240 mail_subject_account_activation_request: "Demande d'activation d'un compte %{value}"
241 241 mail_body_account_activation_request: "Un nouvel utilisateur (%{value}) s'est inscrit. Son compte nΓ©cessite votre approbation :"
242 242 mail_subject_reminder: "%{count} demande(s) arrivent Γ  Γ©chΓ©ance (%{days})"
243 243 mail_body_reminder: "%{count} demande(s) qui vous sont assignΓ©es arrivent Γ  Γ©chΓ©ance dans les %{days} prochains jours :"
244 244 mail_subject_wiki_content_added: "Page wiki '%{id}' ajoutΓ©e"
245 245 mail_body_wiki_content_added: "La page wiki '%{id}' a Γ©tΓ© ajoutΓ©e par %{author}."
246 246 mail_subject_wiki_content_updated: "Page wiki '%{id}' mise Γ  jour"
247 247 mail_body_wiki_content_updated: "La page wiki '%{id}' a Γ©tΓ© mise Γ  jour par %{author}."
248 248
249 249 field_name: Nom
250 250 field_description: Description
251 251 field_summary: RΓ©sumΓ©
252 252 field_is_required: Obligatoire
253 253 field_firstname: PrΓ©nom
254 254 field_lastname: Nom
255 255 field_mail: Email
256 256 field_address: Email
257 257 field_filename: Fichier
258 258 field_filesize: Taille
259 259 field_downloads: TΓ©lΓ©chargements
260 260 field_author: Auteur
261 261 field_created_on: Créé
262 262 field_updated_on: Mis-Γ -jour
263 263 field_closed_on: FermΓ©
264 264 field_field_format: Format
265 265 field_is_for_all: Pour tous les projets
266 266 field_possible_values: Valeurs possibles
267 267 field_regexp: Expression régulière
268 268 field_min_length: Longueur minimum
269 269 field_max_length: Longueur maximum
270 270 field_value: Valeur
271 271 field_category: CatΓ©gorie
272 272 field_title: Titre
273 273 field_project: Projet
274 274 field_issue: Demande
275 275 field_status: Statut
276 276 field_notes: Notes
277 277 field_is_closed: Demande fermΓ©e
278 278 field_is_default: Valeur par dΓ©faut
279 279 field_tracker: Tracker
280 280 field_subject: Sujet
281 281 field_due_date: EchΓ©ance
282 282 field_assigned_to: AssignΓ© Γ 
283 283 field_priority: PrioritΓ©
284 284 field_fixed_version: Version cible
285 285 field_user: Utilisateur
286 286 field_principal: Principal
287 287 field_role: RΓ΄le
288 288 field_homepage: Site web
289 289 field_is_public: Public
290 290 field_parent: Sous-projet de
291 291 field_is_in_roadmap: Demandes affichΓ©es dans la roadmap
292 292 field_login: Identifiant
293 293 field_mail_notification: Notifications par mail
294 294 field_admin: Administrateur
295 295 field_last_login_on: Dernière connexion
296 296 field_language: Langue
297 297 field_effective_date: Date
298 298 field_password: Mot de passe
299 299 field_new_password: Nouveau mot de passe
300 300 field_password_confirmation: Confirmation
301 301 field_version: Version
302 302 field_type: Type
303 303 field_host: HΓ΄te
304 304 field_port: Port
305 305 field_account: Compte
306 306 field_base_dn: Base DN
307 307 field_attr_login: Attribut Identifiant
308 308 field_attr_firstname: Attribut PrΓ©nom
309 309 field_attr_lastname: Attribut Nom
310 310 field_attr_mail: Attribut Email
311 311 field_onthefly: CrΓ©ation des utilisateurs Γ  la volΓ©e
312 312 field_start_date: DΓ©but
313 313 field_done_ratio: "% rΓ©alisΓ©"
314 314 field_auth_source: Mode d'authentification
315 315 field_hide_mail: Cacher mon adresse mail
316 316 field_comments: Commentaire
317 317 field_url: URL
318 318 field_start_page: Page de dΓ©marrage
319 319 field_subproject: Sous-projet
320 320 field_hours: Heures
321 321 field_activity: ActivitΓ©
322 322 field_spent_on: Date
323 323 field_identifier: Identifiant
324 324 field_is_filter: UtilisΓ© comme filtre
325 325 field_issue_to: Demande liΓ©e
326 326 field_delay: Retard
327 327 field_assignable: Demandes assignables Γ  ce rΓ΄le
328 328 field_redirect_existing_links: Rediriger les liens existants
329 329 field_estimated_hours: Temps estimΓ©
330 330 field_column_names: Colonnes
331 331 field_time_entries: Temps passΓ©
332 332 field_time_zone: Fuseau horaire
333 333 field_searchable: UtilisΓ© pour les recherches
334 334 field_default_value: Valeur par dΓ©faut
335 335 field_comments_sorting: Afficher les commentaires
336 336 field_parent_title: Page parent
337 337 field_editable: Modifiable
338 338 field_watcher: Observateur
339 339 field_identity_url: URL OpenID
340 340 field_content: Contenu
341 341 field_group_by: Grouper par
342 342 field_sharing: Partage
343 343 field_parent_issue: TΓ’che parente
344 344 field_member_of_group: Groupe de l'assignΓ©
345 345 field_assigned_to_role: RΓ΄le de l'assignΓ©
346 346 field_text: Champ texte
347 347 field_visible: Visible
348 348 field_warn_on_leaving_unsaved: "M'avertir lorsque je quitte une page contenant du texte non sauvegardΓ©"
349 349 field_issues_visibility: VisibilitΓ© des demandes
350 350 field_is_private: PrivΓ©e
351 351 field_commit_logs_encoding: Encodage des messages de commit
352 352 field_scm_path_encoding: Encodage des chemins
353 353 field_path_to_repository: Chemin du dΓ©pΓ΄t
354 354 field_root_directory: RΓ©pertoire racine
355 355 field_cvsroot: CVSROOT
356 356 field_cvs_module: Module
357 357 field_repository_is_default: DΓ©pΓ΄t principal
358 358 field_multiple: Valeurs multiples
359 359 field_auth_source_ldap_filter: Filtre LDAP
360 360 field_core_fields: Champs standards
361 361 field_timeout: "Timeout (en secondes)"
362 362 field_board_parent: Forum parent
363 363 field_private_notes: Notes privΓ©es
364 364 field_inherit_members: HΓ©riter les membres
365 365 field_generate_password: GΓ©nΓ©rer un mot de passe
366 366 field_must_change_passwd: Doit changer de mot de passe Γ  la prochaine connexion
367 367 field_default_status: Statut par dΓ©faut
368 368 field_users_visibility: VisibilitΓ© des utilisateurs
369 369 field_time_entries_visibility: VisibilitΓ© du temps passΓ©
370 370 field_total_estimated_hours: Temps estimΓ© total
371 field_default_version: Version par dΓ©faut
371 372
372 373 setting_app_title: Titre de l'application
373 374 setting_app_subtitle: Sous-titre de l'application
374 375 setting_welcome_text: Texte d'accueil
375 376 setting_default_language: Langue par dΓ©faut
376 377 setting_login_required: Authentification obligatoire
377 378 setting_self_registration: Inscription des nouveaux utilisateurs
378 379 setting_attachment_max_size: Taille maximale des fichiers
379 380 setting_issues_export_limit: Limite d'exportation des demandes
380 381 setting_mail_from: Adresse d'Γ©mission
381 382 setting_bcc_recipients: Destinataires en copie cachΓ©e (cci)
382 383 setting_plain_text_mail: Mail en texte brut (non HTML)
383 384 setting_host_name: Nom d'hΓ΄te et chemin
384 385 setting_text_formatting: Formatage du texte
385 386 setting_wiki_compression: Compression de l'historique des pages wiki
386 387 setting_feeds_limit: Nombre maximal d'Γ©lΓ©ments dans les flux Atom
387 388 setting_default_projects_public: DΓ©finir les nouveaux projets comme publics par dΓ©faut
388 389 setting_autofetch_changesets: RΓ©cupΓ©ration automatique des commits
389 390 setting_sys_api_enabled: Activer les WS pour la gestion des dΓ©pΓ΄ts
390 391 setting_commit_ref_keywords: Mots-clΓ©s de rΓ©fΓ©rencement
391 392 setting_commit_fix_keywords: Mots-clΓ©s de rΓ©solution
392 393 setting_autologin: DurΓ©e maximale de connexion automatique
393 394 setting_date_format: Format de date
394 395 setting_time_format: Format d'heure
395 396 setting_cross_project_issue_relations: Autoriser les relations entre demandes de diffΓ©rents projets
396 397 setting_cross_project_subtasks: Autoriser les sous-tΓ’ches dans des projets diffΓ©rents
397 398 setting_issue_list_default_columns: Colonnes affichΓ©es par dΓ©faut sur la liste des demandes
398 399 setting_repositories_encodings: Encodages des fichiers et des dΓ©pΓ΄ts
399 400 setting_emails_header: En-tΓͺte des emails
400 401 setting_emails_footer: Pied-de-page des emails
401 402 setting_protocol: Protocole
402 403 setting_per_page_options: Options d'objets affichΓ©s par page
403 404 setting_user_format: Format d'affichage des utilisateurs
404 405 setting_activity_days_default: Nombre de jours affichΓ©s sur l'activitΓ© des projets
405 406 setting_display_subprojects_issues: Afficher par dΓ©faut les demandes des sous-projets sur les projets principaux
406 407 setting_enabled_scm: SCM activΓ©s
407 408 setting_mail_handler_body_delimiters: "Tronquer les emails après l'une de ces lignes"
408 409 setting_mail_handler_api_enabled: "Activer le WS pour la rΓ©ception d'emails"
409 410 setting_mail_handler_api_key: ClΓ© de protection de l'API
410 411 setting_sequential_project_identifiers: GΓ©nΓ©rer des identifiants de projet sΓ©quentiels
411 412 setting_gravatar_enabled: Afficher les Gravatar des utilisateurs
412 413 setting_gravatar_default: Image Gravatar par dΓ©faut
413 414 setting_diff_max_lines_displayed: Nombre maximum de lignes de diff affichΓ©es
414 415 setting_file_max_size_displayed: Taille maximum des fichiers texte affichΓ©s en ligne
415 416 setting_repository_log_display_limit: "Nombre maximum de rΓ©visions affichΓ©es sur l'historique d'un fichier"
416 417 setting_openid: "Autoriser l'authentification et l'enregistrement OpenID"
417 418 setting_password_max_age: Expiration des mots de passe après
418 419 setting_password_min_length: Longueur minimum des mots de passe
419 420 setting_new_project_user_role_id: RΓ΄le donnΓ© Γ  un utilisateur non-administrateur qui crΓ©e un projet
420 421 setting_default_projects_modules: Modules activΓ©s par dΓ©faut pour les nouveaux projets
421 422 setting_issue_done_ratio: Calcul de l'avancement des demandes
422 423 setting_issue_done_ratio_issue_field: 'Utiliser le champ % effectuΓ©'
423 424 setting_issue_done_ratio_issue_status: Utiliser le statut
424 425 setting_start_of_week: Jour de dΓ©but des calendriers
425 426 setting_rest_api_enabled: Activer l'API REST
426 427 setting_cache_formatted_text: Mettre en cache le texte formatΓ©
427 428 setting_default_notification_option: Option de notification par dΓ©faut
428 429 setting_commit_logtime_enabled: Permettre la saisie de temps
429 430 setting_commit_logtime_activity_id: ActivitΓ© pour le temps saisi
430 431 setting_gantt_items_limit: Nombre maximum d'Γ©lΓ©ments affichΓ©s sur le gantt
431 432 setting_issue_group_assignment: Permettre l'assignement des demandes aux groupes
432 433 setting_default_issue_start_date_to_creation_date: Donner Γ  la date de dΓ©but d'une nouvelle demande la valeur de la date du jour
433 434 setting_commit_cross_project_ref: Permettre le rΓ©fΓ©rencement et la rΓ©solution des demandes de tous les autres projets
434 435 setting_unsubscribe: Permettre aux utilisateurs de supprimer leur propre compte
435 436 setting_session_lifetime: DurΓ©e de vie maximale des sessions
436 437 setting_session_timeout: DurΓ©e maximale d'inactivitΓ©
437 438 setting_thumbnails_enabled: Afficher les vignettes des images
438 439 setting_thumbnails_size: Taille des vignettes (en pixels)
439 440 setting_non_working_week_days: Jours non travaillΓ©s
440 441 setting_jsonp_enabled: Activer le support JSONP
441 442 setting_default_projects_tracker_ids: Trackers par dΓ©faut pour les nouveaux projets
442 443 setting_mail_handler_excluded_filenames: Exclure les fichiers attachΓ©s par leur nom
443 444 setting_force_default_language_for_anonymous: Forcer la langue par dΓ©fault pour les utilisateurs anonymes
444 445 setting_force_default_language_for_loggedin: Forcer la langue par dΓ©fault pour les utilisateurs identifiΓ©s
445 446 setting_link_copied_issue: Lier les demandes lors de la copie
446 447 setting_max_additional_emails: Nombre maximal d'adresses email additionnelles
447 448 setting_search_results_per_page: RΓ©sultats de recherche affichΓ©s par page
448 449
449 450 permission_add_project: CrΓ©er un projet
450 451 permission_add_subprojects: CrΓ©er des sous-projets
451 452 permission_edit_project: Modifier le projet
452 453 permission_close_project: Fermer / rΓ©ouvrir le projet
453 454 permission_select_project_modules: Choisir les modules
454 455 permission_manage_members: GΓ©rer les membres
455 456 permission_manage_project_activities: GΓ©rer les activitΓ©s
456 457 permission_manage_versions: GΓ©rer les versions
457 458 permission_manage_categories: GΓ©rer les catΓ©gories de demandes
458 459 permission_view_issues: Voir les demandes
459 460 permission_add_issues: CrΓ©er des demandes
460 461 permission_edit_issues: Modifier les demandes
461 462 permission_copy_issues: Copier les demandes
462 463 permission_manage_issue_relations: GΓ©rer les relations
463 464 permission_set_issues_private: Rendre les demandes publiques ou privΓ©es
464 465 permission_set_own_issues_private: Rendre ses propres demandes publiques ou privΓ©es
465 466 permission_add_issue_notes: Ajouter des notes
466 467 permission_edit_issue_notes: Modifier les notes
467 468 permission_edit_own_issue_notes: Modifier ses propres notes
468 469 permission_view_private_notes: Voir les notes privΓ©es
469 470 permission_set_notes_private: Rendre les notes privΓ©es
470 471 permission_move_issues: DΓ©placer les demandes
471 472 permission_delete_issues: Supprimer les demandes
472 473 permission_manage_public_queries: GΓ©rer les requΓͺtes publiques
473 474 permission_save_queries: Sauvegarder les requΓͺtes
474 475 permission_view_gantt: Voir le gantt
475 476 permission_view_calendar: Voir le calendrier
476 477 permission_view_issue_watchers: Voir la liste des observateurs
477 478 permission_add_issue_watchers: Ajouter des observateurs
478 479 permission_delete_issue_watchers: Supprimer des observateurs
479 480 permission_log_time: Saisir le temps passΓ©
480 481 permission_view_time_entries: Voir le temps passΓ©
481 482 permission_edit_time_entries: Modifier les temps passΓ©s
482 483 permission_edit_own_time_entries: Modifier son propre temps passΓ©
483 484 permission_manage_news: GΓ©rer les annonces
484 485 permission_comment_news: Commenter les annonces
485 486 permission_view_documents: Voir les documents
486 487 permission_add_documents: Ajouter des documents
487 488 permission_edit_documents: Modifier les documents
488 489 permission_delete_documents: Supprimer les documents
489 490 permission_manage_files: GΓ©rer les fichiers
490 491 permission_view_files: Voir les fichiers
491 492 permission_manage_wiki: GΓ©rer le wiki
492 493 permission_rename_wiki_pages: Renommer les pages
493 494 permission_delete_wiki_pages: Supprimer les pages
494 495 permission_view_wiki_pages: Voir le wiki
495 496 permission_view_wiki_edits: "Voir l'historique des modifications"
496 497 permission_edit_wiki_pages: Modifier les pages
497 498 permission_delete_wiki_pages_attachments: Supprimer les fichiers joints
498 499 permission_protect_wiki_pages: ProtΓ©ger les pages
499 500 permission_manage_repository: GΓ©rer le dΓ©pΓ΄t de sources
500 501 permission_browse_repository: Parcourir les sources
501 502 permission_view_changesets: Voir les rΓ©visions
502 503 permission_commit_access: Droit de commit
503 504 permission_manage_boards: GΓ©rer les forums
504 505 permission_view_messages: Voir les messages
505 506 permission_add_messages: Poster un message
506 507 permission_edit_messages: Modifier les messages
507 508 permission_edit_own_messages: Modifier ses propres messages
508 509 permission_delete_messages: Supprimer les messages
509 510 permission_delete_own_messages: Supprimer ses propres messages
510 511 permission_export_wiki_pages: Exporter les pages
511 512 permission_manage_subtasks: GΓ©rer les sous-tΓ’ches
512 513 permission_manage_related_issues: GΓ©rer les demandes associΓ©es
513 514 permission_import_issues: Importer des demandes
514 515
515 516 project_module_issue_tracking: Suivi des demandes
516 517 project_module_time_tracking: Suivi du temps passΓ©
517 518 project_module_news: Publication d'annonces
518 519 project_module_documents: Publication de documents
519 520 project_module_files: Publication de fichiers
520 521 project_module_wiki: Wiki
521 522 project_module_repository: DΓ©pΓ΄t de sources
522 523 project_module_boards: Forums de discussion
523 524 project_module_calendar: Calendrier
524 525 project_module_gantt: Gantt
525 526
526 527 label_user: Utilisateur
527 528 label_user_plural: Utilisateurs
528 529 label_user_new: Nouvel utilisateur
529 530 label_user_anonymous: Anonyme
530 531 label_project: Projet
531 532 label_project_new: Nouveau projet
532 533 label_project_plural: Projets
533 534 label_x_projects:
534 535 zero: aucun projet
535 536 one: un projet
536 537 other: "%{count} projets"
537 538 label_project_all: Tous les projets
538 539 label_project_latest: Derniers projets
539 540 label_issue: Demande
540 541 label_issue_new: Nouvelle demande
541 542 label_issue_plural: Demandes
542 543 label_issue_view_all: Voir toutes les demandes
543 544 label_issues_by: "Demandes par %{value}"
544 545 label_issue_added: Demande ajoutΓ©e
545 546 label_issue_updated: Demande mise Γ  jour
546 547 label_issue_note_added: Note ajoutΓ©e
547 548 label_issue_status_updated: Statut changΓ©
548 549 label_issue_assigned_to_updated: AssignΓ© changΓ©
549 550 label_issue_priority_updated: PrioritΓ© changΓ©e
550 551 label_document: Document
551 552 label_document_new: Nouveau document
552 553 label_document_plural: Documents
553 554 label_document_added: Document ajoutΓ©
554 555 label_role: RΓ΄le
555 556 label_role_plural: RΓ΄les
556 557 label_role_new: Nouveau rΓ΄le
557 558 label_role_and_permissions: RΓ΄les et permissions
558 559 label_role_anonymous: Anonyme
559 560 label_role_non_member: Non membre
560 561 label_member: Membre
561 562 label_member_new: Nouveau membre
562 563 label_member_plural: Membres
563 564 label_tracker: Tracker
564 565 label_tracker_plural: Trackers
565 566 label_tracker_new: Nouveau tracker
566 567 label_workflow: Workflow
567 568 label_issue_status: Statut de demandes
568 569 label_issue_status_plural: Statuts de demandes
569 570 label_issue_status_new: Nouveau statut
570 571 label_issue_category: CatΓ©gorie de demandes
571 572 label_issue_category_plural: CatΓ©gories de demandes
572 573 label_issue_category_new: Nouvelle catΓ©gorie
573 574 label_custom_field: Champ personnalisΓ©
574 575 label_custom_field_plural: Champs personnalisΓ©s
575 576 label_custom_field_new: Nouveau champ personnalisΓ©
576 577 label_enumerations: Listes de valeurs
577 578 label_enumeration_new: Nouvelle valeur
578 579 label_information: Information
579 580 label_information_plural: Informations
580 581 label_please_login: Identification
581 582 label_register: S'enregistrer
582 583 label_login_with_open_id_option: S'authentifier avec OpenID
583 584 label_password_lost: Mot de passe perdu
584 585 label_password_required: Confirmez votre mot de passe pour continuer
585 586 label_home: Accueil
586 587 label_my_page: Ma page
587 588 label_my_account: Mon compte
588 589 label_my_projects: Mes projets
589 590 label_my_page_block: Blocs disponibles
590 591 label_administration: Administration
591 592 label_login: Connexion
592 593 label_logout: DΓ©connexion
593 594 label_help: Aide
594 595 label_reported_issues: Demandes soumises
595 596 label_assigned_issues: Demandes assignΓ©es
596 597 label_assigned_to_me_issues: Demandes qui me sont assignΓ©es
597 598 label_last_login: Dernière connexion
598 599 label_registered_on: Inscrit le
599 600 label_activity: ActivitΓ©
600 601 label_overall_activity: ActivitΓ© globale
601 602 label_user_activity: "ActivitΓ© de %{value}"
602 603 label_new: Nouveau
603 604 label_logged_as: ConnectΓ© en tant que
604 605 label_environment: Environnement
605 606 label_authentication: Authentification
606 607 label_auth_source: Mode d'authentification
607 608 label_auth_source_new: Nouveau mode d'authentification
608 609 label_auth_source_plural: Modes d'authentification
609 610 label_subproject_plural: Sous-projets
610 611 label_subproject_new: Nouveau sous-projet
611 612 label_and_its_subprojects: "%{value} et ses sous-projets"
612 613 label_min_max_length: Longueurs mini - maxi
613 614 label_list: Liste
614 615 label_date: Date
615 616 label_integer: Entier
616 617 label_float: Nombre dΓ©cimal
617 618 label_boolean: BoolΓ©en
618 619 label_string: Texte
619 620 label_text: Texte long
620 621 label_attribute: Attribut
621 622 label_attribute_plural: Attributs
622 623 label_no_data: Aucune donnΓ©e Γ  afficher
623 624 label_change_status: Changer le statut
624 625 label_history: Historique
625 626 label_attachment: Fichier
626 627 label_attachment_new: Nouveau fichier
627 628 label_attachment_delete: Supprimer le fichier
628 629 label_attachment_plural: Fichiers
629 630 label_file_added: Fichier ajoutΓ©
630 631 label_report: Rapport
631 632 label_report_plural: Rapports
632 633 label_news: Annonce
633 634 label_news_new: Nouvelle annonce
634 635 label_news_plural: Annonces
635 636 label_news_latest: Dernières annonces
636 637 label_news_view_all: Voir toutes les annonces
637 638 label_news_added: Annonce ajoutΓ©e
638 639 label_news_comment_added: Commentaire ajoutΓ© Γ  une annonce
639 640 label_settings: Configuration
640 641 label_overview: AperΓ§u
641 642 label_version: Version
642 643 label_version_new: Nouvelle version
643 644 label_version_plural: Versions
644 645 label_close_versions: Fermer les versions terminΓ©es
645 646 label_confirmation: Confirmation
646 647 label_export_to: 'Formats disponibles :'
647 648 label_read: Lire...
648 649 label_public_projects: Projets publics
649 650 label_open_issues: ouvert
650 651 label_open_issues_plural: ouverts
651 652 label_closed_issues: fermΓ©
652 653 label_closed_issues_plural: fermΓ©s
653 654 label_x_open_issues_abbr:
654 655 zero: 0 ouverte
655 656 one: 1 ouverte
656 657 other: "%{count} ouvertes"
657 658 label_x_closed_issues_abbr:
658 659 zero: 0 fermΓ©e
659 660 one: 1 fermΓ©e
660 661 other: "%{count} fermΓ©es"
661 662 label_x_issues:
662 663 zero: 0 demande
663 664 one: 1 demande
664 665 other: "%{count} demandes"
665 666 label_total: Total
666 667 label_total_plural: Totaux
667 668 label_total_time: Temps total
668 669 label_permissions: Permissions
669 670 label_current_status: Statut actuel
670 671 label_new_statuses_allowed: Nouveaux statuts autorisΓ©s
671 672 label_all: tous
672 673 label_any: tous
673 674 label_none: aucun
674 675 label_nobody: personne
675 676 label_next: Suivant
676 677 label_previous: PrΓ©cΓ©dent
677 678 label_used_by: UtilisΓ© par
678 679 label_details: DΓ©tails
679 680 label_add_note: Ajouter une note
680 681 label_calendar: Calendrier
681 682 label_months_from: mois depuis
682 683 label_gantt: Gantt
683 684 label_internal: Interne
684 685 label_last_changes: "%{count} derniers changements"
685 686 label_change_view_all: Voir tous les changements
686 687 label_personalize_page: Personnaliser cette page
687 688 label_comment: Commentaire
688 689 label_comment_plural: Commentaires
689 690 label_x_comments:
690 691 zero: aucun commentaire
691 692 one: un commentaire
692 693 other: "%{count} commentaires"
693 694 label_comment_add: Ajouter un commentaire
694 695 label_comment_added: Commentaire ajoutΓ©
695 696 label_comment_delete: Supprimer les commentaires
696 697 label_query: Rapport personnalisΓ©
697 698 label_query_plural: Rapports personnalisΓ©s
698 699 label_query_new: Nouveau rapport
699 700 label_my_queries: Mes rapports personnalisΓ©s
700 701 label_filter_add: Ajouter le filtre
701 702 label_filter_plural: Filtres
702 703 label_equals: Γ©gal
703 704 label_not_equals: diffΓ©rent
704 705 label_in_less_than: dans moins de
705 706 label_in_more_than: dans plus de
706 707 label_in_the_next_days: dans les prochains jours
707 708 label_in_the_past_days: dans les derniers jours
708 709 label_greater_or_equal: '>='
709 710 label_less_or_equal: '<='
710 711 label_between: entre
711 712 label_in: dans
712 713 label_today: aujourd'hui
713 714 label_all_time: toute la pΓ©riode
714 715 label_yesterday: hier
715 716 label_this_week: cette semaine
716 717 label_last_week: la semaine dernière
717 718 label_last_n_weeks: "les %{count} dernières semaines"
718 719 label_last_n_days: "les %{count} derniers jours"
719 720 label_this_month: ce mois-ci
720 721 label_last_month: le mois dernier
721 722 label_this_year: cette annΓ©e
722 723 label_date_range: PΓ©riode
723 724 label_less_than_ago: il y a moins de
724 725 label_more_than_ago: il y a plus de
725 726 label_ago: il y a
726 727 label_contains: contient
727 728 label_not_contains: ne contient pas
728 729 label_any_issues_in_project: une demande du projet
729 730 label_any_issues_not_in_project: une demande hors du projet
730 731 label_no_issues_in_project: aucune demande du projet
731 732 label_day_plural: jours
732 733 label_repository: DΓ©pΓ΄t
733 734 label_repository_new: Nouveau dΓ©pΓ΄t
734 735 label_repository_plural: DΓ©pΓ΄ts
735 736 label_browse: Parcourir
736 737 label_branch: Branche
737 738 label_tag: Tag
738 739 label_revision: RΓ©vision
739 740 label_revision_plural: RΓ©visions
740 741 label_revision_id: "RΓ©vision %{value}"
741 742 label_associated_revisions: RΓ©visions associΓ©es
742 743 label_added: ajoutΓ©
743 744 label_modified: modifiΓ©
744 745 label_copied: copiΓ©
745 746 label_renamed: renommΓ©
746 747 label_deleted: supprimΓ©
747 748 label_latest_revision: Dernière révision
748 749 label_latest_revision_plural: Dernières révisions
749 750 label_view_revisions: Voir les rΓ©visions
750 751 label_view_all_revisions: Voir toutes les rΓ©visions
751 752 label_max_size: Taille maximale
752 753 label_sort_highest: Remonter en premier
753 754 label_sort_higher: Remonter
754 755 label_sort_lower: Descendre
755 756 label_sort_lowest: Descendre en dernier
756 757 label_roadmap: Roadmap
757 758 label_roadmap_due_in: "Γ‰chΓ©ance dans %{value}"
758 759 label_roadmap_overdue: "En retard de %{value}"
759 760 label_roadmap_no_issues: Aucune demande pour cette version
760 761 label_search: Recherche
761 762 label_result_plural: RΓ©sultats
762 763 label_all_words: Tous les mots
763 764 label_wiki: Wiki
764 765 label_wiki_edit: RΓ©vision wiki
765 766 label_wiki_edit_plural: RΓ©visions wiki
766 767 label_wiki_page: Page wiki
767 768 label_wiki_page_plural: Pages wiki
768 769 label_index_by_title: Index par titre
769 770 label_index_by_date: Index par date
770 771 label_current_version: Version actuelle
771 772 label_preview: PrΓ©visualisation
772 773 label_feed_plural: Flux Atom
773 774 label_changes_details: DΓ©tails de tous les changements
774 775 label_issue_tracking: Suivi des demandes
775 776 label_spent_time: Temps passΓ©
776 777 label_total_spent_time: Temps passΓ© total
777 778 label_overall_spent_time: Temps passΓ© global
778 779 label_f_hour: "%{value} heure"
779 780 label_f_hour_plural: "%{value} heures"
780 781 label_f_hour_short: "%{value} h"
781 782 label_time_tracking: Suivi du temps
782 783 label_change_plural: Changements
783 784 label_statistics: Statistiques
784 785 label_commits_per_month: Commits par mois
785 786 label_commits_per_author: Commits par auteur
786 787 label_diff: diff
787 788 label_view_diff: Voir les diffΓ©rences
788 789 label_diff_inline: en ligne
789 790 label_diff_side_by_side: cΓ΄te Γ  cΓ΄te
790 791 label_options: Options
791 792 label_copy_workflow_from: Copier le workflow de
792 793 label_permissions_report: Synthèse des permissions
793 794 label_watched_issues: Demandes surveillΓ©es
794 795 label_related_issues: Demandes liΓ©es
795 796 label_applied_status: Statut appliquΓ©
796 797 label_loading: Chargement...
797 798 label_relation_new: Nouvelle relation
798 799 label_relation_delete: Supprimer la relation
799 800 label_relates_to: LiΓ© Γ 
800 801 label_duplicates: Duplique
801 802 label_duplicated_by: DupliquΓ© par
802 803 label_blocks: Bloque
803 804 label_blocked_by: BloquΓ© par
804 805 label_precedes: Précède
805 806 label_follows: Suit
806 807 label_copied_to: CopiΓ© vers
807 808 label_copied_from: CopiΓ© depuis
808 809 label_end_to_start: fin Γ  dΓ©but
809 810 label_end_to_end: fin Γ  fin
810 811 label_start_to_start: dΓ©but Γ  dΓ©but
811 812 label_start_to_end: dΓ©but Γ  fin
812 813 label_stay_logged_in: Rester connectΓ©
813 814 label_disabled: dΓ©sactivΓ©
814 815 label_show_completed_versions: Voir les versions passΓ©es
815 816 label_me: moi
816 817 label_board: Forum
817 818 label_board_new: Nouveau forum
818 819 label_board_plural: Forums
819 820 label_board_locked: VerrouillΓ©
820 821 label_board_sticky: Sticky
821 822 label_topic_plural: Discussions
822 823 label_message_plural: Messages
823 824 label_message_last: Dernier message
824 825 label_message_new: Nouveau message
825 826 label_message_posted: Message ajoutΓ©
826 827 label_reply_plural: RΓ©ponses
827 828 label_send_information: Envoyer les informations Γ  l'utilisateur
828 829 label_year: AnnΓ©e
829 830 label_month: Mois
830 831 label_week: Semaine
831 832 label_date_from: Du
832 833 label_date_to: Au
833 834 label_language_based: BasΓ© sur la langue de l'utilisateur
834 835 label_sort_by: "Trier par %{value}"
835 836 label_send_test_email: Envoyer un email de test
836 837 label_feeds_access_key: Clé d'accès Atom
837 838 label_missing_feeds_access_key: Clé d'accès Atom manquante
838 839 label_feeds_access_key_created_on: "Clé d'accès Atom créée il y a %{value}"
839 840 label_module_plural: Modules
840 841 label_added_time_by: "AjoutΓ© par %{author} il y a %{age}"
841 842 label_updated_time_by: "Mis Γ  jour par %{author} il y a %{age}"
842 843 label_updated_time: "Mis Γ  jour il y a %{value}"
843 844 label_jump_to_a_project: Aller Γ  un projet...
844 845 label_file_plural: Fichiers
845 846 label_changeset_plural: RΓ©visions
846 847 label_default_columns: Colonnes par dΓ©faut
847 848 label_no_change_option: (Pas de changement)
848 849 label_bulk_edit_selected_issues: Modifier les demandes sΓ©lectionnΓ©es
849 850 label_bulk_edit_selected_time_entries: Modifier les temps passΓ©s sΓ©lectionnΓ©s
850 851 label_theme: Thème
851 852 label_default: DΓ©faut
852 853 label_search_titles_only: Uniquement dans les titres
853 854 label_user_mail_option_all: "Pour tous les Γ©vΓ©nements de tous mes projets"
854 855 label_user_mail_option_selected: "Pour tous les Γ©vΓ©nements des projets sΓ©lectionnΓ©s..."
855 856 label_user_mail_option_none: Aucune notification
856 857 label_user_mail_option_only_my_events: Seulement pour ce que je surveille
857 858 label_user_mail_option_only_assigned: Seulement pour ce qui m'est assignΓ©
858 859 label_user_mail_option_only_owner: Seulement pour ce que j'ai créé
859 860 label_user_mail_no_self_notified: "Je ne veux pas Γͺtre notifiΓ© des changements que j'effectue"
860 861 label_registration_activation_by_email: activation du compte par email
861 862 label_registration_manual_activation: activation manuelle du compte
862 863 label_registration_automatic_activation: activation automatique du compte
863 864 label_display_per_page: "Par page : %{value}"
864 865 label_age: Γ‚ge
865 866 label_change_properties: Changer les propriΓ©tΓ©s
866 867 label_general: GΓ©nΓ©ral
867 868 label_more: Plus
868 869 label_scm: SCM
869 870 label_plugins: Plugins
870 871 label_ldap_authentication: Authentification LDAP
871 872 label_downloads_abbr: D/L
872 873 label_optional_description: Description facultative
873 874 label_add_another_file: Ajouter un autre fichier
874 875 label_preferences: PrΓ©fΓ©rences
875 876 label_chronological_order: Dans l'ordre chronologique
876 877 label_reverse_chronological_order: Dans l'ordre chronologique inverse
877 878 label_planning: Planning
878 879 label_incoming_emails: Emails entrants
879 880 label_generate_key: GΓ©nΓ©rer une clΓ©
880 881 label_issue_watchers: Observateurs
881 882 label_example: Exemple
882 883 label_display: Affichage
883 884 label_sort: Tri
884 885 label_ascending: Croissant
885 886 label_descending: DΓ©croissant
886 887 label_date_from_to: Du %{start} au %{end}
887 888 label_wiki_content_added: Page wiki ajoutΓ©e
888 889 label_wiki_content_updated: Page wiki mise Γ  jour
889 890 label_group: Groupe
890 891 label_group_plural: Groupes
891 892 label_group_new: Nouveau groupe
892 893 label_group_anonymous: Utilisateurs anonymes
893 894 label_group_non_member: Utilisateurs non membres
894 895 label_time_entry_plural: Temps passΓ©
895 896 label_version_sharing_none: Non partagΓ©
896 897 label_version_sharing_descendants: Avec les sous-projets
897 898 label_version_sharing_hierarchy: Avec toute la hiΓ©rarchie
898 899 label_version_sharing_tree: Avec tout l'arbre
899 900 label_version_sharing_system: Avec tous les projets
900 901 label_update_issue_done_ratios: Mettre Γ  jour l'avancement des demandes
901 902 label_copy_source: Source
902 903 label_copy_target: Cible
903 904 label_copy_same_as_target: Comme la cible
904 905 label_display_used_statuses_only: N'afficher que les statuts utilisΓ©s dans ce tracker
905 906 label_api_access_key: Clé d'accès API
906 907 label_missing_api_access_key: Clé d'accès API manquante
907 908 label_api_access_key_created_on: Clé d'accès API créée il y a %{value}
908 909 label_profile: Profil
909 910 label_subtask_plural: Sous-tΓ’ches
910 911 label_project_copy_notifications: Envoyer les notifications durant la copie du projet
911 912 label_principal_search: "Rechercher un utilisateur ou un groupe :"
912 913 label_user_search: "Rechercher un utilisateur :"
913 914 label_additional_workflow_transitions_for_author: Autorisations supplémentaires lorsque l'utilisateur a créé la demande
914 915 label_additional_workflow_transitions_for_assignee: Autorisations supplΓ©mentaires lorsque la demande est assignΓ©e Γ  l'utilisateur
915 916 label_issues_visibility_all: Toutes les demandes
916 917 label_issues_visibility_public: Toutes les demandes non privΓ©es
917 918 label_issues_visibility_own: Demandes créées par ou assignées à l'utilisateur
918 919 label_git_report_last_commit: Afficher le dernier commit des fichiers et rΓ©pertoires
919 920 label_parent_revision: Parent
920 921 label_child_revision: Enfant
921 922 label_export_options: Options d'exportation %{export_format}
922 923 label_copy_attachments: Copier les fichiers
923 924 label_copy_subtasks: Copier les sous-tΓ’ches
924 925 label_item_position: "%{position} sur %{count}"
925 926 label_completed_versions: Versions passΓ©es
926 927 label_search_for_watchers: Rechercher des observateurs
927 928 label_session_expiration: Expiration des sessions
928 929 label_show_closed_projects: Voir les projets fermΓ©s
929 930 label_status_transitions: Changements de statut
930 931 label_fields_permissions: Permissions sur les champs
931 932 label_readonly: Lecture
932 933 label_required: Obligatoire
933 934 label_hidden: CachΓ©
934 935 label_attribute_of_project: "%{name} du projet"
935 936 label_attribute_of_issue: "%{name} de la demande"
936 937 label_attribute_of_author: "%{name} de l'auteur"
937 938 label_attribute_of_assigned_to: "%{name} de l'assignΓ©"
938 939 label_attribute_of_user: "%{name} de l'utilisateur"
939 940 label_attribute_of_fixed_version: "%{name} de la version cible"
940 941 label_cross_project_descendants: Avec les sous-projets
941 942 label_cross_project_tree: Avec tout l'arbre
942 943 label_cross_project_hierarchy: Avec toute la hiΓ©rarchie
943 944 label_cross_project_system: Avec tous les projets
944 945 label_gantt_progress_line: Ligne de progression
945 946 label_visibility_private: par moi uniquement
946 947 label_visibility_roles: par ces rΓ΄les uniquement
947 948 label_visibility_public: par tout le monde
948 949 label_link: Lien
949 950 label_only: seulement
950 951 label_drop_down_list: liste dΓ©roulante
951 952 label_checkboxes: cases Γ  cocher
952 953 label_radio_buttons: boutons radio
953 954 label_link_values_to: Lier les valeurs vers l'URL
954 955 label_custom_field_select_type: Selectionner le type d'objet auquel attacher le champ personnalisΓ©
955 956 label_check_for_updates: VΓ©rifier les mises Γ  jour
956 957 label_latest_compatible_version: Dernière version compatible
957 958 label_unknown_plugin: Plugin inconnu
958 959 label_add_projects: Ajouter des projets
959 960 label_users_visibility_all: Tous les utilisateurs actifs
960 961 label_users_visibility_members_of_visible_projects: Membres des projets visibles
961 962 label_edit_attachments: Modifier les fichiers attachΓ©s
962 963 label_link_copied_issue: Lier la demande copiΓ©e
963 964 label_ask: Demander
964 965 label_search_attachments_yes: Rechercher les noms et descriptions de fichiers
965 966 label_search_attachments_no: Ne pas rechercher les fichiers
966 967 label_search_attachments_only: Rechercher les fichiers uniquement
967 968 label_search_open_issues_only: Demandes ouvertes uniquement
968 969 label_email_address_plural: Emails
969 970 label_email_address_add: Ajouter une adresse email
970 971 label_enable_notifications: Activer les notifications
971 972 label_disable_notifications: DΓ©sactiver les notifications
972 973 label_blank_value: non renseignΓ©
973 974 label_parent_task_attributes: Attributs des tΓ’ches parentes
974 975 label_time_entries_visibility_all: Tous les temps passΓ©s
975 976 label_time_entries_visibility_own: Ses propres temps passΓ©s
976 977 label_member_management: Gestion des membres
977 978 label_member_management_all_roles: Tous les rΓ΄les
978 979 label_member_management_selected_roles_only: Ces rΓ΄les uniquement
979 980 label_import_issues: Importer des demandes
980 981 label_select_file_to_import: SΓ©lectionner le fichier Γ  importer
981 982 label_fields_separator: SΓ©parateur de champs
982 983 label_fields_wrapper: DΓ©limiteur de texte
983 984 label_encoding: Encodage
984 985 label_comma_char: Virgule
985 986 label_semi_colon_char: Point virgule
986 987 label_quote_char: Apostrophe
987 988 label_double_quote_char: Double apostrophe
988 989 label_fields_mapping: Correspondance des champs
989 990 label_file_content_preview: AperΓ§u du contenu du fichier
990 991 label_create_missing_values: CrΓ©er les valeurs manquantes
991 992 label_api: API
992 993 label_field_format_enumeration: Liste clΓ©/valeur
993 994
994 995 button_login: Connexion
995 996 button_submit: Soumettre
996 997 button_save: Sauvegarder
997 998 button_check_all: Tout cocher
998 999 button_uncheck_all: Tout dΓ©cocher
999 1000 button_collapse_all: Plier tout
1000 1001 button_expand_all: DΓ©plier tout
1001 1002 button_delete: Supprimer
1002 1003 button_create: CrΓ©er
1003 1004 button_create_and_continue: CrΓ©er et continuer
1004 1005 button_test: Tester
1005 1006 button_edit: Modifier
1006 1007 button_edit_associated_wikipage: "Modifier la page wiki associΓ©e: %{page_title}"
1007 1008 button_add: Ajouter
1008 1009 button_change: Changer
1009 1010 button_apply: Appliquer
1010 1011 button_clear: Effacer
1011 1012 button_lock: Verrouiller
1012 1013 button_unlock: DΓ©verrouiller
1013 1014 button_download: TΓ©lΓ©charger
1014 1015 button_list: Lister
1015 1016 button_view: Voir
1016 1017 button_move: DΓ©placer
1017 1018 button_move_and_follow: DΓ©placer et suivre
1018 1019 button_back: Retour
1019 1020 button_cancel: Annuler
1020 1021 button_activate: Activer
1021 1022 button_sort: Trier
1022 1023 button_log_time: Saisir temps
1023 1024 button_rollback: Revenir Γ  cette version
1024 1025 button_watch: Surveiller
1025 1026 button_unwatch: Ne plus surveiller
1026 1027 button_reply: RΓ©pondre
1027 1028 button_archive: Archiver
1028 1029 button_unarchive: DΓ©sarchiver
1029 1030 button_reset: RΓ©initialiser
1030 1031 button_rename: Renommer
1031 1032 button_change_password: Changer de mot de passe
1032 1033 button_copy: Copier
1033 1034 button_copy_and_follow: Copier et suivre
1034 1035 button_annotate: Annoter
1035 1036 button_update: Mettre Γ  jour
1036 1037 button_configure: Configurer
1037 1038 button_quote: Citer
1038 1039 button_duplicate: Dupliquer
1039 1040 button_show: Afficher
1040 1041 button_hide: Cacher
1041 1042 button_edit_section: Modifier cette section
1042 1043 button_export: Exporter
1043 1044 button_delete_my_account: Supprimer mon compte
1044 1045 button_close: Fermer
1045 1046 button_reopen: RΓ©ouvrir
1046 1047 button_import: Importer
1047 1048
1048 1049 status_active: actif
1049 1050 status_registered: enregistrΓ©
1050 1051 status_locked: verrouillΓ©
1051 1052
1052 1053 project_status_active: actif
1053 1054 project_status_closed: fermΓ©
1054 1055 project_status_archived: archivΓ©
1055 1056
1056 1057 version_status_open: ouvert
1057 1058 version_status_locked: verrouillΓ©
1058 1059 version_status_closed: fermΓ©
1059 1060
1060 1061 field_active: Actif
1061 1062
1062 1063 text_select_mail_notifications: Actions pour lesquelles une notification par e-mail est envoyΓ©e
1063 1064 text_regexp_info: ex. ^[A-Z0-9]+$
1064 1065 text_min_max_length_info: 0 pour aucune restriction
1065 1066 text_project_destroy_confirmation: Êtes-vous sûr de vouloir supprimer ce projet et toutes ses données ?
1066 1067 text_subprojects_destroy_warning: "Ses sous-projets : %{value} seront Γ©galement supprimΓ©s."
1067 1068 text_workflow_edit: SΓ©lectionner un tracker et un rΓ΄le pour Γ©diter le workflow
1068 1069 text_are_you_sure: Êtes-vous sûr ?
1069 1070 text_journal_changed: "%{label} changΓ© de %{old} Γ  %{new}"
1070 1071 text_journal_changed_no_detail: "%{label} mis Γ  jour"
1071 1072 text_journal_set_to: "%{label} mis Γ  %{value}"
1072 1073 text_journal_deleted: "%{label} %{old} supprimΓ©"
1073 1074 text_journal_added: "%{label} %{value} ajoutΓ©"
1074 1075 text_tip_issue_begin_day: tΓ’che commenΓ§ant ce jour
1075 1076 text_tip_issue_end_day: tΓ’che finissant ce jour
1076 1077 text_tip_issue_begin_end_day: tΓ’che commenΓ§ant et finissant ce jour
1077 1078 text_project_identifier_info: 'Seuls les lettres minuscules (a-z), chiffres, tirets et tirets bas sont autorisΓ©s, doit commencer par une minuscule.<br />Un fois sauvegardΓ©, l''identifiant ne pourra plus Γͺtre modifiΓ©.'
1078 1079 text_caracters_maximum: "%{count} caractères maximum."
1079 1080 text_caracters_minimum: "%{count} caractères minimum."
1080 1081 text_length_between: "Longueur comprise entre %{min} et %{max} caractères."
1081 1082 text_tracker_no_workflow: Aucun worflow n'est dΓ©fini pour ce tracker
1082 1083 text_unallowed_characters: Caractères non autorisés
1083 1084 text_comma_separated: Plusieurs valeurs possibles (sΓ©parΓ©es par des virgules).
1084 1085 text_line_separated: Plusieurs valeurs possibles (une valeur par ligne).
1085 1086 text_issues_ref_in_commit_messages: RΓ©fΓ©rencement et rΓ©solution des demandes dans les commentaires de commits
1086 1087 text_issue_added: "La demande %{id} a Γ©tΓ© soumise par %{author}."
1087 1088 text_issue_updated: "La demande %{id} a Γ©tΓ© mise Γ  jour par %{author}."
1088 1089 text_wiki_destroy_confirmation: Etes-vous sΓ»r de vouloir supprimer ce wiki et tout son contenu ?
1089 1090 text_issue_category_destroy_question: "%{count} demandes sont affectΓ©es Γ  cette catΓ©gorie. Que voulez-vous faire ?"
1090 1091 text_issue_category_destroy_assignments: N'affecter les demandes Γ  aucune autre catΓ©gorie
1091 1092 text_issue_category_reassign_to: RΓ©affecter les demandes Γ  cette catΓ©gorie
1092 1093 text_user_mail_option: "Pour les projets non sΓ©lectionnΓ©s, vous recevrez seulement des notifications pour ce que vous surveillez ou Γ  quoi vous participez (exemple: demandes dont vous Γͺtes l'auteur ou la personne assignΓ©e)."
1093 1094 text_no_configuration_data: "Les rΓ΄les, trackers, statuts et le workflow ne sont pas encore paramΓ©trΓ©s.\nIl est vivement recommandΓ© de charger le paramΓ©trage par defaut. Vous pourrez le modifier une fois chargΓ©."
1094 1095 text_load_default_configuration: Charger le paramΓ©trage par dΓ©faut
1095 1096 text_status_changed_by_changeset: "AppliquΓ© par commit %{value}."
1096 1097 text_time_logged_by_changeset: "AppliquΓ© par commit %{value}"
1097 1098 text_issues_destroy_confirmation: 'Êtes-vous sûr de vouloir supprimer la ou les demandes(s) selectionnée(s) ?'
1098 1099 text_issues_destroy_descendants_confirmation: "Cela entrainera Γ©galement la suppression de %{count} sous-tΓ’che(s)."
1099 1100 text_time_entries_destroy_confirmation: "Etes-vous sΓ»r de vouloir supprimer les temps passΓ©s sΓ©lectionnΓ©s ?"
1100 1101 text_select_project_modules: 'SΓ©lectionner les modules Γ  activer pour ce projet :'
1101 1102 text_default_administrator_account_changed: Compte administrateur par dΓ©faut changΓ©
1102 1103 text_file_repository_writable: RΓ©pertoire de stockage des fichiers accessible en Γ©criture
1103 1104 text_plugin_assets_writable: RΓ©pertoire public des plugins accessible en Γ©criture
1104 1105 text_rmagick_available: Bibliothèque RMagick présente (optionnelle)
1105 1106 text_convert_available: Binaire convert de ImageMagick prΓ©sent (optionel)
1106 1107 text_destroy_time_entries_question: "%{hours} heures ont Γ©tΓ© enregistrΓ©es sur les demandes Γ  supprimer. Que voulez-vous faire ?"
1107 1108 text_destroy_time_entries: Supprimer les heures
1108 1109 text_assign_time_entries_to_project: Reporter les heures sur le projet
1109 1110 text_reassign_time_entries: 'Reporter les heures sur cette demande:'
1110 1111 text_user_wrote: "%{value} a Γ©crit :"
1111 1112 text_enumeration_destroy_question: "La valeur Β« %{name} Β» est affectΓ©e Γ  %{count} objet(s)."
1112 1113 text_enumeration_category_reassign_to: 'RΓ©affecter les objets Γ  cette valeur:'
1113 1114 text_email_delivery_not_configured: "L'envoi de mail n'est pas configurΓ©, les notifications sont dΓ©sactivΓ©es.\nConfigurez votre serveur SMTP dans config/configuration.yml et redΓ©marrez l'application pour les activer."
1114 1115 text_repository_usernames_mapping: "Vous pouvez sΓ©lectionner ou modifier l'utilisateur Redmine associΓ© Γ  chaque nom d'utilisateur figurant dans l'historique du dΓ©pΓ΄t.\nLes utilisateurs avec le mΓͺme identifiant ou la mΓͺme adresse mail seront automatiquement associΓ©s."
1115 1116 text_diff_truncated: '... Ce diffΓ©rentiel a Γ©tΓ© tronquΓ© car il excΓ¨de la taille maximale pouvant Γͺtre affichΓ©e.'
1116 1117 text_custom_field_possible_values_info: 'Une ligne par valeur'
1117 1118 text_wiki_page_destroy_question: "Cette page possède %{descendants} sous-page(s) et descendante(s). Que voulez-vous faire ?"
1118 1119 text_wiki_page_nullify_children: "Conserver les sous-pages en tant que pages racines"
1119 1120 text_wiki_page_destroy_children: "Supprimer les sous-pages et toutes leurs descedantes"
1120 1121 text_wiki_page_reassign_children: "RΓ©affecter les sous-pages Γ  cette page"
1121 1122 text_own_membership_delete_confirmation: "Vous allez supprimer tout ou partie de vos permissions sur ce projet et ne serez peut-Γͺtre plus autorisΓ© Γ  modifier ce projet.\nEtes-vous sΓ»r de vouloir continuer ?"
1122 1123 text_zoom_in: Zoom avant
1123 1124 text_zoom_out: Zoom arrière
1124 1125 text_warn_on_leaving_unsaved: "Cette page contient du texte non sauvegardΓ© qui sera perdu si vous quittez la page."
1125 1126 text_scm_path_encoding_note: "DΓ©faut : UTF-8"
1126 1127 text_subversion_repository_note: "Exemples (en fonction des protocoles supportΓ©s) : file:///, http://, https://, svn://, svn+[tunnelscheme]://"
1127 1128 text_git_repository_note: "Chemin vers un dΓ©pΓ΄t vide et local (exemples : /gitrepo, c:\\gitrepo)"
1128 1129 text_mercurial_repository_note: "Chemin vers un dΓ©pΓ΄t local (exemples : /hgrepo, c:\\hgrepo)"
1129 1130 text_scm_command: Commande
1130 1131 text_scm_command_version: Version
1131 1132 text_scm_config: Vous pouvez configurer les commandes des SCM dans config/configuration.yml. Redémarrer l'application après modification.
1132 1133 text_scm_command_not_available: Ce SCM n'est pas disponible. Vérifier les paramètres dans la section administration.
1133 1134 text_issue_conflict_resolution_overwrite: "Appliquer quand mΓͺme ma mise Γ  jour (les notes prΓ©cΓ©dentes seront conservΓ©es mais des changements pourront Γͺtre Γ©crasΓ©s)"
1134 1135 text_issue_conflict_resolution_add_notes: "Ajouter mes notes et ignorer mes autres changements"
1135 1136 text_issue_conflict_resolution_cancel: "Annuler ma mise Γ  jour et rΓ©afficher %{link}"
1136 1137 text_account_destroy_confirmation: "Êtes-vous sûr de vouloir continuer ?\nVotre compte sera définitivement supprimé, sans aucune possibilité de le réactiver."
1137 1138 text_session_expiration_settings: "Attention : le changement de ces paramètres peut entrainer l'expiration des sessions utilisateurs en cours, y compris la vôtre."
1138 1139 text_project_closed: Ce projet est fermΓ© et accessible en lecture seule.
1139 1140 text_turning_multiple_off: "Si vous dΓ©sactivez les valeurs multiples, les valeurs multiples seront supprimΓ©es pour n'en conserver qu'une par objet."
1140 1141
1141 1142 default_role_manager: Manager
1142 1143 default_role_developer: DΓ©veloppeur
1143 1144 default_role_reporter: Rapporteur
1144 1145 default_tracker_bug: Anomalie
1145 1146 default_tracker_feature: Evolution
1146 1147 default_tracker_support: Assistance
1147 1148 default_issue_status_new: Nouveau
1148 1149 default_issue_status_in_progress: En cours
1149 1150 default_issue_status_resolved: RΓ©solu
1150 1151 default_issue_status_feedback: Commentaire
1151 1152 default_issue_status_closed: FermΓ©
1152 1153 default_issue_status_rejected: RejetΓ©
1153 1154 default_doc_category_user: Documentation utilisateur
1154 1155 default_doc_category_tech: Documentation technique
1155 1156 default_priority_low: Bas
1156 1157 default_priority_normal: Normal
1157 1158 default_priority_high: Haut
1158 1159 default_priority_urgent: Urgent
1159 1160 default_priority_immediate: ImmΓ©diat
1160 1161 default_activity_design: Conception
1161 1162 default_activity_development: DΓ©veloppement
1162 1163
1163 1164 enumeration_issue_priorities: PrioritΓ©s des demandes
1164 1165 enumeration_doc_categories: CatΓ©gories des documents
1165 1166 enumeration_activities: ActivitΓ©s (suivi du temps)
1166 1167 enumeration_system_activity: Activité système
1167 1168 description_filter: Filtre
1168 1169 description_search: Champ de recherche
1169 1170 description_choose_project: Projets
1170 1171 description_project_scope: Périmètre de recherche
1171 1172 description_notes: Notes
1172 1173 description_message_content: Contenu du message
1173 1174 description_query_sort_criteria_attribute: Critère de tri
1174 1175 description_query_sort_criteria_direction: Ordre de tri
1175 1176 description_user_mail_notification: Option de notification
1176 1177 description_available_columns: Colonnes disponibles
1177 1178 description_selected_columns: Colonnes sΓ©lectionnΓ©es
1178 1179 description_all_columns: Toutes les colonnes
1179 1180 description_issue_category_reassign: Choisir une catΓ©gorie
1180 1181 description_wiki_subpages_reassign: Choisir une nouvelle page parent
1181 1182 description_date_range_list: Choisir une pΓ©riode prΓ©dΓ©finie
1182 1183 description_date_range_interval: Choisir une pΓ©riode
1183 1184 description_date_from: Date de dΓ©but
1184 1185 description_date_to: Date de fin
1185 1186 text_repository_identifier_info: 'Seuls les lettres minuscules (a-z), chiffres, tirets et tirets bas sont autorisΓ©s.<br />Un fois sauvegardΓ©, l''identifiant ne pourra plus Γͺtre modifiΓ©.'
1186 1187 label_parent_task_attributes_derived: Calculated from subtasks
1187 1188 label_parent_task_attributes_independent: Independent of subtasks
@@ -1,4437 +1,4450
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2015 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
20 20 class IssuesControllerTest < ActionController::TestCase
21 21 fixtures :projects,
22 22 :users, :email_addresses,
23 23 :roles,
24 24 :members,
25 25 :member_roles,
26 26 :issues,
27 27 :issue_statuses,
28 28 :issue_relations,
29 29 :versions,
30 30 :trackers,
31 31 :projects_trackers,
32 32 :issue_categories,
33 33 :enabled_modules,
34 34 :enumerations,
35 35 :attachments,
36 36 :workflows,
37 37 :custom_fields,
38 38 :custom_values,
39 39 :custom_fields_projects,
40 40 :custom_fields_trackers,
41 41 :time_entries,
42 42 :journals,
43 43 :journal_details,
44 44 :queries,
45 45 :repositories,
46 46 :changesets
47 47
48 48 include Redmine::I18n
49 49
50 50 def setup
51 51 User.current = nil
52 52 end
53 53
54 54 def test_index
55 55 with_settings :default_language => "en" do
56 56 get :index
57 57 assert_response :success
58 58 assert_template 'index'
59 59 assert_not_nil assigns(:issues)
60 60 assert_nil assigns(:project)
61 61
62 62 # links to visible issues
63 63 assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
64 64 assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
65 65 # private projects hidden
66 66 assert_select 'a[href="/issues/6"]', 0
67 67 assert_select 'a[href="/issues/4"]', 0
68 68 # project column
69 69 assert_select 'th', :text => /Project/
70 70 end
71 71 end
72 72
73 73 def test_index_should_not_list_issues_when_module_disabled
74 74 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
75 75 get :index
76 76 assert_response :success
77 77 assert_template 'index'
78 78 assert_not_nil assigns(:issues)
79 79 assert_nil assigns(:project)
80 80
81 81 assert_select 'a[href="/issues/1"]', 0
82 82 assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
83 83 end
84 84
85 85 def test_index_should_list_visible_issues_only
86 86 get :index, :per_page => 100
87 87 assert_response :success
88 88 assert_not_nil assigns(:issues)
89 89 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
90 90 end
91 91
92 92 def test_index_with_project
93 93 Setting.display_subprojects_issues = 0
94 94 get :index, :project_id => 1
95 95 assert_response :success
96 96 assert_template 'index'
97 97 assert_not_nil assigns(:issues)
98 98
99 99 assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
100 100 assert_select 'a[href="/issues/5"]', 0
101 101 end
102 102
103 103 def test_index_with_project_and_subprojects
104 104 Setting.display_subprojects_issues = 1
105 105 get :index, :project_id => 1
106 106 assert_response :success
107 107 assert_template 'index'
108 108 assert_not_nil assigns(:issues)
109 109
110 110 assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
111 111 assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
112 112 assert_select 'a[href="/issues/6"]', 0
113 113 end
114 114
115 115 def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission
116 116 @request.session[:user_id] = 2
117 117 Setting.display_subprojects_issues = 1
118 118 get :index, :project_id => 1
119 119 assert_response :success
120 120 assert_template 'index'
121 121 assert_not_nil assigns(:issues)
122 122
123 123 assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
124 124 assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
125 125 assert_select 'a[href="/issues/6"]', :text => /Issue of a private subproject/
126 126 end
127 127
128 128 def test_index_with_project_and_default_filter
129 129 get :index, :project_id => 1, :set_filter => 1
130 130 assert_response :success
131 131 assert_template 'index'
132 132 assert_not_nil assigns(:issues)
133 133
134 134 query = assigns(:query)
135 135 assert_not_nil query
136 136 # default filter
137 137 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
138 138 end
139 139
140 140 def test_index_with_project_and_filter
141 141 get :index, :project_id => 1, :set_filter => 1,
142 142 :f => ['tracker_id'],
143 143 :op => {'tracker_id' => '='},
144 144 :v => {'tracker_id' => ['1']}
145 145 assert_response :success
146 146 assert_template 'index'
147 147 assert_not_nil assigns(:issues)
148 148
149 149 query = assigns(:query)
150 150 assert_not_nil query
151 151 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
152 152 end
153 153
154 154 def test_index_with_short_filters
155 155 to_test = {
156 156 'status_id' => {
157 157 'o' => { :op => 'o', :values => [''] },
158 158 'c' => { :op => 'c', :values => [''] },
159 159 '7' => { :op => '=', :values => ['7'] },
160 160 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
161 161 '=7' => { :op => '=', :values => ['7'] },
162 162 '!3' => { :op => '!', :values => ['3'] },
163 163 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
164 164 'subject' => {
165 165 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
166 166 'o' => { :op => '=', :values => ['o'] },
167 167 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
168 168 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
169 169 'tracker_id' => {
170 170 '3' => { :op => '=', :values => ['3'] },
171 171 '=3' => { :op => '=', :values => ['3'] }},
172 172 'start_date' => {
173 173 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
174 174 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
175 175 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
176 176 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
177 177 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
178 178 '<t+2' => { :op => '<t+', :values => ['2'] },
179 179 '>t+2' => { :op => '>t+', :values => ['2'] },
180 180 't+2' => { :op => 't+', :values => ['2'] },
181 181 't' => { :op => 't', :values => [''] },
182 182 'w' => { :op => 'w', :values => [''] },
183 183 '>t-2' => { :op => '>t-', :values => ['2'] },
184 184 '<t-2' => { :op => '<t-', :values => ['2'] },
185 185 't-2' => { :op => 't-', :values => ['2'] }},
186 186 'created_on' => {
187 187 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
188 188 '<t-2' => { :op => '<t-', :values => ['2'] },
189 189 '>t-2' => { :op => '>t-', :values => ['2'] },
190 190 't-2' => { :op => 't-', :values => ['2'] }},
191 191 'cf_1' => {
192 192 'c' => { :op => '=', :values => ['c'] },
193 193 '!c' => { :op => '!', :values => ['c'] },
194 194 '!*' => { :op => '!*', :values => [''] },
195 195 '*' => { :op => '*', :values => [''] }},
196 196 'estimated_hours' => {
197 197 '=13.4' => { :op => '=', :values => ['13.4'] },
198 198 '>=45' => { :op => '>=', :values => ['45'] },
199 199 '<=125' => { :op => '<=', :values => ['125'] },
200 200 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
201 201 '!*' => { :op => '!*', :values => [''] },
202 202 '*' => { :op => '*', :values => [''] }}
203 203 }
204 204
205 205 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
206 206
207 207 to_test.each do |field, expression_and_expected|
208 208 expression_and_expected.each do |filter_expression, expected|
209 209
210 210 get :index, :set_filter => 1, field => filter_expression
211 211
212 212 assert_response :success
213 213 assert_template 'index'
214 214 assert_not_nil assigns(:issues)
215 215
216 216 query = assigns(:query)
217 217 assert_not_nil query
218 218 assert query.has_filter?(field)
219 219 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
220 220 end
221 221 end
222 222 end
223 223
224 224 def test_index_with_project_and_empty_filters
225 225 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
226 226 assert_response :success
227 227 assert_template 'index'
228 228 assert_not_nil assigns(:issues)
229 229
230 230 query = assigns(:query)
231 231 assert_not_nil query
232 232 # no filter
233 233 assert_equal({}, query.filters)
234 234 end
235 235
236 236 def test_index_with_project_custom_field_filter
237 237 field = ProjectCustomField.create!(:name => 'Client', :is_filter => true, :field_format => 'string')
238 238 CustomValue.create!(:custom_field => field, :customized => Project.find(3), :value => 'Foo')
239 239 CustomValue.create!(:custom_field => field, :customized => Project.find(5), :value => 'Foo')
240 240 filter_name = "project.cf_#{field.id}"
241 241 @request.session[:user_id] = 1
242 242
243 243 get :index, :set_filter => 1,
244 244 :f => [filter_name],
245 245 :op => {filter_name => '='},
246 246 :v => {filter_name => ['Foo']}
247 247 assert_response :success
248 248 assert_template 'index'
249 249 assert_equal [3, 5], assigns(:issues).map(&:project_id).uniq.sort
250 250 end
251 251
252 252 def test_index_with_query
253 253 get :index, :project_id => 1, :query_id => 5
254 254 assert_response :success
255 255 assert_template 'index'
256 256 assert_not_nil assigns(:issues)
257 257 assert_nil assigns(:issue_count_by_group)
258 258 end
259 259
260 260 def test_index_with_query_grouped_by_tracker
261 261 get :index, :project_id => 1, :query_id => 6
262 262 assert_response :success
263 263 assert_template 'index'
264 264 assert_not_nil assigns(:issues)
265 265 assert_not_nil assigns(:issue_count_by_group)
266 266 end
267 267
268 268 def test_index_with_query_grouped_and_sorted_by_category
269 269 get :index, :project_id => 1, :set_filter => 1, :group_by => "category", :sort => "category"
270 270 assert_response :success
271 271 assert_template 'index'
272 272 assert_not_nil assigns(:issues)
273 273 assert_not_nil assigns(:issue_count_by_group)
274 274 end
275 275
276 276 def test_index_with_query_grouped_by_list_custom_field
277 277 get :index, :project_id => 1, :query_id => 9
278 278 assert_response :success
279 279 assert_template 'index'
280 280 assert_not_nil assigns(:issues)
281 281 assert_not_nil assigns(:issue_count_by_group)
282 282 end
283 283
284 284 def test_index_with_query_grouped_by_user_custom_field
285 285 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
286 286 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
287 287 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
288 288 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
289 289 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
290 290
291 291 get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}"
292 292 assert_response :success
293 293
294 294 assert_select 'tr.group', 3
295 295 assert_select 'tr.group' do
296 296 assert_select 'a', :text => 'John Smith'
297 297 assert_select 'span.count', :text => '1'
298 298 end
299 299 assert_select 'tr.group' do
300 300 assert_select 'a', :text => 'Dave Lopper'
301 301 assert_select 'span.count', :text => '2'
302 302 end
303 303 end
304 304
305 305 def test_index_grouped_by_boolean_custom_field_should_distinguish_blank_and_false_values
306 306 cf = IssueCustomField.create!(:name => 'Bool', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'bool')
307 307 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '1')
308 308 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '0')
309 309 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '')
310 310
311 311 with_settings :default_language => 'en' do
312 312 get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}"
313 313 assert_response :success
314 314 end
315 315
316 316 assert_select 'tr.group', 3
317 317 assert_select 'tr.group', :text => /Yes/
318 318 assert_select 'tr.group', :text => /No/
319 319 assert_select 'tr.group', :text => /blank/
320 320 end
321 321
322 322 def test_index_grouped_by_boolean_custom_field_with_false_group_in_first_position_should_show_the_group
323 323 cf = IssueCustomField.create!(:name => 'Bool', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'bool', :is_filter => true)
324 324 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '0')
325 325 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '0')
326 326
327 327 with_settings :default_language => 'en' do
328 328 get :index, :project_id => 1, :set_filter => 1, "cf_#{cf.id}" => "*", :group_by => "cf_#{cf.id}"
329 329 assert_response :success
330 330 assert_equal [1, 2], assigns(:issues).map(&:id).sort
331 331 end
332 332
333 333 assert_select 'tr.group', 1
334 334 assert_select 'tr.group', :text => /No/
335 335 end
336 336
337 337 def test_index_with_query_grouped_by_tracker_in_normal_order
338 338 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
339 339
340 340 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc'
341 341 assert_response :success
342 342
343 343 trackers = assigns(:issues).map(&:tracker).uniq
344 344 assert_equal [1, 2, 3], trackers.map(&:id)
345 345 end
346 346
347 347 def test_index_with_query_grouped_by_tracker_in_reverse_order
348 348 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
349 349
350 350 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc,tracker:desc'
351 351 assert_response :success
352 352
353 353 trackers = assigns(:issues).map(&:tracker).uniq
354 354 assert_equal [3, 2, 1], trackers.map(&:id)
355 355 end
356 356
357 357 def test_index_with_query_id_and_project_id_should_set_session_query
358 358 get :index, :project_id => 1, :query_id => 4
359 359 assert_response :success
360 360 assert_kind_of Hash, session[:query]
361 361 assert_equal 4, session[:query][:id]
362 362 assert_equal 1, session[:query][:project_id]
363 363 end
364 364
365 365 def test_index_with_invalid_query_id_should_respond_404
366 366 get :index, :project_id => 1, :query_id => 999
367 367 assert_response 404
368 368 end
369 369
370 370 def test_index_with_cross_project_query_in_session_should_show_project_issues
371 371 q = IssueQuery.create!(:name => "test", :user_id => 2, :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
372 372 @request.session[:query] = {:id => q.id, :project_id => 1}
373 373
374 374 with_settings :display_subprojects_issues => '0' do
375 375 get :index, :project_id => 1
376 376 end
377 377 assert_response :success
378 378 assert_not_nil assigns(:query)
379 379 assert_equal q.id, assigns(:query).id
380 380 assert_equal 1, assigns(:query).project_id
381 381 assert_equal [1], assigns(:issues).map(&:project_id).uniq
382 382 end
383 383
384 384 def test_private_query_should_not_be_available_to_other_users
385 385 q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
386 386 @request.session[:user_id] = 3
387 387
388 388 get :index, :query_id => q.id
389 389 assert_response 403
390 390 end
391 391
392 392 def test_private_query_should_be_available_to_its_user
393 393 q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
394 394 @request.session[:user_id] = 2
395 395
396 396 get :index, :query_id => q.id
397 397 assert_response :success
398 398 end
399 399
400 400 def test_public_query_should_be_available_to_other_users
401 401 q = IssueQuery.create!(:name => "public", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => nil)
402 402 @request.session[:user_id] = 3
403 403
404 404 get :index, :query_id => q.id
405 405 assert_response :success
406 406 end
407 407
408 408 def test_index_should_omit_page_param_in_export_links
409 409 get :index, :page => 2
410 410 assert_response :success
411 411 assert_select 'a.atom[href="/issues.atom"]'
412 412 assert_select 'a.csv[href="/issues.csv"]'
413 413 assert_select 'a.pdf[href="/issues.pdf"]'
414 414 assert_select 'form#csv-export-form[action="/issues.csv"]'
415 415 end
416 416
417 417 def test_index_should_not_warn_when_not_exceeding_export_limit
418 418 with_settings :issues_export_limit => 200 do
419 419 get :index
420 420 assert_select '#csv-export-options p.icon-warning', 0
421 421 end
422 422 end
423 423
424 424 def test_index_should_warn_when_exceeding_export_limit
425 425 with_settings :issues_export_limit => 2 do
426 426 get :index
427 427 assert_select '#csv-export-options p.icon-warning', :text => %r{limit: 2}
428 428 end
429 429 end
430 430
431 431 def test_index_csv
432 432 get :index, :format => 'csv'
433 433 assert_response :success
434 434 assert_not_nil assigns(:issues)
435 435 assert_equal 'text/csv; header=present', @response.content_type
436 436 assert @response.body.starts_with?("#,")
437 437 lines = @response.body.chomp.split("\n")
438 438 assert_equal assigns(:query).columns.size, lines[0].split(',').size
439 439 end
440 440
441 441 def test_index_csv_with_project
442 442 get :index, :project_id => 1, :format => 'csv'
443 443 assert_response :success
444 444 assert_not_nil assigns(:issues)
445 445 assert_equal 'text/csv; header=present', @response.content_type
446 446 end
447 447
448 448 def test_index_csv_with_description
449 449 Issue.generate!(:description => 'test_index_csv_with_description')
450 450
451 451 with_settings :default_language => 'en' do
452 452 get :index, :format => 'csv', :csv => {:description => '1'}
453 453 assert_response :success
454 454 assert_not_nil assigns(:issues)
455 455 end
456 456
457 457 assert_equal 'text/csv; header=present', response.content_type
458 458 headers = response.body.chomp.split("\n").first.split(',')
459 459 assert_include 'Description', headers
460 460 assert_include 'test_index_csv_with_description', response.body
461 461 end
462 462
463 463 def test_index_csv_with_spent_time_column
464 464 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2)
465 465 TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today)
466 466
467 467 get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours)
468 468 assert_response :success
469 469 assert_equal 'text/csv; header=present', @response.content_type
470 470 lines = @response.body.chomp.split("\n")
471 471 assert_include "#{issue.id},#{issue.subject},7.33", lines
472 472 end
473 473
474 474 def test_index_csv_with_all_columns
475 475 get :index, :format => 'csv', :csv => {:columns => 'all'}
476 476 assert_response :success
477 477 assert_not_nil assigns(:issues)
478 478 assert_equal 'text/csv; header=present', @response.content_type
479 479 assert_match /\A#,/, response.body
480 480 lines = response.body.chomp.split("\n")
481 481 assert_equal assigns(:query).available_inline_columns.size, lines[0].split(',').size
482 482 end
483 483
484 484 def test_index_csv_with_multi_column_field
485 485 CustomField.find(1).update_attribute :multiple, true
486 486 issue = Issue.find(1)
487 487 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
488 488 issue.save!
489 489
490 490 get :index, :format => 'csv', :csv => {:columns => 'all'}
491 491 assert_response :success
492 492 lines = @response.body.chomp.split("\n")
493 493 assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
494 494 end
495 495
496 496 def test_index_csv_should_format_float_custom_fields_with_csv_decimal_separator
497 497 field = IssueCustomField.create!(:name => 'Float', :is_for_all => true, :tracker_ids => [1], :field_format => 'float')
498 498 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id => '185.6'})
499 499
500 500 with_settings :default_language => 'fr' do
501 501 get :index, :format => 'csv', :csv => {:columns => 'all'}
502 502 assert_response :success
503 503 issue_line = response.body.chomp.split("\n").map {|line| line.split(';')}.detect {|line| line[0]==issue.id.to_s}
504 504 assert_include '185,60', issue_line
505 505 end
506 506
507 507 with_settings :default_language => 'en' do
508 508 get :index, :format => 'csv', :csv => {:columns => 'all'}
509 509 assert_response :success
510 510 issue_line = response.body.chomp.split("\n").map {|line| line.split(',')}.detect {|line| line[0]==issue.id.to_s}
511 511 assert_include '185.60', issue_line
512 512 end
513 513 end
514 514
515 515 def test_index_csv_should_fill_parent_column_with_parent_id
516 516 Issue.delete_all
517 517 parent = Issue.generate!
518 518 child = Issue.generate!(:parent_issue_id => parent.id)
519 519
520 520 with_settings :default_language => 'en' do
521 521 get :index, :format => 'csv', :c => %w(parent)
522 522 end
523 523 lines = response.body.split("\n")
524 524 assert_include "#{child.id},#{parent.id}", lines
525 525 end
526 526
527 527 def test_index_csv_big_5
528 528 with_settings :default_language => "zh-TW" do
529 529 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88".force_encoding('UTF-8')
530 530 str_big5 = "\xa4@\xa4\xeb".force_encoding('Big5')
531 531 issue = Issue.generate!(:subject => str_utf8)
532 532
533 533 get :index, :project_id => 1,
534 534 :f => ['subject'],
535 535 :op => '=', :values => [str_utf8],
536 536 :format => 'csv'
537 537 assert_equal 'text/csv; header=present', @response.content_type
538 538 lines = @response.body.chomp.split("\n")
539 539 header = lines[0]
540 540 status = "\xaa\xac\xbaA".force_encoding('Big5')
541 541 assert header.include?(status)
542 542 issue_line = lines.find {|l| l =~ /^#{issue.id},/}
543 543 assert issue_line.include?(str_big5)
544 544 end
545 545 end
546 546
547 547 def test_index_csv_cannot_convert_should_be_replaced_big_5
548 548 with_settings :default_language => "zh-TW" do
549 549 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8')
550 550 issue = Issue.generate!(:subject => str_utf8)
551 551
552 552 get :index, :project_id => 1,
553 553 :f => ['subject'],
554 554 :op => '=', :values => [str_utf8],
555 555 :c => ['status', 'subject'],
556 556 :format => 'csv',
557 557 :set_filter => 1
558 558 assert_equal 'text/csv; header=present', @response.content_type
559 559 lines = @response.body.chomp.split("\n")
560 560 header = lines[0]
561 561 issue_line = lines.find {|l| l =~ /^#{issue.id},/}
562 562 s1 = "\xaa\xac\xbaA".force_encoding('Big5') # status
563 563 assert header.include?(s1)
564 564 s2 = issue_line.split(",")[2]
565 565 s3 = "\xa5H?".force_encoding('Big5') # subject
566 566 assert_equal s3, s2
567 567 end
568 568 end
569 569
570 570 def test_index_csv_tw
571 571 with_settings :default_language => "zh-TW" do
572 572 str1 = "test_index_csv_tw"
573 573 issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
574 574
575 575 get :index, :project_id => 1,
576 576 :f => ['subject'],
577 577 :op => '=', :values => [str1],
578 578 :c => ['estimated_hours', 'subject'],
579 579 :format => 'csv',
580 580 :set_filter => 1
581 581 assert_equal 'text/csv; header=present', @response.content_type
582 582 lines = @response.body.chomp.split("\n")
583 583 assert_include "#{issue.id},1234.50,#{str1}", lines
584 584 end
585 585 end
586 586
587 587 def test_index_csv_fr
588 588 with_settings :default_language => "fr" do
589 589 str1 = "test_index_csv_fr"
590 590 issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
591 591
592 592 get :index, :project_id => 1,
593 593 :f => ['subject'],
594 594 :op => '=', :values => [str1],
595 595 :c => ['estimated_hours', 'subject'],
596 596 :format => 'csv',
597 597 :set_filter => 1
598 598 assert_equal 'text/csv; header=present', @response.content_type
599 599 lines = @response.body.chomp.split("\n")
600 600 assert_include "#{issue.id};1234,50;#{str1}", lines
601 601 end
602 602 end
603 603
604 604 def test_index_pdf
605 605 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
606 606 with_settings :default_language => lang do
607 607
608 608 get :index
609 609 assert_response :success
610 610 assert_template 'index'
611 611
612 612 get :index, :format => 'pdf'
613 613 assert_response :success
614 614 assert_not_nil assigns(:issues)
615 615 assert_equal 'application/pdf', @response.content_type
616 616
617 617 get :index, :project_id => 1, :format => 'pdf'
618 618 assert_response :success
619 619 assert_not_nil assigns(:issues)
620 620 assert_equal 'application/pdf', @response.content_type
621 621
622 622 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
623 623 assert_response :success
624 624 assert_not_nil assigns(:issues)
625 625 assert_equal 'application/pdf', @response.content_type
626 626 end
627 627 end
628 628 end
629 629
630 630 def test_index_pdf_with_query_grouped_by_list_custom_field
631 631 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
632 632 assert_response :success
633 633 assert_not_nil assigns(:issues)
634 634 assert_not_nil assigns(:issue_count_by_group)
635 635 assert_equal 'application/pdf', @response.content_type
636 636 end
637 637
638 638 def test_index_atom
639 639 get :index, :project_id => 'ecookbook', :format => 'atom'
640 640 assert_response :success
641 641 assert_template 'common/feed'
642 642 assert_equal 'application/atom+xml', response.content_type
643 643
644 644 assert_select 'feed' do
645 645 assert_select 'link[rel=self][href=?]', 'http://test.host/projects/ecookbook/issues.atom'
646 646 assert_select 'link[rel=alternate][href=?]', 'http://test.host/projects/ecookbook/issues'
647 647 assert_select 'entry link[href=?]', 'http://test.host/issues/1'
648 648 end
649 649 end
650 650
651 651 def test_index_sort
652 652 get :index, :sort => 'tracker,id:desc'
653 653 assert_response :success
654 654
655 655 sort_params = @request.session['issues_index_sort']
656 656 assert sort_params.is_a?(String)
657 657 assert_equal 'tracker,id:desc', sort_params
658 658
659 659 issues = assigns(:issues)
660 660 assert_not_nil issues
661 661 assert !issues.empty?
662 662 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
663 663 assert_select 'table.issues.sort-by-tracker.sort-asc'
664 664 end
665 665
666 666 def test_index_sort_by_field_not_included_in_columns
667 667 Setting.issue_list_default_columns = %w(subject author)
668 668 get :index, :sort => 'tracker'
669 669 end
670 670
671 671 def test_index_sort_by_assigned_to
672 672 get :index, :sort => 'assigned_to'
673 673 assert_response :success
674 674 assignees = assigns(:issues).collect(&:assigned_to).compact
675 675 assert_equal assignees.sort, assignees
676 676 assert_select 'table.issues.sort-by-assigned-to.sort-asc'
677 677 end
678 678
679 679 def test_index_sort_by_assigned_to_desc
680 680 get :index, :sort => 'assigned_to:desc'
681 681 assert_response :success
682 682 assignees = assigns(:issues).collect(&:assigned_to).compact
683 683 assert_equal assignees.sort.reverse, assignees
684 684 assert_select 'table.issues.sort-by-assigned-to.sort-desc'
685 685 end
686 686
687 687 def test_index_group_by_assigned_to
688 688 get :index, :group_by => 'assigned_to', :sort => 'priority'
689 689 assert_response :success
690 690 end
691 691
692 692 def test_index_sort_by_author
693 693 get :index, :sort => 'author'
694 694 assert_response :success
695 695 authors = assigns(:issues).collect(&:author)
696 696 assert_equal authors.sort, authors
697 697 end
698 698
699 699 def test_index_sort_by_author_desc
700 700 get :index, :sort => 'author:desc'
701 701 assert_response :success
702 702 authors = assigns(:issues).collect(&:author)
703 703 assert_equal authors.sort.reverse, authors
704 704 end
705 705
706 706 def test_index_group_by_author
707 707 get :index, :group_by => 'author', :sort => 'priority'
708 708 assert_response :success
709 709 end
710 710
711 711 def test_index_sort_by_spent_hours
712 712 get :index, :sort => 'spent_hours:desc'
713 713 assert_response :success
714 714 hours = assigns(:issues).collect(&:spent_hours)
715 715 assert_equal hours.sort.reverse, hours
716 716 end
717 717
718 718 def test_index_sort_by_total_spent_hours
719 719 get :index, :sort => 'total_spent_hours:desc'
720 720 assert_response :success
721 721 hours = assigns(:issues).collect(&:total_spent_hours)
722 722 assert_equal hours.sort.reverse, hours
723 723 end
724 724
725 725 def test_index_sort_by_total_estimated_hours
726 726 get :index, :sort => 'total_estimated_hours:desc'
727 727 assert_response :success
728 728 hours = assigns(:issues).collect(&:total_estimated_hours)
729 729 assert_equal hours.sort.reverse, hours
730 730 end
731 731
732 732 def test_index_sort_by_user_custom_field
733 733 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
734 734 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
735 735 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
736 736 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
737 737 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
738 738
739 739 get :index, :project_id => 1, :set_filter => 1, :sort => "cf_#{cf.id},id"
740 740 assert_response :success
741 741
742 742 assert_equal [2, 3, 1], assigns(:issues).select {|issue| issue.custom_field_value(cf).present?}.map(&:id)
743 743 end
744 744
745 745 def test_index_with_columns
746 746 columns = ['tracker', 'subject', 'assigned_to']
747 747 get :index, :set_filter => 1, :c => columns
748 748 assert_response :success
749 749
750 750 # query should use specified columns
751 751 query = assigns(:query)
752 752 assert_kind_of IssueQuery, query
753 753 assert_equal columns, query.column_names.map(&:to_s)
754 754
755 755 # columns should be stored in session
756 756 assert_kind_of Hash, session[:query]
757 757 assert_kind_of Array, session[:query][:column_names]
758 758 assert_equal columns, session[:query][:column_names].map(&:to_s)
759 759
760 760 # ensure only these columns are kept in the selected columns list
761 761 assert_select 'select#selected_columns option' do
762 762 assert_select 'option', 3
763 763 assert_select 'option[value=tracker]'
764 764 assert_select 'option[value=project]', 0
765 765 end
766 766 end
767 767
768 768 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
769 769 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
770 770 get :index, :set_filter => 1
771 771
772 772 # query should use specified columns
773 773 query = assigns(:query)
774 774 assert_kind_of IssueQuery, query
775 775 assert_equal [:id, :project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
776 776 end
777 777
778 778 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
779 779 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
780 780 columns = ['id', 'tracker', 'subject', 'assigned_to']
781 781 get :index, :set_filter => 1, :c => columns
782 782
783 783 # query should use specified columns
784 784 query = assigns(:query)
785 785 assert_kind_of IssueQuery, query
786 786 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
787 787 end
788 788
789 789 def test_index_with_default_columns_should_respect_default_columns_order
790 790 columns = ['assigned_to', 'subject', 'status', 'tracker']
791 791 with_settings :issue_list_default_columns => columns do
792 792 get :index, :project_id => 1, :set_filter => 1
793 793
794 794 query = assigns(:query)
795 795 assert_equal (['id'] + columns).map(&:to_sym), query.columns.map(&:name)
796 796 end
797 797 end
798 798
799 799 def test_index_with_custom_field_column
800 800 columns = %w(tracker subject cf_2)
801 801 get :index, :set_filter => 1, :c => columns
802 802 assert_response :success
803 803
804 804 # query should use specified columns
805 805 query = assigns(:query)
806 806 assert_kind_of IssueQuery, query
807 807 assert_equal columns, query.column_names.map(&:to_s)
808 808
809 809 assert_select 'table.issues td.cf_2.string'
810 810 end
811 811
812 812 def test_index_with_multi_custom_field_column
813 813 field = CustomField.find(1)
814 814 field.update_attribute :multiple, true
815 815 issue = Issue.find(1)
816 816 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
817 817 issue.save!
818 818
819 819 get :index, :set_filter => 1, :c => %w(tracker subject cf_1)
820 820 assert_response :success
821 821
822 822 assert_select 'table.issues td.cf_1', :text => 'MySQL, Oracle'
823 823 end
824 824
825 825 def test_index_with_multi_user_custom_field_column
826 826 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
827 827 :tracker_ids => [1], :is_for_all => true)
828 828 issue = Issue.find(1)
829 829 issue.custom_field_values = {field.id => ['2', '3']}
830 830 issue.save!
831 831
832 832 get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"]
833 833 assert_response :success
834 834
835 835 assert_select "table.issues td.cf_#{field.id}" do
836 836 assert_select 'a', 2
837 837 assert_select 'a[href=?]', '/users/2', :text => 'John Smith'
838 838 assert_select 'a[href=?]', '/users/3', :text => 'Dave Lopper'
839 839 end
840 840 end
841 841
842 842 def test_index_with_date_column
843 843 with_settings :date_format => '%d/%m/%Y' do
844 844 Issue.find(1).update_attribute :start_date, '1987-08-24'
845 845 get :index, :set_filter => 1, :c => %w(start_date)
846 846 assert_select "table.issues td.start_date", :text => '24/08/1987'
847 847 end
848 848 end
849 849
850 850 def test_index_with_done_ratio_column
851 851 Issue.find(1).update_attribute :done_ratio, 40
852 852 get :index, :set_filter => 1, :c => %w(done_ratio)
853 853 assert_select 'table.issues td.done_ratio' do
854 854 assert_select 'table.progress' do
855 855 assert_select 'td.closed[style=?]', 'width: 40%;'
856 856 end
857 857 end
858 858 end
859 859
860 860 def test_index_with_spent_hours_column
861 861 Issue.expects(:load_visible_spent_hours).once
862 862 get :index, :set_filter => 1, :c => %w(subject spent_hours)
863 863 assert_select 'table.issues tr#issue-3 td.spent_hours', :text => '1.00'
864 864 end
865 865
866 866 def test_index_with_total_spent_hours_column
867 867 Issue.expects(:load_visible_total_spent_hours).once
868 868 get :index, :set_filter => 1, :c => %w(subject total_spent_hours)
869 869 assert_select 'table.issues tr#issue-3 td.total_spent_hours', :text => '1.00'
870 870 end
871 871
872 872 def test_index_with_total_estimated_hours_column
873 873 get :index, :set_filter => 1, :c => %w(subject total_estimated_hours)
874 874 assert_select 'table.issues td.total_estimated_hours'
875 875 end
876 876
877 877 def test_index_should_not_show_spent_hours_column_without_permission
878 878 Role.anonymous.remove_permission! :view_time_entries
879 879 get :index, :set_filter => 1, :c => %w(subject spent_hours)
880 880 assert_select 'td.spent_hours', 0
881 881 end
882 882
883 883 def test_index_with_fixed_version_column
884 884 get :index, :set_filter => 1, :c => %w(fixed_version)
885 885 assert_select 'table.issues td.fixed_version' do
886 886 assert_select 'a[href=?]', '/versions/2', :text => 'eCookbook - 1.0'
887 887 end
888 888 end
889 889
890 890 def test_index_with_relations_column
891 891 IssueRelation.delete_all
892 892 IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(1), :issue_to => Issue.find(7))
893 893 IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(8), :issue_to => Issue.find(1))
894 894 IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(1), :issue_to => Issue.find(11))
895 895 IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(12), :issue_to => Issue.find(2))
896 896
897 897 get :index, :set_filter => 1, :c => %w(subject relations)
898 898 assert_response :success
899 899 assert_select "tr#issue-1 td.relations" do
900 900 assert_select "span", 3
901 901 assert_select "span", :text => "Related to #7"
902 902 assert_select "span", :text => "Related to #8"
903 903 assert_select "span", :text => "Blocks #11"
904 904 end
905 905 assert_select "tr#issue-2 td.relations" do
906 906 assert_select "span", 1
907 907 assert_select "span", :text => "Blocked by #12"
908 908 end
909 909 assert_select "tr#issue-3 td.relations" do
910 910 assert_select "span", 0
911 911 end
912 912
913 913 get :index, :set_filter => 1, :c => %w(relations), :format => 'csv'
914 914 assert_response :success
915 915 assert_equal 'text/csv; header=present', response.content_type
916 916 lines = response.body.chomp.split("\n")
917 917 assert_include '1,"Related to #7, Related to #8, Blocks #11"', lines
918 918 assert_include '2,Blocked by #12', lines
919 919 assert_include '3,""', lines
920 920
921 921 get :index, :set_filter => 1, :c => %w(subject relations), :format => 'pdf'
922 922 assert_response :success
923 923 assert_equal 'application/pdf', response.content_type
924 924 end
925 925
926 926 def test_index_with_description_column
927 927 get :index, :set_filter => 1, :c => %w(subject description)
928 928
929 929 assert_select 'table.issues thead th', 3 # columns: chekbox + id + subject
930 930 assert_select 'td.description[colspan="3"]', :text => 'Unable to print recipes'
931 931
932 932 get :index, :set_filter => 1, :c => %w(subject description), :format => 'pdf'
933 933 assert_response :success
934 934 assert_equal 'application/pdf', response.content_type
935 935 end
936 936
937 937 def test_index_with_parent_column
938 938 Issue.delete_all
939 939 parent = Issue.generate!
940 940 child = Issue.generate!(:parent_issue_id => parent.id)
941 941
942 942 get :index, :c => %w(parent)
943 943
944 944 assert_select 'td.parent', :text => "#{parent.tracker} ##{parent.id}"
945 945 assert_select 'td.parent a[title=?]', parent.subject
946 946 end
947 947
948 948 def test_index_with_estimated_hours_total
949 949 Issue.delete_all
950 950 Issue.generate!(:estimated_hours => 5.5)
951 951 Issue.generate!(:estimated_hours => 1.1)
952 952
953 953 get :index, :t => %w(estimated_hours)
954 954 assert_response :success
955 955 assert_select '.query-totals'
956 956 assert_select '.total-for-estimated-hours span.value', :text => '6.60'
957 957 assert_select 'input[type=checkbox][name=?][value=estimated_hours][checked=checked]', 't[]'
958 958 end
959 959
960 960 def test_index_with_grouped_query_and_estimated_hours_total
961 961 Issue.delete_all
962 962 Issue.generate!(:estimated_hours => 5.5, :category_id => 1)
963 963 Issue.generate!(:estimated_hours => 2.3, :category_id => 1)
964 964 Issue.generate!(:estimated_hours => 1.1, :category_id => 2)
965 965 Issue.generate!(:estimated_hours => 4.6)
966 966
967 967 get :index, :t => %w(estimated_hours), :group_by => 'category'
968 968 assert_response :success
969 969 assert_select '.query-totals'
970 970 assert_select '.query-totals .total-for-estimated-hours span.value', :text => '13.50'
971 971 assert_select 'tr.group', :text => /Printing/ do
972 972 assert_select '.total-for-estimated-hours span.value', :text => '7.80'
973 973 end
974 974 assert_select 'tr.group', :text => /Recipes/ do
975 975 assert_select '.total-for-estimated-hours span.value', :text => '1.10'
976 976 end
977 977 assert_select 'tr.group', :text => /blank/ do
978 978 assert_select '.total-for-estimated-hours span.value', :text => '4.60'
979 979 end
980 980 end
981 981
982 982 def test_index_with_int_custom_field_total
983 983 field = IssueCustomField.generate!(:field_format => 'int', :is_for_all => true)
984 984 CustomValue.create!(:customized => Issue.find(1), :custom_field => field, :value => '2')
985 985 CustomValue.create!(:customized => Issue.find(2), :custom_field => field, :value => '7')
986 986
987 987 get :index, :t => ["cf_#{field.id}"]
988 988 assert_response :success
989 989 assert_select '.query-totals'
990 990 assert_select ".total-for-cf-#{field.id} span.value", :text => '9'
991 991 end
992 992
993 993 def test_index_totals_should_default_to_settings
994 994 with_settings :issue_list_default_totals => ['estimated_hours'] do
995 995 get :index
996 996 assert_response :success
997 997 assert_select '.total-for-estimated-hours span.value'
998 998 assert_select '.query-totals>span', 1
999 999 end
1000 1000 end
1001 1001
1002 1002 def test_index_send_html_if_query_is_invalid
1003 1003 get :index, :f => ['start_date'], :op => {:start_date => '='}
1004 1004 assert_equal 'text/html', @response.content_type
1005 1005 assert_template 'index'
1006 1006 end
1007 1007
1008 1008 def test_index_send_nothing_if_query_is_invalid
1009 1009 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
1010 1010 assert_equal 'text/csv', @response.content_type
1011 1011 assert @response.body.blank?
1012 1012 end
1013 1013
1014 1014 def test_show_by_anonymous
1015 1015 get :show, :id => 1
1016 1016 assert_response :success
1017 1017 assert_template 'show'
1018 1018 assert_equal Issue.find(1), assigns(:issue)
1019 1019 assert_select 'div.issue div.description', :text => /Unable to print recipes/
1020 1020 # anonymous role is allowed to add a note
1021 1021 assert_select 'form#issue-form' do
1022 1022 assert_select 'fieldset' do
1023 1023 assert_select 'legend', :text => 'Notes'
1024 1024 assert_select 'textarea[name=?]', 'issue[notes]'
1025 1025 end
1026 1026 end
1027 1027 assert_select 'title', :text => "Bug #1: Cannot print recipes - eCookbook - Redmine"
1028 1028 end
1029 1029
1030 1030 def test_show_by_manager
1031 1031 @request.session[:user_id] = 2
1032 1032 get :show, :id => 1
1033 1033 assert_response :success
1034 1034 assert_select 'a', :text => /Quote/
1035 1035 assert_select 'form#issue-form' do
1036 1036 assert_select 'fieldset' do
1037 1037 assert_select 'legend', :text => 'Change properties'
1038 1038 assert_select 'input[name=?]', 'issue[subject]'
1039 1039 end
1040 1040 assert_select 'fieldset' do
1041 1041 assert_select 'legend', :text => 'Log time'
1042 1042 assert_select 'input[name=?]', 'time_entry[hours]'
1043 1043 end
1044 1044 assert_select 'fieldset' do
1045 1045 assert_select 'legend', :text => 'Notes'
1046 1046 assert_select 'textarea[name=?]', 'issue[notes]'
1047 1047 end
1048 1048 end
1049 1049 end
1050 1050
1051 1051 def test_show_should_display_update_form
1052 1052 @request.session[:user_id] = 2
1053 1053 get :show, :id => 1
1054 1054 assert_response :success
1055 1055
1056 1056 assert_select 'form#issue-form' do
1057 1057 assert_select 'input[name=?]', 'issue[is_private]'
1058 1058 assert_select 'select[name=?]', 'issue[project_id]'
1059 1059 assert_select 'select[name=?]', 'issue[tracker_id]'
1060 1060 assert_select 'input[name=?]', 'issue[subject]'
1061 1061 assert_select 'textarea[name=?]', 'issue[description]'
1062 1062 assert_select 'select[name=?]', 'issue[status_id]'
1063 1063 assert_select 'select[name=?]', 'issue[priority_id]'
1064 1064 assert_select 'select[name=?]', 'issue[assigned_to_id]'
1065 1065 assert_select 'select[name=?]', 'issue[category_id]'
1066 1066 assert_select 'select[name=?]', 'issue[fixed_version_id]'
1067 1067 assert_select 'input[name=?]', 'issue[parent_issue_id]'
1068 1068 assert_select 'input[name=?]', 'issue[start_date]'
1069 1069 assert_select 'input[name=?]', 'issue[due_date]'
1070 1070 assert_select 'select[name=?]', 'issue[done_ratio]'
1071 1071 assert_select 'input[name=?]', 'issue[custom_field_values][2]'
1072 1072 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
1073 1073 assert_select 'textarea[name=?]', 'issue[notes]'
1074 1074 end
1075 1075 end
1076 1076
1077 1077 def test_show_should_display_update_form_with_minimal_permissions
1078 1078 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
1079 1079 WorkflowTransition.delete_all :role_id => 1
1080 1080
1081 1081 @request.session[:user_id] = 2
1082 1082 get :show, :id => 1
1083 1083 assert_response :success
1084 1084
1085 1085 assert_select 'form#issue-form' do
1086 1086 assert_select 'input[name=?]', 'issue[is_private]', 0
1087 1087 assert_select 'select[name=?]', 'issue[project_id]', 0
1088 1088 assert_select 'select[name=?]', 'issue[tracker_id]', 0
1089 1089 assert_select 'input[name=?]', 'issue[subject]', 0
1090 1090 assert_select 'textarea[name=?]', 'issue[description]', 0
1091 1091 assert_select 'select[name=?]', 'issue[status_id]', 0
1092 1092 assert_select 'select[name=?]', 'issue[priority_id]', 0
1093 1093 assert_select 'select[name=?]', 'issue[assigned_to_id]', 0
1094 1094 assert_select 'select[name=?]', 'issue[category_id]', 0
1095 1095 assert_select 'select[name=?]', 'issue[fixed_version_id]', 0
1096 1096 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
1097 1097 assert_select 'input[name=?]', 'issue[start_date]', 0
1098 1098 assert_select 'input[name=?]', 'issue[due_date]', 0
1099 1099 assert_select 'select[name=?]', 'issue[done_ratio]', 0
1100 1100 assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0
1101 1101 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
1102 1102 assert_select 'textarea[name=?]', 'issue[notes]'
1103 1103 end
1104 1104 end
1105 1105
1106 1106 def test_show_should_not_display_update_form_without_permissions
1107 1107 Role.find(1).update_attribute :permissions, [:view_issues]
1108 1108
1109 1109 @request.session[:user_id] = 2
1110 1110 get :show, :id => 1
1111 1111 assert_response :success
1112 1112
1113 1113 assert_select 'form#issue-form', 0
1114 1114 end
1115 1115
1116 1116 def test_update_form_should_not_display_inactive_enumerations
1117 1117 assert !IssuePriority.find(15).active?
1118 1118
1119 1119 @request.session[:user_id] = 2
1120 1120 get :show, :id => 1
1121 1121 assert_response :success
1122 1122
1123 1123 assert_select 'form#issue-form' do
1124 1124 assert_select 'select[name=?]', 'issue[priority_id]' do
1125 1125 assert_select 'option[value="4"]'
1126 1126 assert_select 'option[value="15"]', 0
1127 1127 end
1128 1128 end
1129 1129 end
1130 1130
1131 1131 def test_update_form_should_allow_attachment_upload
1132 1132 @request.session[:user_id] = 2
1133 1133 get :show, :id => 1
1134 1134
1135 1135 assert_select 'form#issue-form[method=post][enctype="multipart/form-data"]' do
1136 1136 assert_select 'input[type=file][name=?]', 'attachments[dummy][file]'
1137 1137 end
1138 1138 end
1139 1139
1140 1140 def test_show_should_deny_anonymous_access_without_permission
1141 1141 Role.anonymous.remove_permission!(:view_issues)
1142 1142 get :show, :id => 1
1143 1143 assert_response :redirect
1144 1144 end
1145 1145
1146 1146 def test_show_should_deny_anonymous_access_to_private_issue
1147 1147 Issue.where(:id => 1).update_all(["is_private = ?", true])
1148 1148 get :show, :id => 1
1149 1149 assert_response :redirect
1150 1150 end
1151 1151
1152 1152 def test_show_should_deny_non_member_access_without_permission
1153 1153 Role.non_member.remove_permission!(:view_issues)
1154 1154 @request.session[:user_id] = 9
1155 1155 get :show, :id => 1
1156 1156 assert_response 403
1157 1157 end
1158 1158
1159 1159 def test_show_should_deny_non_member_access_to_private_issue
1160 1160 Issue.where(:id => 1).update_all(["is_private = ?", true])
1161 1161 @request.session[:user_id] = 9
1162 1162 get :show, :id => 1
1163 1163 assert_response 403
1164 1164 end
1165 1165
1166 1166 def test_show_should_deny_member_access_without_permission
1167 1167 Role.find(1).remove_permission!(:view_issues)
1168 1168 @request.session[:user_id] = 2
1169 1169 get :show, :id => 1
1170 1170 assert_response 403
1171 1171 end
1172 1172
1173 1173 def test_show_should_deny_member_access_to_private_issue_without_permission
1174 1174 Issue.where(:id => 1).update_all(["is_private = ?", true])
1175 1175 @request.session[:user_id] = 3
1176 1176 get :show, :id => 1
1177 1177 assert_response 403
1178 1178 end
1179 1179
1180 1180 def test_show_should_allow_author_access_to_private_issue
1181 1181 Issue.where(:id => 1).update_all(["is_private = ?, author_id = 3", true])
1182 1182 @request.session[:user_id] = 3
1183 1183 get :show, :id => 1
1184 1184 assert_response :success
1185 1185 end
1186 1186
1187 1187 def test_show_should_allow_assignee_access_to_private_issue
1188 1188 Issue.where(:id => 1).update_all(["is_private = ?, assigned_to_id = 3", true])
1189 1189 @request.session[:user_id] = 3
1190 1190 get :show, :id => 1
1191 1191 assert_response :success
1192 1192 end
1193 1193
1194 1194 def test_show_should_allow_member_access_to_private_issue_with_permission
1195 1195 Issue.where(:id => 1).update_all(["is_private = ?", true])
1196 1196 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
1197 1197 @request.session[:user_id] = 3
1198 1198 get :show, :id => 1
1199 1199 assert_response :success
1200 1200 end
1201 1201
1202 1202 def test_show_should_not_disclose_relations_to_invisible_issues
1203 1203 Setting.cross_project_issue_relations = '1'
1204 1204 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
1205 1205 # Relation to a private project issue
1206 1206 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
1207 1207
1208 1208 get :show, :id => 1
1209 1209 assert_response :success
1210 1210
1211 1211 assert_select 'div#relations' do
1212 1212 assert_select 'a', :text => /#2$/
1213 1213 assert_select 'a', :text => /#4$/, :count => 0
1214 1214 end
1215 1215 end
1216 1216
1217 1217 def test_show_should_list_subtasks
1218 1218 Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
1219 1219
1220 1220 get :show, :id => 1
1221 1221 assert_response :success
1222 1222
1223 1223 assert_select 'div#issue_tree' do
1224 1224 assert_select 'td.subject', :text => /Child Issue/
1225 1225 end
1226 1226 end
1227 1227
1228 1228 def test_show_should_list_parents
1229 1229 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
1230 1230
1231 1231 get :show, :id => issue.id
1232 1232 assert_response :success
1233 1233
1234 1234 assert_select 'div.subject' do
1235 1235 assert_select 'h3', 'Child Issue'
1236 1236 assert_select 'a[href="/issues/1"]'
1237 1237 end
1238 1238 end
1239 1239
1240 1240 def test_show_should_not_display_prev_next_links_without_query_in_session
1241 1241 get :show, :id => 1
1242 1242 assert_response :success
1243 1243 assert_nil assigns(:prev_issue_id)
1244 1244 assert_nil assigns(:next_issue_id)
1245 1245
1246 1246 assert_select 'div.next-prev-links', 0
1247 1247 end
1248 1248
1249 1249 def test_show_should_display_prev_next_links_with_query_in_session
1250 1250 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1251 1251 @request.session['issues_index_sort'] = 'id'
1252 1252
1253 1253 with_settings :display_subprojects_issues => '0' do
1254 1254 get :show, :id => 3
1255 1255 end
1256 1256
1257 1257 assert_response :success
1258 1258 # Previous and next issues for all projects
1259 1259 assert_equal 2, assigns(:prev_issue_id)
1260 1260 assert_equal 5, assigns(:next_issue_id)
1261 1261
1262 1262 count = Issue.open.visible.count
1263 1263
1264 1264 assert_select 'div.next-prev-links' do
1265 1265 assert_select 'a[href="/issues/2"]', :text => /Previous/
1266 1266 assert_select 'a[href="/issues/5"]', :text => /Next/
1267 1267 assert_select 'span.position', :text => "3 of #{count}"
1268 1268 end
1269 1269 end
1270 1270
1271 1271 def test_show_should_display_prev_next_links_with_saved_query_in_session
1272 1272 query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1,
1273 1273 :filters => {'status_id' => {:values => ['5'], :operator => '='}},
1274 1274 :sort_criteria => [['id', 'asc']])
1275 1275 @request.session[:query] = {:id => query.id, :project_id => nil}
1276 1276
1277 1277 get :show, :id => 11
1278 1278
1279 1279 assert_response :success
1280 1280 assert_equal query, assigns(:query)
1281 1281 # Previous and next issues for all projects
1282 1282 assert_equal 8, assigns(:prev_issue_id)
1283 1283 assert_equal 12, assigns(:next_issue_id)
1284 1284
1285 1285 assert_select 'div.next-prev-links' do
1286 1286 assert_select 'a[href="/issues/8"]', :text => /Previous/
1287 1287 assert_select 'a[href="/issues/12"]', :text => /Next/
1288 1288 end
1289 1289 end
1290 1290
1291 1291 def test_show_should_display_prev_next_links_with_query_and_sort_on_association
1292 1292 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1293 1293
1294 1294 %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
1295 1295 @request.session['issues_index_sort'] = assoc_sort
1296 1296
1297 1297 get :show, :id => 3
1298 1298 assert_response :success, "Wrong response status for #{assoc_sort} sort"
1299 1299
1300 1300 assert_select 'div.next-prev-links' do
1301 1301 assert_select 'a', :text => /(Previous|Next)/
1302 1302 end
1303 1303 end
1304 1304 end
1305 1305
1306 1306 def test_show_should_display_prev_next_links_with_project_query_in_session
1307 1307 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1308 1308 @request.session['issues_index_sort'] = 'id'
1309 1309
1310 1310 with_settings :display_subprojects_issues => '0' do
1311 1311 get :show, :id => 3
1312 1312 end
1313 1313
1314 1314 assert_response :success
1315 1315 # Previous and next issues inside project
1316 1316 assert_equal 2, assigns(:prev_issue_id)
1317 1317 assert_equal 7, assigns(:next_issue_id)
1318 1318
1319 1319 assert_select 'div.next-prev-links' do
1320 1320 assert_select 'a[href="/issues/2"]', :text => /Previous/
1321 1321 assert_select 'a[href="/issues/7"]', :text => /Next/
1322 1322 end
1323 1323 end
1324 1324
1325 1325 def test_show_should_not_display_prev_link_for_first_issue
1326 1326 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1327 1327 @request.session['issues_index_sort'] = 'id'
1328 1328
1329 1329 with_settings :display_subprojects_issues => '0' do
1330 1330 get :show, :id => 1
1331 1331 end
1332 1332
1333 1333 assert_response :success
1334 1334 assert_nil assigns(:prev_issue_id)
1335 1335 assert_equal 2, assigns(:next_issue_id)
1336 1336
1337 1337 assert_select 'div.next-prev-links' do
1338 1338 assert_select 'a', :text => /Previous/, :count => 0
1339 1339 assert_select 'a[href="/issues/2"]', :text => /Next/
1340 1340 end
1341 1341 end
1342 1342
1343 1343 def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
1344 1344 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1}
1345 1345 @request.session['issues_index_sort'] = 'id'
1346 1346
1347 1347 get :show, :id => 1
1348 1348
1349 1349 assert_response :success
1350 1350 assert_nil assigns(:prev_issue_id)
1351 1351 assert_nil assigns(:next_issue_id)
1352 1352
1353 1353 assert_select 'a', :text => /Previous/, :count => 0
1354 1354 assert_select 'a', :text => /Next/, :count => 0
1355 1355 end
1356 1356
1357 1357 def test_show_show_should_display_prev_next_links_with_query_sort_by_user_custom_field
1358 1358 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
1359 1359 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
1360 1360 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
1361 1361 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
1362 1362 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
1363 1363
1364 1364 query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1, :filters => {},
1365 1365 :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']])
1366 1366 @request.session[:query] = {:id => query.id, :project_id => nil}
1367 1367
1368 1368 get :show, :id => 3
1369 1369 assert_response :success
1370 1370
1371 1371 assert_equal 2, assigns(:prev_issue_id)
1372 1372 assert_equal 1, assigns(:next_issue_id)
1373 1373
1374 1374 assert_select 'div.next-prev-links' do
1375 1375 assert_select 'a[href="/issues/2"]', :text => /Previous/
1376 1376 assert_select 'a[href="/issues/1"]', :text => /Next/
1377 1377 end
1378 1378 end
1379 1379
1380 1380 def test_show_should_display_category_field_if_categories_are_defined
1381 1381 Issue.update_all :category_id => nil
1382 1382
1383 1383 get :show, :id => 1
1384 1384 assert_response :success
1385 1385 assert_select 'table.attributes .category'
1386 1386 end
1387 1387
1388 1388 def test_show_should_not_display_category_field_if_no_categories_are_defined
1389 1389 Project.find(1).issue_categories.delete_all
1390 1390
1391 1391 get :show, :id => 1
1392 1392 assert_response :success
1393 1393 assert_select 'table.attributes .category', 0
1394 1394 end
1395 1395
1396 1396 def test_show_should_display_link_to_the_assignee
1397 1397 get :show, :id => 2
1398 1398 assert_response :success
1399 1399 assert_select '.assigned-to' do
1400 1400 assert_select 'a[href="/users/3"]'
1401 1401 end
1402 1402 end
1403 1403
1404 1404 def test_show_should_display_visible_changesets_from_other_projects
1405 1405 project = Project.find(2)
1406 1406 issue = project.issues.first
1407 1407 issue.changeset_ids = [102]
1408 1408 issue.save!
1409 1409 # changesets from other projects should be displayed even if repository
1410 1410 # is disabled on issue's project
1411 1411 project.disable_module! :repository
1412 1412
1413 1413 @request.session[:user_id] = 2
1414 1414 get :show, :id => issue.id
1415 1415
1416 1416 assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/3'
1417 1417 end
1418 1418
1419 1419 def test_show_should_display_watchers
1420 1420 @request.session[:user_id] = 2
1421 1421 Issue.find(1).add_watcher User.find(2)
1422 1422
1423 1423 get :show, :id => 1
1424 1424 assert_select 'div#watchers ul' do
1425 1425 assert_select 'li' do
1426 1426 assert_select 'a[href="/users/2"]'
1427 1427 assert_select 'a img[alt=Delete]'
1428 1428 end
1429 1429 end
1430 1430 end
1431 1431
1432 1432 def test_show_should_display_watchers_with_gravatars
1433 1433 @request.session[:user_id] = 2
1434 1434 Issue.find(1).add_watcher User.find(2)
1435 1435
1436 1436 with_settings :gravatar_enabled => '1' do
1437 1437 get :show, :id => 1
1438 1438 end
1439 1439
1440 1440 assert_select 'div#watchers ul' do
1441 1441 assert_select 'li' do
1442 1442 assert_select 'img.gravatar'
1443 1443 assert_select 'a[href="/users/2"]'
1444 1444 assert_select 'a img[alt=Delete]'
1445 1445 end
1446 1446 end
1447 1447 end
1448 1448
1449 1449 def test_show_with_thumbnails_enabled_should_display_thumbnails
1450 1450 @request.session[:user_id] = 2
1451 1451
1452 1452 with_settings :thumbnails_enabled => '1' do
1453 1453 get :show, :id => 14
1454 1454 assert_response :success
1455 1455 end
1456 1456
1457 1457 assert_select 'div.thumbnails' do
1458 1458 assert_select 'a[href="/attachments/16/testfile.png"]' do
1459 1459 assert_select 'img[src="/attachments/thumbnail/16"]'
1460 1460 end
1461 1461 end
1462 1462 end
1463 1463
1464 1464 def test_show_with_thumbnails_disabled_should_not_display_thumbnails
1465 1465 @request.session[:user_id] = 2
1466 1466
1467 1467 with_settings :thumbnails_enabled => '0' do
1468 1468 get :show, :id => 14
1469 1469 assert_response :success
1470 1470 end
1471 1471
1472 1472 assert_select 'div.thumbnails', 0
1473 1473 end
1474 1474
1475 1475 def test_show_with_multi_custom_field
1476 1476 field = CustomField.find(1)
1477 1477 field.update_attribute :multiple, true
1478 1478 issue = Issue.find(1)
1479 1479 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
1480 1480 issue.save!
1481 1481
1482 1482 get :show, :id => 1
1483 1483 assert_response :success
1484 1484
1485 1485 assert_select 'td', :text => 'MySQL, Oracle'
1486 1486 end
1487 1487
1488 1488 def test_show_with_multi_user_custom_field
1489 1489 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1490 1490 :tracker_ids => [1], :is_for_all => true)
1491 1491 issue = Issue.find(1)
1492 1492 issue.custom_field_values = {field.id => ['2', '3']}
1493 1493 issue.save!
1494 1494
1495 1495 get :show, :id => 1
1496 1496 assert_response :success
1497 1497
1498 1498 assert_select "td.cf_#{field.id}", :text => 'Dave Lopper, John Smith' do
1499 1499 assert_select 'a', :text => 'Dave Lopper'
1500 1500 assert_select 'a', :text => 'John Smith'
1501 1501 end
1502 1502 end
1503 1503
1504 1504 def test_show_should_display_private_notes_with_permission_only
1505 1505 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
1506 1506 @request.session[:user_id] = 2
1507 1507
1508 1508 get :show, :id => 2
1509 1509 assert_response :success
1510 1510 assert_include journal, assigns(:journals)
1511 1511
1512 1512 Role.find(1).remove_permission! :view_private_notes
1513 1513 get :show, :id => 2
1514 1514 assert_response :success
1515 1515 assert_not_include journal, assigns(:journals)
1516 1516 end
1517 1517
1518 1518 def test_show_atom
1519 1519 get :show, :id => 2, :format => 'atom'
1520 1520 assert_response :success
1521 1521 assert_template 'journals/index'
1522 1522 # Inline image
1523 1523 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
1524 1524 end
1525 1525
1526 1526 def test_show_export_to_pdf
1527 1527 issue = Issue.find(3)
1528 1528 assert issue.relations.select{|r| r.other_issue(issue).visible?}.present?
1529 1529 get :show, :id => 3, :format => 'pdf'
1530 1530 assert_response :success
1531 1531 assert_equal 'application/pdf', @response.content_type
1532 1532 assert @response.body.starts_with?('%PDF')
1533 1533 assert_not_nil assigns(:issue)
1534 1534 end
1535 1535
1536 1536 def test_export_to_pdf_with_utf8_u_fffd
1537 1537 # U+FFFD
1538 1538 s = "\xef\xbf\xbd"
1539 1539 s.force_encoding('UTF-8') if s.respond_to?(:force_encoding)
1540 1540 issue = Issue.generate!(:subject => s)
1541 1541 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
1542 1542 with_settings :default_language => lang do
1543 1543 get :show, :id => issue.id, :format => 'pdf'
1544 1544 assert_response :success
1545 1545 assert_equal 'application/pdf', @response.content_type
1546 1546 assert @response.body.starts_with?('%PDF')
1547 1547 assert_not_nil assigns(:issue)
1548 1548 end
1549 1549 end
1550 1550 end
1551 1551
1552 1552 def test_show_export_to_pdf_with_ancestors
1553 1553 issue = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1554 1554
1555 1555 get :show, :id => issue.id, :format => 'pdf'
1556 1556 assert_response :success
1557 1557 assert_equal 'application/pdf', @response.content_type
1558 1558 assert @response.body.starts_with?('%PDF')
1559 1559 end
1560 1560
1561 1561 def test_show_export_to_pdf_with_descendants
1562 1562 c1 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1563 1563 c2 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1564 1564 c3 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => c1.id)
1565 1565
1566 1566 get :show, :id => 1, :format => 'pdf'
1567 1567 assert_response :success
1568 1568 assert_equal 'application/pdf', @response.content_type
1569 1569 assert @response.body.starts_with?('%PDF')
1570 1570 end
1571 1571
1572 1572 def test_show_export_to_pdf_with_journals
1573 1573 get :show, :id => 1, :format => 'pdf'
1574 1574 assert_response :success
1575 1575 assert_equal 'application/pdf', @response.content_type
1576 1576 assert @response.body.starts_with?('%PDF')
1577 1577 end
1578 1578
1579 1579 def test_show_export_to_pdf_with_changesets
1580 1580 [[100], [100, 101], [100, 101, 102]].each do |cs|
1581 1581 issue1 = Issue.find(3)
1582 1582 issue1.changesets = Changeset.find(cs)
1583 1583 issue1.save!
1584 1584 issue = Issue.find(3)
1585 1585 assert_equal issue.changesets.count, cs.size
1586 1586 get :show, :id => 3, :format => 'pdf'
1587 1587 assert_response :success
1588 1588 assert_equal 'application/pdf', @response.content_type
1589 1589 assert @response.body.starts_with?('%PDF')
1590 1590 end
1591 1591 end
1592 1592
1593 1593 def test_show_invalid_should_respond_with_404
1594 1594 get :show, :id => 999
1595 1595 assert_response 404
1596 1596 end
1597 1597
1598 1598 def test_get_new
1599 1599 @request.session[:user_id] = 2
1600 1600 get :new, :project_id => 1, :tracker_id => 1
1601 1601 assert_response :success
1602 1602 assert_template 'new'
1603 1603
1604 1604 assert_select 'form#issue-form[action=?]', '/projects/ecookbook/issues'
1605 1605 assert_select 'form#issue-form' do
1606 1606 assert_select 'input[name=?]', 'issue[is_private]'
1607 1607 assert_select 'select[name=?]', 'issue[project_id]', 0
1608 1608 assert_select 'select[name=?]', 'issue[tracker_id]'
1609 1609 assert_select 'input[name=?]', 'issue[subject]'
1610 1610 assert_select 'textarea[name=?]', 'issue[description]'
1611 1611 assert_select 'select[name=?]', 'issue[status_id]'
1612 1612 assert_select 'select[name=?]', 'issue[priority_id]'
1613 1613 assert_select 'select[name=?]', 'issue[assigned_to_id]'
1614 1614 assert_select 'select[name=?]', 'issue[category_id]'
1615 1615 assert_select 'select[name=?]', 'issue[fixed_version_id]'
1616 1616 assert_select 'input[name=?]', 'issue[parent_issue_id]'
1617 1617 assert_select 'input[name=?]', 'issue[start_date]'
1618 1618 assert_select 'input[name=?]', 'issue[due_date]'
1619 1619 assert_select 'select[name=?]', 'issue[done_ratio]'
1620 1620 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string'
1621 1621 assert_select 'input[name=?]', 'issue[watcher_user_ids][]'
1622 1622 end
1623 1623
1624 1624 # Be sure we don't display inactive IssuePriorities
1625 1625 assert ! IssuePriority.find(15).active?
1626 1626 assert_select 'select[name=?]', 'issue[priority_id]' do
1627 1627 assert_select 'option[value="15"]', 0
1628 1628 end
1629 1629 end
1630 1630
1631 1631 def test_get_new_with_minimal_permissions
1632 1632 Role.find(1).update_attribute :permissions, [:add_issues]
1633 1633 WorkflowTransition.delete_all :role_id => 1
1634 1634
1635 1635 @request.session[:user_id] = 2
1636 1636 get :new, :project_id => 1, :tracker_id => 1
1637 1637 assert_response :success
1638 1638 assert_template 'new'
1639 1639
1640 1640 assert_select 'form#issue-form' do
1641 1641 assert_select 'input[name=?]', 'issue[is_private]', 0
1642 1642 assert_select 'select[name=?]', 'issue[project_id]', 0
1643 1643 assert_select 'select[name=?]', 'issue[tracker_id]'
1644 1644 assert_select 'input[name=?]', 'issue[subject]'
1645 1645 assert_select 'textarea[name=?]', 'issue[description]'
1646 1646 assert_select 'select[name=?]', 'issue[status_id]'
1647 1647 assert_select 'select[name=?]', 'issue[priority_id]'
1648 1648 assert_select 'select[name=?]', 'issue[assigned_to_id]'
1649 1649 assert_select 'select[name=?]', 'issue[category_id]'
1650 1650 assert_select 'select[name=?]', 'issue[fixed_version_id]'
1651 1651 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
1652 1652 assert_select 'input[name=?]', 'issue[start_date]'
1653 1653 assert_select 'input[name=?]', 'issue[due_date]'
1654 1654 assert_select 'select[name=?]', 'issue[done_ratio]'
1655 1655 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string'
1656 1656 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
1657 1657 end
1658 1658 end
1659 1659
1660 1660 def test_new_without_project_id
1661 1661 @request.session[:user_id] = 2
1662 1662 get :new
1663 1663 assert_response :success
1664 1664 assert_template 'new'
1665 1665
1666 1666 assert_select 'form#issue-form[action=?]', '/issues'
1667 1667 assert_select 'form#issue-form' do
1668 1668 assert_select 'select[name=?]', 'issue[project_id]'
1669 1669 end
1670 1670
1671 1671 assert_nil assigns(:project)
1672 1672 assert_not_nil assigns(:issue)
1673 1673 end
1674 1674
1675 1675 def test_new_should_select_default_status
1676 1676 @request.session[:user_id] = 2
1677 1677
1678 1678 get :new, :project_id => 1
1679 1679 assert_response :success
1680 1680 assert_template 'new'
1681 1681 assert_select 'select[name=?]', 'issue[status_id]' do
1682 1682 assert_select 'option[value="1"][selected=selected]'
1683 1683 end
1684 1684 assert_select 'input[name=was_default_status][value="1"]'
1685 1685 end
1686 1686
1687 1687 def test_new_should_propose_allowed_statuses
1688 1688 WorkflowTransition.delete_all
1689 1689 WorkflowTransition.create!(:tracker_id => 1, :role_id => 1, :old_status_id => 0, :new_status_id => 1)
1690 1690 WorkflowTransition.create!(:tracker_id => 1, :role_id => 1, :old_status_id => 0, :new_status_id => 3)
1691 1691 @request.session[:user_id] = 2
1692 1692
1693 1693 get :new, :project_id => 1
1694 1694 assert_response :success
1695 1695 assert_select 'select[name=?]', 'issue[status_id]' do
1696 1696 assert_select 'option[value="1"]'
1697 1697 assert_select 'option[value="3"]'
1698 1698 assert_select 'option', 2
1699 1699 assert_select 'option[value="1"][selected=selected]'
1700 1700 end
1701 1701 end
1702 1702
1703 1703 def test_new_should_propose_allowed_statuses_without_default_status_allowed
1704 1704 WorkflowTransition.delete_all
1705 1705 WorkflowTransition.create!(:tracker_id => 1, :role_id => 1, :old_status_id => 0, :new_status_id => 2)
1706 1706 assert_equal 1, Tracker.find(1).default_status_id
1707 1707 @request.session[:user_id] = 2
1708 1708
1709 1709 get :new, :project_id => 1
1710 1710 assert_response :success
1711 1711 assert_select 'select[name=?]', 'issue[status_id]' do
1712 1712 assert_select 'option[value="2"]'
1713 1713 assert_select 'option', 1
1714 1714 assert_select 'option[value="2"][selected=selected]'
1715 1715 end
1716 1716 end
1717 1717
1718 def test_new_should_preselect_default_version
1719 version = Version.generate!(:project_id => 1)
1720 Project.find(1).update_attribute :default_version_id, version.id
1721 @request.session[:user_id] = 2
1722
1723 get :new, :project_id => 1
1724 assert_response :success
1725 assert_equal version, assigns(:issue).fixed_version
1726 assert_select 'select[name=?]', 'issue[fixed_version_id]' do
1727 assert_select 'option[value=?][selected=selected]', version.id.to_s
1728 end
1729 end
1730
1718 1731 def test_get_new_with_list_custom_field
1719 1732 @request.session[:user_id] = 2
1720 1733 get :new, :project_id => 1, :tracker_id => 1
1721 1734 assert_response :success
1722 1735 assert_template 'new'
1723 1736
1724 1737 assert_select 'select.list_cf[name=?]', 'issue[custom_field_values][1]' do
1725 1738 assert_select 'option', 4
1726 1739 assert_select 'option[value=MySQL]', :text => 'MySQL'
1727 1740 end
1728 1741 end
1729 1742
1730 1743 def test_get_new_with_multi_custom_field
1731 1744 field = IssueCustomField.find(1)
1732 1745 field.update_attribute :multiple, true
1733 1746
1734 1747 @request.session[:user_id] = 2
1735 1748 get :new, :project_id => 1, :tracker_id => 1
1736 1749 assert_response :success
1737 1750 assert_template 'new'
1738 1751
1739 1752 assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do
1740 1753 assert_select 'option', 3
1741 1754 assert_select 'option[value=MySQL]', :text => 'MySQL'
1742 1755 end
1743 1756 assert_select 'input[name=?][type=hidden][value=?]', 'issue[custom_field_values][1][]', ''
1744 1757 end
1745 1758
1746 1759 def test_get_new_with_multi_user_custom_field
1747 1760 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1748 1761 :tracker_ids => [1], :is_for_all => true)
1749 1762
1750 1763 @request.session[:user_id] = 2
1751 1764 get :new, :project_id => 1, :tracker_id => 1
1752 1765 assert_response :success
1753 1766 assert_template 'new'
1754 1767
1755 1768 assert_select 'select[name=?][multiple=multiple]', "issue[custom_field_values][#{field.id}][]" do
1756 1769 assert_select 'option', Project.find(1).users.count
1757 1770 assert_select 'option[value="2"]', :text => 'John Smith'
1758 1771 end
1759 1772 assert_select 'input[name=?][type=hidden][value=?]', "issue[custom_field_values][#{field.id}][]", ''
1760 1773 end
1761 1774
1762 1775 def test_get_new_with_date_custom_field
1763 1776 field = IssueCustomField.create!(:name => 'Date', :field_format => 'date', :tracker_ids => [1], :is_for_all => true)
1764 1777
1765 1778 @request.session[:user_id] = 2
1766 1779 get :new, :project_id => 1, :tracker_id => 1
1767 1780 assert_response :success
1768 1781
1769 1782 assert_select 'input[name=?]', "issue[custom_field_values][#{field.id}]"
1770 1783 end
1771 1784
1772 1785 def test_get_new_with_text_custom_field
1773 1786 field = IssueCustomField.create!(:name => 'Text', :field_format => 'text', :tracker_ids => [1], :is_for_all => true)
1774 1787
1775 1788 @request.session[:user_id] = 2
1776 1789 get :new, :project_id => 1, :tracker_id => 1
1777 1790 assert_response :success
1778 1791
1779 1792 assert_select 'textarea[name=?]', "issue[custom_field_values][#{field.id}]"
1780 1793 end
1781 1794
1782 1795 def test_get_new_without_default_start_date_is_creation_date
1783 1796 with_settings :default_issue_start_date_to_creation_date => 0 do
1784 1797 @request.session[:user_id] = 2
1785 1798 get :new, :project_id => 1, :tracker_id => 1
1786 1799 assert_response :success
1787 1800 assert_template 'new'
1788 1801 assert_select 'input[name=?]', 'issue[start_date]'
1789 1802 assert_select 'input[name=?][value]', 'issue[start_date]', 0
1790 1803 end
1791 1804 end
1792 1805
1793 1806 def test_get_new_with_default_start_date_is_creation_date
1794 1807 with_settings :default_issue_start_date_to_creation_date => 1 do
1795 1808 @request.session[:user_id] = 2
1796 1809 get :new, :project_id => 1, :tracker_id => 1
1797 1810 assert_response :success
1798 1811 assert_template 'new'
1799 1812 assert_select 'input[name=?][value=?]', 'issue[start_date]',
1800 1813 Date.today.to_s
1801 1814 end
1802 1815 end
1803 1816
1804 1817 def test_get_new_form_should_allow_attachment_upload
1805 1818 @request.session[:user_id] = 2
1806 1819 get :new, :project_id => 1, :tracker_id => 1
1807 1820
1808 1821 assert_select 'form[id=issue-form][method=post][enctype="multipart/form-data"]' do
1809 1822 assert_select 'input[name=?][type=file]', 'attachments[dummy][file]'
1810 1823 end
1811 1824 end
1812 1825
1813 1826 def test_get_new_should_prefill_the_form_from_params
1814 1827 @request.session[:user_id] = 2
1815 1828 get :new, :project_id => 1,
1816 1829 :issue => {:tracker_id => 3, :description => 'Prefilled', :custom_field_values => {'2' => 'Custom field value'}}
1817 1830
1818 1831 issue = assigns(:issue)
1819 1832 assert_equal 3, issue.tracker_id
1820 1833 assert_equal 'Prefilled', issue.description
1821 1834 assert_equal 'Custom field value', issue.custom_field_value(2)
1822 1835
1823 1836 assert_select 'select[name=?]', 'issue[tracker_id]' do
1824 1837 assert_select 'option[value="3"][selected=selected]'
1825 1838 end
1826 1839 assert_select 'textarea[name=?]', 'issue[description]', :text => /Prefilled/
1827 1840 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Custom field value'
1828 1841 end
1829 1842
1830 1843 def test_get_new_should_mark_required_fields
1831 1844 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1832 1845 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1833 1846 WorkflowPermission.delete_all
1834 1847 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'required')
1835 1848 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
1836 1849 @request.session[:user_id] = 2
1837 1850
1838 1851 get :new, :project_id => 1
1839 1852 assert_response :success
1840 1853 assert_template 'new'
1841 1854
1842 1855 assert_select 'label[for=issue_start_date]' do
1843 1856 assert_select 'span[class=required]', 0
1844 1857 end
1845 1858 assert_select 'label[for=issue_due_date]' do
1846 1859 assert_select 'span[class=required]'
1847 1860 end
1848 1861 assert_select 'label[for=?]', "issue_custom_field_values_#{cf1.id}" do
1849 1862 assert_select 'span[class=required]', 0
1850 1863 end
1851 1864 assert_select 'label[for=?]', "issue_custom_field_values_#{cf2.id}" do
1852 1865 assert_select 'span[class=required]'
1853 1866 end
1854 1867 end
1855 1868
1856 1869 def test_get_new_should_not_display_readonly_fields
1857 1870 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1858 1871 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1859 1872 WorkflowPermission.delete_all
1860 1873 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
1861 1874 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
1862 1875 @request.session[:user_id] = 2
1863 1876
1864 1877 get :new, :project_id => 1
1865 1878 assert_response :success
1866 1879 assert_template 'new'
1867 1880
1868 1881 assert_select 'input[name=?]', 'issue[start_date]'
1869 1882 assert_select 'input[name=?]', 'issue[due_date]', 0
1870 1883 assert_select 'input[name=?]', "issue[custom_field_values][#{cf1.id}]"
1871 1884 assert_select 'input[name=?]', "issue[custom_field_values][#{cf2.id}]", 0
1872 1885 end
1873 1886
1874 1887 def test_new_with_tracker_set_as_readonly_should_accept_status
1875 1888 WorkflowPermission.delete_all
1876 1889 [1, 2].each do |status_id|
1877 1890 WorkflowPermission.create!(:tracker_id => 1, :old_status_id => status_id, :role_id => 1, :field_name => 'tracker_id', :rule => 'readonly')
1878 1891 end
1879 1892 @request.session[:user_id] = 2
1880 1893
1881 1894 get :new, :project_id => 1, :issue => {:status_id => 2}
1882 1895 assert_select 'select[name=?]', 'issue[tracker_id]', 0
1883 1896 assert_equal 2, assigns(:issue).status_id
1884 1897 end
1885 1898
1886 1899 def test_get_new_without_tracker_id
1887 1900 @request.session[:user_id] = 2
1888 1901 get :new, :project_id => 1
1889 1902 assert_response :success
1890 1903 assert_template 'new'
1891 1904
1892 1905 issue = assigns(:issue)
1893 1906 assert_not_nil issue
1894 1907 assert_equal Project.find(1).trackers.first, issue.tracker
1895 1908 end
1896 1909
1897 1910 def test_get_new_with_no_default_status_should_display_an_error
1898 1911 @request.session[:user_id] = 2
1899 1912 IssueStatus.delete_all
1900 1913
1901 1914 get :new, :project_id => 1
1902 1915 assert_response 500
1903 1916 assert_select_error /No default issue/
1904 1917 end
1905 1918
1906 1919 def test_get_new_with_no_tracker_should_display_an_error
1907 1920 @request.session[:user_id] = 2
1908 1921 Tracker.delete_all
1909 1922
1910 1923 get :new, :project_id => 1
1911 1924 assert_response 500
1912 1925 assert_select_error /No tracker/
1913 1926 end
1914 1927
1915 1928 def test_new_with_invalid_project_id
1916 1929 @request.session[:user_id] = 1
1917 1930 get :new, :project_id => 'invalid'
1918 1931 assert_response 404
1919 1932 end
1920 1933
1921 1934 def test_update_form_for_new_issue
1922 1935 @request.session[:user_id] = 2
1923 1936 xhr :post, :new, :project_id => 1,
1924 1937 :issue => {:tracker_id => 2,
1925 1938 :subject => 'This is the test_new issue',
1926 1939 :description => 'This is the description',
1927 1940 :priority_id => 5}
1928 1941 assert_response :success
1929 1942 assert_template 'new'
1930 1943 assert_template :partial => '_form'
1931 1944 assert_equal 'text/javascript', response.content_type
1932 1945
1933 1946 issue = assigns(:issue)
1934 1947 assert_kind_of Issue, issue
1935 1948 assert_equal 1, issue.project_id
1936 1949 assert_equal 2, issue.tracker_id
1937 1950 assert_equal 'This is the test_new issue', issue.subject
1938 1951 end
1939 1952
1940 1953 def test_update_form_for_new_issue_should_propose_transitions_based_on_initial_status
1941 1954 @request.session[:user_id] = 2
1942 1955 WorkflowTransition.delete_all
1943 1956 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 0, :new_status_id => 2)
1944 1957 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 0, :new_status_id => 5)
1945 1958 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4)
1946 1959
1947 1960 xhr :post, :new, :project_id => 1,
1948 1961 :issue => {:tracker_id => 1,
1949 1962 :status_id => 5,
1950 1963 :subject => 'This is an issue'}
1951 1964
1952 1965 assert_equal 5, assigns(:issue).status_id
1953 1966 assert_equal [2,5], assigns(:allowed_statuses).map(&:id).sort
1954 1967 end
1955 1968
1956 1969 def test_update_form_with_default_status_should_ignore_submitted_status_id_if_equals
1957 1970 @request.session[:user_id] = 2
1958 1971 tracker = Tracker.find(2)
1959 1972 tracker.update! :default_status_id => 2
1960 1973 tracker.generate_transitions! 2, 1, :clear => true
1961 1974
1962 1975 xhr :post, :new, :project_id => 1,
1963 1976 :issue => {:tracker_id => 2,
1964 1977 :status_id => 1},
1965 1978 :was_default_status => 1
1966 1979
1967 1980 assert_equal 2, assigns(:issue).status_id
1968 1981 end
1969 1982
1970 1983 def test_post_create
1971 1984 @request.session[:user_id] = 2
1972 1985 assert_difference 'Issue.count' do
1973 1986 assert_no_difference 'Journal.count' do
1974 1987 post :create, :project_id => 1,
1975 1988 :issue => {:tracker_id => 3,
1976 1989 :status_id => 2,
1977 1990 :subject => 'This is the test_new issue',
1978 1991 :description => 'This is the description',
1979 1992 :priority_id => 5,
1980 1993 :start_date => '2010-11-07',
1981 1994 :estimated_hours => '',
1982 1995 :custom_field_values => {'2' => 'Value for field 2'}}
1983 1996 end
1984 1997 end
1985 1998 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1986 1999
1987 2000 issue = Issue.find_by_subject('This is the test_new issue')
1988 2001 assert_not_nil issue
1989 2002 assert_equal 2, issue.author_id
1990 2003 assert_equal 3, issue.tracker_id
1991 2004 assert_equal 2, issue.status_id
1992 2005 assert_equal Date.parse('2010-11-07'), issue.start_date
1993 2006 assert_nil issue.estimated_hours
1994 2007 v = issue.custom_values.where(:custom_field_id => 2).first
1995 2008 assert_not_nil v
1996 2009 assert_equal 'Value for field 2', v.value
1997 2010 end
1998 2011
1999 2012 def test_post_new_with_group_assignment
2000 2013 group = Group.find(11)
2001 2014 project = Project.find(1)
2002 2015 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
2003 2016
2004 2017 with_settings :issue_group_assignment => '1' do
2005 2018 @request.session[:user_id] = 2
2006 2019 assert_difference 'Issue.count' do
2007 2020 post :create, :project_id => project.id,
2008 2021 :issue => {:tracker_id => 3,
2009 2022 :status_id => 1,
2010 2023 :subject => 'This is the test_new_with_group_assignment issue',
2011 2024 :assigned_to_id => group.id}
2012 2025 end
2013 2026 end
2014 2027 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
2015 2028
2016 2029 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
2017 2030 assert_not_nil issue
2018 2031 assert_equal group, issue.assigned_to
2019 2032 end
2020 2033
2021 2034 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
2022 2035 with_settings :default_issue_start_date_to_creation_date => 0 do
2023 2036 @request.session[:user_id] = 2
2024 2037 assert_difference 'Issue.count' do
2025 2038 post :create, :project_id => 1,
2026 2039 :issue => {:tracker_id => 3,
2027 2040 :status_id => 2,
2028 2041 :subject => 'This is the test_new issue',
2029 2042 :description => 'This is the description',
2030 2043 :priority_id => 5,
2031 2044 :estimated_hours => '',
2032 2045 :custom_field_values => {'2' => 'Value for field 2'}}
2033 2046 end
2034 2047 assert_redirected_to :controller => 'issues', :action => 'show',
2035 2048 :id => Issue.last.id
2036 2049 issue = Issue.find_by_subject('This is the test_new issue')
2037 2050 assert_not_nil issue
2038 2051 assert_nil issue.start_date
2039 2052 end
2040 2053 end
2041 2054
2042 2055 def test_post_create_without_start_date_and_default_start_date_is_creation_date
2043 2056 with_settings :default_issue_start_date_to_creation_date => 1 do
2044 2057 @request.session[:user_id] = 2
2045 2058 assert_difference 'Issue.count' do
2046 2059 post :create, :project_id => 1,
2047 2060 :issue => {:tracker_id => 3,
2048 2061 :status_id => 2,
2049 2062 :subject => 'This is the test_new issue',
2050 2063 :description => 'This is the description',
2051 2064 :priority_id => 5,
2052 2065 :estimated_hours => '',
2053 2066 :custom_field_values => {'2' => 'Value for field 2'}}
2054 2067 end
2055 2068 assert_redirected_to :controller => 'issues', :action => 'show',
2056 2069 :id => Issue.last.id
2057 2070 issue = Issue.find_by_subject('This is the test_new issue')
2058 2071 assert_not_nil issue
2059 2072 assert_equal Date.today, issue.start_date
2060 2073 end
2061 2074 end
2062 2075
2063 2076 def test_post_create_and_continue
2064 2077 @request.session[:user_id] = 2
2065 2078 assert_difference 'Issue.count' do
2066 2079 post :create, :project_id => 1,
2067 2080 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
2068 2081 :continue => ''
2069 2082 end
2070 2083
2071 2084 issue = Issue.order('id DESC').first
2072 2085 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
2073 2086 assert_not_nil flash[:notice], "flash was not set"
2074 2087 assert_select_in flash[:notice],
2075 2088 'a[href=?][title=?]', "/issues/#{issue.id}", "This is first issue", :text => "##{issue.id}"
2076 2089 end
2077 2090
2078 2091 def test_post_create_without_custom_fields_param
2079 2092 @request.session[:user_id] = 2
2080 2093 assert_difference 'Issue.count' do
2081 2094 post :create, :project_id => 1,
2082 2095 :issue => {:tracker_id => 1,
2083 2096 :subject => 'This is the test_new issue',
2084 2097 :description => 'This is the description',
2085 2098 :priority_id => 5}
2086 2099 end
2087 2100 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
2088 2101 end
2089 2102
2090 2103 def test_post_create_with_multi_custom_field
2091 2104 field = IssueCustomField.find_by_name('Database')
2092 2105 field.update_attribute(:multiple, true)
2093 2106
2094 2107 @request.session[:user_id] = 2
2095 2108 assert_difference 'Issue.count' do
2096 2109 post :create, :project_id => 1,
2097 2110 :issue => {:tracker_id => 1,
2098 2111 :subject => 'This is the test_new issue',
2099 2112 :description => 'This is the description',
2100 2113 :priority_id => 5,
2101 2114 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}}
2102 2115 end
2103 2116 assert_response 302
2104 2117 issue = Issue.order('id DESC').first
2105 2118 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort
2106 2119 end
2107 2120
2108 2121 def test_post_create_with_empty_multi_custom_field
2109 2122 field = IssueCustomField.find_by_name('Database')
2110 2123 field.update_attribute(:multiple, true)
2111 2124
2112 2125 @request.session[:user_id] = 2
2113 2126 assert_difference 'Issue.count' do
2114 2127 post :create, :project_id => 1,
2115 2128 :issue => {:tracker_id => 1,
2116 2129 :subject => 'This is the test_new issue',
2117 2130 :description => 'This is the description',
2118 2131 :priority_id => 5,
2119 2132 :custom_field_values => {'1' => ['']}}
2120 2133 end
2121 2134 assert_response 302
2122 2135 issue = Issue.order('id DESC').first
2123 2136 assert_equal [''], issue.custom_field_value(1).sort
2124 2137 end
2125 2138
2126 2139 def test_post_create_with_multi_user_custom_field
2127 2140 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
2128 2141 :tracker_ids => [1], :is_for_all => true)
2129 2142
2130 2143 @request.session[:user_id] = 2
2131 2144 assert_difference 'Issue.count' do
2132 2145 post :create, :project_id => 1,
2133 2146 :issue => {:tracker_id => 1,
2134 2147 :subject => 'This is the test_new issue',
2135 2148 :description => 'This is the description',
2136 2149 :priority_id => 5,
2137 2150 :custom_field_values => {field.id.to_s => ['', '2', '3']}}
2138 2151 end
2139 2152 assert_response 302
2140 2153 issue = Issue.order('id DESC').first
2141 2154 assert_equal ['2', '3'], issue.custom_field_value(field).sort
2142 2155 end
2143 2156
2144 2157 def test_post_create_with_required_custom_field_and_without_custom_fields_param
2145 2158 field = IssueCustomField.find_by_name('Database')
2146 2159 field.update_attribute(:is_required, true)
2147 2160
2148 2161 @request.session[:user_id] = 2
2149 2162 assert_no_difference 'Issue.count' do
2150 2163 post :create, :project_id => 1,
2151 2164 :issue => {:tracker_id => 1,
2152 2165 :subject => 'This is the test_new issue',
2153 2166 :description => 'This is the description',
2154 2167 :priority_id => 5}
2155 2168 end
2156 2169 assert_response :success
2157 2170 assert_template 'new'
2158 2171 issue = assigns(:issue)
2159 2172 assert_not_nil issue
2160 2173 assert_select_error /Database cannot be blank/
2161 2174 end
2162 2175
2163 2176 def test_create_should_validate_required_fields
2164 2177 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
2165 2178 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
2166 2179 WorkflowPermission.delete_all
2167 2180 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'required')
2168 2181 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
2169 2182 @request.session[:user_id] = 2
2170 2183
2171 2184 assert_no_difference 'Issue.count' do
2172 2185 post :create, :project_id => 1, :issue => {
2173 2186 :tracker_id => 2,
2174 2187 :status_id => 1,
2175 2188 :subject => 'Test',
2176 2189 :start_date => '',
2177 2190 :due_date => '',
2178 2191 :custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ''}
2179 2192 }
2180 2193 assert_response :success
2181 2194 assert_template 'new'
2182 2195 end
2183 2196
2184 2197 assert_select_error /Due date cannot be blank/i
2185 2198 assert_select_error /Bar cannot be blank/i
2186 2199 end
2187 2200
2188 2201 def test_create_should_validate_required_list_fields
2189 2202 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => false, :possible_values => ['a', 'b'])
2190 2203 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => true, :possible_values => ['a', 'b'])
2191 2204 WorkflowPermission.delete_all
2192 2205 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf1.id.to_s, :rule => 'required')
2193 2206 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
2194 2207 @request.session[:user_id] = 2
2195 2208
2196 2209 assert_no_difference 'Issue.count' do
2197 2210 post :create, :project_id => 1, :issue => {
2198 2211 :tracker_id => 2,
2199 2212 :status_id => 1,
2200 2213 :subject => 'Test',
2201 2214 :start_date => '',
2202 2215 :due_date => '',
2203 2216 :custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ['']}
2204 2217 }
2205 2218 assert_response :success
2206 2219 assert_template 'new'
2207 2220 end
2208 2221
2209 2222 assert_select_error /Foo cannot be blank/i
2210 2223 assert_select_error /Bar cannot be blank/i
2211 2224 end
2212 2225
2213 2226 def test_create_should_ignore_readonly_fields
2214 2227 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
2215 2228 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
2216 2229 WorkflowPermission.delete_all
2217 2230 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
2218 2231 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
2219 2232 @request.session[:user_id] = 2
2220 2233
2221 2234 assert_difference 'Issue.count' do
2222 2235 post :create, :project_id => 1, :issue => {
2223 2236 :tracker_id => 2,
2224 2237 :status_id => 1,
2225 2238 :subject => 'Test',
2226 2239 :start_date => '2012-07-14',
2227 2240 :due_date => '2012-07-16',
2228 2241 :custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'}
2229 2242 }
2230 2243 assert_response 302
2231 2244 end
2232 2245
2233 2246 issue = Issue.order('id DESC').first
2234 2247 assert_equal Date.parse('2012-07-14'), issue.start_date
2235 2248 assert_nil issue.due_date
2236 2249 assert_equal 'value1', issue.custom_field_value(cf1)
2237 2250 assert_nil issue.custom_field_value(cf2)
2238 2251 end
2239 2252
2240 2253 def test_post_create_with_watchers
2241 2254 @request.session[:user_id] = 2
2242 2255 ActionMailer::Base.deliveries.clear
2243 2256
2244 2257 with_settings :notified_events => %w(issue_added) do
2245 2258 assert_difference 'Watcher.count', 2 do
2246 2259 post :create, :project_id => 1,
2247 2260 :issue => {:tracker_id => 1,
2248 2261 :subject => 'This is a new issue with watchers',
2249 2262 :description => 'This is the description',
2250 2263 :priority_id => 5,
2251 2264 :watcher_user_ids => ['2', '3']}
2252 2265 end
2253 2266 end
2254 2267 issue = Issue.find_by_subject('This is a new issue with watchers')
2255 2268 assert_not_nil issue
2256 2269 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
2257 2270
2258 2271 # Watchers added
2259 2272 assert_equal [2, 3], issue.watcher_user_ids.sort
2260 2273 assert issue.watched_by?(User.find(3))
2261 2274 # Watchers notified
2262 2275 mail = ActionMailer::Base.deliveries.last
2263 2276 assert_not_nil mail
2264 2277 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
2265 2278 end
2266 2279
2267 2280 def test_post_create_subissue
2268 2281 @request.session[:user_id] = 2
2269 2282
2270 2283 assert_difference 'Issue.count' do
2271 2284 post :create, :project_id => 1,
2272 2285 :issue => {:tracker_id => 1,
2273 2286 :subject => 'This is a child issue',
2274 2287 :parent_issue_id => '2'}
2275 2288 assert_response 302
2276 2289 end
2277 2290 issue = Issue.order('id DESC').first
2278 2291 assert_equal Issue.find(2), issue.parent
2279 2292 end
2280 2293
2281 2294 def test_post_create_subissue_with_sharp_parent_id
2282 2295 @request.session[:user_id] = 2
2283 2296
2284 2297 assert_difference 'Issue.count' do
2285 2298 post :create, :project_id => 1,
2286 2299 :issue => {:tracker_id => 1,
2287 2300 :subject => 'This is a child issue',
2288 2301 :parent_issue_id => '#2'}
2289 2302 assert_response 302
2290 2303 end
2291 2304 issue = Issue.order('id DESC').first
2292 2305 assert_equal Issue.find(2), issue.parent
2293 2306 end
2294 2307
2295 2308 def test_post_create_subissue_with_non_visible_parent_id_should_not_validate
2296 2309 @request.session[:user_id] = 2
2297 2310
2298 2311 assert_no_difference 'Issue.count' do
2299 2312 post :create, :project_id => 1,
2300 2313 :issue => {:tracker_id => 1,
2301 2314 :subject => 'This is a child issue',
2302 2315 :parent_issue_id => '4'}
2303 2316
2304 2317 assert_response :success
2305 2318 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '4'
2306 2319 assert_select_error /Parent task is invalid/i
2307 2320 end
2308 2321 end
2309 2322
2310 2323 def test_post_create_subissue_with_non_numeric_parent_id_should_not_validate
2311 2324 @request.session[:user_id] = 2
2312 2325
2313 2326 assert_no_difference 'Issue.count' do
2314 2327 post :create, :project_id => 1,
2315 2328 :issue => {:tracker_id => 1,
2316 2329 :subject => 'This is a child issue',
2317 2330 :parent_issue_id => '01ABC'}
2318 2331
2319 2332 assert_response :success
2320 2333 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '01ABC'
2321 2334 assert_select_error /Parent task is invalid/i
2322 2335 end
2323 2336 end
2324 2337
2325 2338 def test_post_create_private
2326 2339 @request.session[:user_id] = 2
2327 2340
2328 2341 assert_difference 'Issue.count' do
2329 2342 post :create, :project_id => 1,
2330 2343 :issue => {:tracker_id => 1,
2331 2344 :subject => 'This is a private issue',
2332 2345 :is_private => '1'}
2333 2346 end
2334 2347 issue = Issue.order('id DESC').first
2335 2348 assert issue.is_private?
2336 2349 end
2337 2350
2338 2351 def test_post_create_private_with_set_own_issues_private_permission
2339 2352 role = Role.find(1)
2340 2353 role.remove_permission! :set_issues_private
2341 2354 role.add_permission! :set_own_issues_private
2342 2355
2343 2356 @request.session[:user_id] = 2
2344 2357
2345 2358 assert_difference 'Issue.count' do
2346 2359 post :create, :project_id => 1,
2347 2360 :issue => {:tracker_id => 1,
2348 2361 :subject => 'This is a private issue',
2349 2362 :is_private => '1'}
2350 2363 end
2351 2364 issue = Issue.order('id DESC').first
2352 2365 assert issue.is_private?
2353 2366 end
2354 2367
2355 2368 def test_create_without_project_id
2356 2369 @request.session[:user_id] = 2
2357 2370
2358 2371 assert_difference 'Issue.count' do
2359 2372 post :create,
2360 2373 :issue => {:project_id => 3,
2361 2374 :tracker_id => 2,
2362 2375 :subject => 'Foo'}
2363 2376 assert_response 302
2364 2377 end
2365 2378 issue = Issue.order('id DESC').first
2366 2379 assert_equal 3, issue.project_id
2367 2380 assert_equal 2, issue.tracker_id
2368 2381 end
2369 2382
2370 2383 def test_create_without_project_id_and_continue_should_redirect_without_project_id
2371 2384 @request.session[:user_id] = 2
2372 2385
2373 2386 assert_difference 'Issue.count' do
2374 2387 post :create,
2375 2388 :issue => {:project_id => 3,
2376 2389 :tracker_id => 2,
2377 2390 :subject => 'Foo'},
2378 2391 :continue => '1'
2379 2392 assert_redirected_to '/issues/new?issue%5Bproject_id%5D=3&issue%5Btracker_id%5D=2'
2380 2393 end
2381 2394 end
2382 2395
2383 2396 def test_create_without_project_id_should_be_denied_without_permission
2384 2397 Role.non_member.remove_permission! :add_issues
2385 2398 Role.anonymous.remove_permission! :add_issues
2386 2399 @request.session[:user_id] = 2
2387 2400
2388 2401 assert_no_difference 'Issue.count' do
2389 2402 post :create,
2390 2403 :issue => {:project_id => 3,
2391 2404 :tracker_id => 2,
2392 2405 :subject => 'Foo'}
2393 2406 assert_response 422
2394 2407 end
2395 2408 end
2396 2409
2397 2410 def test_create_without_project_id_with_failure
2398 2411 @request.session[:user_id] = 2
2399 2412
2400 2413 post :create,
2401 2414 :issue => {:project_id => 3,
2402 2415 :tracker_id => 2,
2403 2416 :subject => ''}
2404 2417 assert_response :success
2405 2418 assert_nil assigns(:project)
2406 2419 end
2407 2420
2408 2421 def test_post_create_should_send_a_notification
2409 2422 ActionMailer::Base.deliveries.clear
2410 2423 @request.session[:user_id] = 2
2411 2424 with_settings :notified_events => %w(issue_added) do
2412 2425 assert_difference 'Issue.count' do
2413 2426 post :create, :project_id => 1,
2414 2427 :issue => {:tracker_id => 3,
2415 2428 :subject => 'This is the test_new issue',
2416 2429 :description => 'This is the description',
2417 2430 :priority_id => 5,
2418 2431 :estimated_hours => '',
2419 2432 :custom_field_values => {'2' => 'Value for field 2'}}
2420 2433 end
2421 2434 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
2422 2435
2423 2436 assert_equal 1, ActionMailer::Base.deliveries.size
2424 2437 end
2425 2438 end
2426 2439
2427 2440 def test_post_create_should_preserve_fields_values_on_validation_failure
2428 2441 @request.session[:user_id] = 2
2429 2442 post :create, :project_id => 1,
2430 2443 :issue => {:tracker_id => 1,
2431 2444 # empty subject
2432 2445 :subject => '',
2433 2446 :description => 'This is a description',
2434 2447 :priority_id => 6,
2435 2448 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
2436 2449 assert_response :success
2437 2450 assert_template 'new'
2438 2451
2439 2452 assert_select 'textarea[name=?]', 'issue[description]', :text => 'This is a description'
2440 2453 assert_select 'select[name=?]', 'issue[priority_id]' do
2441 2454 assert_select 'option[value="6"][selected=selected]', :text => 'High'
2442 2455 end
2443 2456 # Custom fields
2444 2457 assert_select 'select[name=?]', 'issue[custom_field_values][1]' do
2445 2458 assert_select 'option[value=Oracle][selected=selected]', :text => 'Oracle'
2446 2459 end
2447 2460 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Value for field 2'
2448 2461 end
2449 2462
2450 2463 def test_post_create_with_failure_should_preserve_watchers
2451 2464 assert !User.find(8).member_of?(Project.find(1))
2452 2465
2453 2466 @request.session[:user_id] = 2
2454 2467 post :create, :project_id => 1,
2455 2468 :issue => {:tracker_id => 1,
2456 2469 :watcher_user_ids => ['3', '8']}
2457 2470 assert_response :success
2458 2471 assert_template 'new'
2459 2472
2460 2473 assert_select 'input[name=?][value="2"]:not(checked)', 'issue[watcher_user_ids][]'
2461 2474 assert_select 'input[name=?][value="3"][checked=checked]', 'issue[watcher_user_ids][]'
2462 2475 assert_select 'input[name=?][value="8"][checked=checked]', 'issue[watcher_user_ids][]'
2463 2476 end
2464 2477
2465 2478 def test_post_create_should_ignore_non_safe_attributes
2466 2479 @request.session[:user_id] = 2
2467 2480 assert_nothing_raised do
2468 2481 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
2469 2482 end
2470 2483 end
2471 2484
2472 2485 def test_post_create_with_attachment
2473 2486 set_tmp_attachments_directory
2474 2487 @request.session[:user_id] = 2
2475 2488
2476 2489 assert_difference 'Issue.count' do
2477 2490 assert_difference 'Attachment.count' do
2478 2491 assert_no_difference 'Journal.count' do
2479 2492 post :create, :project_id => 1,
2480 2493 :issue => { :tracker_id => '1', :subject => 'With attachment' },
2481 2494 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2482 2495 end
2483 2496 end
2484 2497 end
2485 2498
2486 2499 issue = Issue.order('id DESC').first
2487 2500 attachment = Attachment.order('id DESC').first
2488 2501
2489 2502 assert_equal issue, attachment.container
2490 2503 assert_equal 2, attachment.author_id
2491 2504 assert_equal 'testfile.txt', attachment.filename
2492 2505 assert_equal 'text/plain', attachment.content_type
2493 2506 assert_equal 'test file', attachment.description
2494 2507 assert_equal 59, attachment.filesize
2495 2508 assert File.exists?(attachment.diskfile)
2496 2509 assert_equal 59, File.size(attachment.diskfile)
2497 2510 end
2498 2511
2499 2512 def test_post_create_with_attachment_should_notify_with_attachments
2500 2513 ActionMailer::Base.deliveries.clear
2501 2514 set_tmp_attachments_directory
2502 2515 @request.session[:user_id] = 2
2503 2516
2504 2517 with_settings :host_name => 'mydomain.foo', :protocol => 'http', :notified_events => %w(issue_added) do
2505 2518 assert_difference 'Issue.count' do
2506 2519 post :create, :project_id => 1,
2507 2520 :issue => { :tracker_id => '1', :subject => 'With attachment' },
2508 2521 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2509 2522 end
2510 2523 end
2511 2524
2512 2525 assert_not_nil ActionMailer::Base.deliveries.last
2513 2526 assert_select_email do
2514 2527 assert_select 'a[href^=?]', 'http://mydomain.foo/attachments/download', 'testfile.txt'
2515 2528 end
2516 2529 end
2517 2530
2518 2531 def test_post_create_with_failure_should_save_attachments
2519 2532 set_tmp_attachments_directory
2520 2533 @request.session[:user_id] = 2
2521 2534
2522 2535 assert_no_difference 'Issue.count' do
2523 2536 assert_difference 'Attachment.count' do
2524 2537 post :create, :project_id => 1,
2525 2538 :issue => { :tracker_id => '1', :subject => '' },
2526 2539 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2527 2540 assert_response :success
2528 2541 assert_template 'new'
2529 2542 end
2530 2543 end
2531 2544
2532 2545 attachment = Attachment.order('id DESC').first
2533 2546 assert_equal 'testfile.txt', attachment.filename
2534 2547 assert File.exists?(attachment.diskfile)
2535 2548 assert_nil attachment.container
2536 2549
2537 2550 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
2538 2551 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
2539 2552 end
2540 2553
2541 2554 def test_post_create_with_failure_should_keep_saved_attachments
2542 2555 set_tmp_attachments_directory
2543 2556 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2544 2557 @request.session[:user_id] = 2
2545 2558
2546 2559 assert_no_difference 'Issue.count' do
2547 2560 assert_no_difference 'Attachment.count' do
2548 2561 post :create, :project_id => 1,
2549 2562 :issue => { :tracker_id => '1', :subject => '' },
2550 2563 :attachments => {'p0' => {'token' => attachment.token}}
2551 2564 assert_response :success
2552 2565 assert_template 'new'
2553 2566 end
2554 2567 end
2555 2568
2556 2569 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
2557 2570 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
2558 2571 end
2559 2572
2560 2573 def test_post_create_should_attach_saved_attachments
2561 2574 set_tmp_attachments_directory
2562 2575 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2563 2576 @request.session[:user_id] = 2
2564 2577
2565 2578 assert_difference 'Issue.count' do
2566 2579 assert_no_difference 'Attachment.count' do
2567 2580 post :create, :project_id => 1,
2568 2581 :issue => { :tracker_id => '1', :subject => 'Saved attachments' },
2569 2582 :attachments => {'p0' => {'token' => attachment.token}}
2570 2583 assert_response 302
2571 2584 end
2572 2585 end
2573 2586
2574 2587 issue = Issue.order('id DESC').first
2575 2588 assert_equal 1, issue.attachments.count
2576 2589
2577 2590 attachment.reload
2578 2591 assert_equal issue, attachment.container
2579 2592 end
2580 2593
2581 2594 def setup_without_workflow_privilege
2582 2595 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2583 2596 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2584 2597 end
2585 2598 private :setup_without_workflow_privilege
2586 2599
2587 2600 test "without workflow privilege #new should propose default status only" do
2588 2601 setup_without_workflow_privilege
2589 2602 get :new, :project_id => 1
2590 2603 assert_response :success
2591 2604 assert_template 'new'
2592 2605
2593 2606 issue = assigns(:issue)
2594 2607 assert_not_nil issue.default_status
2595 2608
2596 2609 assert_select 'select[name=?]', 'issue[status_id]' do
2597 2610 assert_select 'option', 1
2598 2611 assert_select 'option[value=?]', issue.default_status.id.to_s
2599 2612 end
2600 2613 end
2601 2614
2602 2615 test "without workflow privilege #create should accept default status" do
2603 2616 setup_without_workflow_privilege
2604 2617 assert_difference 'Issue.count' do
2605 2618 post :create, :project_id => 1,
2606 2619 :issue => {:tracker_id => 1,
2607 2620 :subject => 'This is an issue',
2608 2621 :status_id => 1}
2609 2622 end
2610 2623 issue = Issue.order('id').last
2611 2624 assert_not_nil issue.default_status
2612 2625 assert_equal issue.default_status, issue.status
2613 2626 end
2614 2627
2615 2628 test "without workflow privilege #create should ignore unauthorized status" do
2616 2629 setup_without_workflow_privilege
2617 2630 assert_difference 'Issue.count' do
2618 2631 post :create, :project_id => 1,
2619 2632 :issue => {:tracker_id => 1,
2620 2633 :subject => 'This is an issue',
2621 2634 :status_id => 3}
2622 2635 end
2623 2636 issue = Issue.order('id').last
2624 2637 assert_not_nil issue.default_status
2625 2638 assert_equal issue.default_status, issue.status
2626 2639 end
2627 2640
2628 2641 test "without workflow privilege #update should ignore status change" do
2629 2642 setup_without_workflow_privilege
2630 2643 assert_difference 'Journal.count' do
2631 2644 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2632 2645 end
2633 2646 assert_equal 1, Issue.find(1).status_id
2634 2647 end
2635 2648
2636 2649 test "without workflow privilege #update ignore attributes changes" do
2637 2650 setup_without_workflow_privilege
2638 2651 assert_difference 'Journal.count' do
2639 2652 put :update, :id => 1,
2640 2653 :issue => {:subject => 'changed', :assigned_to_id => 2,
2641 2654 :notes => 'just trying'}
2642 2655 end
2643 2656 issue = Issue.find(1)
2644 2657 assert_equal "Cannot print recipes", issue.subject
2645 2658 assert_nil issue.assigned_to
2646 2659 end
2647 2660
2648 2661 def setup_with_workflow_privilege
2649 2662 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2650 2663 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1,
2651 2664 :old_status_id => 1, :new_status_id => 3)
2652 2665 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1,
2653 2666 :old_status_id => 1, :new_status_id => 4)
2654 2667 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2655 2668 end
2656 2669 private :setup_with_workflow_privilege
2657 2670
2658 2671 def setup_with_workflow_privilege_and_edit_issues_permission
2659 2672 setup_with_workflow_privilege
2660 2673 Role.anonymous.add_permission! :add_issues, :edit_issues
2661 2674 end
2662 2675 private :setup_with_workflow_privilege_and_edit_issues_permission
2663 2676
2664 2677 test "with workflow privilege and :edit_issues permission should accept authorized status" do
2665 2678 setup_with_workflow_privilege_and_edit_issues_permission
2666 2679 assert_difference 'Journal.count' do
2667 2680 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2668 2681 end
2669 2682 assert_equal 3, Issue.find(1).status_id
2670 2683 end
2671 2684
2672 2685 test "with workflow privilege and :edit_issues permission should ignore unauthorized status" do
2673 2686 setup_with_workflow_privilege_and_edit_issues_permission
2674 2687 assert_difference 'Journal.count' do
2675 2688 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
2676 2689 end
2677 2690 assert_equal 1, Issue.find(1).status_id
2678 2691 end
2679 2692
2680 2693 test "with workflow privilege and :edit_issues permission should accept authorized attributes changes" do
2681 2694 setup_with_workflow_privilege_and_edit_issues_permission
2682 2695 assert_difference 'Journal.count' do
2683 2696 put :update, :id => 1,
2684 2697 :issue => {:subject => 'changed', :assigned_to_id => 2,
2685 2698 :notes => 'just trying'}
2686 2699 end
2687 2700 issue = Issue.find(1)
2688 2701 assert_equal "changed", issue.subject
2689 2702 assert_equal 2, issue.assigned_to_id
2690 2703 end
2691 2704
2692 2705 def test_new_as_copy
2693 2706 @request.session[:user_id] = 2
2694 2707 get :new, :project_id => 1, :copy_from => 1
2695 2708
2696 2709 assert_response :success
2697 2710 assert_template 'new'
2698 2711
2699 2712 assert_not_nil assigns(:issue)
2700 2713 orig = Issue.find(1)
2701 2714 assert_equal 1, assigns(:issue).project_id
2702 2715 assert_equal orig.subject, assigns(:issue).subject
2703 2716 assert assigns(:issue).copy?
2704 2717
2705 2718 assert_select 'form[id=issue-form][action="/projects/ecookbook/issues"]' do
2706 2719 assert_select 'select[name=?]', 'issue[project_id]' do
2707 2720 assert_select 'option[value="1"][selected=selected]', :text => 'eCookbook'
2708 2721 assert_select 'option[value="2"]:not([selected])', :text => 'OnlineStore'
2709 2722 end
2710 2723 assert_select 'input[name=copy_from][value="1"]'
2711 2724 end
2712 2725
2713 2726 # "New issue" menu item should not link to copy
2714 2727 assert_select '#main-menu a.new-issue[href="/projects/ecookbook/issues/new"]'
2715 2728 end
2716 2729
2717 2730 def test_new_as_copy_without_add_issues_permission_should_not_propose_current_project_as_target
2718 2731 user = setup_user_with_copy_but_not_add_permission
2719 2732
2720 2733 @request.session[:user_id] = user.id
2721 2734 get :new, :project_id => 1, :copy_from => 1
2722 2735
2723 2736 assert_response :success
2724 2737 assert_template 'new'
2725 2738 assert_select 'select[name=?]', 'issue[project_id]' do
2726 2739 assert_select 'option[value="1"]', 0
2727 2740 assert_select 'option[value="2"]', :text => 'OnlineStore'
2728 2741 end
2729 2742 end
2730 2743
2731 2744 def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox
2732 2745 @request.session[:user_id] = 2
2733 2746 issue = Issue.find(3)
2734 2747 assert issue.attachments.count > 0
2735 2748 get :new, :project_id => 1, :copy_from => 3
2736 2749
2737 2750 assert_select 'input[name=copy_attachments][type=checkbox][checked=checked][value="1"]'
2738 2751 end
2739 2752
2740 2753 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
2741 2754 @request.session[:user_id] = 2
2742 2755 issue = Issue.find(3)
2743 2756 issue.attachments.delete_all
2744 2757 get :new, :project_id => 1, :copy_from => 3
2745 2758
2746 2759 assert_select 'input[name=copy_attachments]', 0
2747 2760 end
2748 2761
2749 2762 def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox
2750 2763 @request.session[:user_id] = 2
2751 2764 issue = Issue.generate_with_descendants!
2752 2765 get :new, :project_id => 1, :copy_from => issue.id
2753 2766
2754 2767 assert_select 'input[type=checkbox][name=copy_subtasks][checked=checked][value="1"]'
2755 2768 end
2756 2769
2757 2770 def test_new_as_copy_with_invalid_issue_should_respond_with_404
2758 2771 @request.session[:user_id] = 2
2759 2772 get :new, :project_id => 1, :copy_from => 99999
2760 2773 assert_response 404
2761 2774 end
2762 2775
2763 2776 def test_create_as_copy_on_different_project
2764 2777 @request.session[:user_id] = 2
2765 2778 assert_difference 'Issue.count' do
2766 2779 post :create, :project_id => 1, :copy_from => 1,
2767 2780 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2768 2781
2769 2782 assert_not_nil assigns(:issue)
2770 2783 assert assigns(:issue).copy?
2771 2784 end
2772 2785 issue = Issue.order('id DESC').first
2773 2786 assert_redirected_to "/issues/#{issue.id}"
2774 2787
2775 2788 assert_equal 2, issue.project_id
2776 2789 assert_equal 3, issue.tracker_id
2777 2790 assert_equal 'Copy', issue.subject
2778 2791 end
2779 2792
2780 2793 def test_create_as_copy_should_allow_status_to_be_set_to_default
2781 2794 copied = Issue.generate! :status_id => 2
2782 2795 assert_equal 2, copied.reload.status_id
2783 2796
2784 2797 @request.session[:user_id] = 2
2785 2798 assert_difference 'Issue.count' do
2786 2799 post :create, :project_id => 1, :copy_from => copied.id,
2787 2800 :issue => {:project_id => '1', :tracker_id => '1', :status_id => '1'},
2788 2801 :was_default_status => '1'
2789 2802 end
2790 2803 issue = Issue.order('id DESC').first
2791 2804 assert_equal 1, issue.status_id
2792 2805 end
2793 2806
2794 2807 def test_create_as_copy_should_copy_attachments
2795 2808 @request.session[:user_id] = 2
2796 2809 issue = Issue.find(3)
2797 2810 count = issue.attachments.count
2798 2811 assert count > 0
2799 2812 assert_difference 'Issue.count' do
2800 2813 assert_difference 'Attachment.count', count do
2801 2814 post :create, :project_id => 1, :copy_from => 3,
2802 2815 :issue => {:project_id => '1', :tracker_id => '3',
2803 2816 :status_id => '1', :subject => 'Copy with attachments'},
2804 2817 :copy_attachments => '1'
2805 2818 end
2806 2819 end
2807 2820 copy = Issue.order('id DESC').first
2808 2821 assert_equal count, copy.attachments.count
2809 2822 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
2810 2823 end
2811 2824
2812 2825 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
2813 2826 @request.session[:user_id] = 2
2814 2827 issue = Issue.find(3)
2815 2828 count = issue.attachments.count
2816 2829 assert count > 0
2817 2830 assert_difference 'Issue.count' do
2818 2831 assert_no_difference 'Attachment.count' do
2819 2832 post :create, :project_id => 1, :copy_from => 3,
2820 2833 :issue => {:project_id => '1', :tracker_id => '3',
2821 2834 :status_id => '1', :subject => 'Copy with attachments'}
2822 2835 end
2823 2836 end
2824 2837 copy = Issue.order('id DESC').first
2825 2838 assert_equal 0, copy.attachments.count
2826 2839 end
2827 2840
2828 2841 def test_create_as_copy_with_attachments_should_also_add_new_files
2829 2842 @request.session[:user_id] = 2
2830 2843 issue = Issue.find(3)
2831 2844 count = issue.attachments.count
2832 2845 assert count > 0
2833 2846 assert_difference 'Issue.count' do
2834 2847 assert_difference 'Attachment.count', count + 1 do
2835 2848 post :create, :project_id => 1, :copy_from => 3,
2836 2849 :issue => {:project_id => '1', :tracker_id => '3',
2837 2850 :status_id => '1', :subject => 'Copy with attachments'},
2838 2851 :copy_attachments => '1',
2839 2852 :attachments => {'1' =>
2840 2853 {'file' => uploaded_test_file('testfile.txt', 'text/plain'),
2841 2854 'description' => 'test file'}}
2842 2855 end
2843 2856 end
2844 2857 copy = Issue.order('id DESC').first
2845 2858 assert_equal count + 1, copy.attachments.count
2846 2859 end
2847 2860
2848 2861 def test_create_as_copy_should_add_relation_with_copied_issue
2849 2862 @request.session[:user_id] = 2
2850 2863 assert_difference 'Issue.count' do
2851 2864 assert_difference 'IssueRelation.count' do
2852 2865 post :create, :project_id => 1, :copy_from => 1, :link_copy => '1',
2853 2866 :issue => {:project_id => '1', :tracker_id => '3',
2854 2867 :status_id => '1', :subject => 'Copy'}
2855 2868 end
2856 2869 end
2857 2870 copy = Issue.order('id DESC').first
2858 2871 assert_equal 1, copy.relations.size
2859 2872 end
2860 2873
2861 2874 def test_create_as_copy_should_allow_not_to_add_relation_with_copied_issue
2862 2875 @request.session[:user_id] = 2
2863 2876 assert_difference 'Issue.count' do
2864 2877 assert_no_difference 'IssueRelation.count' do
2865 2878 post :create, :project_id => 1, :copy_from => 1,
2866 2879 :issue => {:subject => 'Copy'}
2867 2880 end
2868 2881 end
2869 2882 end
2870 2883
2871 2884 def test_create_as_copy_should_always_add_relation_with_copied_issue_by_setting
2872 2885 with_settings :link_copied_issue => 'yes' do
2873 2886 @request.session[:user_id] = 2
2874 2887 assert_difference 'Issue.count' do
2875 2888 assert_difference 'IssueRelation.count' do
2876 2889 post :create, :project_id => 1, :copy_from => 1,
2877 2890 :issue => {:subject => 'Copy'}
2878 2891 end
2879 2892 end
2880 2893 end
2881 2894 end
2882 2895
2883 2896 def test_create_as_copy_should_never_add_relation_with_copied_issue_by_setting
2884 2897 with_settings :link_copied_issue => 'no' do
2885 2898 @request.session[:user_id] = 2
2886 2899 assert_difference 'Issue.count' do
2887 2900 assert_no_difference 'IssueRelation.count' do
2888 2901 post :create, :project_id => 1, :copy_from => 1, :link_copy => '1',
2889 2902 :issue => {:subject => 'Copy'}
2890 2903 end
2891 2904 end
2892 2905 end
2893 2906 end
2894 2907
2895 2908 def test_create_as_copy_should_copy_subtasks
2896 2909 @request.session[:user_id] = 2
2897 2910 issue = Issue.generate_with_descendants!
2898 2911 count = issue.descendants.count
2899 2912 assert_difference 'Issue.count', count + 1 do
2900 2913 post :create, :project_id => 1, :copy_from => issue.id,
2901 2914 :issue => {:project_id => '1', :tracker_id => '3',
2902 2915 :status_id => '1', :subject => 'Copy with subtasks'},
2903 2916 :copy_subtasks => '1'
2904 2917 end
2905 2918 copy = Issue.where(:parent_id => nil).order('id DESC').first
2906 2919 assert_equal count, copy.descendants.count
2907 2920 assert_equal issue.descendants.map(&:subject).sort, copy.descendants.map(&:subject).sort
2908 2921 end
2909 2922
2910 2923 def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks
2911 2924 @request.session[:user_id] = 2
2912 2925 issue = Issue.generate_with_descendants!
2913 2926 assert_difference 'Issue.count', 1 do
2914 2927 post :create, :project_id => 1, :copy_from => 3,
2915 2928 :issue => {:project_id => '1', :tracker_id => '3',
2916 2929 :status_id => '1', :subject => 'Copy with subtasks'}
2917 2930 end
2918 2931 copy = Issue.where(:parent_id => nil).order('id DESC').first
2919 2932 assert_equal 0, copy.descendants.count
2920 2933 end
2921 2934
2922 2935 def test_create_as_copy_with_failure
2923 2936 @request.session[:user_id] = 2
2924 2937 post :create, :project_id => 1, :copy_from => 1,
2925 2938 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''}
2926 2939
2927 2940 assert_response :success
2928 2941 assert_template 'new'
2929 2942
2930 2943 assert_not_nil assigns(:issue)
2931 2944 assert assigns(:issue).copy?
2932 2945
2933 2946 assert_select 'form#issue-form[action="/projects/ecookbook/issues"]' do
2934 2947 assert_select 'select[name=?]', 'issue[project_id]' do
2935 2948 assert_select 'option[value="1"]:not([selected])', :text => 'eCookbook'
2936 2949 assert_select 'option[value="2"][selected=selected]', :text => 'OnlineStore'
2937 2950 end
2938 2951 assert_select 'input[name=copy_from][value="1"]'
2939 2952 end
2940 2953 end
2941 2954
2942 2955 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
2943 2956 @request.session[:user_id] = 2
2944 2957 assert !User.find(2).member_of?(Project.find(4))
2945 2958
2946 2959 assert_difference 'Issue.count' do
2947 2960 post :create, :project_id => 1, :copy_from => 1,
2948 2961 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2949 2962 end
2950 2963 issue = Issue.order('id DESC').first
2951 2964 assert_equal 1, issue.project_id
2952 2965 end
2953 2966
2954 2967 def test_get_edit
2955 2968 @request.session[:user_id] = 2
2956 2969 get :edit, :id => 1
2957 2970 assert_response :success
2958 2971 assert_template 'edit'
2959 2972 assert_not_nil assigns(:issue)
2960 2973 assert_equal Issue.find(1), assigns(:issue)
2961 2974
2962 2975 # Be sure we don't display inactive IssuePriorities
2963 2976 assert ! IssuePriority.find(15).active?
2964 2977 assert_select 'select[name=?]', 'issue[priority_id]' do
2965 2978 assert_select 'option[value="15"]', 0
2966 2979 end
2967 2980 end
2968 2981
2969 2982 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
2970 2983 @request.session[:user_id] = 2
2971 2984 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
2972 2985
2973 2986 get :edit, :id => 1
2974 2987 assert_select 'input[name=?]', 'time_entry[hours]'
2975 2988 end
2976 2989
2977 2990 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
2978 2991 @request.session[:user_id] = 2
2979 2992 Role.find_by_name('Manager').remove_permission! :log_time
2980 2993
2981 2994 get :edit, :id => 1
2982 2995 assert_select 'input[name=?]', 'time_entry[hours]', 0
2983 2996 end
2984 2997
2985 2998 def test_get_edit_with_params
2986 2999 @request.session[:user_id] = 2
2987 3000 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
2988 3001 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => 10 }
2989 3002 assert_response :success
2990 3003 assert_template 'edit'
2991 3004
2992 3005 issue = assigns(:issue)
2993 3006 assert_not_nil issue
2994 3007
2995 3008 assert_equal 5, issue.status_id
2996 3009 assert_select 'select[name=?]', 'issue[status_id]' do
2997 3010 assert_select 'option[value="5"][selected=selected]', :text => 'Closed'
2998 3011 end
2999 3012
3000 3013 assert_equal 7, issue.priority_id
3001 3014 assert_select 'select[name=?]', 'issue[priority_id]' do
3002 3015 assert_select 'option[value="7"][selected=selected]', :text => 'Urgent'
3003 3016 end
3004 3017
3005 3018 assert_select 'input[name=?][value="2.5"]', 'time_entry[hours]'
3006 3019 assert_select 'select[name=?]', 'time_entry[activity_id]' do
3007 3020 assert_select 'option[value="10"][selected=selected]', :text => 'Development'
3008 3021 end
3009 3022 assert_select 'input[name=?][value=test_get_edit_with_params]', 'time_entry[comments]'
3010 3023 end
3011 3024
3012 3025 def test_get_edit_with_multi_custom_field
3013 3026 field = CustomField.find(1)
3014 3027 field.update_attribute :multiple, true
3015 3028 issue = Issue.find(1)
3016 3029 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
3017 3030 issue.save!
3018 3031
3019 3032 @request.session[:user_id] = 2
3020 3033 get :edit, :id => 1
3021 3034 assert_response :success
3022 3035 assert_template 'edit'
3023 3036
3024 3037 assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do
3025 3038 assert_select 'option', 3
3026 3039 assert_select 'option[value=MySQL][selected=selected]'
3027 3040 assert_select 'option[value=Oracle][selected=selected]'
3028 3041 assert_select 'option[value=PostgreSQL]:not([selected])'
3029 3042 end
3030 3043 end
3031 3044
3032 3045 def test_update_form_for_existing_issue
3033 3046 @request.session[:user_id] = 2
3034 3047 xhr :patch, :edit, :id => 1,
3035 3048 :issue => {:tracker_id => 2,
3036 3049 :subject => 'This is the test_new issue',
3037 3050 :description => 'This is the description',
3038 3051 :priority_id => 5}
3039 3052 assert_response :success
3040 3053 assert_equal 'text/javascript', response.content_type
3041 3054 assert_template 'edit'
3042 3055 assert_template :partial => '_form'
3043 3056
3044 3057 issue = assigns(:issue)
3045 3058 assert_kind_of Issue, issue
3046 3059 assert_equal 1, issue.id
3047 3060 assert_equal 1, issue.project_id
3048 3061 assert_equal 2, issue.tracker_id
3049 3062 assert_equal 'This is the test_new issue', issue.subject
3050 3063 end
3051 3064
3052 3065 def test_update_form_for_existing_issue_should_keep_issue_author
3053 3066 @request.session[:user_id] = 3
3054 3067 xhr :patch, :edit, :id => 1, :issue => {:subject => 'Changed'}
3055 3068 assert_response :success
3056 3069 assert_equal 'text/javascript', response.content_type
3057 3070
3058 3071 issue = assigns(:issue)
3059 3072 assert_equal User.find(2), issue.author
3060 3073 assert_equal 2, issue.author_id
3061 3074 assert_not_equal User.current, issue.author
3062 3075 end
3063 3076
3064 3077 def test_update_form_for_existing_issue_should_propose_transitions_based_on_initial_status
3065 3078 @request.session[:user_id] = 2
3066 3079 WorkflowTransition.delete_all
3067 3080 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
3068 3081 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
3069 3082 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4)
3070 3083
3071 3084 xhr :patch, :edit, :id => 2,
3072 3085 :issue => {:tracker_id => 2,
3073 3086 :status_id => 5,
3074 3087 :subject => 'This is an issue'}
3075 3088
3076 3089 assert_equal 5, assigns(:issue).status_id
3077 3090 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
3078 3091 end
3079 3092
3080 3093 def test_update_form_for_existing_issue_with_project_change
3081 3094 @request.session[:user_id] = 2
3082 3095 xhr :patch, :edit, :id => 1,
3083 3096 :issue => {:project_id => 2,
3084 3097 :tracker_id => 2,
3085 3098 :subject => 'This is the test_new issue',
3086 3099 :description => 'This is the description',
3087 3100 :priority_id => 5}
3088 3101 assert_response :success
3089 3102 assert_template :partial => '_form'
3090 3103
3091 3104 issue = assigns(:issue)
3092 3105 assert_kind_of Issue, issue
3093 3106 assert_equal 1, issue.id
3094 3107 assert_equal 2, issue.project_id
3095 3108 assert_equal 2, issue.tracker_id
3096 3109 assert_equal 'This is the test_new issue', issue.subject
3097 3110 end
3098 3111
3099 3112 def test_update_form_should_keep_category_with_same_when_changing_project
3100 3113 source = Project.generate!
3101 3114 target = Project.generate!
3102 3115 source_category = IssueCategory.create!(:name => 'Foo', :project => source)
3103 3116 target_category = IssueCategory.create!(:name => 'Foo', :project => target)
3104 3117 issue = Issue.generate!(:project => source, :category => source_category)
3105 3118
3106 3119 @request.session[:user_id] = 1
3107 3120 patch :edit, :id => issue.id,
3108 3121 :issue => {:project_id => target.id, :category_id => source_category.id}
3109 3122 assert_response :success
3110 3123
3111 3124 issue = assigns(:issue)
3112 3125 assert_equal target_category, issue.category
3113 3126 end
3114 3127
3115 3128 def test_update_form_should_propose_default_status_for_existing_issue
3116 3129 @request.session[:user_id] = 2
3117 3130 WorkflowTransition.delete_all
3118 3131 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
3119 3132
3120 3133 xhr :patch, :edit, :id => 2
3121 3134 assert_response :success
3122 3135 assert_equal [2,3], assigns(:allowed_statuses).map(&:id).sort
3123 3136 end
3124 3137
3125 3138 def test_put_update_without_custom_fields_param
3126 3139 @request.session[:user_id] = 2
3127 3140
3128 3141 issue = Issue.find(1)
3129 3142 assert_equal '125', issue.custom_value_for(2).value
3130 3143
3131 3144 assert_difference('Journal.count') do
3132 3145 assert_difference('JournalDetail.count') do
3133 3146 put :update, :id => 1, :issue => {:subject => 'New subject'}
3134 3147 end
3135 3148 end
3136 3149 assert_redirected_to :action => 'show', :id => '1'
3137 3150 issue.reload
3138 3151 assert_equal 'New subject', issue.subject
3139 3152 # Make sure custom fields were not cleared
3140 3153 assert_equal '125', issue.custom_value_for(2).value
3141 3154 end
3142 3155
3143 3156 def test_put_update_with_project_change
3144 3157 @request.session[:user_id] = 2
3145 3158 ActionMailer::Base.deliveries.clear
3146 3159
3147 3160 with_settings :notified_events => %w(issue_updated) do
3148 3161 assert_difference('Journal.count') do
3149 3162 assert_difference('JournalDetail.count', 3) do
3150 3163 put :update, :id => 1, :issue => {:project_id => '2',
3151 3164 :tracker_id => '1', # no change
3152 3165 :priority_id => '6',
3153 3166 :category_id => '3'
3154 3167 }
3155 3168 end
3156 3169 end
3157 3170 end
3158 3171 assert_redirected_to :action => 'show', :id => '1'
3159 3172 issue = Issue.find(1)
3160 3173 assert_equal 2, issue.project_id
3161 3174 assert_equal 1, issue.tracker_id
3162 3175 assert_equal 6, issue.priority_id
3163 3176 assert_equal 3, issue.category_id
3164 3177
3165 3178 mail = ActionMailer::Base.deliveries.last
3166 3179 assert_not_nil mail
3167 3180 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
3168 3181 assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail
3169 3182 end
3170 3183
3171 3184 def test_put_update_trying_to_move_issue_to_project_without_tracker_should_not_error
3172 3185 target = Project.generate!(:tracker_ids => [])
3173 3186 assert target.trackers.empty?
3174 3187 issue = Issue.generate!
3175 3188 @request.session[:user_id] = 1
3176 3189
3177 3190 put :update, :id => issue.id, :issue => {:project_id => target.id}
3178 3191 assert_response 302
3179 3192 end
3180 3193
3181 3194 def test_put_update_with_tracker_change
3182 3195 @request.session[:user_id] = 2
3183 3196 ActionMailer::Base.deliveries.clear
3184 3197
3185 3198 with_settings :notified_events => %w(issue_updated) do
3186 3199 assert_difference('Journal.count') do
3187 3200 assert_difference('JournalDetail.count', 2) do
3188 3201 put :update, :id => 1, :issue => {:project_id => '1',
3189 3202 :tracker_id => '2',
3190 3203 :priority_id => '6'
3191 3204 }
3192 3205 end
3193 3206 end
3194 3207 end
3195 3208 assert_redirected_to :action => 'show', :id => '1'
3196 3209 issue = Issue.find(1)
3197 3210 assert_equal 1, issue.project_id
3198 3211 assert_equal 2, issue.tracker_id
3199 3212 assert_equal 6, issue.priority_id
3200 3213 assert_equal 1, issue.category_id
3201 3214
3202 3215 mail = ActionMailer::Base.deliveries.last
3203 3216 assert_not_nil mail
3204 3217 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
3205 3218 assert_mail_body_match "Tracker changed from Bug to Feature request", mail
3206 3219 end
3207 3220
3208 3221 def test_put_update_with_custom_field_change
3209 3222 @request.session[:user_id] = 2
3210 3223 issue = Issue.find(1)
3211 3224 assert_equal '125', issue.custom_value_for(2).value
3212 3225
3213 3226 with_settings :notified_events => %w(issue_updated) do
3214 3227 assert_difference('Journal.count') do
3215 3228 assert_difference('JournalDetail.count', 3) do
3216 3229 put :update, :id => 1, :issue => {:subject => 'Custom field change',
3217 3230 :priority_id => '6',
3218 3231 :category_id => '1', # no change
3219 3232 :custom_field_values => { '2' => 'New custom value' }
3220 3233 }
3221 3234 end
3222 3235 end
3223 3236 end
3224 3237 assert_redirected_to :action => 'show', :id => '1'
3225 3238 issue.reload
3226 3239 assert_equal 'New custom value', issue.custom_value_for(2).value
3227 3240
3228 3241 mail = ActionMailer::Base.deliveries.last
3229 3242 assert_not_nil mail
3230 3243 assert_mail_body_match "Searchable field changed from 125 to New custom value", mail
3231 3244 end
3232 3245
3233 3246 def test_put_update_with_multi_custom_field_change
3234 3247 field = CustomField.find(1)
3235 3248 field.update_attribute :multiple, true
3236 3249 issue = Issue.find(1)
3237 3250 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
3238 3251 issue.save!
3239 3252
3240 3253 @request.session[:user_id] = 2
3241 3254 assert_difference('Journal.count') do
3242 3255 assert_difference('JournalDetail.count', 3) do
3243 3256 put :update, :id => 1,
3244 3257 :issue => {
3245 3258 :subject => 'Custom field change',
3246 3259 :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] }
3247 3260 }
3248 3261 end
3249 3262 end
3250 3263 assert_redirected_to :action => 'show', :id => '1'
3251 3264 assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort
3252 3265 end
3253 3266
3254 3267 def test_put_update_with_status_and_assignee_change
3255 3268 issue = Issue.find(1)
3256 3269 assert_equal 1, issue.status_id
3257 3270 @request.session[:user_id] = 2
3258 3271
3259 3272 with_settings :notified_events => %w(issue_updated) do
3260 3273 assert_difference('TimeEntry.count', 0) do
3261 3274 put :update,
3262 3275 :id => 1,
3263 3276 :issue => { :status_id => 2, :assigned_to_id => 3, :notes => 'Assigned to dlopper' },
3264 3277 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
3265 3278 end
3266 3279 end
3267 3280 assert_redirected_to :action => 'show', :id => '1'
3268 3281 issue.reload
3269 3282 assert_equal 2, issue.status_id
3270 3283 j = Journal.order('id DESC').first
3271 3284 assert_equal 'Assigned to dlopper', j.notes
3272 3285 assert_equal 2, j.details.size
3273 3286
3274 3287 mail = ActionMailer::Base.deliveries.last
3275 3288 assert_mail_body_match "Status changed from New to Assigned", mail
3276 3289 # subject should contain the new status
3277 3290 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
3278 3291 end
3279 3292
3280 3293 def test_put_update_with_note_only
3281 3294 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
3282 3295
3283 3296 with_settings :notified_events => %w(issue_updated) do
3284 3297 # anonymous user
3285 3298 put :update,
3286 3299 :id => 1,
3287 3300 :issue => { :notes => notes }
3288 3301 end
3289 3302 assert_redirected_to :action => 'show', :id => '1'
3290 3303 j = Journal.order('id DESC').first
3291 3304 assert_equal notes, j.notes
3292 3305 assert_equal 0, j.details.size
3293 3306 assert_equal User.anonymous, j.user
3294 3307
3295 3308 mail = ActionMailer::Base.deliveries.last
3296 3309 assert_mail_body_match notes, mail
3297 3310 end
3298 3311
3299 3312 def test_put_update_with_private_note_only
3300 3313 notes = 'Private note'
3301 3314 @request.session[:user_id] = 2
3302 3315
3303 3316 assert_difference 'Journal.count' do
3304 3317 put :update, :id => 1, :issue => {:notes => notes, :private_notes => '1'}
3305 3318 assert_redirected_to :action => 'show', :id => '1'
3306 3319 end
3307 3320
3308 3321 j = Journal.order('id DESC').first
3309 3322 assert_equal notes, j.notes
3310 3323 assert_equal true, j.private_notes
3311 3324 end
3312 3325
3313 3326 def test_put_update_with_private_note_and_changes
3314 3327 notes = 'Private note'
3315 3328 @request.session[:user_id] = 2
3316 3329
3317 3330 assert_difference 'Journal.count', 2 do
3318 3331 put :update, :id => 1, :issue => {:subject => 'New subject', :notes => notes, :private_notes => '1'}
3319 3332 assert_redirected_to :action => 'show', :id => '1'
3320 3333 end
3321 3334
3322 3335 j = Journal.order('id DESC').first
3323 3336 assert_equal notes, j.notes
3324 3337 assert_equal true, j.private_notes
3325 3338 assert_equal 0, j.details.count
3326 3339
3327 3340 j = Journal.order('id DESC').offset(1).first
3328 3341 assert_nil j.notes
3329 3342 assert_equal false, j.private_notes
3330 3343 assert_equal 1, j.details.count
3331 3344 end
3332 3345
3333 3346 def test_put_update_with_note_and_spent_time
3334 3347 @request.session[:user_id] = 2
3335 3348 spent_hours_before = Issue.find(1).spent_hours
3336 3349 assert_difference('TimeEntry.count') do
3337 3350 put :update,
3338 3351 :id => 1,
3339 3352 :issue => { :notes => '2.5 hours added' },
3340 3353 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
3341 3354 end
3342 3355 assert_redirected_to :action => 'show', :id => '1'
3343 3356
3344 3357 issue = Issue.find(1)
3345 3358
3346 3359 j = Journal.order('id DESC').first
3347 3360 assert_equal '2.5 hours added', j.notes
3348 3361 assert_equal 0, j.details.size
3349 3362
3350 3363 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
3351 3364 assert_not_nil t
3352 3365 assert_equal 2.5, t.hours
3353 3366 assert_equal spent_hours_before + 2.5, issue.spent_hours
3354 3367 end
3355 3368
3356 3369 def test_put_update_should_preserve_parent_issue_even_if_not_visible
3357 3370 parent = Issue.generate!(:project_id => 1, :is_private => true)
3358 3371 issue = Issue.generate!(:parent_issue_id => parent.id)
3359 3372 assert !parent.visible?(User.find(3))
3360 3373 @request.session[:user_id] = 3
3361 3374
3362 3375 get :edit, :id => issue.id
3363 3376 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', parent.id.to_s
3364 3377
3365 3378 put :update, :id => issue.id, :issue => {:subject => 'New subject', :parent_issue_id => parent.id.to_s}
3366 3379 assert_response 302
3367 3380 assert_equal parent, issue.parent
3368 3381 end
3369 3382
3370 3383 def test_put_update_with_attachment_only
3371 3384 set_tmp_attachments_directory
3372 3385
3373 3386 # Delete all fixtured journals, a race condition can occur causing the wrong
3374 3387 # journal to get fetched in the next find.
3375 3388 Journal.delete_all
3376 3389
3377 3390 with_settings :notified_events => %w(issue_updated) do
3378 3391 # anonymous user
3379 3392 assert_difference 'Attachment.count' do
3380 3393 put :update, :id => 1,
3381 3394 :issue => {:notes => ''},
3382 3395 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
3383 3396 end
3384 3397 end
3385 3398
3386 3399 assert_redirected_to :action => 'show', :id => '1'
3387 3400 j = Issue.find(1).journals.reorder('id DESC').first
3388 3401 assert j.notes.blank?
3389 3402 assert_equal 1, j.details.size
3390 3403 assert_equal 'testfile.txt', j.details.first.value
3391 3404 assert_equal User.anonymous, j.user
3392 3405
3393 3406 attachment = Attachment.order('id DESC').first
3394 3407 assert_equal Issue.find(1), attachment.container
3395 3408 assert_equal User.anonymous, attachment.author
3396 3409 assert_equal 'testfile.txt', attachment.filename
3397 3410 assert_equal 'text/plain', attachment.content_type
3398 3411 assert_equal 'test file', attachment.description
3399 3412 assert_equal 59, attachment.filesize
3400 3413 assert File.exists?(attachment.diskfile)
3401 3414 assert_equal 59, File.size(attachment.diskfile)
3402 3415
3403 3416 mail = ActionMailer::Base.deliveries.last
3404 3417 assert_mail_body_match 'testfile.txt', mail
3405 3418 end
3406 3419
3407 3420 def test_put_update_with_failure_should_save_attachments
3408 3421 set_tmp_attachments_directory
3409 3422 @request.session[:user_id] = 2
3410 3423
3411 3424 assert_no_difference 'Journal.count' do
3412 3425 assert_difference 'Attachment.count' do
3413 3426 put :update, :id => 1,
3414 3427 :issue => { :subject => '' },
3415 3428 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
3416 3429 assert_response :success
3417 3430 assert_template 'edit'
3418 3431 end
3419 3432 end
3420 3433
3421 3434 attachment = Attachment.order('id DESC').first
3422 3435 assert_equal 'testfile.txt', attachment.filename
3423 3436 assert File.exists?(attachment.diskfile)
3424 3437 assert_nil attachment.container
3425 3438
3426 3439 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
3427 3440 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
3428 3441 end
3429 3442
3430 3443 def test_put_update_with_failure_should_keep_saved_attachments
3431 3444 set_tmp_attachments_directory
3432 3445 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
3433 3446 @request.session[:user_id] = 2
3434 3447
3435 3448 assert_no_difference 'Journal.count' do
3436 3449 assert_no_difference 'Attachment.count' do
3437 3450 put :update, :id => 1,
3438 3451 :issue => { :subject => '' },
3439 3452 :attachments => {'p0' => {'token' => attachment.token}}
3440 3453 assert_response :success
3441 3454 assert_template 'edit'
3442 3455 end
3443 3456 end
3444 3457
3445 3458 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
3446 3459 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
3447 3460 end
3448 3461
3449 3462 def test_put_update_should_attach_saved_attachments
3450 3463 set_tmp_attachments_directory
3451 3464 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
3452 3465 @request.session[:user_id] = 2
3453 3466
3454 3467 assert_difference 'Journal.count' do
3455 3468 assert_difference 'JournalDetail.count' do
3456 3469 assert_no_difference 'Attachment.count' do
3457 3470 put :update, :id => 1,
3458 3471 :issue => {:notes => 'Attachment added'},
3459 3472 :attachments => {'p0' => {'token' => attachment.token}}
3460 3473 assert_redirected_to '/issues/1'
3461 3474 end
3462 3475 end
3463 3476 end
3464 3477
3465 3478 attachment.reload
3466 3479 assert_equal Issue.find(1), attachment.container
3467 3480
3468 3481 journal = Journal.order('id DESC').first
3469 3482 assert_equal 1, journal.details.size
3470 3483 assert_equal 'testfile.txt', journal.details.first.value
3471 3484 end
3472 3485
3473 3486 def test_put_update_with_attachment_that_fails_to_save
3474 3487 set_tmp_attachments_directory
3475 3488
3476 3489 # anonymous user
3477 3490 with_settings :attachment_max_size => 0 do
3478 3491 put :update,
3479 3492 :id => 1,
3480 3493 :issue => {:notes => ''},
3481 3494 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
3482 3495 assert_redirected_to :action => 'show', :id => '1'
3483 3496 assert_equal '1 file(s) could not be saved.', flash[:warning]
3484 3497 end
3485 3498 end
3486 3499
3487 3500 def test_put_update_with_no_change
3488 3501 issue = Issue.find(1)
3489 3502 issue.journals.clear
3490 3503 ActionMailer::Base.deliveries.clear
3491 3504
3492 3505 put :update,
3493 3506 :id => 1,
3494 3507 :issue => {:notes => ''}
3495 3508 assert_redirected_to :action => 'show', :id => '1'
3496 3509
3497 3510 issue.reload
3498 3511 assert issue.journals.empty?
3499 3512 # No email should be sent
3500 3513 assert ActionMailer::Base.deliveries.empty?
3501 3514 end
3502 3515
3503 3516 def test_put_update_should_send_a_notification
3504 3517 @request.session[:user_id] = 2
3505 3518 ActionMailer::Base.deliveries.clear
3506 3519 issue = Issue.find(1)
3507 3520 old_subject = issue.subject
3508 3521 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
3509 3522
3510 3523 with_settings :notified_events => %w(issue_updated) do
3511 3524 put :update, :id => 1, :issue => {:subject => new_subject,
3512 3525 :priority_id => '6',
3513 3526 :category_id => '1' # no change
3514 3527 }
3515 3528 assert_equal 1, ActionMailer::Base.deliveries.size
3516 3529 end
3517 3530 end
3518 3531
3519 3532 def test_put_update_with_invalid_spent_time_hours_only
3520 3533 @request.session[:user_id] = 2
3521 3534 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
3522 3535
3523 3536 assert_no_difference('Journal.count') do
3524 3537 put :update,
3525 3538 :id => 1,
3526 3539 :issue => {:notes => notes},
3527 3540 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
3528 3541 end
3529 3542 assert_response :success
3530 3543 assert_template 'edit'
3531 3544
3532 3545 assert_select_error /Activity cannot be blank/
3533 3546 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
3534 3547 assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2z'
3535 3548 end
3536 3549
3537 3550 def test_put_update_with_invalid_spent_time_comments_only
3538 3551 @request.session[:user_id] = 2
3539 3552 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
3540 3553
3541 3554 assert_no_difference('Journal.count') do
3542 3555 put :update,
3543 3556 :id => 1,
3544 3557 :issue => {:notes => notes},
3545 3558 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
3546 3559 end
3547 3560 assert_response :success
3548 3561 assert_template 'edit'
3549 3562
3550 3563 assert_select_error /Activity cannot be blank/
3551 3564 assert_select_error /Hours cannot be blank/
3552 3565 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
3553 3566 assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'this is my comment'
3554 3567 end
3555 3568
3556 3569 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
3557 3570 issue = Issue.find(2)
3558 3571 @request.session[:user_id] = 2
3559 3572
3560 3573 put :update,
3561 3574 :id => issue.id,
3562 3575 :issue => {
3563 3576 :fixed_version_id => 4
3564 3577 }
3565 3578
3566 3579 assert_response :redirect
3567 3580 issue.reload
3568 3581 assert_equal 4, issue.fixed_version_id
3569 3582 assert_not_equal issue.project_id, issue.fixed_version.project_id
3570 3583 end
3571 3584
3572 3585 def test_put_update_should_redirect_back_using_the_back_url_parameter
3573 3586 issue = Issue.find(2)
3574 3587 @request.session[:user_id] = 2
3575 3588
3576 3589 put :update,
3577 3590 :id => issue.id,
3578 3591 :issue => {
3579 3592 :fixed_version_id => 4
3580 3593 },
3581 3594 :back_url => '/issues'
3582 3595
3583 3596 assert_response :redirect
3584 3597 assert_redirected_to '/issues'
3585 3598 end
3586 3599
3587 3600 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
3588 3601 issue = Issue.find(2)
3589 3602 @request.session[:user_id] = 2
3590 3603
3591 3604 put :update,
3592 3605 :id => issue.id,
3593 3606 :issue => {
3594 3607 :fixed_version_id => 4
3595 3608 },
3596 3609 :back_url => 'http://google.com'
3597 3610
3598 3611 assert_response :redirect
3599 3612 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
3600 3613 end
3601 3614
3602 3615 def test_get_bulk_edit
3603 3616 @request.session[:user_id] = 2
3604 3617 get :bulk_edit, :ids => [1, 3]
3605 3618 assert_response :success
3606 3619 assert_template 'bulk_edit'
3607 3620
3608 3621 assert_select 'ul#bulk-selection' do
3609 3622 assert_select 'li', 2
3610 3623 assert_select 'li a', :text => 'Bug #1'
3611 3624 end
3612 3625
3613 3626 assert_select 'form#bulk_edit_form[action=?]', '/issues/bulk_update' do
3614 3627 assert_select 'input[name=?]', 'ids[]', 2
3615 3628 assert_select 'input[name=?][value="1"][type=hidden]', 'ids[]'
3616 3629
3617 3630 assert_select 'select[name=?]', 'issue[project_id]'
3618 3631 assert_select 'input[name=?]', 'issue[parent_issue_id]'
3619 3632
3620 3633 # Project specific custom field, date type
3621 3634 field = CustomField.find(9)
3622 3635 assert !field.is_for_all?
3623 3636 assert_equal 'date', field.field_format
3624 3637 assert_select 'input[name=?]', 'issue[custom_field_values][9]'
3625 3638
3626 3639 # System wide custom field
3627 3640 assert CustomField.find(1).is_for_all?
3628 3641 assert_select 'select[name=?]', 'issue[custom_field_values][1]'
3629 3642
3630 3643 # Be sure we don't display inactive IssuePriorities
3631 3644 assert ! IssuePriority.find(15).active?
3632 3645 assert_select 'select[name=?]', 'issue[priority_id]' do
3633 3646 assert_select 'option[value="15"]', 0
3634 3647 end
3635 3648 end
3636 3649 end
3637 3650
3638 3651 def test_get_bulk_edit_on_different_projects
3639 3652 @request.session[:user_id] = 2
3640 3653 get :bulk_edit, :ids => [1, 2, 6]
3641 3654 assert_response :success
3642 3655 assert_template 'bulk_edit'
3643 3656
3644 3657 # Can not set issues from different projects as children of an issue
3645 3658 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
3646 3659
3647 3660 # Project specific custom field, date type
3648 3661 field = CustomField.find(9)
3649 3662 assert !field.is_for_all?
3650 3663 assert !field.project_ids.include?(Issue.find(6).project_id)
3651 3664 assert_select 'input[name=?]', 'issue[custom_field_values][9]', 0
3652 3665 end
3653 3666
3654 3667 def test_get_bulk_edit_with_user_custom_field
3655 3668 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :tracker_ids => [1,2,3])
3656 3669
3657 3670 @request.session[:user_id] = 2
3658 3671 get :bulk_edit, :ids => [1, 2]
3659 3672 assert_response :success
3660 3673 assert_template 'bulk_edit'
3661 3674
3662 3675 assert_select 'select.user_cf[name=?]', "issue[custom_field_values][#{field.id}]" do
3663 3676 assert_select 'option', Project.find(1).users.count + 2 # "no change" + "none" options
3664 3677 end
3665 3678 end
3666 3679
3667 3680 def test_get_bulk_edit_with_version_custom_field
3668 3681 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1,2,3])
3669 3682
3670 3683 @request.session[:user_id] = 2
3671 3684 get :bulk_edit, :ids => [1, 2]
3672 3685 assert_response :success
3673 3686 assert_template 'bulk_edit'
3674 3687
3675 3688 assert_select 'select.version_cf[name=?]', "issue[custom_field_values][#{field.id}]" do
3676 3689 assert_select 'option', Project.find(1).shared_versions.count + 2 # "no change" + "none" options
3677 3690 end
3678 3691 end
3679 3692
3680 3693 def test_get_bulk_edit_with_multi_custom_field
3681 3694 field = CustomField.find(1)
3682 3695 field.update_attribute :multiple, true
3683 3696
3684 3697 @request.session[:user_id] = 2
3685 3698 get :bulk_edit, :ids => [1, 3]
3686 3699 assert_response :success
3687 3700 assert_template 'bulk_edit'
3688 3701
3689 3702 assert_select 'select[name=?]', 'issue[custom_field_values][1][]' do
3690 3703 assert_select 'option', field.possible_values.size + 1 # "none" options
3691 3704 end
3692 3705 end
3693 3706
3694 3707 def test_bulk_edit_should_propose_to_clear_text_custom_fields
3695 3708 @request.session[:user_id] = 2
3696 3709 get :bulk_edit, :ids => [1, 3]
3697 3710 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', '__none__'
3698 3711 end
3699 3712
3700 3713 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
3701 3714 WorkflowTransition.delete_all
3702 3715 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
3703 3716 :old_status_id => 1, :new_status_id => 1)
3704 3717 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
3705 3718 :old_status_id => 1, :new_status_id => 3)
3706 3719 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
3707 3720 :old_status_id => 1, :new_status_id => 4)
3708 3721 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
3709 3722 :old_status_id => 2, :new_status_id => 1)
3710 3723 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
3711 3724 :old_status_id => 2, :new_status_id => 3)
3712 3725 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
3713 3726 :old_status_id => 2, :new_status_id => 5)
3714 3727 @request.session[:user_id] = 2
3715 3728 get :bulk_edit, :ids => [1, 2]
3716 3729
3717 3730 assert_response :success
3718 3731 statuses = assigns(:available_statuses)
3719 3732 assert_not_nil statuses
3720 3733 assert_equal [1, 3], statuses.map(&:id).sort
3721 3734
3722 3735 assert_select 'select[name=?]', 'issue[status_id]' do
3723 3736 assert_select 'option', 3 # 2 statuses + "no change" option
3724 3737 end
3725 3738 end
3726 3739
3727 3740 def test_bulk_edit_should_propose_target_project_open_shared_versions
3728 3741 @request.session[:user_id] = 2
3729 3742 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3730 3743 assert_response :success
3731 3744 assert_template 'bulk_edit'
3732 3745 assert_equal Project.find(1).shared_versions.open.to_a.sort, assigns(:versions).sort
3733 3746
3734 3747 assert_select 'select[name=?]', 'issue[fixed_version_id]' do
3735 3748 assert_select 'option', :text => '2.0'
3736 3749 end
3737 3750 end
3738 3751
3739 3752 def test_bulk_edit_should_propose_target_project_categories
3740 3753 @request.session[:user_id] = 2
3741 3754 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3742 3755 assert_response :success
3743 3756 assert_template 'bulk_edit'
3744 3757 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort
3745 3758
3746 3759 assert_select 'select[name=?]', 'issue[category_id]' do
3747 3760 assert_select 'option', :text => 'Recipes'
3748 3761 end
3749 3762 end
3750 3763
3751 3764 def test_bulk_edit_should_only_propose_issues_trackers_custom_fields
3752 3765 IssueCustomField.delete_all
3753 3766 field = IssueCustomField.generate!(:tracker_ids => [1], :is_for_all => true)
3754 3767 IssueCustomField.generate!(:tracker_ids => [2], :is_for_all => true)
3755 3768 @request.session[:user_id] = 2
3756 3769
3757 3770 issue_ids = Issue.where(:project_id => 1, :tracker_id => 1).limit(2).ids
3758 3771 get :bulk_edit, :ids => issue_ids
3759 3772 assert_equal [field], assigns(:custom_fields)
3760 3773 end
3761 3774
3762 3775 def test_bulk_update
3763 3776 @request.session[:user_id] = 2
3764 3777 # update issues priority
3765 3778 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
3766 3779 :issue => {:priority_id => 7,
3767 3780 :assigned_to_id => '',
3768 3781 :custom_field_values => {'2' => ''}}
3769 3782
3770 3783 assert_response 302
3771 3784 # check that the issues were updated
3772 3785 assert_equal [7, 7], Issue.where(:id =>[1, 2]).collect {|i| i.priority.id}
3773 3786
3774 3787 issue = Issue.find(1)
3775 3788 journal = issue.journals.reorder('created_on DESC').first
3776 3789 assert_equal '125', issue.custom_value_for(2).value
3777 3790 assert_equal 'Bulk editing', journal.notes
3778 3791 assert_equal 1, journal.details.size
3779 3792 end
3780 3793
3781 3794 def test_bulk_update_with_group_assignee
3782 3795 group = Group.find(11)
3783 3796 project = Project.find(1)
3784 3797 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
3785 3798
3786 3799 @request.session[:user_id] = 2
3787 3800 # update issues assignee
3788 3801 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
3789 3802 :issue => {:priority_id => '',
3790 3803 :assigned_to_id => group.id,
3791 3804 :custom_field_values => {'2' => ''}}
3792 3805
3793 3806 assert_response 302
3794 3807 assert_equal [group, group], Issue.where(:id => [1, 2]).collect {|i| i.assigned_to}
3795 3808 end
3796 3809
3797 3810 def test_bulk_update_on_different_projects
3798 3811 @request.session[:user_id] = 2
3799 3812 # update issues priority
3800 3813 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
3801 3814 :issue => {:priority_id => 7,
3802 3815 :assigned_to_id => '',
3803 3816 :custom_field_values => {'2' => ''}}
3804 3817
3805 3818 assert_response 302
3806 3819 # check that the issues were updated
3807 3820 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
3808 3821
3809 3822 issue = Issue.find(1)
3810 3823 journal = issue.journals.reorder('created_on DESC').first
3811 3824 assert_equal '125', issue.custom_value_for(2).value
3812 3825 assert_equal 'Bulk editing', journal.notes
3813 3826 assert_equal 1, journal.details.size
3814 3827 end
3815 3828
3816 3829 def test_bulk_update_on_different_projects_without_rights
3817 3830 @request.session[:user_id] = 3
3818 3831 user = User.find(3)
3819 3832 action = { :controller => "issues", :action => "bulk_update" }
3820 3833 assert user.allowed_to?(action, Issue.find(1).project)
3821 3834 assert ! user.allowed_to?(action, Issue.find(6).project)
3822 3835 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
3823 3836 :issue => {:priority_id => 7,
3824 3837 :assigned_to_id => '',
3825 3838 :custom_field_values => {'2' => ''}}
3826 3839 assert_response 403
3827 3840 assert_not_equal "Bulk should fail", Journal.last.notes
3828 3841 end
3829 3842
3830 3843 def test_bullk_update_should_send_a_notification
3831 3844 @request.session[:user_id] = 2
3832 3845 ActionMailer::Base.deliveries.clear
3833 3846 with_settings :notified_events => %w(issue_updated) do
3834 3847 post(:bulk_update,
3835 3848 {
3836 3849 :ids => [1, 2],
3837 3850 :notes => 'Bulk editing',
3838 3851 :issue => {
3839 3852 :priority_id => 7,
3840 3853 :assigned_to_id => '',
3841 3854 :custom_field_values => {'2' => ''}
3842 3855 }
3843 3856 })
3844 3857 assert_response 302
3845 3858 assert_equal 2, ActionMailer::Base.deliveries.size
3846 3859 end
3847 3860 end
3848 3861
3849 3862 def test_bulk_update_project
3850 3863 @request.session[:user_id] = 2
3851 3864 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
3852 3865 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3853 3866 # Issues moved to project 2
3854 3867 assert_equal 2, Issue.find(1).project_id
3855 3868 assert_equal 2, Issue.find(2).project_id
3856 3869 # No tracker change
3857 3870 assert_equal 1, Issue.find(1).tracker_id
3858 3871 assert_equal 2, Issue.find(2).tracker_id
3859 3872 end
3860 3873
3861 3874 def test_bulk_update_project_on_single_issue_should_follow_when_needed
3862 3875 @request.session[:user_id] = 2
3863 3876 post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
3864 3877 assert_redirected_to '/issues/1'
3865 3878 end
3866 3879
3867 3880 def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
3868 3881 @request.session[:user_id] = 2
3869 3882 post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
3870 3883 assert_redirected_to '/projects/onlinestore/issues'
3871 3884 end
3872 3885
3873 3886 def test_bulk_update_tracker
3874 3887 @request.session[:user_id] = 2
3875 3888 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
3876 3889 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3877 3890 assert_equal 2, Issue.find(1).tracker_id
3878 3891 assert_equal 2, Issue.find(2).tracker_id
3879 3892 end
3880 3893
3881 3894 def test_bulk_update_status
3882 3895 @request.session[:user_id] = 2
3883 3896 # update issues priority
3884 3897 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
3885 3898 :issue => {:priority_id => '',
3886 3899 :assigned_to_id => '',
3887 3900 :status_id => '5'}
3888 3901
3889 3902 assert_response 302
3890 3903 issue = Issue.find(1)
3891 3904 assert issue.closed?
3892 3905 end
3893 3906
3894 3907 def test_bulk_update_priority
3895 3908 @request.session[:user_id] = 2
3896 3909 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
3897 3910
3898 3911 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3899 3912 assert_equal 6, Issue.find(1).priority_id
3900 3913 assert_equal 6, Issue.find(2).priority_id
3901 3914 end
3902 3915
3903 3916 def test_bulk_update_with_notes
3904 3917 @request.session[:user_id] = 2
3905 3918 post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
3906 3919
3907 3920 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3908 3921 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
3909 3922 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
3910 3923 end
3911 3924
3912 3925 def test_bulk_update_parent_id
3913 3926 IssueRelation.delete_all
3914 3927 @request.session[:user_id] = 2
3915 3928 post :bulk_update, :ids => [1, 3],
3916 3929 :notes => 'Bulk editing parent',
3917 3930 :issue => {:priority_id => '', :assigned_to_id => '',
3918 3931 :status_id => '', :parent_issue_id => '2'}
3919 3932 assert_response 302
3920 3933 parent = Issue.find(2)
3921 3934 assert_equal parent.id, Issue.find(1).parent_id
3922 3935 assert_equal parent.id, Issue.find(3).parent_id
3923 3936 assert_equal [1, 3], parent.children.collect(&:id).sort
3924 3937 end
3925 3938
3926 3939 def test_bulk_update_custom_field
3927 3940 @request.session[:user_id] = 2
3928 3941 # update issues priority
3929 3942 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
3930 3943 :issue => {:priority_id => '',
3931 3944 :assigned_to_id => '',
3932 3945 :custom_field_values => {'2' => '777'}}
3933 3946
3934 3947 assert_response 302
3935 3948
3936 3949 issue = Issue.find(1)
3937 3950 journal = issue.journals.reorder('created_on DESC').first
3938 3951 assert_equal '777', issue.custom_value_for(2).value
3939 3952 assert_equal 1, journal.details.size
3940 3953 assert_equal '125', journal.details.first.old_value
3941 3954 assert_equal '777', journal.details.first.value
3942 3955 end
3943 3956
3944 3957 def test_bulk_update_custom_field_to_blank
3945 3958 @request.session[:user_id] = 2
3946 3959 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing custom field',
3947 3960 :issue => {:priority_id => '',
3948 3961 :assigned_to_id => '',
3949 3962 :custom_field_values => {'1' => '__none__'}}
3950 3963 assert_response 302
3951 3964 assert_equal '', Issue.find(1).custom_field_value(1)
3952 3965 assert_equal '', Issue.find(3).custom_field_value(1)
3953 3966 end
3954 3967
3955 3968 def test_bulk_update_multi_custom_field
3956 3969 field = CustomField.find(1)
3957 3970 field.update_attribute :multiple, true
3958 3971
3959 3972 @request.session[:user_id] = 2
3960 3973 post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field',
3961 3974 :issue => {:priority_id => '',
3962 3975 :assigned_to_id => '',
3963 3976 :custom_field_values => {'1' => ['MySQL', 'Oracle']}}
3964 3977
3965 3978 assert_response 302
3966 3979
3967 3980 assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort
3968 3981 assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort
3969 3982 # the custom field is not associated with the issue tracker
3970 3983 assert_nil Issue.find(2).custom_field_value(1)
3971 3984 end
3972 3985
3973 3986 def test_bulk_update_multi_custom_field_to_blank
3974 3987 field = CustomField.find(1)
3975 3988 field.update_attribute :multiple, true
3976 3989
3977 3990 @request.session[:user_id] = 2
3978 3991 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing multi custom field',
3979 3992 :issue => {:priority_id => '',
3980 3993 :assigned_to_id => '',
3981 3994 :custom_field_values => {'1' => ['__none__']}}
3982 3995 assert_response 302
3983 3996 assert_equal [''], Issue.find(1).custom_field_value(1)
3984 3997 assert_equal [''], Issue.find(3).custom_field_value(1)
3985 3998 end
3986 3999
3987 4000 def test_bulk_update_unassign
3988 4001 assert_not_nil Issue.find(2).assigned_to
3989 4002 @request.session[:user_id] = 2
3990 4003 # unassign issues
3991 4004 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
3992 4005 assert_response 302
3993 4006 # check that the issues were updated
3994 4007 assert_nil Issue.find(2).assigned_to
3995 4008 end
3996 4009
3997 4010 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
3998 4011 @request.session[:user_id] = 2
3999 4012
4000 4013 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
4001 4014
4002 4015 assert_response :redirect
4003 4016 issues = Issue.find([1,2])
4004 4017 issues.each do |issue|
4005 4018 assert_equal 4, issue.fixed_version_id
4006 4019 assert_not_equal issue.project_id, issue.fixed_version.project_id
4007 4020 end
4008 4021 end
4009 4022
4010 4023 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
4011 4024 @request.session[:user_id] = 2
4012 4025 post :bulk_update, :ids => [1,2], :back_url => '/issues'
4013 4026
4014 4027 assert_response :redirect
4015 4028 assert_redirected_to '/issues'
4016 4029 end
4017 4030
4018 4031 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
4019 4032 @request.session[:user_id] = 2
4020 4033 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
4021 4034
4022 4035 assert_response :redirect
4023 4036 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
4024 4037 end
4025 4038
4026 4039 def test_bulk_update_with_all_failures_should_show_errors
4027 4040 @request.session[:user_id] = 2
4028 4041 post :bulk_update, :ids => [1, 2], :issue => {:start_date => 'foo'}
4029 4042
4030 4043 assert_response :success
4031 4044 assert_template 'bulk_edit'
4032 4045 assert_select '#errorExplanation span', :text => 'Failed to save 2 issue(s) on 2 selected: #1, #2.'
4033 4046 assert_select '#errorExplanation ul li', :text => 'Start date is not a valid date: #1, #2'
4034 4047
4035 4048 assert_equal [1, 2], assigns[:issues].map(&:id)
4036 4049 end
4037 4050
4038 4051 def test_bulk_update_with_some_failures_should_show_errors
4039 4052 issue1 = Issue.generate!(:start_date => '2013-05-12')
4040 4053 issue2 = Issue.generate!(:start_date => '2013-05-15')
4041 4054 issue3 = Issue.generate!
4042 4055 @request.session[:user_id] = 2
4043 4056 post :bulk_update, :ids => [issue1.id, issue2.id, issue3.id],
4044 4057 :issue => {:due_date => '2013-05-01'}
4045 4058 assert_response :success
4046 4059 assert_template 'bulk_edit'
4047 4060 assert_select '#errorExplanation span',
4048 4061 :text => "Failed to save 2 issue(s) on 3 selected: ##{issue1.id}, ##{issue2.id}."
4049 4062 assert_select '#errorExplanation ul li',
4050 4063 :text => "Due date must be greater than start date: ##{issue1.id}, ##{issue2.id}"
4051 4064 assert_equal [issue1.id, issue2.id], assigns[:issues].map(&:id)
4052 4065 end
4053 4066
4054 4067 def test_bulk_update_with_failure_should_preserved_form_values
4055 4068 @request.session[:user_id] = 2
4056 4069 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2', :start_date => 'foo'}
4057 4070
4058 4071 assert_response :success
4059 4072 assert_template 'bulk_edit'
4060 4073 assert_select 'select[name=?]', 'issue[tracker_id]' do
4061 4074 assert_select 'option[value="2"][selected=selected]'
4062 4075 end
4063 4076 assert_select 'input[name=?][value=?]', 'issue[start_date]', 'foo'
4064 4077 end
4065 4078
4066 4079 def test_get_bulk_copy
4067 4080 @request.session[:user_id] = 2
4068 4081 get :bulk_edit, :ids => [1, 2, 3], :copy => '1'
4069 4082 assert_response :success
4070 4083 assert_template 'bulk_edit'
4071 4084
4072 4085 issues = assigns(:issues)
4073 4086 assert_not_nil issues
4074 4087 assert_equal [1, 2, 3], issues.map(&:id).sort
4075 4088
4076 4089 assert_select 'select[name=?]', 'issue[project_id]' do
4077 4090 assert_select 'option[value=""]'
4078 4091 end
4079 4092 assert_select 'input[name=copy_attachments]'
4080 4093 end
4081 4094
4082 4095 def test_get_bulk_copy_without_add_issues_permission_should_not_propose_current_project_as_target
4083 4096 user = setup_user_with_copy_but_not_add_permission
4084 4097 @request.session[:user_id] = user.id
4085 4098
4086 4099 get :bulk_edit, :ids => [1, 2, 3], :copy => '1'
4087 4100 assert_response :success
4088 4101 assert_template 'bulk_edit'
4089 4102
4090 4103 assert_select 'select[name=?]', 'issue[project_id]' do
4091 4104 assert_select 'option[value=""]', 0
4092 4105 assert_select 'option[value="2"]'
4093 4106 end
4094 4107 end
4095 4108
4096 4109 def test_bulk_copy_to_another_project
4097 4110 @request.session[:user_id] = 2
4098 4111 assert_difference 'Issue.count', 2 do
4099 4112 assert_no_difference 'Project.find(1).issues.count' do
4100 4113 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
4101 4114 end
4102 4115 end
4103 4116 assert_redirected_to '/projects/ecookbook/issues'
4104 4117
4105 4118 copies = Issue.order('id DESC').limit(issues.size)
4106 4119 copies.each do |copy|
4107 4120 assert_equal 2, copy.project_id
4108 4121 end
4109 4122 end
4110 4123
4111 4124 def test_bulk_copy_without_add_issues_permission_should_be_allowed_on_project_with_permission
4112 4125 user = setup_user_with_copy_but_not_add_permission
4113 4126 @request.session[:user_id] = user.id
4114 4127
4115 4128 assert_difference 'Issue.count', 3 do
4116 4129 post :bulk_update, :ids => [1, 2, 3], :issue => {:project_id => '2'}, :copy => '1'
4117 4130 assert_response 302
4118 4131 end
4119 4132 end
4120 4133
4121 4134 def test_bulk_copy_on_same_project_without_add_issues_permission_should_be_denied
4122 4135 user = setup_user_with_copy_but_not_add_permission
4123 4136 @request.session[:user_id] = user.id
4124 4137
4125 4138 post :bulk_update, :ids => [1, 2, 3], :issue => {:project_id => ''}, :copy => '1'
4126 4139 assert_response 403
4127 4140 end
4128 4141
4129 4142 def test_bulk_copy_on_different_project_without_add_issues_permission_should_be_denied
4130 4143 user = setup_user_with_copy_but_not_add_permission
4131 4144 @request.session[:user_id] = user.id
4132 4145
4133 4146 post :bulk_update, :ids => [1, 2, 3], :issue => {:project_id => '1'}, :copy => '1'
4134 4147 assert_response 403
4135 4148 end
4136 4149
4137 4150 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
4138 4151 @request.session[:user_id] = 2
4139 4152 issues = [
4140 4153 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1,
4141 4154 :priority_id => 2, :subject => 'issue 1', :author_id => 1,
4142 4155 :assigned_to_id => nil),
4143 4156 Issue.create!(:project_id => 2, :tracker_id => 3, :status_id => 2,
4144 4157 :priority_id => 1, :subject => 'issue 2', :author_id => 2,
4145 4158 :assigned_to_id => 3)
4146 4159 ]
4147 4160 assert_difference 'Issue.count', issues.size do
4148 4161 post :bulk_update, :ids => issues.map(&:id), :copy => '1',
4149 4162 :issue => {
4150 4163 :project_id => '', :tracker_id => '', :assigned_to_id => '',
4151 4164 :status_id => '', :start_date => '', :due_date => ''
4152 4165 }
4153 4166 end
4154 4167
4155 4168 copies = Issue.order('id DESC').limit(issues.size)
4156 4169 issues.each do |orig|
4157 4170 copy = copies.detect {|c| c.subject == orig.subject}
4158 4171 assert_not_nil copy
4159 4172 assert_equal orig.project_id, copy.project_id
4160 4173 assert_equal orig.tracker_id, copy.tracker_id
4161 4174 assert_equal orig.status_id, copy.status_id
4162 4175 assert_equal orig.assigned_to_id, copy.assigned_to_id
4163 4176 assert_equal orig.priority_id, copy.priority_id
4164 4177 end
4165 4178 end
4166 4179
4167 4180 def test_bulk_copy_should_allow_changing_the_issue_attributes
4168 4181 # Fixes random test failure with Mysql
4169 4182 # where Issue.where(:project_id => 2).limit(2).order('id desc')
4170 4183 # doesn't return the expected results
4171 4184 Issue.delete_all("project_id=2")
4172 4185
4173 4186 @request.session[:user_id] = 2
4174 4187 assert_difference 'Issue.count', 2 do
4175 4188 assert_no_difference 'Project.find(1).issues.count' do
4176 4189 post :bulk_update, :ids => [1, 2], :copy => '1',
4177 4190 :issue => {
4178 4191 :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
4179 4192 :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31'
4180 4193 }
4181 4194 end
4182 4195 end
4183 4196
4184 4197 copied_issues = Issue.where(:project_id => 2).limit(2).order('id desc').to_a
4185 4198 assert_equal 2, copied_issues.size
4186 4199 copied_issues.each do |issue|
4187 4200 assert_equal 2, issue.project_id, "Project is incorrect"
4188 4201 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
4189 4202 assert_equal 1, issue.status_id, "Status is incorrect"
4190 4203 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
4191 4204 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
4192 4205 end
4193 4206 end
4194 4207
4195 4208 def test_bulk_copy_should_allow_adding_a_note
4196 4209 @request.session[:user_id] = 2
4197 4210 assert_difference 'Issue.count', 1 do
4198 4211 post :bulk_update, :ids => [1], :copy => '1',
4199 4212 :notes => 'Copying one issue',
4200 4213 :issue => {
4201 4214 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
4202 4215 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
4203 4216 }
4204 4217 end
4205 4218 issue = Issue.order('id DESC').first
4206 4219 assert_equal 1, issue.journals.size
4207 4220 journal = issue.journals.first
4208 4221 assert_equal 'Copying one issue', journal.notes
4209 4222 end
4210 4223
4211 4224 def test_bulk_copy_should_allow_not_copying_the_attachments
4212 4225 attachment_count = Issue.find(3).attachments.size
4213 4226 assert attachment_count > 0
4214 4227 @request.session[:user_id] = 2
4215 4228
4216 4229 assert_difference 'Issue.count', 1 do
4217 4230 assert_no_difference 'Attachment.count' do
4218 4231 post :bulk_update, :ids => [3], :copy => '1', :copy_attachments => '0',
4219 4232 :issue => {
4220 4233 :project_id => ''
4221 4234 }
4222 4235 end
4223 4236 end
4224 4237 end
4225 4238
4226 4239 def test_bulk_copy_should_allow_copying_the_attachments
4227 4240 attachment_count = Issue.find(3).attachments.size
4228 4241 assert attachment_count > 0
4229 4242 @request.session[:user_id] = 2
4230 4243
4231 4244 assert_difference 'Issue.count', 1 do
4232 4245 assert_difference 'Attachment.count', attachment_count do
4233 4246 post :bulk_update, :ids => [3], :copy => '1', :copy_attachments => '1',
4234 4247 :issue => {
4235 4248 :project_id => ''
4236 4249 }
4237 4250 end
4238 4251 end
4239 4252 end
4240 4253
4241 4254 def test_bulk_copy_should_add_relations_with_copied_issues
4242 4255 @request.session[:user_id] = 2
4243 4256
4244 4257 assert_difference 'Issue.count', 2 do
4245 4258 assert_difference 'IssueRelation.count', 2 do
4246 4259 post :bulk_update, :ids => [1, 3], :copy => '1', :link_copy => '1',
4247 4260 :issue => {
4248 4261 :project_id => '1'
4249 4262 }
4250 4263 end
4251 4264 end
4252 4265 end
4253 4266
4254 4267 def test_bulk_copy_should_allow_not_copying_the_subtasks
4255 4268 issue = Issue.generate_with_descendants!
4256 4269 @request.session[:user_id] = 2
4257 4270
4258 4271 assert_difference 'Issue.count', 1 do
4259 4272 post :bulk_update, :ids => [issue.id], :copy => '1', :copy_subtasks => '0',
4260 4273 :issue => {
4261 4274 :project_id => ''
4262 4275 }
4263 4276 end
4264 4277 end
4265 4278
4266 4279 def test_bulk_copy_should_allow_copying_the_subtasks
4267 4280 issue = Issue.generate_with_descendants!
4268 4281 count = issue.descendants.count
4269 4282 @request.session[:user_id] = 2
4270 4283
4271 4284 assert_difference 'Issue.count', count+1 do
4272 4285 post :bulk_update, :ids => [issue.id], :copy => '1', :copy_subtasks => '1',
4273 4286 :issue => {
4274 4287 :project_id => ''
4275 4288 }
4276 4289 end
4277 4290 copy = Issue.where(:parent_id => nil).order("id DESC").first
4278 4291 assert_equal count, copy.descendants.count
4279 4292 end
4280 4293
4281 4294 def test_bulk_copy_should_not_copy_selected_subtasks_twice
4282 4295 issue = Issue.generate_with_descendants!
4283 4296 count = issue.descendants.count
4284 4297 @request.session[:user_id] = 2
4285 4298
4286 4299 assert_difference 'Issue.count', count+1 do
4287 4300 post :bulk_update, :ids => issue.self_and_descendants.map(&:id), :copy => '1', :copy_subtasks => '1',
4288 4301 :issue => {
4289 4302 :project_id => ''
4290 4303 }
4291 4304 end
4292 4305 copy = Issue.where(:parent_id => nil).order("id DESC").first
4293 4306 assert_equal count, copy.descendants.count
4294 4307 end
4295 4308
4296 4309 def test_bulk_copy_to_another_project_should_follow_when_needed
4297 4310 @request.session[:user_id] = 2
4298 4311 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
4299 4312 issue = Issue.order('id DESC').first
4300 4313 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
4301 4314 end
4302 4315
4303 4316 def test_bulk_copy_with_all_failures_should_display_errors
4304 4317 @request.session[:user_id] = 2
4305 4318 post :bulk_update, :ids => [1, 2], :copy => '1', :issue => {:start_date => 'foo'}
4306 4319
4307 4320 assert_response :success
4308 4321 end
4309 4322
4310 4323 def test_destroy_issue_with_no_time_entries
4311 4324 assert_nil TimeEntry.find_by_issue_id(2)
4312 4325 @request.session[:user_id] = 2
4313 4326
4314 4327 assert_difference 'Issue.count', -1 do
4315 4328 delete :destroy, :id => 2
4316 4329 end
4317 4330 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
4318 4331 assert_nil Issue.find_by_id(2)
4319 4332 end
4320 4333
4321 4334 def test_destroy_issues_with_time_entries
4322 4335 @request.session[:user_id] = 2
4323 4336
4324 4337 assert_no_difference 'Issue.count' do
4325 4338 delete :destroy, :ids => [1, 3]
4326 4339 end
4327 4340 assert_response :success
4328 4341 assert_template 'destroy'
4329 4342 assert_not_nil assigns(:hours)
4330 4343 assert Issue.find_by_id(1) && Issue.find_by_id(3)
4331 4344
4332 4345 assert_select 'form' do
4333 4346 assert_select 'input[name=_method][value=delete]'
4334 4347 end
4335 4348 end
4336 4349
4337 4350 def test_destroy_issues_and_destroy_time_entries
4338 4351 @request.session[:user_id] = 2
4339 4352
4340 4353 assert_difference 'Issue.count', -2 do
4341 4354 assert_difference 'TimeEntry.count', -3 do
4342 4355 delete :destroy, :ids => [1, 3], :todo => 'destroy'
4343 4356 end
4344 4357 end
4345 4358 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
4346 4359 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
4347 4360 assert_nil TimeEntry.find_by_id([1, 2])
4348 4361 end
4349 4362
4350 4363 def test_destroy_issues_and_assign_time_entries_to_project
4351 4364 @request.session[:user_id] = 2
4352 4365
4353 4366 assert_difference 'Issue.count', -2 do
4354 4367 assert_no_difference 'TimeEntry.count' do
4355 4368 delete :destroy, :ids => [1, 3], :todo => 'nullify'
4356 4369 end
4357 4370 end
4358 4371 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
4359 4372 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
4360 4373 assert_nil TimeEntry.find(1).issue_id
4361 4374 assert_nil TimeEntry.find(2).issue_id
4362 4375 end
4363 4376
4364 4377 def test_destroy_issues_and_reassign_time_entries_to_another_issue
4365 4378 @request.session[:user_id] = 2
4366 4379
4367 4380 assert_difference 'Issue.count', -2 do
4368 4381 assert_no_difference 'TimeEntry.count' do
4369 4382 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
4370 4383 end
4371 4384 end
4372 4385 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
4373 4386 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
4374 4387 assert_equal 2, TimeEntry.find(1).issue_id
4375 4388 assert_equal 2, TimeEntry.find(2).issue_id
4376 4389 end
4377 4390
4378 4391 def test_destroy_issues_and_reassign_time_entries_to_an_invalid_issue_should_fail
4379 4392 @request.session[:user_id] = 2
4380 4393
4381 4394 assert_no_difference 'Issue.count' do
4382 4395 assert_no_difference 'TimeEntry.count' do
4383 4396 # try to reassign time to an issue of another project
4384 4397 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 4
4385 4398 end
4386 4399 end
4387 4400 assert_response :success
4388 4401 assert_template 'destroy'
4389 4402 end
4390 4403
4391 4404 def test_destroy_issues_from_different_projects
4392 4405 @request.session[:user_id] = 2
4393 4406
4394 4407 assert_difference 'Issue.count', -3 do
4395 4408 delete :destroy, :ids => [1, 2, 6], :todo => 'destroy'
4396 4409 end
4397 4410 assert_redirected_to :controller => 'issues', :action => 'index'
4398 4411 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
4399 4412 end
4400 4413
4401 4414 def test_destroy_parent_and_child_issues
4402 4415 parent = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Parent Issue')
4403 4416 child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Child Issue', :parent_issue_id => parent.id)
4404 4417 assert child.is_descendant_of?(parent.reload)
4405 4418
4406 4419 @request.session[:user_id] = 2
4407 4420 assert_difference 'Issue.count', -2 do
4408 4421 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
4409 4422 end
4410 4423 assert_response 302
4411 4424 end
4412 4425
4413 4426 def test_destroy_invalid_should_respond_with_404
4414 4427 @request.session[:user_id] = 2
4415 4428 assert_no_difference 'Issue.count' do
4416 4429 delete :destroy, :id => 999
4417 4430 end
4418 4431 assert_response 404
4419 4432 end
4420 4433
4421 4434 def test_default_search_scope
4422 4435 get :index
4423 4436
4424 4437 assert_select 'div#quick-search form' do
4425 4438 assert_select 'input[name=issues][value="1"][type=hidden]'
4426 4439 end
4427 4440 end
4428 4441
4429 4442 def setup_user_with_copy_but_not_add_permission
4430 4443 Role.all.each {|r| r.remove_permission! :add_issues}
4431 4444 Role.find_by_name('Manager').add_permission! :add_issues
4432 4445 user = User.generate!
4433 4446 User.add_to_project(user, Project.find(1), Role.find_by_name('Developer'))
4434 4447 User.add_to_project(user, Project.find(2), Role.find_by_name('Manager'))
4435 4448 user
4436 4449 end
4437 4450 end
@@ -1,2759 +1,2767
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2015 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
20 20 class IssueTest < ActiveSupport::TestCase
21 21 fixtures :projects, :users, :email_addresses, :members, :member_roles, :roles,
22 22 :groups_users,
23 23 :trackers, :projects_trackers,
24 24 :enabled_modules,
25 25 :versions,
26 26 :issue_statuses, :issue_categories, :issue_relations, :workflows,
27 27 :enumerations,
28 28 :issues, :journals, :journal_details,
29 29 :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values,
30 30 :time_entries
31 31
32 32 include Redmine::I18n
33 33
34 34 def setup
35 35 set_language_if_valid 'en'
36 36 end
37 37
38 38 def teardown
39 39 User.current = nil
40 40 end
41 41
42 42 def test_initialize
43 43 issue = Issue.new
44 44
45 45 assert_nil issue.project_id
46 46 assert_nil issue.tracker_id
47 47 assert_nil issue.status_id
48 48 assert_nil issue.author_id
49 49 assert_nil issue.assigned_to_id
50 50 assert_nil issue.category_id
51 51
52 52 assert_equal IssuePriority.default, issue.priority
53 53 end
54 54
55 55 def test_create
56 56 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
57 57 :status_id => 1, :priority => IssuePriority.all.first,
58 58 :subject => 'test_create',
59 59 :description => 'IssueTest#test_create', :estimated_hours => '1:30')
60 60 assert issue.save
61 61 issue.reload
62 62 assert_equal 1.5, issue.estimated_hours
63 63 end
64 64
65 65 def test_create_minimal
66 66 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :subject => 'test_create')
67 67 assert issue.save
68 68 assert_equal issue.tracker.default_status, issue.status
69 69 assert issue.description.nil?
70 70 assert_nil issue.estimated_hours
71 71 end
72 72
73 73 def test_create_with_all_fields_disabled
74 74 tracker = Tracker.find(1)
75 75 tracker.core_fields = []
76 76 tracker.save!
77 77
78 78 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :subject => 'test_create_with_all_fields_disabled')
79 79 assert_save issue
80 80 end
81 81
82 82 def test_start_date_format_should_be_validated
83 83 set_language_if_valid 'en'
84 84 ['2012', 'ABC', '2012-15-20'].each do |invalid_date|
85 85 issue = Issue.new(:start_date => invalid_date)
86 86 assert !issue.valid?
87 87 assert_include 'Start date is not a valid date', issue.errors.full_messages, "No error found for invalid date #{invalid_date}"
88 88 end
89 89 end
90 90
91 91 def test_due_date_format_should_be_validated
92 92 set_language_if_valid 'en'
93 93 ['2012', 'ABC', '2012-15-20'].each do |invalid_date|
94 94 issue = Issue.new(:due_date => invalid_date)
95 95 assert !issue.valid?
96 96 assert_include 'Due date is not a valid date', issue.errors.full_messages, "No error found for invalid date #{invalid_date}"
97 97 end
98 98 end
99 99
100 100 def test_due_date_lesser_than_start_date_should_not_validate
101 101 set_language_if_valid 'en'
102 102 issue = Issue.new(:start_date => '2012-10-06', :due_date => '2012-10-02')
103 103 assert !issue.valid?
104 104 assert_include 'Due date must be greater than start date', issue.errors.full_messages
105 105 end
106 106
107 107 def test_start_date_lesser_than_soonest_start_should_not_validate_on_create
108 108 issue = Issue.generate(:start_date => '2013-06-04')
109 109 issue.stubs(:soonest_start).returns(Date.parse('2013-06-10'))
110 110 assert !issue.valid?
111 111 assert_include "Start date cannot be earlier than 06/10/2013 because of preceding issues", issue.errors.full_messages
112 112 end
113 113
114 114 def test_start_date_lesser_than_soonest_start_should_not_validate_on_update_if_changed
115 115 issue = Issue.generate!(:start_date => '2013-06-04')
116 116 issue.stubs(:soonest_start).returns(Date.parse('2013-06-10'))
117 117 issue.start_date = '2013-06-07'
118 118 assert !issue.valid?
119 119 assert_include "Start date cannot be earlier than 06/10/2013 because of preceding issues", issue.errors.full_messages
120 120 end
121 121
122 122 def test_start_date_lesser_than_soonest_start_should_validate_on_update_if_unchanged
123 123 issue = Issue.generate!(:start_date => '2013-06-04')
124 124 issue.stubs(:soonest_start).returns(Date.parse('2013-06-10'))
125 125 assert issue.valid?
126 126 end
127 127
128 128 def test_estimated_hours_should_be_validated
129 129 set_language_if_valid 'en'
130 130 ['-2'].each do |invalid|
131 131 issue = Issue.new(:estimated_hours => invalid)
132 132 assert !issue.valid?
133 133 assert_include 'Estimated time is invalid', issue.errors.full_messages
134 134 end
135 135 end
136 136
137 137 def test_create_with_required_custom_field
138 138 set_language_if_valid 'en'
139 139 field = IssueCustomField.find_by_name('Database')
140 140 field.update_attribute(:is_required, true)
141 141
142 142 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1,
143 143 :status_id => 1, :subject => 'test_create',
144 144 :description => 'IssueTest#test_create_with_required_custom_field')
145 145 assert issue.available_custom_fields.include?(field)
146 146 # No value for the custom field
147 147 assert !issue.save
148 148 assert_equal ["Database cannot be blank"], issue.errors.full_messages
149 149 # Blank value
150 150 issue.custom_field_values = { field.id => '' }
151 151 assert !issue.save
152 152 assert_equal ["Database cannot be blank"], issue.errors.full_messages
153 153 # Invalid value
154 154 issue.custom_field_values = { field.id => 'SQLServer' }
155 155 assert !issue.save
156 156 assert_equal ["Database is not included in the list"], issue.errors.full_messages
157 157 # Valid value
158 158 issue.custom_field_values = { field.id => 'PostgreSQL' }
159 159 assert issue.save
160 160 issue.reload
161 161 assert_equal 'PostgreSQL', issue.custom_value_for(field).value
162 162 end
163 163
164 164 def test_create_with_group_assignment
165 165 with_settings :issue_group_assignment => '1' do
166 166 assert Issue.new(:project_id => 2, :tracker_id => 1, :author_id => 1,
167 167 :subject => 'Group assignment',
168 168 :assigned_to_id => 11).save
169 169 issue = Issue.order('id DESC').first
170 170 assert_kind_of Group, issue.assigned_to
171 171 assert_equal Group.find(11), issue.assigned_to
172 172 end
173 173 end
174 174
175 175 def test_create_with_parent_issue_id
176 176 issue = Issue.new(:project_id => 1, :tracker_id => 1,
177 177 :author_id => 1, :subject => 'Group assignment',
178 178 :parent_issue_id => 1)
179 179 assert_save issue
180 180 assert_equal 1, issue.parent_issue_id
181 181 assert_equal Issue.find(1), issue.parent
182 182 end
183 183
184 184 def test_create_with_sharp_parent_issue_id
185 185 issue = Issue.new(:project_id => 1, :tracker_id => 1,
186 186 :author_id => 1, :subject => 'Group assignment',
187 187 :parent_issue_id => "#1")
188 188 assert_save issue
189 189 assert_equal 1, issue.parent_issue_id
190 190 assert_equal Issue.find(1), issue.parent
191 191 end
192 192
193 193 def test_create_with_invalid_parent_issue_id
194 194 set_language_if_valid 'en'
195 195 issue = Issue.new(:project_id => 1, :tracker_id => 1,
196 196 :author_id => 1, :subject => 'Group assignment',
197 197 :parent_issue_id => '01ABC')
198 198 assert !issue.save
199 199 assert_equal '01ABC', issue.parent_issue_id
200 200 assert_include 'Parent task is invalid', issue.errors.full_messages
201 201 end
202 202
203 203 def test_create_with_invalid_sharp_parent_issue_id
204 204 set_language_if_valid 'en'
205 205 issue = Issue.new(:project_id => 1, :tracker_id => 1,
206 206 :author_id => 1, :subject => 'Group assignment',
207 207 :parent_issue_id => '#01ABC')
208 208 assert !issue.save
209 209 assert_equal '#01ABC', issue.parent_issue_id
210 210 assert_include 'Parent task is invalid', issue.errors.full_messages
211 211 end
212 212
213 213 def assert_visibility_match(user, issues)
214 214 assert_equal issues.collect(&:id).sort, Issue.all.select {|issue| issue.visible?(user)}.collect(&:id).sort
215 215 end
216 216
217 217 def test_visible_scope_for_anonymous
218 218 # Anonymous user should see issues of public projects only
219 219 issues = Issue.visible(User.anonymous).to_a
220 220 assert issues.any?
221 221 assert_nil issues.detect {|issue| !issue.project.is_public?}
222 222 assert_nil issues.detect {|issue| issue.is_private?}
223 223 assert_visibility_match User.anonymous, issues
224 224 end
225 225
226 226 def test_visible_scope_for_anonymous_without_view_issues_permissions
227 227 # Anonymous user should not see issues without permission
228 228 Role.anonymous.remove_permission!(:view_issues)
229 229 issues = Issue.visible(User.anonymous).to_a
230 230 assert issues.empty?
231 231 assert_visibility_match User.anonymous, issues
232 232 end
233 233
234 234 def test_visible_scope_for_anonymous_without_view_issues_permissions_and_membership
235 235 Role.anonymous.remove_permission!(:view_issues)
236 236 Member.create!(:project_id => 1, :principal => Group.anonymous, :role_ids => [2])
237 237
238 238 issues = Issue.visible(User.anonymous).all
239 239 assert issues.any?
240 240 assert_equal [1], issues.map(&:project_id).uniq.sort
241 241 assert_visibility_match User.anonymous, issues
242 242 end
243 243
244 244 def test_anonymous_should_not_see_private_issues_with_issues_visibility_set_to_default
245 245 assert Role.anonymous.update_attribute(:issues_visibility, 'default')
246 246 issue = Issue.generate!(:author => User.anonymous, :assigned_to => User.anonymous, :is_private => true)
247 247 assert_nil Issue.where(:id => issue.id).visible(User.anonymous).first
248 248 assert !issue.visible?(User.anonymous)
249 249 end
250 250
251 251 def test_anonymous_should_not_see_private_issues_with_issues_visibility_set_to_own
252 252 assert Role.anonymous.update_attribute(:issues_visibility, 'own')
253 253 issue = Issue.generate!(:author => User.anonymous, :assigned_to => User.anonymous, :is_private => true)
254 254 assert_nil Issue.where(:id => issue.id).visible(User.anonymous).first
255 255 assert !issue.visible?(User.anonymous)
256 256 end
257 257
258 258 def test_visible_scope_for_non_member
259 259 user = User.find(9)
260 260 assert user.projects.empty?
261 261 # Non member user should see issues of public projects only
262 262 issues = Issue.visible(user).to_a
263 263 assert issues.any?
264 264 assert_nil issues.detect {|issue| !issue.project.is_public?}
265 265 assert_nil issues.detect {|issue| issue.is_private?}
266 266 assert_visibility_match user, issues
267 267 end
268 268
269 269 def test_visible_scope_for_non_member_with_own_issues_visibility
270 270 Role.non_member.update_attribute :issues_visibility, 'own'
271 271 Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 9, :subject => 'Issue by non member')
272 272 user = User.find(9)
273 273
274 274 issues = Issue.visible(user).to_a
275 275 assert issues.any?
276 276 assert_nil issues.detect {|issue| issue.author != user}
277 277 assert_visibility_match user, issues
278 278 end
279 279
280 280 def test_visible_scope_for_non_member_without_view_issues_permissions
281 281 # Non member user should not see issues without permission
282 282 Role.non_member.remove_permission!(:view_issues)
283 283 user = User.find(9)
284 284 assert user.projects.empty?
285 285 issues = Issue.visible(user).to_a
286 286 assert issues.empty?
287 287 assert_visibility_match user, issues
288 288 end
289 289
290 290 def test_visible_scope_for_non_member_without_view_issues_permissions_and_membership
291 291 Role.non_member.remove_permission!(:view_issues)
292 292 Member.create!(:project_id => 1, :principal => Group.non_member, :role_ids => [2])
293 293 user = User.find(9)
294 294
295 295 issues = Issue.visible(user).all
296 296 assert issues.any?
297 297 assert_equal [1], issues.map(&:project_id).uniq.sort
298 298 assert_visibility_match user, issues
299 299 end
300 300
301 301 def test_visible_scope_for_member
302 302 user = User.find(9)
303 303 # User should see issues of projects for which user has view_issues permissions only
304 304 Role.non_member.remove_permission!(:view_issues)
305 305 Member.create!(:principal => user, :project_id => 3, :role_ids => [2])
306 306 issues = Issue.visible(user).to_a
307 307 assert issues.any?
308 308 assert_nil issues.detect {|issue| issue.project_id != 3}
309 309 assert_nil issues.detect {|issue| issue.is_private?}
310 310 assert_visibility_match user, issues
311 311 end
312 312
313 313 def test_visible_scope_for_member_without_view_issues_permission_and_non_member_role_having_the_permission
314 314 Role.non_member.add_permission!(:view_issues)
315 315 Role.find(1).remove_permission!(:view_issues)
316 316 user = User.find(2)
317 317
318 318 assert_equal 0, Issue.where(:project_id => 1).visible(user).count
319 319 assert_equal false, Issue.where(:project_id => 1).first.visible?(user)
320 320 end
321 321
322 322 def test_visible_scope_for_member_with_groups_should_return_assigned_issues
323 323 user = User.find(8)
324 324 assert user.groups.any?
325 325 Member.create!(:principal => user.groups.first, :project_id => 1, :role_ids => [2])
326 326 Role.non_member.remove_permission!(:view_issues)
327 327
328 328 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 3,
329 329 :status_id => 1, :priority => IssuePriority.all.first,
330 330 :subject => 'Assignment test',
331 331 :assigned_to => user.groups.first,
332 332 :is_private => true)
333 333
334 334 Role.find(2).update_attribute :issues_visibility, 'default'
335 335 issues = Issue.visible(User.find(8)).to_a
336 336 assert issues.any?
337 337 assert issues.include?(issue)
338 338
339 339 Role.find(2).update_attribute :issues_visibility, 'own'
340 340 issues = Issue.visible(User.find(8)).to_a
341 341 assert issues.any?
342 342 assert_include issue, issues
343 343 end
344 344
345 345 def test_visible_scope_for_admin
346 346 user = User.find(1)
347 347 user.members.each(&:destroy)
348 348 assert user.projects.empty?
349 349 issues = Issue.visible(user).to_a
350 350 assert issues.any?
351 351 # Admin should see issues on private projects that admin does not belong to
352 352 assert issues.detect {|issue| !issue.project.is_public?}
353 353 # Admin should see private issues of other users
354 354 assert issues.detect {|issue| issue.is_private? && issue.author != user}
355 355 assert_visibility_match user, issues
356 356 end
357 357
358 358 def test_visible_scope_with_project
359 359 project = Project.find(1)
360 360 issues = Issue.visible(User.find(2), :project => project).to_a
361 361 projects = issues.collect(&:project).uniq
362 362 assert_equal 1, projects.size
363 363 assert_equal project, projects.first
364 364 end
365 365
366 366 def test_visible_scope_with_project_and_subprojects
367 367 project = Project.find(1)
368 368 issues = Issue.visible(User.find(2), :project => project, :with_subprojects => true).to_a
369 369 projects = issues.collect(&:project).uniq
370 370 assert projects.size > 1
371 371 assert_equal [], projects.select {|p| !p.is_or_is_descendant_of?(project)}
372 372 end
373 373
374 374 def test_visible_and_nested_set_scopes
375 375 user = User.generate!
376 376 parent = Issue.generate!(:assigned_to => user)
377 377 assert parent.visible?(user)
378 378 child1 = Issue.generate!(:parent_issue_id => parent.id, :assigned_to => user)
379 379 child2 = Issue.generate!(:parent_issue_id => parent.id, :assigned_to => user)
380 380 parent.reload
381 381 child1.reload
382 382 child2.reload
383 383 assert child1.visible?(user)
384 384 assert child2.visible?(user)
385 385 assert_equal 2, parent.descendants.count
386 386 assert_equal 2, parent.descendants.visible(user).count
387 387 # awesome_nested_set 2-1-stable branch has regression.
388 388 # https://github.com/collectiveidea/awesome_nested_set/commit/3d5ac746542b564f6586c2316180254b088bebb6
389 389 # ActiveRecord::StatementInvalid: SQLite3::SQLException: ambiguous column name: lft:
390 390 assert_equal 2, parent.descendants.collect{|i| i}.size
391 391 assert_equal 2, parent.descendants.visible(user).collect{|i| i}.size
392 392 end
393 393
394 394 def test_visible_scope_with_unsaved_user_should_not_raise_an_error
395 395 user = User.new
396 396 assert_nothing_raised do
397 397 Issue.visible(user).to_a
398 398 end
399 399 end
400 400
401 401 def test_open_scope
402 402 issues = Issue.open.to_a
403 403 assert_nil issues.detect(&:closed?)
404 404 end
405 405
406 406 def test_open_scope_with_arg
407 407 issues = Issue.open(false).to_a
408 408 assert_equal issues, issues.select(&:closed?)
409 409 end
410 410
411 411 def test_fixed_version_scope_with_a_version_should_return_its_fixed_issues
412 412 version = Version.find(2)
413 413 assert version.fixed_issues.any?
414 414 assert_equal version.fixed_issues.to_a.sort, Issue.fixed_version(version).to_a.sort
415 415 end
416 416
417 417 def test_fixed_version_scope_with_empty_array_should_return_no_result
418 418 assert_equal 0, Issue.fixed_version([]).count
419 419 end
420 420
421 421 def test_assigned_to_scope_should_return_issues_assigned_to_the_user
422 422 user = User.generate!
423 423 issue = Issue.generate!
424 424 Issue.where(:id => issue.id).update_all :assigned_to_id => user.id
425 425 assert_equal [issue], Issue.assigned_to(user).to_a
426 426 end
427 427
428 428 def test_assigned_to_scope_should_return_issues_assigned_to_the_user_groups
429 429 group = Group.generate!
430 430 user = User.generate!
431 431 group.users << user
432 432 issue = Issue.generate!
433 433 Issue.where(:id => issue.id).update_all :assigned_to_id => group.id
434 434 assert_equal [issue], Issue.assigned_to(user).to_a
435 435 end
436 436
437 437 def test_errors_full_messages_should_include_custom_fields_errors
438 438 field = IssueCustomField.find_by_name('Database')
439 439
440 440 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1,
441 441 :status_id => 1, :subject => 'test_create',
442 442 :description => 'IssueTest#test_create_with_required_custom_field')
443 443 assert issue.available_custom_fields.include?(field)
444 444 # Invalid value
445 445 issue.custom_field_values = { field.id => 'SQLServer' }
446 446
447 447 assert !issue.valid?
448 448 assert_equal 1, issue.errors.full_messages.size
449 449 assert_equal "Database #{I18n.translate('activerecord.errors.messages.inclusion')}",
450 450 issue.errors.full_messages.first
451 451 end
452 452
453 453 def test_update_issue_with_required_custom_field
454 454 field = IssueCustomField.find_by_name('Database')
455 455 field.update_attribute(:is_required, true)
456 456
457 457 issue = Issue.find(1)
458 458 assert_nil issue.custom_value_for(field)
459 459 assert issue.available_custom_fields.include?(field)
460 460 # No change to custom values, issue can be saved
461 461 assert issue.save
462 462 # Blank value
463 463 issue.custom_field_values = { field.id => '' }
464 464 assert !issue.save
465 465 # Valid value
466 466 issue.custom_field_values = { field.id => 'PostgreSQL' }
467 467 assert issue.save
468 468 issue.reload
469 469 assert_equal 'PostgreSQL', issue.custom_value_for(field).value
470 470 end
471 471
472 472 def test_should_not_update_attributes_if_custom_fields_validation_fails
473 473 issue = Issue.find(1)
474 474 field = IssueCustomField.find_by_name('Database')
475 475 assert issue.available_custom_fields.include?(field)
476 476
477 477 issue.custom_field_values = { field.id => 'Invalid' }
478 478 issue.subject = 'Should be not be saved'
479 479 assert !issue.save
480 480
481 481 issue.reload
482 482 assert_equal "Cannot print recipes", issue.subject
483 483 end
484 484
485 485 def test_should_not_recreate_custom_values_objects_on_update
486 486 field = IssueCustomField.find_by_name('Database')
487 487
488 488 issue = Issue.find(1)
489 489 issue.custom_field_values = { field.id => 'PostgreSQL' }
490 490 assert issue.save
491 491 custom_value = issue.custom_value_for(field)
492 492 issue.reload
493 493 issue.custom_field_values = { field.id => 'MySQL' }
494 494 assert issue.save
495 495 issue.reload
496 496 assert_equal custom_value.id, issue.custom_value_for(field).id
497 497 end
498 498
499 def test_setting_project_should_set_version_to_default_version
500 version = Version.generate!(:project_id => 1)
501 Project.find(1).update_attribute(:default_version_id, version.id)
502
503 issue = Issue.new(:project_id => 1)
504 assert_equal version, issue.fixed_version
505 end
506
499 507 def test_should_not_update_custom_fields_on_changing_tracker_with_different_custom_fields
500 508 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1,
501 509 :status_id => 1, :subject => 'Test',
502 510 :custom_field_values => {'2' => 'Test'})
503 511 assert !Tracker.find(2).custom_field_ids.include?(2)
504 512
505 513 issue = Issue.find(issue.id)
506 514 issue.attributes = {:tracker_id => 2, :custom_field_values => {'1' => ''}}
507 515
508 516 issue = Issue.find(issue.id)
509 517 custom_value = issue.custom_value_for(2)
510 518 assert_not_nil custom_value
511 519 assert_equal 'Test', custom_value.value
512 520 end
513 521
514 522 def test_assigning_tracker_id_should_reload_custom_fields_values
515 523 issue = Issue.new(:project => Project.find(1))
516 524 assert issue.custom_field_values.empty?
517 525 issue.tracker_id = 1
518 526 assert issue.custom_field_values.any?
519 527 end
520 528
521 529 def test_assigning_attributes_should_assign_project_and_tracker_first
522 530 seq = sequence('seq')
523 531 issue = Issue.new
524 532 issue.expects(:project_id=).in_sequence(seq)
525 533 issue.expects(:tracker_id=).in_sequence(seq)
526 534 issue.expects(:subject=).in_sequence(seq)
527 535 issue.attributes = {:tracker_id => 2, :project_id => 1, :subject => 'Test'}
528 536 end
529 537
530 538 def test_assigning_tracker_and_custom_fields_should_assign_custom_fields
531 539 attributes = ActiveSupport::OrderedHash.new
532 540 attributes['custom_field_values'] = { '1' => 'MySQL' }
533 541 attributes['tracker_id'] = '1'
534 542 issue = Issue.new(:project => Project.find(1))
535 543 issue.attributes = attributes
536 544 assert_equal 'MySQL', issue.custom_field_value(1)
537 545 end
538 546
539 547 def test_changing_tracker_should_clear_disabled_core_fields
540 548 tracker = Tracker.find(2)
541 549 tracker.core_fields = tracker.core_fields - %w(due_date)
542 550 tracker.save!
543 551
544 552 issue = Issue.generate!(:tracker_id => 1, :start_date => Date.today, :due_date => Date.today)
545 553 issue.save!
546 554
547 555 issue.tracker_id = 2
548 556 issue.save!
549 557 assert_not_nil issue.start_date
550 558 assert_nil issue.due_date
551 559 end
552 560
553 561 def test_changing_tracker_should_not_add_cleared_fields_to_journal
554 562 tracker = Tracker.find(2)
555 563 tracker.core_fields = tracker.core_fields - %w(due_date)
556 564 tracker.save!
557 565
558 566 issue = Issue.generate!(:tracker_id => 1, :due_date => Date.today)
559 567 issue.save!
560 568
561 569 assert_difference 'Journal.count' do
562 570 issue.init_journal User.find(1)
563 571 issue.tracker_id = 2
564 572 issue.save!
565 573 assert_nil issue.due_date
566 574 end
567 575 journal = Journal.order('id DESC').first
568 576 assert_equal 1, journal.details.count
569 577 end
570 578
571 579 def test_reload_should_reload_custom_field_values
572 580 issue = Issue.generate!
573 581 issue.custom_field_values = {'2' => 'Foo'}
574 582 issue.save!
575 583
576 584 issue = Issue.order('id desc').first
577 585 assert_equal 'Foo', issue.custom_field_value(2)
578 586
579 587 issue.custom_field_values = {'2' => 'Bar'}
580 588 assert_equal 'Bar', issue.custom_field_value(2)
581 589
582 590 issue.reload
583 591 assert_equal 'Foo', issue.custom_field_value(2)
584 592 end
585 593
586 594 def test_should_update_issue_with_disabled_tracker
587 595 p = Project.find(1)
588 596 issue = Issue.find(1)
589 597
590 598 p.trackers.delete(issue.tracker)
591 599 assert !p.trackers.include?(issue.tracker)
592 600
593 601 issue.reload
594 602 issue.subject = 'New subject'
595 603 assert issue.save
596 604 end
597 605
598 606 def test_should_not_set_a_disabled_tracker
599 607 p = Project.find(1)
600 608 p.trackers.delete(Tracker.find(2))
601 609
602 610 issue = Issue.find(1)
603 611 issue.tracker_id = 2
604 612 issue.subject = 'New subject'
605 613 assert !issue.save
606 614 assert_not_equal [], issue.errors[:tracker_id]
607 615 end
608 616
609 617 def test_category_based_assignment
610 618 issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3,
611 619 :status_id => 1, :priority => IssuePriority.all.first,
612 620 :subject => 'Assignment test',
613 621 :description => 'Assignment test', :category_id => 1)
614 622 assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to
615 623 end
616 624
617 625 def test_new_statuses_allowed_to
618 626 WorkflowTransition.delete_all
619 627 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
620 628 :old_status_id => 1, :new_status_id => 2,
621 629 :author => false, :assignee => false)
622 630 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
623 631 :old_status_id => 1, :new_status_id => 3,
624 632 :author => true, :assignee => false)
625 633 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
626 634 :old_status_id => 1, :new_status_id => 4,
627 635 :author => false, :assignee => true)
628 636 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
629 637 :old_status_id => 1, :new_status_id => 5,
630 638 :author => true, :assignee => true)
631 639 status = IssueStatus.find(1)
632 640 role = Role.find(1)
633 641 tracker = Tracker.find(1)
634 642 user = User.find(2)
635 643
636 644 issue = Issue.generate!(:tracker => tracker, :status => status,
637 645 :project_id => 1, :author_id => 1)
638 646 assert_equal [1, 2], issue.new_statuses_allowed_to(user).map(&:id)
639 647
640 648 issue = Issue.generate!(:tracker => tracker, :status => status,
641 649 :project_id => 1, :author => user)
642 650 assert_equal [1, 2, 3, 5], issue.new_statuses_allowed_to(user).map(&:id)
643 651
644 652 issue = Issue.generate!(:tracker => tracker, :status => status,
645 653 :project_id => 1, :author_id => 1,
646 654 :assigned_to => user)
647 655 assert_equal [1, 2, 4, 5], issue.new_statuses_allowed_to(user).map(&:id)
648 656
649 657 issue = Issue.generate!(:tracker => tracker, :status => status,
650 658 :project_id => 1, :author => user,
651 659 :assigned_to => user)
652 660 assert_equal [1, 2, 3, 4, 5], issue.new_statuses_allowed_to(user).map(&:id)
653 661
654 662 group = Group.generate!
655 663 group.users << user
656 664 issue = Issue.generate!(:tracker => tracker, :status => status,
657 665 :project_id => 1, :author => user,
658 666 :assigned_to => group)
659 667 assert_equal [1, 2, 3, 4, 5], issue.new_statuses_allowed_to(user).map(&:id)
660 668 end
661 669
662 670 def test_new_statuses_allowed_to_should_consider_group_assignment
663 671 WorkflowTransition.delete_all
664 672 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
665 673 :old_status_id => 1, :new_status_id => 4,
666 674 :author => false, :assignee => true)
667 675 user = User.find(2)
668 676 group = Group.generate!
669 677 group.users << user
670 678
671 679 issue = Issue.generate!(:author_id => 1, :assigned_to => group)
672 680 assert_include 4, issue.new_statuses_allowed_to(user).map(&:id)
673 681 end
674 682
675 683 def test_new_statuses_allowed_to_should_return_all_transitions_for_admin
676 684 admin = User.find(1)
677 685 issue = Issue.find(1)
678 686 assert !admin.member_of?(issue.project)
679 687 expected_statuses = [issue.status] +
680 688 WorkflowTransition.where(:old_status_id => issue.status_id).
681 689 map(&:new_status).uniq.sort
682 690 assert_equal expected_statuses, issue.new_statuses_allowed_to(admin)
683 691 end
684 692
685 693 def test_new_statuses_allowed_to_should_return_default_and_current_status_when_copying
686 694 issue = Issue.find(1).copy
687 695 assert_equal [1], issue.new_statuses_allowed_to(User.find(2)).map(&:id)
688 696
689 697 issue = Issue.find(2).copy
690 698 assert_equal [1, 2], issue.new_statuses_allowed_to(User.find(2)).map(&:id)
691 699 end
692 700
693 701 def test_safe_attributes_names_should_not_include_disabled_field
694 702 tracker = Tracker.new(:core_fields => %w(assigned_to_id fixed_version_id))
695 703
696 704 issue = Issue.new(:tracker => tracker)
697 705 assert_include 'tracker_id', issue.safe_attribute_names
698 706 assert_include 'status_id', issue.safe_attribute_names
699 707 assert_include 'subject', issue.safe_attribute_names
700 708 assert_include 'description', issue.safe_attribute_names
701 709 assert_include 'custom_field_values', issue.safe_attribute_names
702 710 assert_include 'custom_fields', issue.safe_attribute_names
703 711 assert_include 'lock_version', issue.safe_attribute_names
704 712
705 713 tracker.core_fields.each do |field|
706 714 assert_include field, issue.safe_attribute_names
707 715 end
708 716
709 717 tracker.disabled_core_fields.each do |field|
710 718 assert_not_include field, issue.safe_attribute_names
711 719 end
712 720 end
713 721
714 722 def test_safe_attributes_should_ignore_disabled_fields
715 723 tracker = Tracker.find(1)
716 724 tracker.core_fields = %w(assigned_to_id due_date)
717 725 tracker.save!
718 726
719 727 issue = Issue.new(:tracker => tracker)
720 728 issue.safe_attributes = {'start_date' => '2012-07-14', 'due_date' => '2012-07-14'}
721 729 assert_nil issue.start_date
722 730 assert_equal Date.parse('2012-07-14'), issue.due_date
723 731 end
724 732
725 733 def test_safe_attributes_should_accept_target_tracker_enabled_fields
726 734 source = Tracker.find(1)
727 735 source.core_fields = []
728 736 source.save!
729 737 target = Tracker.find(2)
730 738 target.core_fields = %w(assigned_to_id due_date)
731 739 target.save!
732 740
733 741 issue = Issue.new(:tracker => source)
734 742 issue.safe_attributes = {'tracker_id' => 2, 'due_date' => '2012-07-14'}
735 743 assert_equal target, issue.tracker
736 744 assert_equal Date.parse('2012-07-14'), issue.due_date
737 745 end
738 746
739 747 def test_safe_attributes_should_not_include_readonly_fields
740 748 WorkflowPermission.delete_all
741 749 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
742 750 :role_id => 1, :field_name => 'due_date',
743 751 :rule => 'readonly')
744 752 user = User.find(2)
745 753
746 754 issue = Issue.new(:project_id => 1, :tracker_id => 1)
747 755 assert_equal %w(due_date), issue.read_only_attribute_names(user)
748 756 assert_not_include 'due_date', issue.safe_attribute_names(user)
749 757
750 758 issue.send :safe_attributes=, {'start_date' => '2012-07-14', 'due_date' => '2012-07-14'}, user
751 759 assert_equal Date.parse('2012-07-14'), issue.start_date
752 760 assert_nil issue.due_date
753 761 end
754 762
755 763 def test_safe_attributes_should_not_include_readonly_custom_fields
756 764 cf1 = IssueCustomField.create!(:name => 'Writable field',
757 765 :field_format => 'string',
758 766 :is_for_all => true, :tracker_ids => [1])
759 767 cf2 = IssueCustomField.create!(:name => 'Readonly field',
760 768 :field_format => 'string',
761 769 :is_for_all => true, :tracker_ids => [1])
762 770 WorkflowPermission.delete_all
763 771 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
764 772 :role_id => 1, :field_name => cf2.id.to_s,
765 773 :rule => 'readonly')
766 774 user = User.find(2)
767 775 issue = Issue.new(:project_id => 1, :tracker_id => 1)
768 776 assert_equal [cf2.id.to_s], issue.read_only_attribute_names(user)
769 777 assert_not_include cf2.id.to_s, issue.safe_attribute_names(user)
770 778
771 779 issue.send :safe_attributes=, {'custom_field_values' => {
772 780 cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'
773 781 }}, user
774 782 assert_equal 'value1', issue.custom_field_value(cf1)
775 783 assert_nil issue.custom_field_value(cf2)
776 784
777 785 issue.send :safe_attributes=, {'custom_fields' => [
778 786 {'id' => cf1.id.to_s, 'value' => 'valuea'},
779 787 {'id' => cf2.id.to_s, 'value' => 'valueb'}
780 788 ]}, user
781 789 assert_equal 'valuea', issue.custom_field_value(cf1)
782 790 assert_nil issue.custom_field_value(cf2)
783 791 end
784 792
785 793 def test_editable_custom_field_values_should_return_non_readonly_custom_values
786 794 cf1 = IssueCustomField.create!(:name => 'Writable field', :field_format => 'string',
787 795 :is_for_all => true, :tracker_ids => [1, 2])
788 796 cf2 = IssueCustomField.create!(:name => 'Readonly field', :field_format => 'string',
789 797 :is_for_all => true, :tracker_ids => [1, 2])
790 798 WorkflowPermission.delete_all
791 799 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1,
792 800 :field_name => cf2.id.to_s, :rule => 'readonly')
793 801 user = User.find(2)
794 802
795 803 issue = Issue.new(:project_id => 1, :tracker_id => 1)
796 804 values = issue.editable_custom_field_values(user)
797 805 assert values.detect {|value| value.custom_field == cf1}
798 806 assert_nil values.detect {|value| value.custom_field == cf2}
799 807
800 808 issue.tracker_id = 2
801 809 values = issue.editable_custom_field_values(user)
802 810 assert values.detect {|value| value.custom_field == cf1}
803 811 assert values.detect {|value| value.custom_field == cf2}
804 812 end
805 813
806 814 def test_editable_custom_fields_should_return_custom_field_that_is_enabled_for_the_role_only
807 815 enabled_cf = IssueCustomField.generate!(:is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [1,2])
808 816 disabled_cf = IssueCustomField.generate!(:is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [2])
809 817 user = User.find(2)
810 818 issue = Issue.new(:project_id => 1, :tracker_id => 1)
811 819
812 820 assert_include enabled_cf, issue.editable_custom_fields(user)
813 821 assert_not_include disabled_cf, issue.editable_custom_fields(user)
814 822 end
815 823
816 824 def test_safe_attributes_should_accept_target_tracker_writable_fields
817 825 WorkflowPermission.delete_all
818 826 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
819 827 :role_id => 1, :field_name => 'due_date',
820 828 :rule => 'readonly')
821 829 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2,
822 830 :role_id => 1, :field_name => 'start_date',
823 831 :rule => 'readonly')
824 832 user = User.find(2)
825 833
826 834 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1)
827 835
828 836 issue.send :safe_attributes=, {'start_date' => '2012-07-12',
829 837 'due_date' => '2012-07-14'}, user
830 838 assert_equal Date.parse('2012-07-12'), issue.start_date
831 839 assert_nil issue.due_date
832 840
833 841 issue.send :safe_attributes=, {'start_date' => '2012-07-15',
834 842 'due_date' => '2012-07-16',
835 843 'tracker_id' => 2}, user
836 844 assert_equal Date.parse('2012-07-12'), issue.start_date
837 845 assert_equal Date.parse('2012-07-16'), issue.due_date
838 846 end
839 847
840 848 def test_safe_attributes_should_accept_target_status_writable_fields
841 849 WorkflowPermission.delete_all
842 850 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
843 851 :role_id => 1, :field_name => 'due_date',
844 852 :rule => 'readonly')
845 853 WorkflowPermission.create!(:old_status_id => 2, :tracker_id => 1,
846 854 :role_id => 1, :field_name => 'start_date',
847 855 :rule => 'readonly')
848 856 user = User.find(2)
849 857
850 858 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1)
851 859
852 860 issue.send :safe_attributes=, {'start_date' => '2012-07-12',
853 861 'due_date' => '2012-07-14'},
854 862 user
855 863 assert_equal Date.parse('2012-07-12'), issue.start_date
856 864 assert_nil issue.due_date
857 865
858 866 issue.send :safe_attributes=, {'start_date' => '2012-07-15',
859 867 'due_date' => '2012-07-16',
860 868 'status_id' => 2},
861 869 user
862 870 assert_equal Date.parse('2012-07-12'), issue.start_date
863 871 assert_equal Date.parse('2012-07-16'), issue.due_date
864 872 end
865 873
866 874 def test_required_attributes_should_be_validated
867 875 cf = IssueCustomField.create!(:name => 'Foo', :field_format => 'string',
868 876 :is_for_all => true, :tracker_ids => [1, 2])
869 877
870 878 WorkflowPermission.delete_all
871 879 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
872 880 :role_id => 1, :field_name => 'due_date',
873 881 :rule => 'required')
874 882 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
875 883 :role_id => 1, :field_name => 'category_id',
876 884 :rule => 'required')
877 885 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
878 886 :role_id => 1, :field_name => cf.id.to_s,
879 887 :rule => 'required')
880 888
881 889 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2,
882 890 :role_id => 1, :field_name => 'start_date',
883 891 :rule => 'required')
884 892 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2,
885 893 :role_id => 1, :field_name => cf.id.to_s,
886 894 :rule => 'required')
887 895 user = User.find(2)
888 896
889 897 issue = Issue.new(:project_id => 1, :tracker_id => 1,
890 898 :status_id => 1, :subject => 'Required fields',
891 899 :author => user)
892 900 assert_equal [cf.id.to_s, "category_id", "due_date"],
893 901 issue.required_attribute_names(user).sort
894 902 assert !issue.save, "Issue was saved"
895 903 assert_equal ["Category cannot be blank", "Due date cannot be blank", "Foo cannot be blank"],
896 904 issue.errors.full_messages.sort
897 905
898 906 issue.tracker_id = 2
899 907 assert_equal [cf.id.to_s, "start_date"], issue.required_attribute_names(user).sort
900 908 assert !issue.save, "Issue was saved"
901 909 assert_equal ["Foo cannot be blank", "Start date cannot be blank"],
902 910 issue.errors.full_messages.sort
903 911
904 912 issue.start_date = Date.today
905 913 issue.custom_field_values = {cf.id.to_s => 'bar'}
906 914 assert issue.save
907 915 end
908 916
909 917 def test_required_attribute_that_is_disabled_for_the_tracker_should_not_be_required
910 918 WorkflowPermission.delete_all
911 919 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
912 920 :role_id => 1, :field_name => 'start_date',
913 921 :rule => 'required')
914 922 user = User.find(2)
915 923
916 924 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1,
917 925 :subject => 'Required fields', :author => user)
918 926 assert !issue.save
919 927 assert_include "Start date cannot be blank", issue.errors.full_messages
920 928
921 929 tracker = Tracker.find(1)
922 930 tracker.core_fields -= %w(start_date)
923 931 tracker.save!
924 932 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1,
925 933 :subject => 'Required fields', :author => user)
926 934 assert issue.save
927 935 end
928 936
929 937 def test_category_should_not_be_required_if_project_has_no_categories
930 938 Project.find(1).issue_categories.delete_all
931 939 WorkflowPermission.delete_all
932 940 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
933 941 :role_id => 1, :field_name => 'category_id',:rule => 'required')
934 942 user = User.find(2)
935 943
936 944 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1,
937 945 :subject => 'Required fields', :author => user)
938 946 assert_save issue
939 947 end
940 948
941 949 def test_fixed_version_should_not_be_required_no_assignable_versions
942 950 Version.delete_all
943 951 WorkflowPermission.delete_all
944 952 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
945 953 :role_id => 1, :field_name => 'fixed_version_id',:rule => 'required')
946 954 user = User.find(2)
947 955
948 956 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1,
949 957 :subject => 'Required fields', :author => user)
950 958 assert_save issue
951 959 end
952 960
953 961 def test_required_custom_field_that_is_not_visible_for_the_user_should_not_be_required
954 962 CustomField.delete_all
955 963 field = IssueCustomField.generate!(:is_required => true, :visible => false, :role_ids => [1], :trackers => Tracker.all, :is_for_all => true)
956 964 user = User.generate!
957 965 User.add_to_project(user, Project.find(1), Role.find(2))
958 966
959 967 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1,
960 968 :subject => 'Required fields', :author => user)
961 969 assert_save issue
962 970 end
963 971
964 972 def test_required_custom_field_that_is_visible_for_the_user_should_be_required
965 973 CustomField.delete_all
966 974 field = IssueCustomField.generate!(:is_required => true, :visible => false, :role_ids => [1], :trackers => Tracker.all, :is_for_all => true)
967 975 user = User.generate!
968 976 User.add_to_project(user, Project.find(1), Role.find(1))
969 977
970 978 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1,
971 979 :subject => 'Required fields', :author => user)
972 980 assert !issue.save
973 981 assert_include "#{field.name} cannot be blank", issue.errors.full_messages
974 982 end
975 983
976 984 def test_required_attribute_names_for_multiple_roles_should_intersect_rules
977 985 WorkflowPermission.delete_all
978 986 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
979 987 :role_id => 1, :field_name => 'due_date',
980 988 :rule => 'required')
981 989 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
982 990 :role_id => 1, :field_name => 'start_date',
983 991 :rule => 'required')
984 992 user = User.find(2)
985 993 member = Member.find(1)
986 994 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1)
987 995
988 996 assert_equal %w(due_date start_date), issue.required_attribute_names(user).sort
989 997
990 998 member.role_ids = [1, 2]
991 999 member.save!
992 1000 assert_equal [], issue.required_attribute_names(user.reload)
993 1001
994 1002 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
995 1003 :role_id => 2, :field_name => 'due_date',
996 1004 :rule => 'required')
997 1005 assert_equal %w(due_date), issue.required_attribute_names(user)
998 1006
999 1007 member.role_ids = [1, 2, 3]
1000 1008 member.save!
1001 1009 assert_equal [], issue.required_attribute_names(user.reload)
1002 1010
1003 1011 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
1004 1012 :role_id => 3, :field_name => 'due_date',
1005 1013 :rule => 'readonly')
1006 1014 # required + readonly => required
1007 1015 assert_equal %w(due_date), issue.required_attribute_names(user)
1008 1016 end
1009 1017
1010 1018 def test_read_only_attribute_names_for_multiple_roles_should_intersect_rules
1011 1019 WorkflowPermission.delete_all
1012 1020 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
1013 1021 :role_id => 1, :field_name => 'due_date',
1014 1022 :rule => 'readonly')
1015 1023 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
1016 1024 :role_id => 1, :field_name => 'start_date',
1017 1025 :rule => 'readonly')
1018 1026 user = User.find(2)
1019 1027 member = Member.find(1)
1020 1028 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1)
1021 1029
1022 1030 assert_equal %w(due_date start_date), issue.read_only_attribute_names(user).sort
1023 1031
1024 1032 member.role_ids = [1, 2]
1025 1033 member.save!
1026 1034 assert_equal [], issue.read_only_attribute_names(user.reload)
1027 1035
1028 1036 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
1029 1037 :role_id => 2, :field_name => 'due_date',
1030 1038 :rule => 'readonly')
1031 1039 assert_equal %w(due_date), issue.read_only_attribute_names(user)
1032 1040 end
1033 1041
1034 1042 # A field that is not visible by role 2 and readonly by role 1 should be readonly for user with role 1 and 2
1035 1043 def test_read_only_attribute_names_should_include_custom_fields_that_combine_readonly_and_not_visible_for_roles
1036 1044 field = IssueCustomField.generate!(
1037 1045 :is_for_all => true, :trackers => Tracker.all, :visible => false, :role_ids => [1]
1038 1046 )
1039 1047 WorkflowPermission.delete_all
1040 1048 WorkflowPermission.create!(
1041 1049 :old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => field.id, :rule => 'readonly'
1042 1050 )
1043 1051 user = User.generate!
1044 1052 project = Project.find(1)
1045 1053 User.add_to_project(user, project, Role.where(:id => [1, 2]))
1046 1054
1047 1055 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1)
1048 1056 assert_equal [field.id.to_s], issue.read_only_attribute_names(user)
1049 1057 end
1050 1058
1051 1059 def test_workflow_rules_should_ignore_roles_without_issue_permissions
1052 1060 role = Role.generate! :permissions => [:view_issues, :edit_issues]
1053 1061 ignored_role = Role.generate! :permissions => [:view_issues]
1054 1062
1055 1063 WorkflowPermission.delete_all
1056 1064 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
1057 1065 :role => role, :field_name => 'due_date',
1058 1066 :rule => 'required')
1059 1067 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
1060 1068 :role => role, :field_name => 'start_date',
1061 1069 :rule => 'readonly')
1062 1070 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
1063 1071 :role => role, :field_name => 'done_ratio',
1064 1072 :rule => 'readonly')
1065 1073 user = User.generate!
1066 1074 User.add_to_project user, Project.find(1), [role, ignored_role]
1067 1075
1068 1076 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1)
1069 1077
1070 1078 assert_equal %w(due_date), issue.required_attribute_names(user)
1071 1079 assert_equal %w(done_ratio start_date), issue.read_only_attribute_names(user).sort
1072 1080 end
1073 1081
1074 1082 def test_workflow_rules_should_work_for_member_with_duplicate_role
1075 1083 WorkflowPermission.delete_all
1076 1084 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
1077 1085 :role_id => 1, :field_name => 'due_date',
1078 1086 :rule => 'required')
1079 1087 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
1080 1088 :role_id => 1, :field_name => 'start_date',
1081 1089 :rule => 'readonly')
1082 1090
1083 1091 user = User.generate!
1084 1092 m = Member.new(:user_id => user.id, :project_id => 1)
1085 1093 m.member_roles.build(:role_id => 1)
1086 1094 m.member_roles.build(:role_id => 1)
1087 1095 m.save!
1088 1096
1089 1097 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1)
1090 1098
1091 1099 assert_equal %w(due_date), issue.required_attribute_names(user)
1092 1100 assert_equal %w(start_date), issue.read_only_attribute_names(user)
1093 1101 end
1094 1102
1095 1103 def test_copy
1096 1104 issue = Issue.new.copy_from(1)
1097 1105 assert issue.copy?
1098 1106 assert issue.save
1099 1107 issue.reload
1100 1108 orig = Issue.find(1)
1101 1109 assert_equal orig.subject, issue.subject
1102 1110 assert_equal orig.tracker, issue.tracker
1103 1111 assert_equal "125", issue.custom_value_for(2).value
1104 1112 end
1105 1113
1106 1114 def test_copy_should_copy_status
1107 1115 orig = Issue.find(8)
1108 1116 assert orig.status != orig.default_status
1109 1117
1110 1118 issue = Issue.new.copy_from(orig)
1111 1119 assert issue.save
1112 1120 issue.reload
1113 1121 assert_equal orig.status, issue.status
1114 1122 end
1115 1123
1116 1124 def test_copy_should_add_relation_with_copied_issue
1117 1125 copied = Issue.find(1)
1118 1126 issue = Issue.new.copy_from(copied)
1119 1127 assert issue.save
1120 1128 issue.reload
1121 1129
1122 1130 assert_equal 1, issue.relations.size
1123 1131 relation = issue.relations.first
1124 1132 assert_equal 'copied_to', relation.relation_type
1125 1133 assert_equal copied, relation.issue_from
1126 1134 assert_equal issue, relation.issue_to
1127 1135 end
1128 1136
1129 1137 def test_copy_should_copy_subtasks
1130 1138 issue = Issue.generate_with_descendants!
1131 1139
1132 1140 copy = issue.reload.copy
1133 1141 copy.author = User.find(7)
1134 1142 assert_difference 'Issue.count', 1+issue.descendants.count do
1135 1143 assert copy.save
1136 1144 end
1137 1145 copy.reload
1138 1146 assert_equal %w(Child1 Child2), copy.children.map(&:subject).sort
1139 1147 child_copy = copy.children.detect {|c| c.subject == 'Child1'}
1140 1148 assert_equal %w(Child11), child_copy.children.map(&:subject).sort
1141 1149 assert_equal copy.author, child_copy.author
1142 1150 end
1143 1151
1144 1152 def test_copy_as_a_child_of_copied_issue_should_not_copy_itself
1145 1153 parent = Issue.generate!
1146 1154 child1 = Issue.generate!(:parent_issue_id => parent.id, :subject => 'Child 1')
1147 1155 child2 = Issue.generate!(:parent_issue_id => parent.id, :subject => 'Child 2')
1148 1156
1149 1157 copy = parent.reload.copy
1150 1158 copy.parent_issue_id = parent.id
1151 1159 copy.author = User.find(7)
1152 1160 assert_difference 'Issue.count', 3 do
1153 1161 assert copy.save
1154 1162 end
1155 1163 parent.reload
1156 1164 copy.reload
1157 1165 assert_equal parent, copy.parent
1158 1166 assert_equal 3, parent.children.count
1159 1167 assert_equal 5, parent.descendants.count
1160 1168 assert_equal 2, copy.children.count
1161 1169 assert_equal 2, copy.descendants.count
1162 1170 end
1163 1171
1164 1172 def test_copy_as_a_descendant_of_copied_issue_should_not_copy_itself
1165 1173 parent = Issue.generate!
1166 1174 child1 = Issue.generate!(:parent_issue_id => parent.id, :subject => 'Child 1')
1167 1175 child2 = Issue.generate!(:parent_issue_id => parent.id, :subject => 'Child 2')
1168 1176
1169 1177 copy = parent.reload.copy
1170 1178 copy.parent_issue_id = child1.id
1171 1179 copy.author = User.find(7)
1172 1180 assert_difference 'Issue.count', 3 do
1173 1181 assert copy.save
1174 1182 end
1175 1183 parent.reload
1176 1184 child1.reload
1177 1185 copy.reload
1178 1186 assert_equal child1, copy.parent
1179 1187 assert_equal 2, parent.children.count
1180 1188 assert_equal 5, parent.descendants.count
1181 1189 assert_equal 1, child1.children.count
1182 1190 assert_equal 3, child1.descendants.count
1183 1191 assert_equal 2, copy.children.count
1184 1192 assert_equal 2, copy.descendants.count
1185 1193 end
1186 1194
1187 1195 def test_copy_should_copy_subtasks_to_target_project
1188 1196 issue = Issue.generate_with_descendants!
1189 1197
1190 1198 copy = issue.copy(:project_id => 3)
1191 1199 assert_difference 'Issue.count', 1+issue.descendants.count do
1192 1200 assert copy.save
1193 1201 end
1194 1202 assert_equal [3], copy.reload.descendants.map(&:project_id).uniq
1195 1203 end
1196 1204
1197 1205 def test_copy_should_not_copy_subtasks_twice_when_saving_twice
1198 1206 issue = Issue.generate_with_descendants!
1199 1207
1200 1208 copy = issue.reload.copy
1201 1209 assert_difference 'Issue.count', 1+issue.descendants.count do
1202 1210 assert copy.save
1203 1211 assert copy.save
1204 1212 end
1205 1213 end
1206 1214
1207 1215 def test_should_not_call_after_project_change_on_creation
1208 1216 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1,
1209 1217 :subject => 'Test', :author_id => 1)
1210 1218 issue.expects(:after_project_change).never
1211 1219 issue.save!
1212 1220 end
1213 1221
1214 1222 def test_should_not_call_after_project_change_on_update
1215 1223 issue = Issue.find(1)
1216 1224 issue.project = Project.find(1)
1217 1225 issue.subject = 'No project change'
1218 1226 issue.expects(:after_project_change).never
1219 1227 issue.save!
1220 1228 end
1221 1229
1222 1230 def test_should_call_after_project_change_on_project_change
1223 1231 issue = Issue.find(1)
1224 1232 issue.project = Project.find(2)
1225 1233 issue.expects(:after_project_change).once
1226 1234 issue.save!
1227 1235 end
1228 1236
1229 1237 def test_adding_journal_should_update_timestamp
1230 1238 issue = Issue.find(1)
1231 1239 updated_on_was = issue.updated_on
1232 1240
1233 1241 issue.init_journal(User.first, "Adding notes")
1234 1242 assert_difference 'Journal.count' do
1235 1243 assert issue.save
1236 1244 end
1237 1245 issue.reload
1238 1246
1239 1247 assert_not_equal updated_on_was, issue.updated_on
1240 1248 end
1241 1249
1242 1250 def test_should_close_duplicates
1243 1251 # Create 3 issues
1244 1252 issue1 = Issue.generate!
1245 1253 issue2 = Issue.generate!
1246 1254 issue3 = Issue.generate!
1247 1255
1248 1256 # 2 is a dupe of 1
1249 1257 IssueRelation.create!(:issue_from => issue2, :issue_to => issue1,
1250 1258 :relation_type => IssueRelation::TYPE_DUPLICATES)
1251 1259 # And 3 is a dupe of 2
1252 1260 # IssueRelation.create!(:issue_from => issue3, :issue_to => issue2,
1253 1261 # :relation_type => IssueRelation::TYPE_DUPLICATES)
1254 1262 # And 3 is a dupe of 1 (circular duplicates)
1255 1263 IssueRelation.create!(:issue_from => issue3, :issue_to => issue1,
1256 1264 :relation_type => IssueRelation::TYPE_DUPLICATES)
1257 1265
1258 1266 assert issue1.reload.duplicates.include?(issue2)
1259 1267
1260 1268 # Closing issue 1
1261 1269 issue1.init_journal(User.first, "Closing issue1")
1262 1270 issue1.status = IssueStatus.where(:is_closed => true).first
1263 1271 assert issue1.save
1264 1272 # 2 and 3 should be also closed
1265 1273 assert issue2.reload.closed?
1266 1274 assert issue3.reload.closed?
1267 1275 end
1268 1276
1269 1277 def test_should_not_close_duplicated_issue
1270 1278 issue1 = Issue.generate!
1271 1279 issue2 = Issue.generate!
1272 1280
1273 1281 # 2 is a dupe of 1
1274 1282 IssueRelation.create(:issue_from => issue2, :issue_to => issue1,
1275 1283 :relation_type => IssueRelation::TYPE_DUPLICATES)
1276 1284 # 2 is a dup of 1 but 1 is not a duplicate of 2
1277 1285 assert !issue2.reload.duplicates.include?(issue1)
1278 1286
1279 1287 # Closing issue 2
1280 1288 issue2.init_journal(User.first, "Closing issue2")
1281 1289 issue2.status = IssueStatus.where(:is_closed => true).first
1282 1290 assert issue2.save
1283 1291 # 1 should not be also closed
1284 1292 assert !issue1.reload.closed?
1285 1293 end
1286 1294
1287 1295 def test_assignable_versions
1288 1296 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1,
1289 1297 :status_id => 1, :fixed_version_id => 1,
1290 1298 :subject => 'New issue')
1291 1299 assert_equal ['open'], issue.assignable_versions.collect(&:status).uniq
1292 1300 end
1293 1301
1294 1302 def test_should_not_be_able_to_assign_a_new_issue_to_a_closed_version
1295 1303 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1,
1296 1304 :status_id => 1, :fixed_version_id => 1,
1297 1305 :subject => 'New issue')
1298 1306 assert !issue.save
1299 1307 assert_not_equal [], issue.errors[:fixed_version_id]
1300 1308 end
1301 1309
1302 1310 def test_should_not_be_able_to_assign_a_new_issue_to_a_locked_version
1303 1311 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1,
1304 1312 :status_id => 1, :fixed_version_id => 2,
1305 1313 :subject => 'New issue')
1306 1314 assert !issue.save
1307 1315 assert_not_equal [], issue.errors[:fixed_version_id]
1308 1316 end
1309 1317
1310 1318 def test_should_be_able_to_assign_a_new_issue_to_an_open_version
1311 1319 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1,
1312 1320 :status_id => 1, :fixed_version_id => 3,
1313 1321 :subject => 'New issue')
1314 1322 assert issue.save
1315 1323 end
1316 1324
1317 1325 def test_should_be_able_to_update_an_issue_assigned_to_a_closed_version
1318 1326 issue = Issue.find(11)
1319 1327 assert_equal 'closed', issue.fixed_version.status
1320 1328 issue.subject = 'Subject changed'
1321 1329 assert issue.save
1322 1330 end
1323 1331
1324 1332 def test_should_not_be_able_to_reopen_an_issue_assigned_to_a_closed_version
1325 1333 issue = Issue.find(11)
1326 1334 issue.status_id = 1
1327 1335 assert !issue.save
1328 1336 assert_not_equal [], issue.errors[:base]
1329 1337 end
1330 1338
1331 1339 def test_should_be_able_to_reopen_and_reassign_an_issue_assigned_to_a_closed_version
1332 1340 issue = Issue.find(11)
1333 1341 issue.status_id = 1
1334 1342 issue.fixed_version_id = 3
1335 1343 assert issue.save
1336 1344 end
1337 1345
1338 1346 def test_should_be_able_to_reopen_an_issue_assigned_to_a_locked_version
1339 1347 issue = Issue.find(12)
1340 1348 assert_equal 'locked', issue.fixed_version.status
1341 1349 issue.status_id = 1
1342 1350 assert issue.save
1343 1351 end
1344 1352
1345 1353 def test_should_not_be_able_to_keep_unshared_version_when_changing_project
1346 1354 issue = Issue.find(2)
1347 1355 assert_equal 2, issue.fixed_version_id
1348 1356 issue.project_id = 3
1349 1357 assert_nil issue.fixed_version_id
1350 1358 issue.fixed_version_id = 2
1351 1359 assert !issue.save
1352 1360 assert_include 'Target version is not included in the list', issue.errors.full_messages
1353 1361 end
1354 1362
1355 1363 def test_should_keep_shared_version_when_changing_project
1356 1364 Version.find(2).update_attribute :sharing, 'tree'
1357 1365
1358 1366 issue = Issue.find(2)
1359 1367 assert_equal 2, issue.fixed_version_id
1360 1368 issue.project_id = 3
1361 1369 assert_equal 2, issue.fixed_version_id
1362 1370 assert issue.save
1363 1371 end
1364 1372
1365 1373 def test_allowed_target_projects_should_include_projects_with_issue_tracking_enabled
1366 1374 assert_include Project.find(2), Issue.allowed_target_projects(User.find(2))
1367 1375 end
1368 1376
1369 1377 def test_allowed_target_projects_should_not_include_projects_with_issue_tracking_disabled
1370 1378 Project.find(2).disable_module! :issue_tracking
1371 1379 assert_not_include Project.find(2), Issue.allowed_target_projects(User.find(2))
1372 1380 end
1373 1381
1374 1382 def test_allowed_target_projects_should_not_include_projects_without_trackers
1375 1383 project = Project.generate!(:tracker_ids => [])
1376 1384 assert project.trackers.empty?
1377 1385 assert_not_include project, Issue.allowed_target_projects(User.find(1))
1378 1386 end
1379 1387
1380 1388 def test_move_to_another_project_with_same_category
1381 1389 issue = Issue.find(1)
1382 1390 issue.project = Project.find(2)
1383 1391 assert issue.save
1384 1392 issue.reload
1385 1393 assert_equal 2, issue.project_id
1386 1394 # Category changes
1387 1395 assert_equal 4, issue.category_id
1388 1396 # Make sure time entries were move to the target project
1389 1397 assert_equal 2, issue.time_entries.first.project_id
1390 1398 end
1391 1399
1392 1400 def test_move_to_another_project_without_same_category
1393 1401 issue = Issue.find(2)
1394 1402 issue.project = Project.find(2)
1395 1403 assert issue.save
1396 1404 issue.reload
1397 1405 assert_equal 2, issue.project_id
1398 1406 # Category cleared
1399 1407 assert_nil issue.category_id
1400 1408 end
1401 1409
1402 1410 def test_move_to_another_project_should_clear_fixed_version_when_not_shared
1403 1411 issue = Issue.find(1)
1404 1412 issue.update_attribute(:fixed_version_id, 1)
1405 1413 issue.project = Project.find(2)
1406 1414 assert issue.save
1407 1415 issue.reload
1408 1416 assert_equal 2, issue.project_id
1409 1417 # Cleared fixed_version
1410 1418 assert_equal nil, issue.fixed_version
1411 1419 end
1412 1420
1413 1421 def test_move_to_another_project_should_keep_fixed_version_when_shared_with_the_target_project
1414 1422 issue = Issue.find(1)
1415 1423 issue.update_attribute(:fixed_version_id, 4)
1416 1424 issue.project = Project.find(5)
1417 1425 assert issue.save
1418 1426 issue.reload
1419 1427 assert_equal 5, issue.project_id
1420 1428 # Keep fixed_version
1421 1429 assert_equal 4, issue.fixed_version_id
1422 1430 end
1423 1431
1424 1432 def test_move_to_another_project_should_clear_fixed_version_when_not_shared_with_the_target_project
1425 1433 issue = Issue.find(1)
1426 1434 issue.update_attribute(:fixed_version_id, 1)
1427 1435 issue.project = Project.find(5)
1428 1436 assert issue.save
1429 1437 issue.reload
1430 1438 assert_equal 5, issue.project_id
1431 1439 # Cleared fixed_version
1432 1440 assert_equal nil, issue.fixed_version
1433 1441 end
1434 1442
1435 1443 def test_move_to_another_project_should_keep_fixed_version_when_shared_systemwide
1436 1444 issue = Issue.find(1)
1437 1445 issue.update_attribute(:fixed_version_id, 7)
1438 1446 issue.project = Project.find(2)
1439 1447 assert issue.save
1440 1448 issue.reload
1441 1449 assert_equal 2, issue.project_id
1442 1450 # Keep fixed_version
1443 1451 assert_equal 7, issue.fixed_version_id
1444 1452 end
1445 1453
1446 1454 def test_move_to_another_project_should_keep_parent_if_valid
1447 1455 issue = Issue.find(1)
1448 1456 issue.update_attribute(:parent_issue_id, 2)
1449 1457 issue.project = Project.find(3)
1450 1458 assert issue.save
1451 1459 issue.reload
1452 1460 assert_equal 2, issue.parent_id
1453 1461 end
1454 1462
1455 1463 def test_move_to_another_project_should_clear_parent_if_not_valid
1456 1464 issue = Issue.find(1)
1457 1465 issue.update_attribute(:parent_issue_id, 2)
1458 1466 issue.project = Project.find(2)
1459 1467 assert issue.save
1460 1468 issue.reload
1461 1469 assert_nil issue.parent_id
1462 1470 end
1463 1471
1464 1472 def test_move_to_another_project_with_disabled_tracker
1465 1473 issue = Issue.find(1)
1466 1474 target = Project.find(2)
1467 1475 target.tracker_ids = [3]
1468 1476 target.save
1469 1477 issue.project = target
1470 1478 assert issue.save
1471 1479 issue.reload
1472 1480 assert_equal 2, issue.project_id
1473 1481 assert_equal 3, issue.tracker_id
1474 1482 end
1475 1483
1476 1484 def test_copy_to_the_same_project
1477 1485 issue = Issue.find(1)
1478 1486 copy = issue.copy
1479 1487 assert_difference 'Issue.count' do
1480 1488 copy.save!
1481 1489 end
1482 1490 assert_kind_of Issue, copy
1483 1491 assert_equal issue.project, copy.project
1484 1492 assert_equal "125", copy.custom_value_for(2).value
1485 1493 end
1486 1494
1487 1495 def test_copy_to_another_project_and_tracker
1488 1496 issue = Issue.find(1)
1489 1497 copy = issue.copy(:project_id => 3, :tracker_id => 2)
1490 1498 assert_difference 'Issue.count' do
1491 1499 copy.save!
1492 1500 end
1493 1501 copy.reload
1494 1502 assert_kind_of Issue, copy
1495 1503 assert_equal Project.find(3), copy.project
1496 1504 assert_equal Tracker.find(2), copy.tracker
1497 1505 # Custom field #2 is not associated with target tracker
1498 1506 assert_nil copy.custom_value_for(2)
1499 1507 end
1500 1508
1501 1509 test "#copy should not create a journal" do
1502 1510 copy = Issue.find(1).copy({:project_id => 3, :tracker_id => 2, :assigned_to_id => 3}, :link => false)
1503 1511 copy.save!
1504 1512 assert_equal 0, copy.reload.journals.size
1505 1513 end
1506 1514
1507 1515 test "#copy should allow assigned_to changes" do
1508 1516 copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3)
1509 1517 assert_equal 3, copy.assigned_to_id
1510 1518 end
1511 1519
1512 1520 test "#copy should allow status changes" do
1513 1521 copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :status_id => 2)
1514 1522 assert_equal 2, copy.status_id
1515 1523 end
1516 1524
1517 1525 test "#copy should allow start date changes" do
1518 1526 date = Date.today
1519 1527 copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :start_date => date)
1520 1528 assert_equal date, copy.start_date
1521 1529 end
1522 1530
1523 1531 test "#copy should allow due date changes" do
1524 1532 date = Date.today
1525 1533 copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :due_date => date)
1526 1534 assert_equal date, copy.due_date
1527 1535 end
1528 1536
1529 1537 test "#copy should set current user as author" do
1530 1538 User.current = User.find(9)
1531 1539 copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2)
1532 1540 assert_equal User.current, copy.author
1533 1541 end
1534 1542
1535 1543 test "#copy should create a journal with notes" do
1536 1544 date = Date.today
1537 1545 notes = "Notes added when copying"
1538 1546 copy = Issue.find(1).copy({:project_id => 3, :tracker_id => 2, :start_date => date}, :link => false)
1539 1547 copy.init_journal(User.current, notes)
1540 1548 copy.save!
1541 1549
1542 1550 assert_equal 1, copy.journals.size
1543 1551 journal = copy.journals.first
1544 1552 assert_equal 0, journal.details.size
1545 1553 assert_equal notes, journal.notes
1546 1554 end
1547 1555
1548 1556 def test_valid_parent_project
1549 1557 issue = Issue.find(1)
1550 1558 issue_in_same_project = Issue.find(2)
1551 1559 issue_in_child_project = Issue.find(5)
1552 1560 issue_in_grandchild_project = Issue.generate!(:project_id => 6, :tracker_id => 1)
1553 1561 issue_in_other_child_project = Issue.find(6)
1554 1562 issue_in_different_tree = Issue.find(4)
1555 1563
1556 1564 with_settings :cross_project_subtasks => '' do
1557 1565 assert_equal true, issue.valid_parent_project?(issue_in_same_project)
1558 1566 assert_equal false, issue.valid_parent_project?(issue_in_child_project)
1559 1567 assert_equal false, issue.valid_parent_project?(issue_in_grandchild_project)
1560 1568 assert_equal false, issue.valid_parent_project?(issue_in_different_tree)
1561 1569 end
1562 1570
1563 1571 with_settings :cross_project_subtasks => 'system' do
1564 1572 assert_equal true, issue.valid_parent_project?(issue_in_same_project)
1565 1573 assert_equal true, issue.valid_parent_project?(issue_in_child_project)
1566 1574 assert_equal true, issue.valid_parent_project?(issue_in_different_tree)
1567 1575 end
1568 1576
1569 1577 with_settings :cross_project_subtasks => 'tree' do
1570 1578 assert_equal true, issue.valid_parent_project?(issue_in_same_project)
1571 1579 assert_equal true, issue.valid_parent_project?(issue_in_child_project)
1572 1580 assert_equal true, issue.valid_parent_project?(issue_in_grandchild_project)
1573 1581 assert_equal false, issue.valid_parent_project?(issue_in_different_tree)
1574 1582
1575 1583 assert_equal true, issue_in_child_project.valid_parent_project?(issue_in_same_project)
1576 1584 assert_equal true, issue_in_child_project.valid_parent_project?(issue_in_other_child_project)
1577 1585 end
1578 1586
1579 1587 with_settings :cross_project_subtasks => 'descendants' do
1580 1588 assert_equal true, issue.valid_parent_project?(issue_in_same_project)
1581 1589 assert_equal false, issue.valid_parent_project?(issue_in_child_project)
1582 1590 assert_equal false, issue.valid_parent_project?(issue_in_grandchild_project)
1583 1591 assert_equal false, issue.valid_parent_project?(issue_in_different_tree)
1584 1592
1585 1593 assert_equal true, issue_in_child_project.valid_parent_project?(issue)
1586 1594 assert_equal false, issue_in_child_project.valid_parent_project?(issue_in_other_child_project)
1587 1595 end
1588 1596 end
1589 1597
1590 1598 def test_recipients_should_include_previous_assignee
1591 1599 user = User.find(3)
1592 1600 user.members.update_all ["mail_notification = ?", false]
1593 1601 user.update_attribute :mail_notification, 'only_assigned'
1594 1602
1595 1603 issue = Issue.find(2)
1596 1604 issue.assigned_to = nil
1597 1605 assert_include user.mail, issue.recipients
1598 1606 issue.save!
1599 1607 assert !issue.recipients.include?(user.mail)
1600 1608 end
1601 1609
1602 1610 def test_recipients_should_not_include_users_that_cannot_view_the_issue
1603 1611 issue = Issue.find(12)
1604 1612 assert issue.recipients.include?(issue.author.mail)
1605 1613 # copy the issue to a private project
1606 1614 copy = issue.copy(:project_id => 5, :tracker_id => 2)
1607 1615 # author is not a member of project anymore
1608 1616 assert !copy.recipients.include?(copy.author.mail)
1609 1617 end
1610 1618
1611 1619 def test_recipients_should_include_the_assigned_group_members
1612 1620 group_member = User.generate!
1613 1621 group = Group.generate!
1614 1622 group.users << group_member
1615 1623
1616 1624 issue = Issue.find(12)
1617 1625 issue.assigned_to = group
1618 1626 assert issue.recipients.include?(group_member.mail)
1619 1627 end
1620 1628
1621 1629 def test_watcher_recipients_should_not_include_users_that_cannot_view_the_issue
1622 1630 user = User.find(3)
1623 1631 issue = Issue.find(9)
1624 1632 Watcher.create!(:user => user, :watchable => issue)
1625 1633 assert issue.watched_by?(user)
1626 1634 assert !issue.watcher_recipients.include?(user.mail)
1627 1635 end
1628 1636
1629 1637 def test_issue_destroy
1630 1638 Issue.find(1).destroy
1631 1639 assert_nil Issue.find_by_id(1)
1632 1640 assert_nil TimeEntry.find_by_issue_id(1)
1633 1641 end
1634 1642
1635 1643 def test_destroy_should_delete_time_entries_custom_values
1636 1644 issue = Issue.generate!
1637 1645 time_entry = TimeEntry.generate!(:issue => issue, :custom_field_values => {10 => '1'})
1638 1646
1639 1647 assert_difference 'CustomValue.where(:customized_type => "TimeEntry").count', -1 do
1640 1648 assert issue.destroy
1641 1649 end
1642 1650 end
1643 1651
1644 1652 def test_destroying_a_deleted_issue_should_not_raise_an_error
1645 1653 issue = Issue.find(1)
1646 1654 Issue.find(1).destroy
1647 1655
1648 1656 assert_nothing_raised do
1649 1657 assert_no_difference 'Issue.count' do
1650 1658 issue.destroy
1651 1659 end
1652 1660 assert issue.destroyed?
1653 1661 end
1654 1662 end
1655 1663
1656 1664 def test_destroying_a_stale_issue_should_not_raise_an_error
1657 1665 issue = Issue.find(1)
1658 1666 Issue.find(1).update_attribute :subject, "Updated"
1659 1667
1660 1668 assert_nothing_raised do
1661 1669 assert_difference 'Issue.count', -1 do
1662 1670 issue.destroy
1663 1671 end
1664 1672 assert issue.destroyed?
1665 1673 end
1666 1674 end
1667 1675
1668 1676 def test_blocked
1669 1677 blocked_issue = Issue.find(9)
1670 1678 blocking_issue = Issue.find(10)
1671 1679
1672 1680 assert blocked_issue.blocked?
1673 1681 assert !blocking_issue.blocked?
1674 1682 end
1675 1683
1676 1684 def test_blocked_issues_dont_allow_closed_statuses
1677 1685 blocked_issue = Issue.find(9)
1678 1686
1679 1687 allowed_statuses = blocked_issue.new_statuses_allowed_to(users(:users_002))
1680 1688 assert !allowed_statuses.empty?
1681 1689 closed_statuses = allowed_statuses.select {|st| st.is_closed?}
1682 1690 assert closed_statuses.empty?
1683 1691 end
1684 1692
1685 1693 def test_unblocked_issues_allow_closed_statuses
1686 1694 blocking_issue = Issue.find(10)
1687 1695
1688 1696 allowed_statuses = blocking_issue.new_statuses_allowed_to(users(:users_002))
1689 1697 assert !allowed_statuses.empty?
1690 1698 closed_statuses = allowed_statuses.select {|st| st.is_closed?}
1691 1699 assert !closed_statuses.empty?
1692 1700 end
1693 1701
1694 1702 def test_reschedule_an_issue_without_dates
1695 1703 with_settings :non_working_week_days => [] do
1696 1704 issue = Issue.new(:start_date => nil, :due_date => nil)
1697 1705 issue.reschedule_on '2012-10-09'.to_date
1698 1706 assert_equal '2012-10-09'.to_date, issue.start_date
1699 1707 assert_equal '2012-10-09'.to_date, issue.due_date
1700 1708 end
1701 1709
1702 1710 with_settings :non_working_week_days => %w(6 7) do
1703 1711 issue = Issue.new(:start_date => nil, :due_date => nil)
1704 1712 issue.reschedule_on '2012-10-09'.to_date
1705 1713 assert_equal '2012-10-09'.to_date, issue.start_date
1706 1714 assert_equal '2012-10-09'.to_date, issue.due_date
1707 1715
1708 1716 issue = Issue.new(:start_date => nil, :due_date => nil)
1709 1717 issue.reschedule_on '2012-10-13'.to_date
1710 1718 assert_equal '2012-10-15'.to_date, issue.start_date
1711 1719 assert_equal '2012-10-15'.to_date, issue.due_date
1712 1720 end
1713 1721 end
1714 1722
1715 1723 def test_reschedule_an_issue_with_start_date
1716 1724 with_settings :non_working_week_days => [] do
1717 1725 issue = Issue.new(:start_date => '2012-10-09', :due_date => nil)
1718 1726 issue.reschedule_on '2012-10-13'.to_date
1719 1727 assert_equal '2012-10-13'.to_date, issue.start_date
1720 1728 assert_equal '2012-10-13'.to_date, issue.due_date
1721 1729 end
1722 1730
1723 1731 with_settings :non_working_week_days => %w(6 7) do
1724 1732 issue = Issue.new(:start_date => '2012-10-09', :due_date => nil)
1725 1733 issue.reschedule_on '2012-10-11'.to_date
1726 1734 assert_equal '2012-10-11'.to_date, issue.start_date
1727 1735 assert_equal '2012-10-11'.to_date, issue.due_date
1728 1736
1729 1737 issue = Issue.new(:start_date => '2012-10-09', :due_date => nil)
1730 1738 issue.reschedule_on '2012-10-13'.to_date
1731 1739 assert_equal '2012-10-15'.to_date, issue.start_date
1732 1740 assert_equal '2012-10-15'.to_date, issue.due_date
1733 1741 end
1734 1742 end
1735 1743
1736 1744 def test_reschedule_an_issue_with_start_and_due_dates
1737 1745 with_settings :non_working_week_days => [] do
1738 1746 issue = Issue.new(:start_date => '2012-10-09', :due_date => '2012-10-15')
1739 1747 issue.reschedule_on '2012-10-13'.to_date
1740 1748 assert_equal '2012-10-13'.to_date, issue.start_date
1741 1749 assert_equal '2012-10-19'.to_date, issue.due_date
1742 1750 end
1743 1751
1744 1752 with_settings :non_working_week_days => %w(6 7) do
1745 1753 issue = Issue.new(:start_date => '2012-10-09', :due_date => '2012-10-19') # 8 working days
1746 1754 issue.reschedule_on '2012-10-11'.to_date
1747 1755 assert_equal '2012-10-11'.to_date, issue.start_date
1748 1756 assert_equal '2012-10-23'.to_date, issue.due_date
1749 1757
1750 1758 issue = Issue.new(:start_date => '2012-10-09', :due_date => '2012-10-19')
1751 1759 issue.reschedule_on '2012-10-13'.to_date
1752 1760 assert_equal '2012-10-15'.to_date, issue.start_date
1753 1761 assert_equal '2012-10-25'.to_date, issue.due_date
1754 1762 end
1755 1763 end
1756 1764
1757 1765 def test_rescheduling_an_issue_to_a_later_due_date_should_reschedule_following_issue
1758 1766 issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
1759 1767 issue2 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
1760 1768 IssueRelation.create!(:issue_from => issue1, :issue_to => issue2,
1761 1769 :relation_type => IssueRelation::TYPE_PRECEDES)
1762 1770 assert_equal Date.parse('2012-10-18'), issue2.reload.start_date
1763 1771
1764 1772 issue1.reload
1765 1773 issue1.due_date = '2012-10-23'
1766 1774 issue1.save!
1767 1775 issue2.reload
1768 1776 assert_equal Date.parse('2012-10-24'), issue2.start_date
1769 1777 assert_equal Date.parse('2012-10-26'), issue2.due_date
1770 1778 end
1771 1779
1772 1780 def test_rescheduling_an_issue_to_an_earlier_due_date_should_reschedule_following_issue
1773 1781 issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
1774 1782 issue2 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
1775 1783 IssueRelation.create!(:issue_from => issue1, :issue_to => issue2,
1776 1784 :relation_type => IssueRelation::TYPE_PRECEDES)
1777 1785 assert_equal Date.parse('2012-10-18'), issue2.reload.start_date
1778 1786
1779 1787 issue1.reload
1780 1788 issue1.start_date = '2012-09-17'
1781 1789 issue1.due_date = '2012-09-18'
1782 1790 issue1.save!
1783 1791 issue2.reload
1784 1792 assert_equal Date.parse('2012-09-19'), issue2.start_date
1785 1793 assert_equal Date.parse('2012-09-21'), issue2.due_date
1786 1794 end
1787 1795
1788 1796 def test_rescheduling_reschedule_following_issue_earlier_should_consider_other_preceding_issues
1789 1797 issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
1790 1798 issue2 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
1791 1799 issue3 = Issue.generate!(:start_date => '2012-10-01', :due_date => '2012-10-02')
1792 1800 IssueRelation.create!(:issue_from => issue1, :issue_to => issue2,
1793 1801 :relation_type => IssueRelation::TYPE_PRECEDES)
1794 1802 IssueRelation.create!(:issue_from => issue3, :issue_to => issue2,
1795 1803 :relation_type => IssueRelation::TYPE_PRECEDES)
1796 1804 assert_equal Date.parse('2012-10-18'), issue2.reload.start_date
1797 1805
1798 1806 issue1.reload
1799 1807 issue1.start_date = '2012-09-17'
1800 1808 issue1.due_date = '2012-09-18'
1801 1809 issue1.save!
1802 1810 issue2.reload
1803 1811 # Issue 2 must start after Issue 3
1804 1812 assert_equal Date.parse('2012-10-03'), issue2.start_date
1805 1813 assert_equal Date.parse('2012-10-05'), issue2.due_date
1806 1814 end
1807 1815
1808 1816 def test_rescheduling_a_stale_issue_should_not_raise_an_error
1809 1817 with_settings :non_working_week_days => [] do
1810 1818 stale = Issue.find(1)
1811 1819 issue = Issue.find(1)
1812 1820 issue.subject = "Updated"
1813 1821 issue.save!
1814 1822 date = 10.days.from_now.to_date
1815 1823 assert_nothing_raised do
1816 1824 stale.reschedule_on!(date)
1817 1825 end
1818 1826 assert_equal date, stale.reload.start_date
1819 1827 end
1820 1828 end
1821 1829
1822 1830 def test_child_issue_should_consider_parent_soonest_start_on_create
1823 1831 set_language_if_valid 'en'
1824 1832 issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
1825 1833 issue2 = Issue.generate!(:start_date => '2012-10-18', :due_date => '2012-10-20')
1826 1834 IssueRelation.create!(:issue_from => issue1, :issue_to => issue2,
1827 1835 :relation_type => IssueRelation::TYPE_PRECEDES)
1828 1836 issue1.reload
1829 1837 issue2.reload
1830 1838 assert_equal Date.parse('2012-10-18'), issue2.start_date
1831 1839
1832 1840 with_settings :date_format => '%m/%d/%Y' do
1833 1841 child = Issue.new(:parent_issue_id => issue2.id, :start_date => '2012-10-16',
1834 1842 :project_id => 1, :tracker_id => 1, :status_id => 1, :subject => 'Child', :author_id => 1)
1835 1843 assert !child.valid?
1836 1844 assert_include 'Start date cannot be earlier than 10/18/2012 because of preceding issues', child.errors.full_messages
1837 1845 assert_equal Date.parse('2012-10-18'), child.soonest_start
1838 1846 child.start_date = '2012-10-18'
1839 1847 assert child.save
1840 1848 end
1841 1849 end
1842 1850
1843 1851 def test_setting_parent_to_a_dependent_issue_should_not_validate
1844 1852 set_language_if_valid 'en'
1845 1853 issue1 = Issue.generate!
1846 1854 issue2 = Issue.generate!
1847 1855 issue3 = Issue.generate!
1848 1856 IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_PRECEDES)
1849 1857 IssueRelation.create!(:issue_from => issue3, :issue_to => issue1, :relation_type => IssueRelation::TYPE_PRECEDES)
1850 1858 issue3.reload
1851 1859 issue3.parent_issue_id = issue2.id
1852 1860 assert !issue3.valid?
1853 1861 assert_include 'Parent task is invalid', issue3.errors.full_messages
1854 1862 end
1855 1863
1856 1864 def test_setting_parent_should_not_allow_circular_dependency
1857 1865 set_language_if_valid 'en'
1858 1866 issue1 = Issue.generate!
1859 1867 issue2 = Issue.generate!
1860 1868 IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_PRECEDES)
1861 1869 issue3 = Issue.generate!
1862 1870 issue2.reload
1863 1871 issue2.parent_issue_id = issue3.id
1864 1872 issue2.save!
1865 1873 issue4 = Issue.generate!
1866 1874 IssueRelation.create!(:issue_from => issue3, :issue_to => issue4, :relation_type => IssueRelation::TYPE_PRECEDES)
1867 1875 issue4.reload
1868 1876 issue4.parent_issue_id = issue1.id
1869 1877 assert !issue4.valid?
1870 1878 assert_include 'Parent task is invalid', issue4.errors.full_messages
1871 1879 end
1872 1880
1873 1881 def test_overdue
1874 1882 assert Issue.new(:due_date => 1.day.ago.to_date).overdue?
1875 1883 assert !Issue.new(:due_date => Date.today).overdue?
1876 1884 assert !Issue.new(:due_date => 1.day.from_now.to_date).overdue?
1877 1885 assert !Issue.new(:due_date => nil).overdue?
1878 1886 assert !Issue.new(:due_date => 1.day.ago.to_date,
1879 1887 :status => IssueStatus.where(:is_closed => true).first
1880 1888 ).overdue?
1881 1889 end
1882 1890
1883 1891 test "#behind_schedule? should be false if the issue has no start_date" do
1884 1892 assert !Issue.new(:start_date => nil,
1885 1893 :due_date => 1.day.from_now.to_date,
1886 1894 :done_ratio => 0).behind_schedule?
1887 1895 end
1888 1896
1889 1897 test "#behind_schedule? should be false if the issue has no end_date" do
1890 1898 assert !Issue.new(:start_date => 1.day.from_now.to_date,
1891 1899 :due_date => nil,
1892 1900 :done_ratio => 0).behind_schedule?
1893 1901 end
1894 1902
1895 1903 test "#behind_schedule? should be false if the issue has more done than it's calendar time" do
1896 1904 assert !Issue.new(:start_date => 50.days.ago.to_date,
1897 1905 :due_date => 50.days.from_now.to_date,
1898 1906 :done_ratio => 90).behind_schedule?
1899 1907 end
1900 1908
1901 1909 test "#behind_schedule? should be true if the issue hasn't been started at all" do
1902 1910 assert Issue.new(:start_date => 1.day.ago.to_date,
1903 1911 :due_date => 1.day.from_now.to_date,
1904 1912 :done_ratio => 0).behind_schedule?
1905 1913 end
1906 1914
1907 1915 test "#behind_schedule? should be true if the issue has used more calendar time than it's done ratio" do
1908 1916 assert Issue.new(:start_date => 100.days.ago.to_date,
1909 1917 :due_date => Date.today,
1910 1918 :done_ratio => 90).behind_schedule?
1911 1919 end
1912 1920
1913 1921 test "#assignable_users should be Users" do
1914 1922 assert_kind_of User, Issue.find(1).assignable_users.first
1915 1923 end
1916 1924
1917 1925 test "#assignable_users should include the issue author" do
1918 1926 non_project_member = User.generate!
1919 1927 issue = Issue.generate!(:author => non_project_member)
1920 1928
1921 1929 assert issue.assignable_users.include?(non_project_member)
1922 1930 end
1923 1931
1924 1932 test "#assignable_users should include the current assignee" do
1925 1933 user = User.generate!
1926 1934 issue = Issue.generate!(:assigned_to => user)
1927 1935 user.lock!
1928 1936
1929 1937 assert Issue.find(issue.id).assignable_users.include?(user)
1930 1938 end
1931 1939
1932 1940 test "#assignable_users should not show the issue author twice" do
1933 1941 assignable_user_ids = Issue.find(1).assignable_users.collect(&:id)
1934 1942 assert_equal 2, assignable_user_ids.length
1935 1943
1936 1944 assignable_user_ids.each do |user_id|
1937 1945 assert_equal 1, assignable_user_ids.select {|i| i == user_id}.length,
1938 1946 "User #{user_id} appears more or less than once"
1939 1947 end
1940 1948 end
1941 1949
1942 1950 test "#assignable_users with issue_group_assignment should include groups" do
1943 1951 issue = Issue.new(:project => Project.find(2))
1944 1952
1945 1953 with_settings :issue_group_assignment => '1' do
1946 1954 assert_equal %w(Group User), issue.assignable_users.map {|a| a.class.name}.uniq.sort
1947 1955 assert issue.assignable_users.include?(Group.find(11))
1948 1956 end
1949 1957 end
1950 1958
1951 1959 test "#assignable_users without issue_group_assignment should not include groups" do
1952 1960 issue = Issue.new(:project => Project.find(2))
1953 1961
1954 1962 with_settings :issue_group_assignment => '0' do
1955 1963 assert_equal %w(User), issue.assignable_users.map {|a| a.class.name}.uniq.sort
1956 1964 assert !issue.assignable_users.include?(Group.find(11))
1957 1965 end
1958 1966 end
1959 1967
1960 1968 def test_assignable_users_should_not_include_builtin_groups
1961 1969 Member.create!(:project_id => 1, :principal => Group.non_member, :role_ids => [1])
1962 1970 Member.create!(:project_id => 1, :principal => Group.anonymous, :role_ids => [1])
1963 1971 issue = Issue.new(:project => Project.find(1))
1964 1972
1965 1973 with_settings :issue_group_assignment => '1' do
1966 1974 assert_nil issue.assignable_users.detect {|u| u.is_a?(GroupBuiltin)}
1967 1975 end
1968 1976 end
1969 1977
1970 1978 def test_create_should_send_email_notification
1971 1979 ActionMailer::Base.deliveries.clear
1972 1980 issue = Issue.new(:project_id => 1, :tracker_id => 1,
1973 1981 :author_id => 3, :status_id => 1,
1974 1982 :priority => IssuePriority.all.first,
1975 1983 :subject => 'test_create', :estimated_hours => '1:30')
1976 1984 with_settings :notified_events => %w(issue_added) do
1977 1985 assert issue.save
1978 1986 assert_equal 1, ActionMailer::Base.deliveries.size
1979 1987 end
1980 1988 end
1981 1989
1982 1990 def test_create_should_send_one_email_notification_with_both_settings
1983 1991 ActionMailer::Base.deliveries.clear
1984 1992 issue = Issue.new(:project_id => 1, :tracker_id => 1,
1985 1993 :author_id => 3, :status_id => 1,
1986 1994 :priority => IssuePriority.all.first,
1987 1995 :subject => 'test_create', :estimated_hours => '1:30')
1988 1996 with_settings :notified_events => %w(issue_added issue_updated) do
1989 1997 assert issue.save
1990 1998 assert_equal 1, ActionMailer::Base.deliveries.size
1991 1999 end
1992 2000 end
1993 2001
1994 2002 def test_create_should_not_send_email_notification_with_no_setting
1995 2003 ActionMailer::Base.deliveries.clear
1996 2004 issue = Issue.new(:project_id => 1, :tracker_id => 1,
1997 2005 :author_id => 3, :status_id => 1,
1998 2006 :priority => IssuePriority.all.first,
1999 2007 :subject => 'test_create', :estimated_hours => '1:30')
2000 2008 with_settings :notified_events => [] do
2001 2009 assert issue.save
2002 2010 assert_equal 0, ActionMailer::Base.deliveries.size
2003 2011 end
2004 2012 end
2005 2013
2006 2014 def test_update_should_notify_previous_assignee
2007 2015 ActionMailer::Base.deliveries.clear
2008 2016 user = User.find(3)
2009 2017 user.members.update_all ["mail_notification = ?", false]
2010 2018 user.update_attribute :mail_notification, 'only_assigned'
2011 2019
2012 2020 with_settings :notified_events => %w(issue_updated) do
2013 2021 issue = Issue.find(2)
2014 2022 issue.init_journal User.find(1)
2015 2023 issue.assigned_to = nil
2016 2024 issue.save!
2017 2025 assert_include user.mail, ActionMailer::Base.deliveries.last.bcc
2018 2026 end
2019 2027 end
2020 2028
2021 2029 def test_stale_issue_should_not_send_email_notification
2022 2030 ActionMailer::Base.deliveries.clear
2023 2031 issue = Issue.find(1)
2024 2032 stale = Issue.find(1)
2025 2033
2026 2034 issue.init_journal(User.find(1))
2027 2035 issue.subject = 'Subjet update'
2028 2036 with_settings :notified_events => %w(issue_updated) do
2029 2037 assert issue.save
2030 2038 assert_equal 1, ActionMailer::Base.deliveries.size
2031 2039 ActionMailer::Base.deliveries.clear
2032 2040
2033 2041 stale.init_journal(User.find(1))
2034 2042 stale.subject = 'Another subjet update'
2035 2043 assert_raise ActiveRecord::StaleObjectError do
2036 2044 stale.save
2037 2045 end
2038 2046 assert ActionMailer::Base.deliveries.empty?
2039 2047 end
2040 2048 end
2041 2049
2042 2050 def test_journalized_description
2043 2051 IssueCustomField.delete_all
2044 2052
2045 2053 i = Issue.first
2046 2054 old_description = i.description
2047 2055 new_description = "This is the new description"
2048 2056
2049 2057 i.init_journal(User.find(2))
2050 2058 i.description = new_description
2051 2059 assert_difference 'Journal.count', 1 do
2052 2060 assert_difference 'JournalDetail.count', 1 do
2053 2061 i.save!
2054 2062 end
2055 2063 end
2056 2064
2057 2065 detail = JournalDetail.order('id DESC').first
2058 2066 assert_equal i, detail.journal.journalized
2059 2067 assert_equal 'attr', detail.property
2060 2068 assert_equal 'description', detail.prop_key
2061 2069 assert_equal old_description, detail.old_value
2062 2070 assert_equal new_description, detail.value
2063 2071 end
2064 2072
2065 2073 def test_blank_descriptions_should_not_be_journalized
2066 2074 IssueCustomField.delete_all
2067 2075 Issue.where(:id => 1).update_all("description = NULL")
2068 2076
2069 2077 i = Issue.find(1)
2070 2078 i.init_journal(User.find(2))
2071 2079 i.subject = "blank description"
2072 2080 i.description = "\r\n"
2073 2081
2074 2082 assert_difference 'Journal.count', 1 do
2075 2083 assert_difference 'JournalDetail.count', 1 do
2076 2084 i.save!
2077 2085 end
2078 2086 end
2079 2087 end
2080 2088
2081 2089 def test_journalized_multi_custom_field
2082 2090 field = IssueCustomField.create!(:name => 'filter', :field_format => 'list',
2083 2091 :is_filter => true, :is_for_all => true,
2084 2092 :tracker_ids => [1],
2085 2093 :possible_values => ['value1', 'value2', 'value3'],
2086 2094 :multiple => true)
2087 2095
2088 2096 issue = Issue.create!(:project_id => 1, :tracker_id => 1,
2089 2097 :subject => 'Test', :author_id => 1)
2090 2098
2091 2099 assert_difference 'Journal.count' do
2092 2100 assert_difference 'JournalDetail.count' do
2093 2101 issue.init_journal(User.first)
2094 2102 issue.custom_field_values = {field.id => ['value1']}
2095 2103 issue.save!
2096 2104 end
2097 2105 assert_difference 'JournalDetail.count' do
2098 2106 issue.init_journal(User.first)
2099 2107 issue.custom_field_values = {field.id => ['value1', 'value2']}
2100 2108 issue.save!
2101 2109 end
2102 2110 assert_difference 'JournalDetail.count', 2 do
2103 2111 issue.init_journal(User.first)
2104 2112 issue.custom_field_values = {field.id => ['value3', 'value2']}
2105 2113 issue.save!
2106 2114 end
2107 2115 assert_difference 'JournalDetail.count', 2 do
2108 2116 issue.init_journal(User.first)
2109 2117 issue.custom_field_values = {field.id => nil}
2110 2118 issue.save!
2111 2119 end
2112 2120 end
2113 2121 end
2114 2122
2115 2123 def test_description_eol_should_be_normalized
2116 2124 i = Issue.new(:description => "CR \r LF \n CRLF \r\n")
2117 2125 assert_equal "CR \r\n LF \r\n CRLF \r\n", i.description
2118 2126 end
2119 2127
2120 2128 def test_saving_twice_should_not_duplicate_journal_details
2121 2129 i = Issue.first
2122 2130 i.init_journal(User.find(2), 'Some notes')
2123 2131 # initial changes
2124 2132 i.subject = 'New subject'
2125 2133 i.done_ratio = i.done_ratio + 10
2126 2134 assert_difference 'Journal.count' do
2127 2135 assert i.save
2128 2136 end
2129 2137 # 1 more change
2130 2138 i.priority = IssuePriority.where("id <> ?", i.priority_id).first
2131 2139 assert_no_difference 'Journal.count' do
2132 2140 assert_difference 'JournalDetail.count', 1 do
2133 2141 i.save
2134 2142 end
2135 2143 end
2136 2144 # no more change
2137 2145 assert_no_difference 'Journal.count' do
2138 2146 assert_no_difference 'JournalDetail.count' do
2139 2147 i.save
2140 2148 end
2141 2149 end
2142 2150 end
2143 2151
2144 2152 def test_all_dependent_issues
2145 2153 IssueRelation.delete_all
2146 2154 assert IssueRelation.create!(:issue_from => Issue.find(1),
2147 2155 :issue_to => Issue.find(2),
2148 2156 :relation_type => IssueRelation::TYPE_PRECEDES)
2149 2157 assert IssueRelation.create!(:issue_from => Issue.find(2),
2150 2158 :issue_to => Issue.find(3),
2151 2159 :relation_type => IssueRelation::TYPE_PRECEDES)
2152 2160 assert IssueRelation.create!(:issue_from => Issue.find(3),
2153 2161 :issue_to => Issue.find(8),
2154 2162 :relation_type => IssueRelation::TYPE_PRECEDES)
2155 2163
2156 2164 assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort
2157 2165 end
2158 2166
2159 2167 def test_all_dependent_issues_with_subtask
2160 2168 IssueRelation.delete_all
2161 2169
2162 2170 project = Project.generate!(:name => "testproject")
2163 2171
2164 2172 parentIssue = Issue.generate!(:project => project)
2165 2173 childIssue1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue.id)
2166 2174 childIssue2 = Issue.generate!(:project => project, :parent_issue_id => parentIssue.id)
2167 2175
2168 2176 assert_equal [childIssue1.id, childIssue2.id].sort, parentIssue.all_dependent_issues.collect(&:id).uniq.sort
2169 2177 end
2170 2178
2171 2179 def test_all_dependent_issues_does_not_include_self
2172 2180 IssueRelation.delete_all
2173 2181
2174 2182 project = Project.generate!(:name => "testproject")
2175 2183
2176 2184 parentIssue = Issue.generate!(:project => project)
2177 2185 childIssue = Issue.generate!(:project => project, :parent_issue_id => parentIssue.id)
2178 2186
2179 2187 assert_equal [childIssue.id], parentIssue.all_dependent_issues.collect(&:id)
2180 2188 end
2181 2189
2182 2190 def test_all_dependent_issues_with_parenttask_and_sibling
2183 2191 IssueRelation.delete_all
2184 2192
2185 2193 project = Project.generate!(:name => "testproject")
2186 2194
2187 2195 parentIssue = Issue.generate!(:project => project)
2188 2196 childIssue1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue.id)
2189 2197 childIssue2 = Issue.generate!(:project => project, :parent_issue_id => parentIssue.id)
2190 2198
2191 2199 assert_equal [parentIssue.id].sort, childIssue1.all_dependent_issues.collect(&:id)
2192 2200 end
2193 2201
2194 2202 def test_all_dependent_issues_with_relation_to_leaf_in_other_tree
2195 2203 IssueRelation.delete_all
2196 2204
2197 2205 project = Project.generate!(:name => "testproject")
2198 2206
2199 2207 parentIssue1 = Issue.generate!(:project => project)
2200 2208 childIssue1_1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue1.id)
2201 2209 childIssue1_2 = Issue.generate!(:project => project, :parent_issue_id => parentIssue1.id)
2202 2210
2203 2211 parentIssue2 = Issue.generate!(:project => project)
2204 2212 childIssue2_1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue2.id)
2205 2213 childIssue2_2 = Issue.generate!(:project => project, :parent_issue_id => parentIssue2.id)
2206 2214
2207 2215
2208 2216 assert IssueRelation.create(:issue_from => parentIssue1,
2209 2217 :issue_to => childIssue2_2,
2210 2218 :relation_type => IssueRelation::TYPE_BLOCKS)
2211 2219
2212 2220 assert_equal [childIssue1_1.id, childIssue1_2.id, parentIssue2.id, childIssue2_2.id].sort,
2213 2221 parentIssue1.all_dependent_issues.collect(&:id).uniq.sort
2214 2222 end
2215 2223
2216 2224 def test_all_dependent_issues_with_relation_to_parent_in_other_tree
2217 2225 IssueRelation.delete_all
2218 2226
2219 2227 project = Project.generate!(:name => "testproject")
2220 2228
2221 2229 parentIssue1 = Issue.generate!(:project => project)
2222 2230 childIssue1_1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue1.id)
2223 2231 childIssue1_2 = Issue.generate!(:project => project, :parent_issue_id => parentIssue1.id)
2224 2232
2225 2233 parentIssue2 = Issue.generate!(:project => project)
2226 2234 childIssue2_1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue2.id)
2227 2235 childIssue2_2 = Issue.generate!(:project => project, :parent_issue_id => parentIssue2.id)
2228 2236
2229 2237
2230 2238 assert IssueRelation.create(:issue_from => parentIssue1,
2231 2239 :issue_to => parentIssue2,
2232 2240 :relation_type => IssueRelation::TYPE_BLOCKS)
2233 2241
2234 2242 assert_equal [childIssue1_1.id, childIssue1_2.id, parentIssue2.id, childIssue2_1.id, childIssue2_2.id].sort,
2235 2243 parentIssue1.all_dependent_issues.collect(&:id).uniq.sort
2236 2244 end
2237 2245
2238 2246 def test_all_dependent_issues_with_transitive_relation
2239 2247 IssueRelation.delete_all
2240 2248
2241 2249 project = Project.generate!(:name => "testproject")
2242 2250
2243 2251 parentIssue1 = Issue.generate!(:project => project)
2244 2252 childIssue1_1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue1.id)
2245 2253
2246 2254 parentIssue2 = Issue.generate!(:project => project)
2247 2255 childIssue2_1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue2.id)
2248 2256
2249 2257 independentIssue = Issue.generate!(:project => project)
2250 2258
2251 2259 assert IssueRelation.create(:issue_from => parentIssue1,
2252 2260 :issue_to => childIssue2_1,
2253 2261 :relation_type => IssueRelation::TYPE_RELATES)
2254 2262
2255 2263 assert IssueRelation.create(:issue_from => childIssue2_1,
2256 2264 :issue_to => independentIssue,
2257 2265 :relation_type => IssueRelation::TYPE_RELATES)
2258 2266
2259 2267 assert_equal [childIssue1_1.id, parentIssue2.id, childIssue2_1.id, independentIssue.id].sort,
2260 2268 parentIssue1.all_dependent_issues.collect(&:id).uniq.sort
2261 2269 end
2262 2270
2263 2271 def test_all_dependent_issues_with_transitive_relation2
2264 2272 IssueRelation.delete_all
2265 2273
2266 2274 project = Project.generate!(:name => "testproject")
2267 2275
2268 2276 parentIssue1 = Issue.generate!(:project => project)
2269 2277 childIssue1_1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue1.id)
2270 2278
2271 2279 parentIssue2 = Issue.generate!(:project => project)
2272 2280 childIssue2_1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue2.id)
2273 2281
2274 2282 independentIssue = Issue.generate!(:project => project)
2275 2283
2276 2284 assert IssueRelation.create(:issue_from => parentIssue1,
2277 2285 :issue_to => independentIssue,
2278 2286 :relation_type => IssueRelation::TYPE_RELATES)
2279 2287
2280 2288 assert IssueRelation.create(:issue_from => independentIssue,
2281 2289 :issue_to => childIssue2_1,
2282 2290 :relation_type => IssueRelation::TYPE_RELATES)
2283 2291
2284 2292 assert_equal [childIssue1_1.id, parentIssue2.id, childIssue2_1.id, independentIssue.id].sort,
2285 2293 parentIssue1.all_dependent_issues.collect(&:id).uniq.sort
2286 2294
2287 2295 end
2288 2296
2289 2297 def test_all_dependent_issues_with_persistent_circular_dependency
2290 2298 IssueRelation.delete_all
2291 2299 assert IssueRelation.create!(:issue_from => Issue.find(1),
2292 2300 :issue_to => Issue.find(2),
2293 2301 :relation_type => IssueRelation::TYPE_PRECEDES)
2294 2302 assert IssueRelation.create!(:issue_from => Issue.find(2),
2295 2303 :issue_to => Issue.find(3),
2296 2304 :relation_type => IssueRelation::TYPE_PRECEDES)
2297 2305
2298 2306 r = IssueRelation.create!(:issue_from => Issue.find(3),
2299 2307 :issue_to => Issue.find(7),
2300 2308 :relation_type => IssueRelation::TYPE_PRECEDES)
2301 2309 IssueRelation.where(["id = ?", r.id]).update_all("issue_to_id = 1")
2302 2310
2303 2311 assert_equal [2, 3], Issue.find(1).all_dependent_issues.collect(&:id).sort
2304 2312 end
2305 2313
2306 2314 def test_all_dependent_issues_with_persistent_multiple_circular_dependencies
2307 2315 IssueRelation.delete_all
2308 2316 assert IssueRelation.create!(:issue_from => Issue.find(1),
2309 2317 :issue_to => Issue.find(2),
2310 2318 :relation_type => IssueRelation::TYPE_RELATES)
2311 2319 assert IssueRelation.create!(:issue_from => Issue.find(2),
2312 2320 :issue_to => Issue.find(3),
2313 2321 :relation_type => IssueRelation::TYPE_RELATES)
2314 2322 assert IssueRelation.create!(:issue_from => Issue.find(3),
2315 2323 :issue_to => Issue.find(8),
2316 2324 :relation_type => IssueRelation::TYPE_RELATES)
2317 2325
2318 2326 r = IssueRelation.create!(:issue_from => Issue.find(8),
2319 2327 :issue_to => Issue.find(7),
2320 2328 :relation_type => IssueRelation::TYPE_RELATES)
2321 2329 IssueRelation.where(["id = ?", r.id]).update_all("issue_to_id = 2")
2322 2330
2323 2331 r = IssueRelation.create!(:issue_from => Issue.find(3),
2324 2332 :issue_to => Issue.find(7),
2325 2333 :relation_type => IssueRelation::TYPE_RELATES)
2326 2334 IssueRelation.where(["id = ?", r.id]).update_all("issue_to_id = 1")
2327 2335
2328 2336 assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort
2329 2337 end
2330 2338
2331 2339 test "#done_ratio should use the issue_status according to Setting.issue_done_ratio" do
2332 2340 @issue = Issue.find(1)
2333 2341 @issue_status = IssueStatus.find(1)
2334 2342 @issue_status.update_attribute(:default_done_ratio, 50)
2335 2343 @issue2 = Issue.find(2)
2336 2344 @issue_status2 = IssueStatus.find(2)
2337 2345 @issue_status2.update_attribute(:default_done_ratio, 0)
2338 2346
2339 2347 with_settings :issue_done_ratio => 'issue_field' do
2340 2348 assert_equal 0, @issue.done_ratio
2341 2349 assert_equal 30, @issue2.done_ratio
2342 2350 end
2343 2351
2344 2352 with_settings :issue_done_ratio => 'issue_status' do
2345 2353 assert_equal 50, @issue.done_ratio
2346 2354 assert_equal 0, @issue2.done_ratio
2347 2355 end
2348 2356 end
2349 2357
2350 2358 test "#update_done_ratio_from_issue_status should update done_ratio according to Setting.issue_done_ratio" do
2351 2359 @issue = Issue.find(1)
2352 2360 @issue_status = IssueStatus.find(1)
2353 2361 @issue_status.update_attribute(:default_done_ratio, 50)
2354 2362 @issue2 = Issue.find(2)
2355 2363 @issue_status2 = IssueStatus.find(2)
2356 2364 @issue_status2.update_attribute(:default_done_ratio, 0)
2357 2365
2358 2366 with_settings :issue_done_ratio => 'issue_field' do
2359 2367 @issue.update_done_ratio_from_issue_status
2360 2368 @issue2.update_done_ratio_from_issue_status
2361 2369
2362 2370 assert_equal 0, @issue.read_attribute(:done_ratio)
2363 2371 assert_equal 30, @issue2.read_attribute(:done_ratio)
2364 2372 end
2365 2373
2366 2374 with_settings :issue_done_ratio => 'issue_status' do
2367 2375 @issue.update_done_ratio_from_issue_status
2368 2376 @issue2.update_done_ratio_from_issue_status
2369 2377
2370 2378 assert_equal 50, @issue.read_attribute(:done_ratio)
2371 2379 assert_equal 0, @issue2.read_attribute(:done_ratio)
2372 2380 end
2373 2381 end
2374 2382
2375 2383 test "#by_tracker" do
2376 2384 User.current = User.anonymous
2377 2385 groups = Issue.by_tracker(Project.find(1))
2378 2386 assert_equal 3, groups.count
2379 2387 assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i}
2380 2388 end
2381 2389
2382 2390 test "#by_version" do
2383 2391 User.current = User.anonymous
2384 2392 groups = Issue.by_version(Project.find(1))
2385 2393 assert_equal 3, groups.count
2386 2394 assert_equal 3, groups.inject(0) {|sum, group| sum + group['total'].to_i}
2387 2395 end
2388 2396
2389 2397 test "#by_priority" do
2390 2398 User.current = User.anonymous
2391 2399 groups = Issue.by_priority(Project.find(1))
2392 2400 assert_equal 4, groups.count
2393 2401 assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i}
2394 2402 end
2395 2403
2396 2404 test "#by_category" do
2397 2405 User.current = User.anonymous
2398 2406 groups = Issue.by_category(Project.find(1))
2399 2407 assert_equal 2, groups.count
2400 2408 assert_equal 3, groups.inject(0) {|sum, group| sum + group['total'].to_i}
2401 2409 end
2402 2410
2403 2411 test "#by_assigned_to" do
2404 2412 User.current = User.anonymous
2405 2413 groups = Issue.by_assigned_to(Project.find(1))
2406 2414 assert_equal 2, groups.count
2407 2415 assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i}
2408 2416 end
2409 2417
2410 2418 test "#by_author" do
2411 2419 User.current = User.anonymous
2412 2420 groups = Issue.by_author(Project.find(1))
2413 2421 assert_equal 4, groups.count
2414 2422 assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i}
2415 2423 end
2416 2424
2417 2425 test "#by_subproject" do
2418 2426 User.current = User.anonymous
2419 2427 groups = Issue.by_subproject(Project.find(1))
2420 2428 # Private descendant not visible
2421 2429 assert_equal 1, groups.count
2422 2430 assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i}
2423 2431 end
2424 2432
2425 2433 def test_recently_updated_scope
2426 2434 #should return the last updated issue
2427 2435 assert_equal Issue.reorder("updated_on DESC").first, Issue.recently_updated.limit(1).first
2428 2436 end
2429 2437
2430 2438 def test_on_active_projects_scope
2431 2439 assert Project.find(2).archive
2432 2440
2433 2441 before = Issue.on_active_project.length
2434 2442 # test inclusion to results
2435 2443 issue = Issue.generate!(:tracker => Project.find(2).trackers.first)
2436 2444 assert_equal before + 1, Issue.on_active_project.length
2437 2445
2438 2446 # Move to an archived project
2439 2447 issue.project = Project.find(2)
2440 2448 assert issue.save
2441 2449 assert_equal before, Issue.on_active_project.length
2442 2450 end
2443 2451
2444 2452 test "Issue#recipients should include project recipients" do
2445 2453 issue = Issue.generate!
2446 2454 assert issue.project.recipients.present?
2447 2455 issue.project.recipients.each do |project_recipient|
2448 2456 assert issue.recipients.include?(project_recipient)
2449 2457 end
2450 2458 end
2451 2459
2452 2460 test "Issue#recipients should include the author if the author is active" do
2453 2461 issue = Issue.generate!(:author => User.generate!)
2454 2462 assert issue.author, "No author set for Issue"
2455 2463 assert issue.recipients.include?(issue.author.mail)
2456 2464 end
2457 2465
2458 2466 test "Issue#recipients should include the assigned to user if the assigned to user is active" do
2459 2467 issue = Issue.generate!(:assigned_to => User.generate!)
2460 2468 assert issue.assigned_to, "No assigned_to set for Issue"
2461 2469 assert issue.recipients.include?(issue.assigned_to.mail)
2462 2470 end
2463 2471
2464 2472 test "Issue#recipients should not include users who opt out of all email" do
2465 2473 issue = Issue.generate!(:author => User.generate!)
2466 2474 issue.author.update_attribute(:mail_notification, :none)
2467 2475 assert !issue.recipients.include?(issue.author.mail)
2468 2476 end
2469 2477
2470 2478 test "Issue#recipients should not include the issue author if they are only notified of assigned issues" do
2471 2479 issue = Issue.generate!(:author => User.generate!)
2472 2480 issue.author.update_attribute(:mail_notification, :only_assigned)
2473 2481 assert !issue.recipients.include?(issue.author.mail)
2474 2482 end
2475 2483
2476 2484 test "Issue#recipients should not include the assigned user if they are only notified of owned issues" do
2477 2485 issue = Issue.generate!(:assigned_to => User.generate!)
2478 2486 issue.assigned_to.update_attribute(:mail_notification, :only_owner)
2479 2487 assert !issue.recipients.include?(issue.assigned_to.mail)
2480 2488 end
2481 2489
2482 2490 def test_last_journal_id_with_journals_should_return_the_journal_id
2483 2491 assert_equal 2, Issue.find(1).last_journal_id
2484 2492 end
2485 2493
2486 2494 def test_last_journal_id_without_journals_should_return_nil
2487 2495 assert_nil Issue.find(3).last_journal_id
2488 2496 end
2489 2497
2490 2498 def test_journals_after_should_return_journals_with_greater_id
2491 2499 assert_equal [Journal.find(2)], Issue.find(1).journals_after('1')
2492 2500 assert_equal [], Issue.find(1).journals_after('2')
2493 2501 end
2494 2502
2495 2503 def test_journals_after_with_blank_arg_should_return_all_journals
2496 2504 assert_equal [Journal.find(1), Journal.find(2)], Issue.find(1).journals_after('')
2497 2505 end
2498 2506
2499 2507 def test_css_classes_should_include_tracker
2500 2508 issue = Issue.new(:tracker => Tracker.find(2))
2501 2509 classes = issue.css_classes.split(' ')
2502 2510 assert_include 'tracker-2', classes
2503 2511 end
2504 2512
2505 2513 def test_css_classes_should_include_priority
2506 2514 issue = Issue.new(:priority => IssuePriority.find(8))
2507 2515 classes = issue.css_classes.split(' ')
2508 2516 assert_include 'priority-8', classes
2509 2517 assert_include 'priority-highest', classes
2510 2518 end
2511 2519
2512 2520 def test_css_classes_should_include_user_and_group_assignment
2513 2521 project = Project.first
2514 2522 user = User.generate!
2515 2523 group = Group.generate!
2516 2524 Member.create!(:principal => group, :project => project, :role_ids => [1, 2])
2517 2525 group.users << user
2518 2526 assert user.member_of?(project)
2519 2527 issue1 = Issue.generate(:assigned_to_id => group.id)
2520 2528 assert_include 'assigned-to-my-group', issue1.css_classes(user)
2521 2529 assert_not_include 'assigned-to-me', issue1.css_classes(user)
2522 2530 issue2 = Issue.generate(:assigned_to_id => user.id)
2523 2531 assert_not_include 'assigned-to-my-group', issue2.css_classes(user)
2524 2532 assert_include 'assigned-to-me', issue2.css_classes(user)
2525 2533 end
2526 2534
2527 2535 def test_save_attachments_with_hash_should_save_attachments_in_keys_order
2528 2536 set_tmp_attachments_directory
2529 2537 issue = Issue.generate!
2530 2538 issue.save_attachments({
2531 2539 'p0' => {'file' => mock_file_with_options(:original_filename => 'upload')},
2532 2540 '3' => {'file' => mock_file_with_options(:original_filename => 'bar')},
2533 2541 '1' => {'file' => mock_file_with_options(:original_filename => 'foo')}
2534 2542 })
2535 2543 issue.attach_saved_attachments
2536 2544
2537 2545 assert_equal 3, issue.reload.attachments.count
2538 2546 assert_equal %w(upload foo bar), issue.attachments.map(&:filename)
2539 2547 end
2540 2548
2541 2549 def test_closed_on_should_be_nil_when_creating_an_open_issue
2542 2550 issue = Issue.generate!(:status_id => 1).reload
2543 2551 assert !issue.closed?
2544 2552 assert_nil issue.closed_on
2545 2553 end
2546 2554
2547 2555 def test_closed_on_should_be_set_when_creating_a_closed_issue
2548 2556 issue = Issue.generate!(:status_id => 5).reload
2549 2557 assert issue.closed?
2550 2558 assert_not_nil issue.closed_on
2551 2559 assert_equal issue.updated_on, issue.closed_on
2552 2560 assert_equal issue.created_on, issue.closed_on
2553 2561 end
2554 2562
2555 2563 def test_closed_on_should_be_nil_when_updating_an_open_issue
2556 2564 issue = Issue.find(1)
2557 2565 issue.subject = 'Not closed yet'
2558 2566 issue.save!
2559 2567 issue.reload
2560 2568 assert_nil issue.closed_on
2561 2569 end
2562 2570
2563 2571 def test_closed_on_should_be_set_when_closing_an_open_issue
2564 2572 issue = Issue.find(1)
2565 2573 issue.subject = 'Now closed'
2566 2574 issue.status_id = 5
2567 2575 issue.save!
2568 2576 issue.reload
2569 2577 assert_not_nil issue.closed_on
2570 2578 assert_equal issue.updated_on, issue.closed_on
2571 2579 end
2572 2580
2573 2581 def test_closed_on_should_not_be_updated_when_updating_a_closed_issue
2574 2582 issue = Issue.open(false).first
2575 2583 was_closed_on = issue.closed_on
2576 2584 assert_not_nil was_closed_on
2577 2585 issue.subject = 'Updating a closed issue'
2578 2586 issue.save!
2579 2587 issue.reload
2580 2588 assert_equal was_closed_on, issue.closed_on
2581 2589 end
2582 2590
2583 2591 def test_closed_on_should_be_preserved_when_reopening_a_closed_issue
2584 2592 issue = Issue.open(false).first
2585 2593 was_closed_on = issue.closed_on
2586 2594 assert_not_nil was_closed_on
2587 2595 issue.subject = 'Reopening a closed issue'
2588 2596 issue.status_id = 1
2589 2597 issue.save!
2590 2598 issue.reload
2591 2599 assert !issue.closed?
2592 2600 assert_equal was_closed_on, issue.closed_on
2593 2601 end
2594 2602
2595 2603 def test_status_was_should_return_nil_for_new_issue
2596 2604 issue = Issue.new
2597 2605 assert_nil issue.status_was
2598 2606 end
2599 2607
2600 2608 def test_status_was_should_return_status_before_change
2601 2609 issue = Issue.find(1)
2602 2610 issue.status = IssueStatus.find(2)
2603 2611 assert_equal IssueStatus.find(1), issue.status_was
2604 2612 end
2605 2613
2606 2614 def test_status_was_should_return_status_before_change_with_status_id
2607 2615 issue = Issue.find(1)
2608 2616 assert_equal IssueStatus.find(1), issue.status
2609 2617 issue.status_id = 2
2610 2618 assert_equal IssueStatus.find(1), issue.status_was
2611 2619 end
2612 2620
2613 2621 def test_status_was_should_be_reset_on_save
2614 2622 issue = Issue.find(1)
2615 2623 issue.status = IssueStatus.find(2)
2616 2624 assert_equal IssueStatus.find(1), issue.status_was
2617 2625 assert issue.save!
2618 2626 assert_equal IssueStatus.find(2), issue.status_was
2619 2627 end
2620 2628
2621 2629 def test_closing_should_return_true_when_closing_an_issue
2622 2630 issue = Issue.find(1)
2623 2631 issue.status = IssueStatus.find(2)
2624 2632 assert_equal false, issue.closing?
2625 2633 issue.status = IssueStatus.find(5)
2626 2634 assert_equal true, issue.closing?
2627 2635 end
2628 2636
2629 2637 def test_closing_should_return_true_when_closing_an_issue_with_status_id
2630 2638 issue = Issue.find(1)
2631 2639 issue.status_id = 2
2632 2640 assert_equal false, issue.closing?
2633 2641 issue.status_id = 5
2634 2642 assert_equal true, issue.closing?
2635 2643 end
2636 2644
2637 2645 def test_closing_should_return_true_for_new_closed_issue
2638 2646 issue = Issue.new
2639 2647 assert_equal false, issue.closing?
2640 2648 issue.status = IssueStatus.find(5)
2641 2649 assert_equal true, issue.closing?
2642 2650 end
2643 2651
2644 2652 def test_closing_should_return_true_for_new_closed_issue_with_status_id
2645 2653 issue = Issue.new
2646 2654 assert_equal false, issue.closing?
2647 2655 issue.status_id = 5
2648 2656 assert_equal true, issue.closing?
2649 2657 end
2650 2658
2651 2659 def test_closing_should_be_reset_after_save
2652 2660 issue = Issue.find(1)
2653 2661 issue.status_id = 5
2654 2662 assert_equal true, issue.closing?
2655 2663 issue.save!
2656 2664 assert_equal false, issue.closing?
2657 2665 end
2658 2666
2659 2667 def test_reopening_should_return_true_when_reopening_an_issue
2660 2668 issue = Issue.find(8)
2661 2669 issue.status = IssueStatus.find(6)
2662 2670 assert_equal false, issue.reopening?
2663 2671 issue.status = IssueStatus.find(2)
2664 2672 assert_equal true, issue.reopening?
2665 2673 end
2666 2674
2667 2675 def test_reopening_should_return_true_when_reopening_an_issue_with_status_id
2668 2676 issue = Issue.find(8)
2669 2677 issue.status_id = 6
2670 2678 assert_equal false, issue.reopening?
2671 2679 issue.status_id = 2
2672 2680 assert_equal true, issue.reopening?
2673 2681 end
2674 2682
2675 2683 def test_reopening_should_return_false_for_new_open_issue
2676 2684 issue = Issue.new
2677 2685 issue.status = IssueStatus.find(1)
2678 2686 assert_equal false, issue.reopening?
2679 2687 end
2680 2688
2681 2689 def test_reopening_should_be_reset_after_save
2682 2690 issue = Issue.find(8)
2683 2691 issue.status_id = 2
2684 2692 assert_equal true, issue.reopening?
2685 2693 issue.save!
2686 2694 assert_equal false, issue.reopening?
2687 2695 end
2688 2696
2689 2697 def test_default_status_without_tracker_should_be_nil
2690 2698 issue = Issue.new
2691 2699 assert_nil issue.tracker
2692 2700 assert_nil issue.default_status
2693 2701 end
2694 2702
2695 2703 def test_default_status_should_be_tracker_default_status
2696 2704 issue = Issue.new(:tracker_id => 1)
2697 2705 assert_not_nil issue.status
2698 2706 assert_equal issue.tracker.default_status, issue.default_status
2699 2707 end
2700 2708
2701 2709 def test_initializing_with_tracker_should_set_default_status
2702 2710 issue = Issue.new(:tracker => Tracker.find(1))
2703 2711 assert_not_nil issue.status
2704 2712 assert_equal issue.default_status, issue.status
2705 2713 end
2706 2714
2707 2715 def test_initializing_with_tracker_id_should_set_default_status
2708 2716 issue = Issue.new(:tracker_id => 1)
2709 2717 assert_not_nil issue.status
2710 2718 assert_equal issue.default_status, issue.status
2711 2719 end
2712 2720
2713 2721 def test_setting_tracker_should_set_default_status
2714 2722 issue = Issue.new
2715 2723 issue.tracker = Tracker.find(1)
2716 2724 assert_not_nil issue.status
2717 2725 assert_equal issue.default_status, issue.status
2718 2726 end
2719 2727
2720 2728 def test_changing_tracker_should_set_default_status_if_status_was_default
2721 2729 WorkflowTransition.delete_all
2722 2730 WorkflowTransition.create! :role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1
2723 2731 Tracker.find(2).update! :default_status_id => 2
2724 2732
2725 2733 issue = Issue.new(:tracker_id => 1, :status_id => 1)
2726 2734 assert_equal IssueStatus.find(1), issue.status
2727 2735 issue.tracker = Tracker.find(2)
2728 2736 assert_equal IssueStatus.find(2), issue.status
2729 2737 end
2730 2738
2731 2739 def test_changing_tracker_should_set_default_status_if_status_is_not_used_by_tracker
2732 2740 WorkflowTransition.delete_all
2733 2741 Tracker.find(2).update! :default_status_id => 2
2734 2742
2735 2743 issue = Issue.new(:tracker_id => 1, :status_id => 3)
2736 2744 assert_equal IssueStatus.find(3), issue.status
2737 2745 issue.tracker = Tracker.find(2)
2738 2746 assert_equal IssueStatus.find(2), issue.status
2739 2747 end
2740 2748
2741 2749 def test_changing_tracker_should_keep_status_if_status_was_not_default_and_is_used_by_tracker
2742 2750 WorkflowTransition.delete_all
2743 2751 WorkflowTransition.create! :role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3
2744 2752 Tracker.find(2).update! :default_status_id => 2
2745 2753
2746 2754 issue = Issue.new(:tracker_id => 1, :status_id => 3)
2747 2755 assert_equal IssueStatus.find(3), issue.status
2748 2756 issue.tracker = Tracker.find(2)
2749 2757 assert_equal IssueStatus.find(3), issue.status
2750 2758 end
2751 2759
2752 2760 def test_assigned_to_was_with_a_group
2753 2761 group = Group.find(10)
2754 2762
2755 2763 issue = Issue.generate!(:assigned_to => group)
2756 2764 issue.reload.assigned_to = nil
2757 2765 assert_equal group, issue.assigned_to_was
2758 2766 end
2759 2767 end
General Comments 0
You need to be logged in to leave comments. Login now