]> source.dussan.org Git - redmine.git/commitdiff
Merged r22895 and r22896 from trunk to 5.1-stable (#40860).
authorGo MAEDA <maeda@farend.jp>
Thu, 27 Jun 2024 04:49:38 +0000 (04:49 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 27 Jun 2024 04:49:38 +0000 (04:49 +0000)
git-svn-id: https://svn.redmine.org/redmine/branches/5.1-stable@22900 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
test/unit/issue_test.rb

index dddb9df6b43269de52fcf415937f069c23803259..6e69b5560c49e065cfa39905f9e38bde761754cc 100644 (file)
@@ -2069,7 +2069,7 @@ class Issue < ActiveRecord::Base
       tracker.disabled_core_fields.each do |attribute|
         send "#{attribute}=", nil
       end
-      self.priority_id ||= IssuePriority.default&.id || IssuePriority.active.first.id
+      self.priority_id ||= IssuePriority.default&.id || IssuePriority.active.first&.id
       self.done_ratio ||= 0
     end
   end
index 34739b62f46e8478fded4862d8665a379e141182..3be86a1a41b76647eb06debcf7022afd8276aea6 100644 (file)
@@ -83,6 +83,16 @@ class IssueTest < ActiveSupport::TestCase
     assert_save issue
   end
 
+  def test_create_with_no_priority_defined
+    IssuePriority.delete_all
+    issue = Issue.new(
+      project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create_with_no_priority_defined'
+    )
+
+    assert_nothing_raised {assert_not issue.save}
+    assert_include 'Priority cannot be blank', issue.errors.full_messages
+  end
+
   def test_default_priority_should_be_set_when_priority_field_is_disabled
     tracker = Tracker.find(1)
     tracker.core_fields = tracker.core_fields - ['priority_id']