forked from spring-attic/grails-data-mapping
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 spring-attic#23 from zyro23/GRAILS-9750
potential fix for GRAILS-9750
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...-gorm-test/src/test/groovy/org/grails/datastore/gorm/DetachedCriteriaJpaEntitySpec.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,57 @@ | ||
package org.grails.datastore.gorm | ||
|
||
import grails.gorm.tests.GormDatastoreSpec | ||
|
||
import javax.persistence.Entity | ||
|
||
import org.grails.datastore.gorm.query.transform.ApplyDetachedCriteriaTransform | ||
|
||
import spock.lang.Issue | ||
|
||
/** | ||
* ensure that detached criteria ast transformations work on annotated jpa entities | ||
*/ | ||
@ApplyDetachedCriteriaTransform | ||
@Issue('GRAILS-9750') | ||
class DetachedCriteriaJpaEntitySpec extends GormDatastoreSpec { | ||
|
||
@Override | ||
List getDomainClasses() { | ||
return [Todo] | ||
} | ||
|
||
def "test a where query on a jpa entity"() { | ||
given: "a todo" | ||
new Todo(title: "todo").save(flush: true) | ||
session.clear() | ||
|
||
when: "query without restrictions" | ||
def results = Todo.findAll {} | ||
|
||
then: "one todo" | ||
results.size() == 1 | ||
|
||
when: "query with matching restrictions" | ||
results = Todo.findAll { | ||
title == "todo" | ||
} | ||
|
||
then: "one todo" | ||
results.size() == 1 | ||
|
||
when: "query with not matching restrictions" | ||
results = Todo.findAll { | ||
title == "no match" | ||
} | ||
|
||
then: "no todo" | ||
results.size() == 0 | ||
} | ||
|
||
} | ||
|
||
@javax.persistence.Entity | ||
class Todo { | ||
Long id | ||
String title | ||
} |
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