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