]> source.dussan.org Git - redmine.git/commitdiff
Improved @fixed_version_id@ validation (#37171).
authorMarius Balteanu <marius.balteanu@zitec.com>
Thu, 16 Jun 2022 15:13:09 +0000 (15:13 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Thu, 16 Jun 2022 15:13:09 +0000 (15:13 +0000)
Patch by Holger Just.

git-svn-id: https://svn.redmine.org/redmine/trunk@21638 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 4e4355f564d3d3e73827c26297209c2b523cfdc0..84907a475f55e99455dd7de73fe767fa323034d0 100644 (file)
@@ -751,8 +751,8 @@ class Issue < ActiveRecord::Base
       errors.add :start_date, :earlier_than_minimum_start_date, :date => format_date(soonest_start)
     end
 
-    if project && fixed_version
-      if !assignable_versions.include?(fixed_version)
+    if project && fixed_version_id
+      if fixed_version.nil? || assignable_versions.exclude?(fixed_version)
         errors.add :fixed_version_id, :inclusion
       elsif reopening? && fixed_version.closed?
         errors.add :base, I18n.t(:error_can_not_reopen_issue_on_closed_version)
index 0c09ef5e100323a0ab60835f1cdf74376c45e696..f054cee9659f9c22c0e9ac2ca79b2a0815de935b 100644 (file)
@@ -1650,6 +1650,14 @@ class IssueTest < ActiveSupport::TestCase
     assert_equal ['open'], issue.assignable_versions.collect(&:status).uniq
   end
 
+  def test_should_not_be_able_to_set_an_invalid_version_id
+    issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1,
+                      :status_id => 1, :fixed_version_id => 424242,
+                      :subject => 'New issue')
+    assert !issue.save
+    assert_not_equal [], issue.errors[:fixed_version_id]
+  end
+
   def test_should_not_be_able_to_assign_a_new_issue_to_a_closed_version
     issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1,
                       :status_id => 1, :fixed_version_id => 1,