Add uniqueness validation to labels
LabelLink
model is not validating uniqueness of labels on target relationship,
which makes possible to add labels twice to the same issuable.
Fortunately this is being prevented on Issuable::BaseService
so it is not causing us any problems.
For now we can only reproduce this when writing specs using factories. Check !40465 (comment 402635353).
Maybe we should consider to add a validation at model level. Something like:
validates :label, uniqueness: { scope: [:target_type, :target_id] }, unless: -> :importing?
We could also consider adding a validation to prevent project labels being added to epics.
Edited by Felipe Artur