##// END OF EJS Templates
Actually block issues from closing when a blocking issue isn't closed (#1740)....
Jean-Philippe Lang -
r2700:6994d1c23b8d
parent child
Show More
@@ -0,0 +1,7
1 issue_relation_001:
2 id: 1
3 issue_from_id: 10
4 issue_to_id: 9
5 relation_type: blocks
6 delay:
7
@@ -1,316 +1,322
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class Issue < ActiveRecord::Base
18 class Issue < ActiveRecord::Base
19 belongs_to :project
19 belongs_to :project
20 belongs_to :tracker
20 belongs_to :tracker
21 belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id'
21 belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id'
22 belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
22 belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
23 belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id'
23 belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id'
24 belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id'
24 belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id'
25 belongs_to :priority, :class_name => 'IssuePriority', :foreign_key => 'priority_id'
25 belongs_to :priority, :class_name => 'IssuePriority', :foreign_key => 'priority_id'
26 belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
26 belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
27
27
28 has_many :journals, :as => :journalized, :dependent => :destroy
28 has_many :journals, :as => :journalized, :dependent => :destroy
29 has_many :time_entries, :dependent => :delete_all
29 has_many :time_entries, :dependent => :delete_all
30 has_and_belongs_to_many :changesets, :order => "#{Changeset.table_name}.committed_on ASC, #{Changeset.table_name}.id ASC"
30 has_and_belongs_to_many :changesets, :order => "#{Changeset.table_name}.committed_on ASC, #{Changeset.table_name}.id ASC"
31
31
32 has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all
32 has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all
33 has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
33 has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
34
34
35 acts_as_attachable :after_remove => :attachment_removed
35 acts_as_attachable :after_remove => :attachment_removed
36 acts_as_customizable
36 acts_as_customizable
37 acts_as_watchable
37 acts_as_watchable
38 acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"],
38 acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"],
39 :include => [:project, :journals],
39 :include => [:project, :journals],
40 # sort by id so that limited eager loading doesn't break with postgresql
40 # sort by id so that limited eager loading doesn't break with postgresql
41 :order_column => "#{table_name}.id"
41 :order_column => "#{table_name}.id"
42 acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id}: #{o.subject}"},
42 acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id}: #{o.subject}"},
43 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}},
43 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}},
44 :type => Proc.new {|o| 'issue' + (o.closed? ? ' closed' : '') }
44 :type => Proc.new {|o| 'issue' + (o.closed? ? ' closed' : '') }
45
45
46 acts_as_activity_provider :find_options => {:include => [:project, :author, :tracker]},
46 acts_as_activity_provider :find_options => {:include => [:project, :author, :tracker]},
47 :author_key => :author_id
47 :author_key => :author_id
48
48
49 validates_presence_of :subject, :priority, :project, :tracker, :author, :status
49 validates_presence_of :subject, :priority, :project, :tracker, :author, :status
50 validates_length_of :subject, :maximum => 255
50 validates_length_of :subject, :maximum => 255
51 validates_inclusion_of :done_ratio, :in => 0..100
51 validates_inclusion_of :done_ratio, :in => 0..100
52 validates_numericality_of :estimated_hours, :allow_nil => true
52 validates_numericality_of :estimated_hours, :allow_nil => true
53
53
54 named_scope :visible, lambda {|*args| { :include => :project,
54 named_scope :visible, lambda {|*args| { :include => :project,
55 :conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } }
55 :conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } }
56
56
57 named_scope :open, :conditions => ["#{IssueStatus.table_name}.is_closed = ?", false], :include => :status
57 named_scope :open, :conditions => ["#{IssueStatus.table_name}.is_closed = ?", false], :include => :status
58
58
59 after_save :create_journal
59 after_save :create_journal
60
60
61 # Returns true if usr or current user is allowed to view the issue
61 # Returns true if usr or current user is allowed to view the issue
62 def visible?(usr=nil)
62 def visible?(usr=nil)
63 (usr || User.current).allowed_to?(:view_issues, self.project)
63 (usr || User.current).allowed_to?(:view_issues, self.project)
64 end
64 end
65
65
66 def after_initialize
66 def after_initialize
67 if new_record?
67 if new_record?
68 # set default values for new records only
68 # set default values for new records only
69 self.status ||= IssueStatus.default
69 self.status ||= IssueStatus.default
70 self.priority ||= IssuePriority.default
70 self.priority ||= IssuePriority.default
71 end
71 end
72 end
72 end
73
73
74 # Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields
74 # Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields
75 def available_custom_fields
75 def available_custom_fields
76 (project && tracker) ? project.all_issue_custom_fields.select {|c| tracker.custom_fields.include? c } : []
76 (project && tracker) ? project.all_issue_custom_fields.select {|c| tracker.custom_fields.include? c } : []
77 end
77 end
78
78
79 def copy_from(arg)
79 def copy_from(arg)
80 issue = arg.is_a?(Issue) ? arg : Issue.find(arg)
80 issue = arg.is_a?(Issue) ? arg : Issue.find(arg)
81 self.attributes = issue.attributes.dup
81 self.attributes = issue.attributes.dup
82 self.custom_values = issue.custom_values.collect {|v| v.clone}
82 self.custom_values = issue.custom_values.collect {|v| v.clone}
83 self
83 self
84 end
84 end
85
85
86 # Moves/copies an issue to a new project and tracker
86 # Moves/copies an issue to a new project and tracker
87 # Returns the moved/copied issue on success, false on failure
87 # Returns the moved/copied issue on success, false on failure
88 def move_to(new_project, new_tracker = nil, options = {})
88 def move_to(new_project, new_tracker = nil, options = {})
89 options ||= {}
89 options ||= {}
90 issue = options[:copy] ? self.clone : self
90 issue = options[:copy] ? self.clone : self
91 transaction do
91 transaction do
92 if new_project && issue.project_id != new_project.id
92 if new_project && issue.project_id != new_project.id
93 # delete issue relations
93 # delete issue relations
94 unless Setting.cross_project_issue_relations?
94 unless Setting.cross_project_issue_relations?
95 issue.relations_from.clear
95 issue.relations_from.clear
96 issue.relations_to.clear
96 issue.relations_to.clear
97 end
97 end
98 # issue is moved to another project
98 # issue is moved to another project
99 # reassign to the category with same name if any
99 # reassign to the category with same name if any
100 new_category = issue.category.nil? ? nil : new_project.issue_categories.find_by_name(issue.category.name)
100 new_category = issue.category.nil? ? nil : new_project.issue_categories.find_by_name(issue.category.name)
101 issue.category = new_category
101 issue.category = new_category
102 issue.fixed_version = nil
102 issue.fixed_version = nil
103 issue.project = new_project
103 issue.project = new_project
104 end
104 end
105 if new_tracker
105 if new_tracker
106 issue.tracker = new_tracker
106 issue.tracker = new_tracker
107 end
107 end
108 if options[:copy]
108 if options[:copy]
109 issue.custom_field_values = self.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
109 issue.custom_field_values = self.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
110 issue.status = self.status
110 issue.status = self.status
111 end
111 end
112 if issue.save
112 if issue.save
113 unless options[:copy]
113 unless options[:copy]
114 # Manually update project_id on related time entries
114 # Manually update project_id on related time entries
115 TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
115 TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
116 end
116 end
117 else
117 else
118 Issue.connection.rollback_db_transaction
118 Issue.connection.rollback_db_transaction
119 return false
119 return false
120 end
120 end
121 end
121 end
122 return issue
122 return issue
123 end
123 end
124
124
125 def priority_id=(pid)
125 def priority_id=(pid)
126 self.priority = nil
126 self.priority = nil
127 write_attribute(:priority_id, pid)
127 write_attribute(:priority_id, pid)
128 end
128 end
129
129
130 def estimated_hours=(h)
130 def estimated_hours=(h)
131 write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)
131 write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)
132 end
132 end
133
133
134 def validate
134 def validate
135 if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty?
135 if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty?
136 errors.add :due_date, :not_a_date
136 errors.add :due_date, :not_a_date
137 end
137 end
138
138
139 if self.due_date and self.start_date and self.due_date < self.start_date
139 if self.due_date and self.start_date and self.due_date < self.start_date
140 errors.add :due_date, :greater_than_start_date
140 errors.add :due_date, :greater_than_start_date
141 end
141 end
142
142
143 if start_date && soonest_start && start_date < soonest_start
143 if start_date && soonest_start && start_date < soonest_start
144 errors.add :start_date, :invalid
144 errors.add :start_date, :invalid
145 end
145 end
146 end
146 end
147
147
148 def validate_on_create
148 def validate_on_create
149 errors.add :tracker_id, :invalid unless project.trackers.include?(tracker)
149 errors.add :tracker_id, :invalid unless project.trackers.include?(tracker)
150 end
150 end
151
151
152 def before_create
152 def before_create
153 # default assignment based on category
153 # default assignment based on category
154 if assigned_to.nil? && category && category.assigned_to
154 if assigned_to.nil? && category && category.assigned_to
155 self.assigned_to = category.assigned_to
155 self.assigned_to = category.assigned_to
156 end
156 end
157 end
157 end
158
158
159 def after_save
159 def after_save
160 # Reload is needed in order to get the right status
160 # Reload is needed in order to get the right status
161 reload
161 reload
162
162
163 # Update start/due dates of following issues
163 # Update start/due dates of following issues
164 relations_from.each(&:set_issue_to_dates)
164 relations_from.each(&:set_issue_to_dates)
165
165
166 # Close duplicates if the issue was closed
166 # Close duplicates if the issue was closed
167 if @issue_before_change && !@issue_before_change.closed? && self.closed?
167 if @issue_before_change && !@issue_before_change.closed? && self.closed?
168 duplicates.each do |duplicate|
168 duplicates.each do |duplicate|
169 # Reload is need in case the duplicate was updated by a previous duplicate
169 # Reload is need in case the duplicate was updated by a previous duplicate
170 duplicate.reload
170 duplicate.reload
171 # Don't re-close it if it's already closed
171 # Don't re-close it if it's already closed
172 next if duplicate.closed?
172 next if duplicate.closed?
173 # Same user and notes
173 # Same user and notes
174 duplicate.init_journal(@current_journal.user, @current_journal.notes)
174 duplicate.init_journal(@current_journal.user, @current_journal.notes)
175 duplicate.update_attribute :status, self.status
175 duplicate.update_attribute :status, self.status
176 end
176 end
177 end
177 end
178 end
178 end
179
179
180 def init_journal(user, notes = "")
180 def init_journal(user, notes = "")
181 @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes)
181 @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes)
182 @issue_before_change = self.clone
182 @issue_before_change = self.clone
183 @issue_before_change.status = self.status
183 @issue_before_change.status = self.status
184 @custom_values_before_change = {}
184 @custom_values_before_change = {}
185 self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value }
185 self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value }
186 # Make sure updated_on is updated when adding a note.
186 # Make sure updated_on is updated when adding a note.
187 updated_on_will_change!
187 updated_on_will_change!
188 @current_journal
188 @current_journal
189 end
189 end
190
190
191 # Return true if the issue is closed, otherwise false
191 # Return true if the issue is closed, otherwise false
192 def closed?
192 def closed?
193 self.status.is_closed?
193 self.status.is_closed?
194 end
194 end
195
195
196 # Returns true if the issue is overdue
196 # Returns true if the issue is overdue
197 def overdue?
197 def overdue?
198 !due_date.nil? && (due_date < Date.today) && !status.is_closed?
198 !due_date.nil? && (due_date < Date.today) && !status.is_closed?
199 end
199 end
200
200
201 # Users the issue can be assigned to
201 # Users the issue can be assigned to
202 def assignable_users
202 def assignable_users
203 project.assignable_users
203 project.assignable_users
204 end
204 end
205
205
206 # Returns true if this issue is blocked by another issue that is still open
207 def blocked?
208 !relations_to.detect {|ir| ir.relation_type == 'blocks' && !ir.issue_from.closed?}.nil?
209 end
210
206 # Returns an array of status that user is able to apply
211 # Returns an array of status that user is able to apply
207 def new_statuses_allowed_to(user)
212 def new_statuses_allowed_to(user)
208 statuses = status.find_new_statuses_allowed_to(user.roles_for_project(project), tracker)
213 statuses = status.find_new_statuses_allowed_to(user.roles_for_project(project), tracker)
209 statuses << status unless statuses.empty?
214 statuses << status unless statuses.empty?
210 statuses.uniq.sort
215 statuses = statuses.uniq.sort
216 blocked? ? statuses.reject {|s| s.is_closed?} : statuses
211 end
217 end
212
218
213 # Returns the mail adresses of users that should be notified for the issue
219 # Returns the mail adresses of users that should be notified for the issue
214 def recipients
220 def recipients
215 recipients = project.recipients
221 recipients = project.recipients
216 # Author and assignee are always notified unless they have been locked
222 # Author and assignee are always notified unless they have been locked
217 recipients << author.mail if author && author.active?
223 recipients << author.mail if author && author.active?
218 recipients << assigned_to.mail if assigned_to && assigned_to.active?
224 recipients << assigned_to.mail if assigned_to && assigned_to.active?
219 recipients.compact.uniq
225 recipients.compact.uniq
220 end
226 end
221
227
222 # Returns the total number of hours spent on this issue.
228 # Returns the total number of hours spent on this issue.
223 #
229 #
224 # Example:
230 # Example:
225 # spent_hours => 0
231 # spent_hours => 0
226 # spent_hours => 50
232 # spent_hours => 50
227 def spent_hours
233 def spent_hours
228 @spent_hours ||= time_entries.sum(:hours) || 0
234 @spent_hours ||= time_entries.sum(:hours) || 0
229 end
235 end
230
236
231 def relations
237 def relations
232 (relations_from + relations_to).sort
238 (relations_from + relations_to).sort
233 end
239 end
234
240
235 def all_dependent_issues
241 def all_dependent_issues
236 dependencies = []
242 dependencies = []
237 relations_from.each do |relation|
243 relations_from.each do |relation|
238 dependencies << relation.issue_to
244 dependencies << relation.issue_to
239 dependencies += relation.issue_to.all_dependent_issues
245 dependencies += relation.issue_to.all_dependent_issues
240 end
246 end
241 dependencies
247 dependencies
242 end
248 end
243
249
244 # Returns an array of issues that duplicate this one
250 # Returns an array of issues that duplicate this one
245 def duplicates
251 def duplicates
246 relations_to.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.issue_from}
252 relations_to.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.issue_from}
247 end
253 end
248
254
249 # Returns the due date or the target due date if any
255 # Returns the due date or the target due date if any
250 # Used on gantt chart
256 # Used on gantt chart
251 def due_before
257 def due_before
252 due_date || (fixed_version ? fixed_version.effective_date : nil)
258 due_date || (fixed_version ? fixed_version.effective_date : nil)
253 end
259 end
254
260
255 # Returns the time scheduled for this issue.
261 # Returns the time scheduled for this issue.
256 #
262 #
257 # Example:
263 # Example:
258 # Start Date: 2/26/09, End Date: 3/04/09
264 # Start Date: 2/26/09, End Date: 3/04/09
259 # duration => 6
265 # duration => 6
260 def duration
266 def duration
261 (start_date && due_date) ? due_date - start_date : 0
267 (start_date && due_date) ? due_date - start_date : 0
262 end
268 end
263
269
264 def soonest_start
270 def soonest_start
265 @soonest_start ||= relations_to.collect{|relation| relation.successor_soonest_start}.compact.min
271 @soonest_start ||= relations_to.collect{|relation| relation.successor_soonest_start}.compact.min
266 end
272 end
267
273
268 def to_s
274 def to_s
269 "#{tracker} ##{id}: #{subject}"
275 "#{tracker} ##{id}: #{subject}"
270 end
276 end
271
277
272 # Returns a string of css classes that apply to the issue
278 # Returns a string of css classes that apply to the issue
273 def css_classes
279 def css_classes
274 s = "issue status-#{status.position} priority-#{priority.position}"
280 s = "issue status-#{status.position} priority-#{priority.position}"
275 s << ' closed' if closed?
281 s << ' closed' if closed?
276 s << ' overdue' if overdue?
282 s << ' overdue' if overdue?
277 s << ' created-by-me' if User.current.logged? && author_id == User.current.id
283 s << ' created-by-me' if User.current.logged? && author_id == User.current.id
278 s << ' assigned-to-me' if User.current.logged? && assigned_to_id == User.current.id
284 s << ' assigned-to-me' if User.current.logged? && assigned_to_id == User.current.id
279 s
285 s
280 end
286 end
281
287
282 private
288 private
283
289
284 # Callback on attachment deletion
290 # Callback on attachment deletion
285 def attachment_removed(obj)
291 def attachment_removed(obj)
286 journal = init_journal(User.current)
292 journal = init_journal(User.current)
287 journal.details << JournalDetail.new(:property => 'attachment',
293 journal.details << JournalDetail.new(:property => 'attachment',
288 :prop_key => obj.id,
294 :prop_key => obj.id,
289 :old_value => obj.filename)
295 :old_value => obj.filename)
290 journal.save
296 journal.save
291 end
297 end
292
298
293 # Saves the changes in a Journal
299 # Saves the changes in a Journal
294 # Called after_save
300 # Called after_save
295 def create_journal
301 def create_journal
296 if @current_journal
302 if @current_journal
297 # attributes changes
303 # attributes changes
298 (Issue.column_names - %w(id description lock_version created_on updated_on)).each {|c|
304 (Issue.column_names - %w(id description lock_version created_on updated_on)).each {|c|
299 @current_journal.details << JournalDetail.new(:property => 'attr',
305 @current_journal.details << JournalDetail.new(:property => 'attr',
300 :prop_key => c,
306 :prop_key => c,
301 :old_value => @issue_before_change.send(c),
307 :old_value => @issue_before_change.send(c),
302 :value => send(c)) unless send(c)==@issue_before_change.send(c)
308 :value => send(c)) unless send(c)==@issue_before_change.send(c)
303 }
309 }
304 # custom fields changes
310 # custom fields changes
305 custom_values.each {|c|
311 custom_values.each {|c|
306 next if (@custom_values_before_change[c.custom_field_id]==c.value ||
312 next if (@custom_values_before_change[c.custom_field_id]==c.value ||
307 (@custom_values_before_change[c.custom_field_id].blank? && c.value.blank?))
313 (@custom_values_before_change[c.custom_field_id].blank? && c.value.blank?))
308 @current_journal.details << JournalDetail.new(:property => 'cf',
314 @current_journal.details << JournalDetail.new(:property => 'cf',
309 :prop_key => c.custom_field_id,
315 :prop_key => c.custom_field_id,
310 :old_value => @custom_values_before_change[c.custom_field_id],
316 :old_value => @custom_values_before_change[c.custom_field_id],
311 :value => c.value)
317 :value => c.value)
312 }
318 }
313 @current_journal.save
319 @current_journal.save
314 end
320 end
315 end
321 end
316 end
322 end
@@ -1,128 +1,159
1 ---
1 ---
2 issues_001:
2 issues_001:
3 created_on: <%= 3.days.ago.to_date.to_s(:db) %>
3 created_on: <%= 3.days.ago.to_date.to_s(:db) %>
4 project_id: 1
4 project_id: 1
5 updated_on: <%= 1.day.ago.to_date.to_s(:db) %>
5 updated_on: <%= 1.day.ago.to_date.to_s(:db) %>
6 priority_id: 4
6 priority_id: 4
7 subject: Can't print recipes
7 subject: Can't print recipes
8 id: 1
8 id: 1
9 fixed_version_id:
9 fixed_version_id:
10 category_id: 1
10 category_id: 1
11 description: Unable to print recipes
11 description: Unable to print recipes
12 tracker_id: 1
12 tracker_id: 1
13 assigned_to_id:
13 assigned_to_id:
14 author_id: 2
14 author_id: 2
15 status_id: 1
15 status_id: 1
16 start_date: <%= 1.day.ago.to_date.to_s(:db) %>
16 start_date: <%= 1.day.ago.to_date.to_s(:db) %>
17 due_date: <%= 10.day.from_now.to_date.to_s(:db) %>
17 due_date: <%= 10.day.from_now.to_date.to_s(:db) %>
18 issues_002:
18 issues_002:
19 created_on: 2006-07-19 21:04:21 +02:00
19 created_on: 2006-07-19 21:04:21 +02:00
20 project_id: 1
20 project_id: 1
21 updated_on: 2006-07-19 21:09:50 +02:00
21 updated_on: 2006-07-19 21:09:50 +02:00
22 priority_id: 5
22 priority_id: 5
23 subject: Add ingredients categories
23 subject: Add ingredients categories
24 id: 2
24 id: 2
25 fixed_version_id: 2
25 fixed_version_id: 2
26 category_id:
26 category_id:
27 description: Ingredients of the recipe should be classified by categories
27 description: Ingredients of the recipe should be classified by categories
28 tracker_id: 2
28 tracker_id: 2
29 assigned_to_id: 3
29 assigned_to_id: 3
30 author_id: 2
30 author_id: 2
31 status_id: 2
31 status_id: 2
32 start_date: <%= 2.day.ago.to_date.to_s(:db) %>
32 start_date: <%= 2.day.ago.to_date.to_s(:db) %>
33 due_date:
33 due_date:
34 issues_003:
34 issues_003:
35 created_on: 2006-07-19 21:07:27 +02:00
35 created_on: 2006-07-19 21:07:27 +02:00
36 project_id: 1
36 project_id: 1
37 updated_on: 2006-07-19 21:07:27 +02:00
37 updated_on: 2006-07-19 21:07:27 +02:00
38 priority_id: 4
38 priority_id: 4
39 subject: Error 281 when updating a recipe
39 subject: Error 281 when updating a recipe
40 id: 3
40 id: 3
41 fixed_version_id:
41 fixed_version_id:
42 category_id:
42 category_id:
43 description: Error 281 is encountered when saving a recipe
43 description: Error 281 is encountered when saving a recipe
44 tracker_id: 1
44 tracker_id: 1
45 assigned_to_id: 3
45 assigned_to_id: 3
46 author_id: 2
46 author_id: 2
47 status_id: 1
47 status_id: 1
48 start_date: <%= 1.day.from_now.to_date.to_s(:db) %>
48 start_date: <%= 1.day.from_now.to_date.to_s(:db) %>
49 due_date: <%= 40.day.ago.to_date.to_s(:db) %>
49 due_date: <%= 40.day.ago.to_date.to_s(:db) %>
50 issues_004:
50 issues_004:
51 created_on: <%= 5.days.ago.to_date.to_s(:db) %>
51 created_on: <%= 5.days.ago.to_date.to_s(:db) %>
52 project_id: 2
52 project_id: 2
53 updated_on: <%= 2.days.ago.to_date.to_s(:db) %>
53 updated_on: <%= 2.days.ago.to_date.to_s(:db) %>
54 priority_id: 4
54 priority_id: 4
55 subject: Issue on project 2
55 subject: Issue on project 2
56 id: 4
56 id: 4
57 fixed_version_id:
57 fixed_version_id:
58 category_id:
58 category_id:
59 description: Issue on project 2
59 description: Issue on project 2
60 tracker_id: 1
60 tracker_id: 1
61 assigned_to_id: 2
61 assigned_to_id: 2
62 author_id: 2
62 author_id: 2
63 status_id: 1
63 status_id: 1
64 issues_005:
64 issues_005:
65 created_on: <%= 5.days.ago.to_date.to_s(:db) %>
65 created_on: <%= 5.days.ago.to_date.to_s(:db) %>
66 project_id: 3
66 project_id: 3
67 updated_on: <%= 2.days.ago.to_date.to_s(:db) %>
67 updated_on: <%= 2.days.ago.to_date.to_s(:db) %>
68 priority_id: 4
68 priority_id: 4
69 subject: Subproject issue
69 subject: Subproject issue
70 id: 5
70 id: 5
71 fixed_version_id:
71 fixed_version_id:
72 category_id:
72 category_id:
73 description: This is an issue on a cookbook subproject
73 description: This is an issue on a cookbook subproject
74 tracker_id: 1
74 tracker_id: 1
75 assigned_to_id:
75 assigned_to_id:
76 author_id: 2
76 author_id: 2
77 status_id: 1
77 status_id: 1
78 issues_006:
78 issues_006:
79 created_on: <%= 1.minute.ago.to_date.to_s(:db) %>
79 created_on: <%= 1.minute.ago.to_date.to_s(:db) %>
80 project_id: 5
80 project_id: 5
81 updated_on: <%= 1.minute.ago.to_date.to_s(:db) %>
81 updated_on: <%= 1.minute.ago.to_date.to_s(:db) %>
82 priority_id: 4
82 priority_id: 4
83 subject: Issue of a private subproject
83 subject: Issue of a private subproject
84 id: 6
84 id: 6
85 fixed_version_id:
85 fixed_version_id:
86 category_id:
86 category_id:
87 description: This is an issue of a private subproject of cookbook
87 description: This is an issue of a private subproject of cookbook
88 tracker_id: 1
88 tracker_id: 1
89 assigned_to_id:
89 assigned_to_id:
90 author_id: 2
90 author_id: 2
91 status_id: 1
91 status_id: 1
92 start_date: <%= Date.today.to_s(:db) %>
92 start_date: <%= Date.today.to_s(:db) %>
93 due_date: <%= 1.days.from_now.to_date.to_s(:db) %>
93 due_date: <%= 1.days.from_now.to_date.to_s(:db) %>
94 issues_007:
94 issues_007:
95 created_on: <%= 10.days.ago.to_date.to_s(:db) %>
95 created_on: <%= 10.days.ago.to_date.to_s(:db) %>
96 project_id: 1
96 project_id: 1
97 updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
97 updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
98 priority_id: 5
98 priority_id: 5
99 subject: Issue due today
99 subject: Issue due today
100 id: 7
100 id: 7
101 fixed_version_id:
101 fixed_version_id:
102 category_id:
102 category_id:
103 description: This is an issue that is due today
103 description: This is an issue that is due today
104 tracker_id: 1
104 tracker_id: 1
105 assigned_to_id:
105 assigned_to_id:
106 author_id: 2
106 author_id: 2
107 status_id: 1
107 status_id: 1
108 start_date: <%= 10.days.ago.to_s(:db) %>
108 start_date: <%= 10.days.ago.to_s(:db) %>
109 due_date: <%= Date.today.to_s(:db) %>
109 due_date: <%= Date.today.to_s(:db) %>
110 lock_version: 0
110 lock_version: 0
111 issues_008:
111 issues_008:
112 created_on: <%= 10.days.ago.to_date.to_s(:db) %>
112 created_on: <%= 10.days.ago.to_date.to_s(:db) %>
113 project_id: 1
113 project_id: 1
114 updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
114 updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
115 priority_id: 5
115 priority_id: 5
116 subject: Closed issue
116 subject: Closed issue
117 id: 8
117 id: 8
118 fixed_version_id:
118 fixed_version_id:
119 category_id:
119 category_id:
120 description: This is a closed issue.
120 description: This is a closed issue.
121 tracker_id: 1
121 tracker_id: 1
122 assigned_to_id:
122 assigned_to_id:
123 author_id: 2
123 author_id: 2
124 status_id: 5
124 status_id: 5
125 start_date:
125 start_date:
126 due_date:
126 due_date:
127 lock_version: 0
127 lock_version: 0
128
128 issues_009:
129 created_on: <%= 1.minute.ago.to_date.to_s(:db) %>
130 project_id: 5
131 updated_on: <%= 1.minute.ago.to_date.to_s(:db) %>
132 priority_id: 5
133 subject: Blocked Issue
134 id: 9
135 fixed_version_id:
136 category_id:
137 description: This is an issue that is blocked by issue #10
138 tracker_id: 1
139 assigned_to_id:
140 author_id: 2
141 status_id: 1
142 start_date: <%= Date.today.to_s(:db) %>
143 due_date: <%= 1.days.from_now.to_date.to_s(:db) %>
144 issues_010:
145 created_on: <%= 1.minute.ago.to_date.to_s(:db) %>
146 project_id: 5
147 updated_on: <%= 1.minute.ago.to_date.to_s(:db) %>
148 priority_id: 5
149 subject: Issue Doing the Blocking
150 id: 10
151 fixed_version_id:
152 category_id:
153 description: This is an issue that blocks issue #9
154 tracker_id: 1
155 assigned_to_id:
156 author_id: 2
157 status_id: 1
158 start_date: <%= Date.today.to_s(:db) %>
159 due_date: <%= 1.days.from_now.to_date.to_s(:db) %>
@@ -1,275 +1,301
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19
19
20 class IssueTest < Test::Unit::TestCase
20 class IssueTest < Test::Unit::TestCase
21 fixtures :projects, :users, :members, :member_roles,
21 fixtures :projects, :users, :members, :member_roles,
22 :trackers, :projects_trackers,
22 :trackers, :projects_trackers,
23 :issue_statuses, :issue_categories,
23 :issue_statuses, :issue_categories, :issue_relations, :workflows,
24 :enumerations,
24 :enumerations,
25 :issues,
25 :issues,
26 :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values,
26 :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values,
27 :time_entries
27 :time_entries
28
28
29 def test_create
29 def test_create
30 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create', :description => 'IssueTest#test_create', :estimated_hours => '1:30')
30 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create', :description => 'IssueTest#test_create', :estimated_hours => '1:30')
31 assert issue.save
31 assert issue.save
32 issue.reload
32 issue.reload
33 assert_equal 1.5, issue.estimated_hours
33 assert_equal 1.5, issue.estimated_hours
34 end
34 end
35
35
36 def test_create_minimal
36 def test_create_minimal
37 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create')
37 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create')
38 assert issue.save
38 assert issue.save
39 assert issue.description.nil?
39 assert issue.description.nil?
40 end
40 end
41
41
42 def test_create_with_required_custom_field
42 def test_create_with_required_custom_field
43 field = IssueCustomField.find_by_name('Database')
43 field = IssueCustomField.find_by_name('Database')
44 field.update_attribute(:is_required, true)
44 field.update_attribute(:is_required, true)
45
45
46 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'test_create', :description => 'IssueTest#test_create_with_required_custom_field')
46 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'test_create', :description => 'IssueTest#test_create_with_required_custom_field')
47 assert issue.available_custom_fields.include?(field)
47 assert issue.available_custom_fields.include?(field)
48 # No value for the custom field
48 # No value for the custom field
49 assert !issue.save
49 assert !issue.save
50 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
50 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
51 # Blank value
51 # Blank value
52 issue.custom_field_values = { field.id => '' }
52 issue.custom_field_values = { field.id => '' }
53 assert !issue.save
53 assert !issue.save
54 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
54 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
55 # Invalid value
55 # Invalid value
56 issue.custom_field_values = { field.id => 'SQLServer' }
56 issue.custom_field_values = { field.id => 'SQLServer' }
57 assert !issue.save
57 assert !issue.save
58 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
58 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
59 # Valid value
59 # Valid value
60 issue.custom_field_values = { field.id => 'PostgreSQL' }
60 issue.custom_field_values = { field.id => 'PostgreSQL' }
61 assert issue.save
61 assert issue.save
62 issue.reload
62 issue.reload
63 assert_equal 'PostgreSQL', issue.custom_value_for(field).value
63 assert_equal 'PostgreSQL', issue.custom_value_for(field).value
64 end
64 end
65
65
66 def test_errors_full_messages_should_include_custom_fields_errors
66 def test_errors_full_messages_should_include_custom_fields_errors
67 field = IssueCustomField.find_by_name('Database')
67 field = IssueCustomField.find_by_name('Database')
68
68
69 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'test_create', :description => 'IssueTest#test_create_with_required_custom_field')
69 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'test_create', :description => 'IssueTest#test_create_with_required_custom_field')
70 assert issue.available_custom_fields.include?(field)
70 assert issue.available_custom_fields.include?(field)
71 # Invalid value
71 # Invalid value
72 issue.custom_field_values = { field.id => 'SQLServer' }
72 issue.custom_field_values = { field.id => 'SQLServer' }
73
73
74 assert !issue.valid?
74 assert !issue.valid?
75 assert_equal 1, issue.errors.full_messages.size
75 assert_equal 1, issue.errors.full_messages.size
76 assert_equal "Database #{I18n.translate('activerecord.errors.messages.inclusion')}", issue.errors.full_messages.first
76 assert_equal "Database #{I18n.translate('activerecord.errors.messages.inclusion')}", issue.errors.full_messages.first
77 end
77 end
78
78
79 def test_update_issue_with_required_custom_field
79 def test_update_issue_with_required_custom_field
80 field = IssueCustomField.find_by_name('Database')
80 field = IssueCustomField.find_by_name('Database')
81 field.update_attribute(:is_required, true)
81 field.update_attribute(:is_required, true)
82
82
83 issue = Issue.find(1)
83 issue = Issue.find(1)
84 assert_nil issue.custom_value_for(field)
84 assert_nil issue.custom_value_for(field)
85 assert issue.available_custom_fields.include?(field)
85 assert issue.available_custom_fields.include?(field)
86 # No change to custom values, issue can be saved
86 # No change to custom values, issue can be saved
87 assert issue.save
87 assert issue.save
88 # Blank value
88 # Blank value
89 issue.custom_field_values = { field.id => '' }
89 issue.custom_field_values = { field.id => '' }
90 assert !issue.save
90 assert !issue.save
91 # Valid value
91 # Valid value
92 issue.custom_field_values = { field.id => 'PostgreSQL' }
92 issue.custom_field_values = { field.id => 'PostgreSQL' }
93 assert issue.save
93 assert issue.save
94 issue.reload
94 issue.reload
95 assert_equal 'PostgreSQL', issue.custom_value_for(field).value
95 assert_equal 'PostgreSQL', issue.custom_value_for(field).value
96 end
96 end
97
97
98 def test_should_not_update_attributes_if_custom_fields_validation_fails
98 def test_should_not_update_attributes_if_custom_fields_validation_fails
99 issue = Issue.find(1)
99 issue = Issue.find(1)
100 field = IssueCustomField.find_by_name('Database')
100 field = IssueCustomField.find_by_name('Database')
101 assert issue.available_custom_fields.include?(field)
101 assert issue.available_custom_fields.include?(field)
102
102
103 issue.custom_field_values = { field.id => 'Invalid' }
103 issue.custom_field_values = { field.id => 'Invalid' }
104 issue.subject = 'Should be not be saved'
104 issue.subject = 'Should be not be saved'
105 assert !issue.save
105 assert !issue.save
106
106
107 issue.reload
107 issue.reload
108 assert_equal "Can't print recipes", issue.subject
108 assert_equal "Can't print recipes", issue.subject
109 end
109 end
110
110
111 def test_should_not_recreate_custom_values_objects_on_update
111 def test_should_not_recreate_custom_values_objects_on_update
112 field = IssueCustomField.find_by_name('Database')
112 field = IssueCustomField.find_by_name('Database')
113
113
114 issue = Issue.find(1)
114 issue = Issue.find(1)
115 issue.custom_field_values = { field.id => 'PostgreSQL' }
115 issue.custom_field_values = { field.id => 'PostgreSQL' }
116 assert issue.save
116 assert issue.save
117 custom_value = issue.custom_value_for(field)
117 custom_value = issue.custom_value_for(field)
118 issue.reload
118 issue.reload
119 issue.custom_field_values = { field.id => 'MySQL' }
119 issue.custom_field_values = { field.id => 'MySQL' }
120 assert issue.save
120 assert issue.save
121 issue.reload
121 issue.reload
122 assert_equal custom_value.id, issue.custom_value_for(field).id
122 assert_equal custom_value.id, issue.custom_value_for(field).id
123 end
123 end
124
124
125 def test_category_based_assignment
125 def test_category_based_assignment
126 issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Assignment test', :description => 'Assignment test', :category_id => 1)
126 issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Assignment test', :description => 'Assignment test', :category_id => 1)
127 assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to
127 assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to
128 end
128 end
129
129
130 def test_copy
130 def test_copy
131 issue = Issue.new.copy_from(1)
131 issue = Issue.new.copy_from(1)
132 assert issue.save
132 assert issue.save
133 issue.reload
133 issue.reload
134 orig = Issue.find(1)
134 orig = Issue.find(1)
135 assert_equal orig.subject, issue.subject
135 assert_equal orig.subject, issue.subject
136 assert_equal orig.tracker, issue.tracker
136 assert_equal orig.tracker, issue.tracker
137 assert_equal orig.custom_values.first.value, issue.custom_values.first.value
137 assert_equal orig.custom_values.first.value, issue.custom_values.first.value
138 end
138 end
139
139
140 def test_should_close_duplicates
140 def test_should_close_duplicates
141 # Create 3 issues
141 # Create 3 issues
142 issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Duplicates test', :description => 'Duplicates test')
142 issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Duplicates test', :description => 'Duplicates test')
143 assert issue1.save
143 assert issue1.save
144 issue2 = issue1.clone
144 issue2 = issue1.clone
145 assert issue2.save
145 assert issue2.save
146 issue3 = issue1.clone
146 issue3 = issue1.clone
147 assert issue3.save
147 assert issue3.save
148
148
149 # 2 is a dupe of 1
149 # 2 is a dupe of 1
150 IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES)
150 IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES)
151 # And 3 is a dupe of 2
151 # And 3 is a dupe of 2
152 IssueRelation.create(:issue_from => issue3, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES)
152 IssueRelation.create(:issue_from => issue3, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES)
153 # And 3 is a dupe of 1 (circular duplicates)
153 # And 3 is a dupe of 1 (circular duplicates)
154 IssueRelation.create(:issue_from => issue3, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES)
154 IssueRelation.create(:issue_from => issue3, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES)
155
155
156 assert issue1.reload.duplicates.include?(issue2)
156 assert issue1.reload.duplicates.include?(issue2)
157
157
158 # Closing issue 1
158 # Closing issue 1
159 issue1.init_journal(User.find(:first), "Closing issue1")
159 issue1.init_journal(User.find(:first), "Closing issue1")
160 issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true}
160 issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true}
161 assert issue1.save
161 assert issue1.save
162 # 2 and 3 should be also closed
162 # 2 and 3 should be also closed
163 assert issue2.reload.closed?
163 assert issue2.reload.closed?
164 assert issue3.reload.closed?
164 assert issue3.reload.closed?
165 end
165 end
166
166
167 def test_should_not_close_duplicated_issue
167 def test_should_not_close_duplicated_issue
168 # Create 3 issues
168 # Create 3 issues
169 issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Duplicates test', :description => 'Duplicates test')
169 issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Duplicates test', :description => 'Duplicates test')
170 assert issue1.save
170 assert issue1.save
171 issue2 = issue1.clone
171 issue2 = issue1.clone
172 assert issue2.save
172 assert issue2.save
173
173
174 # 2 is a dupe of 1
174 # 2 is a dupe of 1
175 IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES)
175 IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES)
176 # 2 is a dup of 1 but 1 is not a duplicate of 2
176 # 2 is a dup of 1 but 1 is not a duplicate of 2
177 assert !issue2.reload.duplicates.include?(issue1)
177 assert !issue2.reload.duplicates.include?(issue1)
178
178
179 # Closing issue 2
179 # Closing issue 2
180 issue2.init_journal(User.find(:first), "Closing issue2")
180 issue2.init_journal(User.find(:first), "Closing issue2")
181 issue2.status = IssueStatus.find :first, :conditions => {:is_closed => true}
181 issue2.status = IssueStatus.find :first, :conditions => {:is_closed => true}
182 assert issue2.save
182 assert issue2.save
183 # 1 should not be also closed
183 # 1 should not be also closed
184 assert !issue1.reload.closed?
184 assert !issue1.reload.closed?
185 end
185 end
186
186
187 def test_move_to_another_project_with_same_category
187 def test_move_to_another_project_with_same_category
188 issue = Issue.find(1)
188 issue = Issue.find(1)
189 assert issue.move_to(Project.find(2))
189 assert issue.move_to(Project.find(2))
190 issue.reload
190 issue.reload
191 assert_equal 2, issue.project_id
191 assert_equal 2, issue.project_id
192 # Category changes
192 # Category changes
193 assert_equal 4, issue.category_id
193 assert_equal 4, issue.category_id
194 # Make sure time entries were move to the target project
194 # Make sure time entries were move to the target project
195 assert_equal 2, issue.time_entries.first.project_id
195 assert_equal 2, issue.time_entries.first.project_id
196 end
196 end
197
197
198 def test_move_to_another_project_without_same_category
198 def test_move_to_another_project_without_same_category
199 issue = Issue.find(2)
199 issue = Issue.find(2)
200 assert issue.move_to(Project.find(2))
200 assert issue.move_to(Project.find(2))
201 issue.reload
201 issue.reload
202 assert_equal 2, issue.project_id
202 assert_equal 2, issue.project_id
203 # Category cleared
203 # Category cleared
204 assert_nil issue.category_id
204 assert_nil issue.category_id
205 end
205 end
206
206
207 def test_copy_to_the_same_project
207 def test_copy_to_the_same_project
208 issue = Issue.find(1)
208 issue = Issue.find(1)
209 copy = nil
209 copy = nil
210 assert_difference 'Issue.count' do
210 assert_difference 'Issue.count' do
211 copy = issue.move_to(issue.project, nil, :copy => true)
211 copy = issue.move_to(issue.project, nil, :copy => true)
212 end
212 end
213 assert_kind_of Issue, copy
213 assert_kind_of Issue, copy
214 assert_equal issue.project, copy.project
214 assert_equal issue.project, copy.project
215 assert_equal "125", copy.custom_value_for(2).value
215 assert_equal "125", copy.custom_value_for(2).value
216 end
216 end
217
217
218 def test_copy_to_another_project_and_tracker
218 def test_copy_to_another_project_and_tracker
219 issue = Issue.find(1)
219 issue = Issue.find(1)
220 copy = nil
220 copy = nil
221 assert_difference 'Issue.count' do
221 assert_difference 'Issue.count' do
222 copy = issue.move_to(Project.find(3), Tracker.find(2), :copy => true)
222 copy = issue.move_to(Project.find(3), Tracker.find(2), :copy => true)
223 end
223 end
224 assert_kind_of Issue, copy
224 assert_kind_of Issue, copy
225 assert_equal Project.find(3), copy.project
225 assert_equal Project.find(3), copy.project
226 assert_equal Tracker.find(2), copy.tracker
226 assert_equal Tracker.find(2), copy.tracker
227 # Custom field #2 is not associated with target tracker
227 # Custom field #2 is not associated with target tracker
228 assert_nil copy.custom_value_for(2)
228 assert_nil copy.custom_value_for(2)
229 end
229 end
230
230
231 def test_issue_destroy
231 def test_issue_destroy
232 Issue.find(1).destroy
232 Issue.find(1).destroy
233 assert_nil Issue.find_by_id(1)
233 assert_nil Issue.find_by_id(1)
234 assert_nil TimeEntry.find_by_issue_id(1)
234 assert_nil TimeEntry.find_by_issue_id(1)
235 end
235 end
236
236
237 def test_blocked
238 blocked_issue = Issue.find(9)
239 blocking_issue = Issue.find(10)
240
241 assert blocked_issue.blocked?
242 assert !blocking_issue.blocked?
243 end
244
245 def test_blocked_issues_dont_allow_closed_statuses
246 blocked_issue = Issue.find(9)
247
248 allowed_statuses = blocked_issue.new_statuses_allowed_to(users(:users_002))
249 assert !allowed_statuses.empty?
250 closed_statuses = allowed_statuses.select {|st| st.is_closed?}
251 assert closed_statuses.empty?
252 end
253
254 def test_unblocked_issues_allow_closed_statuses
255 blocking_issue = Issue.find(10)
256
257 allowed_statuses = blocking_issue.new_statuses_allowed_to(users(:users_002))
258 assert !allowed_statuses.empty?
259 closed_statuses = allowed_statuses.select {|st| st.is_closed?}
260 assert !closed_statuses.empty?
261 end
262
237 def test_overdue
263 def test_overdue
238 assert Issue.new(:due_date => 1.day.ago.to_date).overdue?
264 assert Issue.new(:due_date => 1.day.ago.to_date).overdue?
239 assert !Issue.new(:due_date => Date.today).overdue?
265 assert !Issue.new(:due_date => Date.today).overdue?
240 assert !Issue.new(:due_date => 1.day.from_now.to_date).overdue?
266 assert !Issue.new(:due_date => 1.day.from_now.to_date).overdue?
241 assert !Issue.new(:due_date => nil).overdue?
267 assert !Issue.new(:due_date => nil).overdue?
242 assert !Issue.new(:due_date => 1.day.ago.to_date, :status => IssueStatus.find(:first, :conditions => {:is_closed => true})).overdue?
268 assert !Issue.new(:due_date => 1.day.ago.to_date, :status => IssueStatus.find(:first, :conditions => {:is_closed => true})).overdue?
243 end
269 end
244
270
245 def test_assignable_users
271 def test_assignable_users
246 assert_kind_of User, Issue.find(1).assignable_users.first
272 assert_kind_of User, Issue.find(1).assignable_users.first
247 end
273 end
248
274
249 def test_create_should_send_email_notification
275 def test_create_should_send_email_notification
250 ActionMailer::Base.deliveries.clear
276 ActionMailer::Base.deliveries.clear
251 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create', :estimated_hours => '1:30')
277 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create', :estimated_hours => '1:30')
252
278
253 assert issue.save
279 assert issue.save
254 assert_equal 1, ActionMailer::Base.deliveries.size
280 assert_equal 1, ActionMailer::Base.deliveries.size
255 end
281 end
256
282
257 def test_stale_issue_should_not_send_email_notification
283 def test_stale_issue_should_not_send_email_notification
258 ActionMailer::Base.deliveries.clear
284 ActionMailer::Base.deliveries.clear
259 issue = Issue.find(1)
285 issue = Issue.find(1)
260 stale = Issue.find(1)
286 stale = Issue.find(1)
261
287
262 issue.init_journal(User.find(1))
288 issue.init_journal(User.find(1))
263 issue.subject = 'Subjet update'
289 issue.subject = 'Subjet update'
264 assert issue.save
290 assert issue.save
265 assert_equal 1, ActionMailer::Base.deliveries.size
291 assert_equal 1, ActionMailer::Base.deliveries.size
266 ActionMailer::Base.deliveries.clear
292 ActionMailer::Base.deliveries.clear
267
293
268 stale.init_journal(User.find(1))
294 stale.init_journal(User.find(1))
269 stale.subject = 'Another subjet update'
295 stale.subject = 'Another subjet update'
270 assert_raise ActiveRecord::StaleObjectError do
296 assert_raise ActiveRecord::StaleObjectError do
271 stale.save
297 stale.save
272 end
298 end
273 assert ActionMailer::Base.deliveries.empty?
299 assert ActionMailer::Base.deliveries.empty?
274 end
300 end
275 end
301 end
General Comments 0
You need to be logged in to leave comments. Login now