0003-Add-IssuePriority-high-and-low-helpers.patch

Jan from Planio www.plan.io, 2020-01-07 06:23

Download (2.57 KB)

View differences:

app/models/issue_priority.rb
54 54
    end
55 55
  end
56 56

  
57
  def high?
58
    position > self.class.default_or_middle.position
59
  end
60

  
61
  def low?
62
    position < self.class.default_or_middle.position
63
  end
64

  
57 65
  # Updates position_name for active priorities
58 66
  # Called from migration 20121026003537_populate_enumerations_position_name
59 67
  def self.compute_position_names
test/unit/issue_priority_test.rb
90 90
    assert_equal %w(lowest low2 default high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
91 91
  end
92 92

  
93
  def test_low_high_helpers
94
    IssuePriority.delete_all
95

  
96
    priorities = [1, 2, 3, 4, 5, 6].map {|i| IssuePriority.create!(:name => "P#{i}")}
97

  
98
    middle = IssuePriority.find_by_position(3)
99

  
100
    [1, 2].each do |p|
101
      assert IssuePriority.find_by_position(p).low?
102
      assert !IssuePriority.find_by_position(p).high?
103
    end
104

  
105
    assert !middle.high?
106
    assert !middle.low?
107

  
108
    [4, 5, 6].each do |p|
109
      assert IssuePriority.find_by_position(p).high?
110
      assert !IssuePriority.find_by_position(p).low?
111
    end
112

  
113
    default = IssuePriority.find_by_position(5)
114
    default.update_attributes is_default: true
115

  
116
    [1, 2, 3, 4].each do |p|
117
      assert IssuePriority.find_by_position(p).low?
118
      assert !IssuePriority.find_by_position(p).high?
119
    end
120

  
121
    assert !default.high?
122
    assert !default.low?
123

  
124
    [6].each do |p|
125
      assert IssuePriority.find_by_position(p).high?
126
      assert !IssuePriority.find_by_position(p).low?
127
    end
128
  end
129

  
93 130
  def test_adding_a_priority_should_update_position_names
94 131
    priority = IssuePriority.create!(:name => 'New')
95 132
    assert_equal %w(lowest default high4 high3 high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
96
-