Project

General

Profile

Defect #21504 » 21504-recalculate_issue_priority_position_name_on_active_change.patch

Felix Schäfer, 2015-12-13 21:06

View differences:

app/models/issue.rb
810 810
  # Users the issue can be assigned to
811 811
  def assignable_users
812 812
    users = project.assignable_users.to_a
813
    users << author if author
813
    users << author if (author && !author.anonymous?)
814 814
    users << assigned_to if assigned_to
815 815
    users.uniq.sort
816 816
  end
app/models/issue_priority.rb
19 19
  has_many :issues, :foreign_key => 'priority_id'
20 20

  
21 21
  after_destroy {|priority| priority.class.compute_position_names}
22
  after_save {|priority| priority.class.compute_position_names if priority.position_changed? && priority.position}
22
  after_save {|priority| priority.class.compute_position_names if (priority.position_changed? && priority.position) || priority.active_changed?}
23 23

  
24 24
  OptionName = :enumeration_issue_priorities
25 25

  
test/unit/issue_priority_test.rb
99 99
    assert_equal %w(lowest default high4 high3 high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
100 100
  end
101 101

  
102
  def test_moving_a_priority_should_update_position_names
103
    prio = IssuePriority.first
104
    prio.move_to = 'lowest'
105
    prio.reload
106
    assert_equal 'highest', prio.position_name
107
  end
108

  
109
  def test_deactivating_a_priority_should_update_position_names
110
    prio = IssuePriority.active.order(:position).last
111
    prio.active = false
112
    prio.save
113
    assert_equal 'highest', IssuePriority.active.order(:position).last.position_name
114
  end
115

  
102 116
  def test_destroying_a_priority_should_update_position_names
103 117
    IssuePriority.find_by_position_name('highest').destroy
104 118
    assert_equal %w(lowest default high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
    (1-1/1)