diff --git a/app/models/issue.rb b/app/models/issue.rb index ec6e8a12ac2d2982bdd8c5e742d6b3d4cb3ec653..48702fab902746523510623e7c60db8d3a4ec7a2 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -117,7 +117,7 @@ def most_recent validates :confidential, inclusion: { in: [true, false], message: 'must be a boolean' } validate :allowed_work_item_type_change, on: :update, if: :work_item_type_id_changed? - validate :due_date_after_start_date + validate :due_date_after_start_date, if: :validate_due_date? validate :parent_link_confidentiality alias_attribute :external_author, :service_desk_reply_to @@ -891,6 +891,10 @@ def linked_issues_select 'issue_links.created_at as issue_link_created_at', 'issue_links.updated_at as issue_link_updated_at']) end + + def validate_due_date? + true + end end Issue.prepend_mod_with('Issue') diff --git a/ee/app/models/ee/work_item.rb b/ee/app/models/ee/work_item.rb index f597ebd825dddf67b7daa94009df96a9f7148704..cc908110f49ece7694a65d7cb4185edd14da5ee2 100644 --- a/ee/app/models/ee/work_item.rb +++ b/ee/app/models/ee/work_item.rb @@ -135,5 +135,12 @@ def allowed_work_item_type_change def previous_type_was_epic? changes["work_item_type_id"].first == ::WorkItems::Type.default_by_type(:epic).id end + + override :validate_due_date? + def validate_due_date? + return false if epic_work_item? + + super + end end end diff --git a/ee/spec/models/work_item_spec.rb b/ee/spec/models/work_item_spec.rb index 2420ca038ec7a32ac981ba23b1649c9e2aa6385c..2f554617efe2a74fbe5ce750a58aa3c05bd04b39 100644 --- a/ee/spec/models/work_item_spec.rb +++ b/ee/spec/models/work_item_spec.rb @@ -21,6 +21,28 @@ .inverse_of(:work_item) end + describe 'custom validations' do + subject(:valid?) { work_item.valid? } + + describe 'due_date_after_start_date' do + context 'when type is epic' do + context 'when both values are not present' do + let(:work_item) { build(:work_item, :epic, namespace: reusable_group) } + + it { is_expected.to be_truthy } + end + + context 'when due date is before start date' do + let(:work_item) do + build(:work_item, :epic, namespace: reusable_group, due_date: 1.week.ago, start_date: 1.week.from_now) + end + + it { is_expected.to be_truthy } + end + end + end + end + describe '#supported_quick_action_commands' do subject { work_item.supported_quick_action_commands }