1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-01-31 19:47:14 +00:00

Fix NoMethodError in IssuePriority#high and #low when no default or active priorities exist (#42066).

Patch by Go MAEDA (user:maeda).


git-svn-id: https://svn.redmine.org/redmine/trunk@23431 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA 2025-01-05 03:04:59 +00:00
parent 32203e4ebb
commit 3712ecb01f
2 changed files with 22 additions and 2 deletions

View File

@ -60,11 +60,15 @@ class IssuePriority < Enumeration
end
def high?
position > self.class.default_or_middle.position
return false unless (baseline_position = self.class.default_or_middle&.position)
position > baseline_position
end
def low?
position < self.class.default_or_middle.position
return false unless (baseline_position = self.class.default_or_middle&.position)
position < baseline_position
end
# Updates position_name for active priorities

View File

@ -156,4 +156,20 @@ class IssuePriorityTest < ActiveSupport::TestCase
IssuePriority.find_by_position_name('highest').destroy
assert_equal %w(lowest default high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
end
def test_high_should_return_false_when_no_default_priority_and_no_active_priorities
IssuePriority.update_all(active: false, is_default: false)
priority = IssuePriority.order(:position).last # Highest priority
assert_nothing_raised do
assert_equal false, priority.high?
end
end
def test_low_should_return_false_when_no_default_priority_and_no_active_priorities
IssuePriority.update_all(active: false, is_default: false)
priority = IssuePriority.order(:position).first # Lowest priority
assert_nothing_raised do
assert_equal false, priority.low?
end
end
end