-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for GRAILS-4981 "findBy in validation constraint causes error if …
…another instance is associated"
- Loading branch information
1 parent
28f4547
commit 9c87f77
Showing
2 changed files
with
75 additions
and
0 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
45 changes: 45 additions & 0 deletions
45
...test/org/codehaus/groovy/grails/orm/hibernate/CustomValidatorAndDynamicFinderTests.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,45 @@ | ||
package org.codehaus.groovy.grails.orm.hibernate | ||
|
||
import org.hibernate.FlushMode | ||
|
||
/** | ||
* @author Graeme Rocher | ||
* @since 1.1 | ||
*/ | ||
|
||
public class CustomValidatorAndDynamicFinderTests extends AbstractGrailsHibernateTests{ | ||
|
||
protected void onSetUp() { | ||
gcl.parseClass(''' | ||
import grails.persistence.* | ||
@Entity | ||
class Foo { | ||
String name | ||
Foo partner | ||
static constraints = { | ||
name(validator: {name, foo -> | ||
Foo similarFoo = Foo.findByNameIlike(name) | ||
if (similarFoo && similarFoo.id != foo.id) return ['similar'] | ||
}) | ||
} | ||
} | ||
''') | ||
} | ||
|
||
// test for GRAILS-4981 | ||
void testCustomValidatorWithFinder() { | ||
session.setFlushMode(FlushMode.AUTO) | ||
def Foo = ga.getDomainClass("Foo").clazz | ||
|
||
def foo = Foo.newInstance(name: 'partner1') | ||
assert foo.save() | ||
def partner = Foo.newInstance(name: 'partner2') | ||
assert partner.save() | ||
foo.partner = partner | ||
assert foo.save() | ||
|
||
} | ||
} |