Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

closes #6 thx man. Offset has a similar problem

  • Loading branch information...
commit 7b658b7968a768a80fe48905bba57b825acb1c6c 1 parent ac2a083
@fabiooshiro authored
View
2  PlasticCriteriaGrailsPlugin.groovy
@@ -1,5 +1,5 @@
class PlasticCriteriaGrailsPlugin {
- def version = "0.7"
+ def version = "0.8"
def grailsVersion = "1.3 > *"
def pluginExcludes = [
'grails-app/domain/**',
View
41 src/groovy/plastic/criteria/CriteriaDocTests.groovy
@@ -544,4 +544,45 @@ class CriteriaDocTests {
assert 'Soleil levant 1' == rs[2].name
}
+ // next release 0.8
+ void test_bug_list_size_smaller_than_max_results(){
+ def monet = new Artist(name: 'Monet').save()
+ new Portrait(artist: monet, name: 'Soleil levant 2').save()
+ new Portrait(artist: monet, name: 'Soleil levant 3').save()
+ new Portrait(artist: monet, name: 'Soleil levant 1').save()
+ def rs = Portrait.createCriteria().list([sort: 'name', order: 'desc']){
+ maxResults(5)
+ }
+ assert 3 == rs.size()
+ }
+
+ void test_list_size_smaller_than_offset_case1(){
+ def monet = new Artist(name: 'Monet').save()
+ new Portrait(artist: monet, name: 'Soleil levant 1').save()
+ def rs = Portrait.createCriteria().list([max: 3, offset: 5]){
+ eq('artist', monet)
+ }
+ assert 0 == rs.size()
+ }
+
+ void test_list_size_smaller_than_offset_case2(){
+ def monet = new Artist(name: 'Monet').save()
+ new Portrait(artist: monet, name: 'Soleil levant 1').save()
+ new Portrait(artist: monet, name: 'Soleil levant 2').save()
+ def rs = Portrait.createCriteria().list([max: 3, offset: 1]){
+ eq('artist', monet)
+ }
+ assert 1 == rs.size()
+ assert 'Soleil levant 2' == rs[0].name
+ }
+
+ void test_list_size_smaller_than_offset_case3(){
+ def monet = new Artist(name: 'Monet').save()
+ new Portrait(artist: monet, name: 'Soleil levant 1').save()
+ new Portrait(artist: monet, name: 'Soleil levant 2').save()
+ def rs = Portrait.createCriteria().list([max: 3, offset: 2]){
+ eq('artist', monet)
+ }
+ assert 0 == rs.size()
+ }
}
View
9 src/groovy/plastic/criteria/PlasticCriteria.groovy
@@ -239,10 +239,11 @@ class PlasticCriteria {
}
def _maxAndOffset(ls){
- if(_offset) ls = ls[_offset..-1]
- if(_maxRes) ls = ls[0..(_maxRes -1)]
- ls
- }
+ if(_offset >= ls.size()) return []
+ if(_offset) ls = ls[_offset..-1]
+ if(_maxRes) ls = ls[0..(Math.min(_maxRes,ls.size())-1)]
+ ls
+ }
def _handleUniqueResult(ls){
if(uniqueResult){
Please sign in to comment.
Something went wrong with that request. Please try again.