]> source.dussan.org Git - redmine.git/commitdiff
Don't require category or target version when they are not available (#20583).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 24 Oct 2015 06:22:55 +0000 (06:22 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 24 Oct 2015 06:22:55 +0000 (06:22 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@14733 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index d07041ff1747556d0d7c767a3e088ae1d717c0e6..9301dc9f7ca180c873166d2605b3cba6560233a3 100644 (file)
@@ -677,6 +677,8 @@ class Issue < ActiveRecord::Base
         end
       else
         if respond_to?(attribute) && send(attribute).blank? && !disabled_core_fields.include?(attribute)
+          next if attribute == 'category_id' && project.try(:issue_categories).blank?
+          next if attribute == 'fixed_version_id' && assignable_versions.blank?
           errors.add attribute, :blank
         end
       end
index 4b9fbda0b1fa3c753b1168890bfb98f090a936c0..1da9f71e23c426eeee9f9997259a345c0d2448bd 100644 (file)
@@ -926,6 +926,30 @@ class IssueTest < ActiveSupport::TestCase
     assert issue.save
   end
 
+  def test_category_should_not_be_required_if_project_has_no_categories
+    Project.find(1).issue_categories.delete_all
+    WorkflowPermission.delete_all
+    WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
+      :role_id => 1, :field_name => 'category_id',:rule => 'required')
+    user = User.find(2)
+
+    issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1,
+                      :subject => 'Required fields', :author => user)
+    assert_save issue
+  end
+
+  def test_fixed_version_should_not_be_required_no_assignable_versions
+    Version.delete_all
+    WorkflowPermission.delete_all
+    WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
+      :role_id => 1, :field_name => 'fixed_version_id',:rule => 'required')
+    user = User.find(2)
+
+    issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1,
+                      :subject => 'Required fields', :author => user)
+    assert_save issue
+  end
+
   def test_required_custom_field_that_is_not_visible_for_the_user_should_not_be_required
     CustomField.delete_all
     field = IssueCustomField.generate!(:is_required => true, :visible => false, :role_ids => [1], :trackers => Tracker.all, :is_for_all => true)