Project

General

Profile

Patch #28494 » 0002-Recalculate-issue-priority-position-names-if-default.patch

Tomomi Yuzuriha, 2018-05-08 08:03

View differences:

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.saved_change_to_position? && priority.position) || priority.saved_change_to_active?}
22
  after_save {|priority| priority.class.compute_position_names if (priority.saved_change_to_position? && priority.position) || priority.saved_change_to_active? || priority.saved_change_to_is_default?}
23 23

  
24 24
  OptionName = :enumeration_issue_priorities
25 25

  
test/unit/issue_priority_test.rb
95 95
    assert_equal 'highest', IssuePriority.active.order(:position).last.position_name
96 96
  end
97 97

  
98
  def test_defaulting_a_priority_should_update_position_names
99
    prio = IssuePriority.first
100
    prio.is_default = true
101
    prio.save
102
    assert_equal %w(default high4 high3 high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
103
  end
104

  
98 105
  def test_destroying_a_priority_should_update_position_names
99 106
    IssuePriority.find_by_position_name('highest').destroy
100 107
    assert_equal %w(lowest default high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
(2-2/3)