before_create :default_assign
before_save :close_duplicates, :update_done_ratio_from_issue_status,
- :force_updated_on_change, :update_closed_on
+ :force_updated_on_change, :update_closed_on, :set_assigned_to_was
after_save {|issue| issue.send :after_project_change if !issue.id_changed? && issue.project_id_changed?}
after_save :reschedule_following_issues, :update_nested_set_attributes,
:update_parent_attributes, :create_journal
after_save :after_create_from_copy
after_destroy :update_parent_attributes
after_create :send_notification
+ # Keep it at the end of after_save callbacks
+ after_save :clear_assigned_to_was
# Returns a SQL conditions string used to find all issues visible by the specified user
def self.visible_condition(user, options={})
end
end
+ # Returns the previous assignee if changed
def assigned_to_was
- if assigned_to_id_changed? && assigned_to_id_was.present?
- @assigned_to_was ||= User.find_by_id(assigned_to_id_was)
+ # assigned_to_id_was is reset before after_save callbacks
+ user_id = @previous_assigned_to_id || assigned_to_id_was
+ if user_id && user_id != assigned_to_id
+ @assigned_to_was ||= User.find_by_id(user_id)
end
end
end
end
+ # Stores the previous assignee so we can still have access
+ # to it during after_save callbacks (assigned_to_id_was is reset)
+ def set_assigned_to_was
+ @previous_assigned_to_id = assigned_to_id_was
+ end
+
+ # Clears the previous assignee at the end of after_save callbacks
+ def clear_assigned_to_was
+ @assigned_to_was = nil
+ @previous_assigned_to_id = nil
+ end
+
# Query generator for selecting groups of issue counts for a project
# based on specific criteria
#
assert_equal 1, ActionMailer::Base.deliveries.size
end
+ def test_update_should_notify_previous_assignee
+ ActionMailer::Base.deliveries.clear
+ user = User.find(3)
+ user.members.update_all ["mail_notification = ?", false]
+ user.update_attribute :mail_notification, 'only_assigned'
+
+ issue = Issue.find(2)
+ issue.init_journal User.find(1)
+ issue.assigned_to = nil
+ issue.save!
+ assert_include user.mail, ActionMailer::Base.deliveries.last.bcc
+ end
+
def test_stale_issue_should_not_send_email_notification
ActionMailer::Base.deliveries.clear
issue = Issue.find(1)