Commit f935b688 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'db/design-management-version-issue-validation' into 'master'

Enforce every design version belongs to an issue with a model validation

See merge request gitlab-org/gitlab-ee!15786
parents 021744ae ca7403d0
......@@ -37,6 +37,10 @@ module DesignManagement
validates :designs, presence: true
validates :sha, presence: true
validates :sha, uniqueness: { case_sensitive: false, scope: :issue_id }
# We are not validating the issue object as it incurs an extra query to fetch
# the record from the DB. Instead, we rely on the foreign key constraint to
# ensure referential integrity.
validates :issue_id, presence: true
sha_attribute :sha
......
......@@ -28,6 +28,7 @@ describe DesignManagement::Version do
it { is_expected.to be_valid }
it { is_expected.to validate_presence_of(:sha) }
it { is_expected.to validate_presence_of(:designs) }
it { is_expected.to validate_presence_of(:issue_id) }
it { is_expected.to validate_uniqueness_of(:sha).scoped_to(:issue_id).case_insensitive }
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment