This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from eugenypozharsky/GRAILS-9936
(GRAILS-9936) Fixed unique constraint
- Loading branch information
Showing
2 changed files
with
55 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...nate/src/test/groovy/grails/gorm/tests/UniqueConstraintGroupWhithowtVersioningSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package grails.gorm.tests | ||
|
||
import grails.persistence.Entity | ||
import spock.lang.Issue | ||
|
||
class UniqueConstraintGroupWithoutVersioningSpec extends GormDatastoreSpec{ | ||
|
||
@Issue('GRAILS-9936') | ||
void "Test transient uniqueness handling"() { | ||
given:"Some linked objects" | ||
def a2 = new UniqueConstraintTestParentEntity(prop: "prop1") | ||
a2.id = 1 | ||
def b3 = new UniqueConstraintTestChildEntity(prop: "b1", a: a2) | ||
a2.bs = [b3] | ||
when:"validate child item" | ||
def processed = true | ||
try { | ||
b3.validate() | ||
} catch (Exception ex) { | ||
processed = false | ||
} | ||
then:"no exception is thrown" | ||
processed | ||
} | ||
|
||
@Override | ||
List getDomainClasses() { | ||
[UniqueConstraintTestParentEntity, UniqueConstraintTestChildEntity] | ||
} | ||
|
||
def setup() {} | ||
} | ||
|
||
@Entity | ||
class UniqueConstraintTestParentEntity { | ||
Long id | ||
String prop | ||
static hasMany = [bs: UniqueConstraintTestChildEntity] | ||
static mapping = { | ||
version false | ||
id generator: "assigned" | ||
} | ||
} | ||
|
||
@Entity | ||
class UniqueConstraintTestChildEntity { | ||
String prop | ||
static belongsTo = [a: UniqueConstraintTestParentEntity] | ||
|
||
static constraints = { | ||
prop unique:["a"] | ||
} | ||
} |