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.
Support for query-by-example across all the GORM implementations
- Loading branch information
1 parent
9968b73
commit 2b898b0
Showing
5 changed files
with
208 additions
and
33 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
54 changes: 54 additions & 0 deletions
54
grails-datastore-gorm-tck/src/main/groovy/grails/gorm/tests/FindByExampleSpec.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,54 @@ | ||
package grails.gorm.tests | ||
|
||
class FindByExampleSpec extends GormDatastoreSpec{ | ||
|
||
def "Test findAll by example"() { | ||
given: | ||
new Plant(name:"Pineapple", goesInPatch:false).save() | ||
new Plant(name:"Cabbage", goesInPatch:true).save() | ||
new Plant(name:"Kiwi", goesInPatch:false).save(flush:true) | ||
session.clear() | ||
when: | ||
def results = Plant.findAll(new Plant(goesInPatch:false)) | ||
then: | ||
results.size() == 2 | ||
"Pineapple" in results*.name | ||
"Kiwi" in results*.name | ||
|
||
when: | ||
results = Plant.findAll(new Plant(name:"Cabbage",goesInPatch:false)) | ||
|
||
then: | ||
results.size() == 0 | ||
|
||
when: | ||
results = Plant.findAll(new Plant(name:"Cabbage",goesInPatch:true)) | ||
|
||
then: | ||
results.size() == 1 | ||
"Cabbage" in results*.name | ||
|
||
} | ||
|
||
|
||
def "Test find by example"() { | ||
given: | ||
new Plant(name:"Pineapple", goesInPatch:false).save() | ||
new Plant(name:"Cabbage", goesInPatch:true).save() | ||
new Plant(name:"Kiwi", goesInPatch:false).save(flush:true) | ||
session.clear() | ||
|
||
when: | ||
Plant result = Plant.find(new Plant(name:"Cabbage",goesInPatch:false)) | ||
|
||
then: | ||
result == null | ||
|
||
when: | ||
result = Plant.find(new Plant(name:"Cabbage",goesInPatch:true)) | ||
|
||
then: | ||
result != null | ||
result.name == "Cabbage" | ||
} | ||
} |
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
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
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