Skip to content

Commit

Permalink
Merge pull request #310 from yakworks/nameCodeDescription-constraints
Browse files Browse the repository at this point in the history
Name code description constraints
  • Loading branch information
jdabal committed Jun 15, 2021
2 parents 8763944 + aca4aac commit bc146de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ trait NameCodeDescription extends NameDescription {
]

void beforeValidate() {
if(!this.name) this.name = code.replaceAll('-',' ')
if(!this.name && this.code) this.name = code.replaceAll('-',' ')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ class NameCodeDescriptionSpec extends Specification implements DomainRepoTest<T
'a-b' == tag.code
}

void "test no code or name"() {
when: 'no code so cannot be created'
def tag = new Tag(entityName: 'Attachment')

then: 'should fail'
!tag.validate()
}

void "code regex validation should succeed"() {
when:
def tag = Tag.create('code': 'aA12-_', name: 'tag', entityName: 'Attachment')
Expand Down

0 comments on commit bc146de

Please sign in to comment.