diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-18 11:11:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-18 11:11:44 +0000 |
commit | 25989ab7ef1a444ed2abd5479f176d58e1d9462a (patch) | |
tree | 271bb24f3c7178f320cb9de0be0833a285327d09 /app/models/description_version.rb | |
parent | 9bbb32b29703f3ce33dd35d5101145774b793a6d (diff) | |
download | gitlab-ce-25989ab7ef1a444ed2abd5479f176d58e1d9462a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/description_version.rb')
-rw-r--r-- | app/models/description_version.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/models/description_version.rb b/app/models/description_version.rb new file mode 100644 index 00000000000..abab7f94212 --- /dev/null +++ b/app/models/description_version.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class DescriptionVersion < ApplicationRecord + belongs_to :issue + belongs_to :merge_request + + validate :exactly_one_issuable + + def self.issuable_attrs + %i(issue merge_request).freeze + end + + private + + def exactly_one_issuable + issuable_count = self.class.issuable_attrs.count { |attr| self["#{attr}_id"] } + + errors.add(:base, "Exactly one of #{self.class.issuable_attrs.join(', ')} is required") if issuable_count != 1 + end +end + +DescriptionVersion.prepend_if_ee('EE::DescriptionVersion') |