Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getTotalCount() tests for sorting parameters (7.3.x backport) #1760

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add getTotalCount() tests for sorting parameters
This is to check that a getTotalCount() implementation should not
have sorting in the generated query. Otherwise, depending on the
database and its strictness configuration, the query might fail.
  • Loading branch information
darxriggs committed Oct 5, 2023
commit 12183b793ad97f2008d9ca39870c8ccd761b510e
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ class PagedResultSpec extends GormDatastoreSpec {
results.totalCount == 6
}

void "Test that a paged result list is returned from the list() method with pagination and sorting params"() {
given:"Some people"
createPeople()

when:"The list method is used with pagination params"
def results = Person.list(offset:2, max:2, sort:'firstName', order:'DESC')

then:"You get a paged result list back"
results.getClass().simpleName == 'PagedResultList' // Grails/Hibernate has a custom class in different package
results.size() == 2
results[0].firstName == "Homer"
results[1].firstName == "Fred"
results.totalCount == 6
}

void "Test that a getTotalCount will return 0 on empty result from the criteria"() {
given:"Some people"
createPeople()
Expand Down Expand Up @@ -57,6 +72,23 @@ class PagedResultSpec extends GormDatastoreSpec {
results.totalCount == 4
}

void "Test that a paged result list is returned from the critera with pagination and sorting params"() {
given:"Some people"
createPeople()

when:"The list method is used with pagination params"
def results = Person.createCriteria().list(offset:1, max:2, sort:'firstName', order:'DESC') {
eq 'lastName', 'Simpson'
}

then:"You get a paged result list back"
results.getClass().simpleName == 'PagedResultList' // Grails/Hibernate has a custom class in different package
results.size() == 2
results[0].firstName == "Lisa"
results[1].firstName == "Homer"
results.totalCount == 4
}

protected void createPeople() {
new Person(firstName: "Homer", lastName: "Simpson", age:45).save()
new Person(firstName: "Marge", lastName: "Simpson", age:40).save()
Expand Down