@@ -56,6 +56,8 class Issue < ActiveRecord::Base | |||||
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 | |||
|
60 | ||||
59 | # 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 | |
60 | def visible?(usr=nil) |
|
62 | def visible?(usr=nil) | |
61 | (usr || User.current).allowed_to?(:view_issues, self.project) |
|
63 | (usr || User.current).allowed_to?(:view_issues, self.project) | |
@@ -154,30 +156,6 class Issue < ActiveRecord::Base | |||||
154 | end |
|
156 | end | |
155 | end |
|
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 | def after_save |
|
159 | def after_save | |
182 | # Reload is needed in order to get the right status |
|
160 | # Reload is needed in order to get the right status | |
183 | reload |
|
161 | reload | |
@@ -301,4 +279,28 class Issue < ActiveRecord::Base | |||||
301 | :old_value => obj.filename) |
|
279 | :old_value => obj.filename) | |
302 | journal.save |
|
280 | journal.save | |
303 | end |
|
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 | end |
|
306 | end |
@@ -249,4 +249,23 class IssueTest < Test::Unit::TestCase | |||||
249 | assert issue.save |
|
249 | assert issue.save | |
250 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
250 | assert_equal 1, ActionMailer::Base.deliveries.size | |
251 | end |
|
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 | end |
|
271 | end |
General Comments 0
You need to be logged in to leave comments.
Login now