You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by ja...@apache.org on 2026/05/29 02:21:52 UTC
(grails-core) branch test/map-sort-coverage created (now 0c61ec0e42)
This is an automated email from the ASF dual-hosted git repository.
jamesfredley pushed a change to branch test/map-sort-coverage
in repository https://gitbox.apache.org/repos/asf/grails-core.git
at 0c61ec0e42 Add test coverage for Map-based multi-field sort
This branch includes the following new commits:
new 0c61ec0e42 Add test coverage for Map-based multi-field sort
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(grails-core) 01/01: Add test coverage for Map-based multi-field sort
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jamesfredley pushed a commit to branch test/map-sort-coverage
in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit 0c61ec0e427f827320937b83557282debbafa24f
Author: James Fredley <ja...@users.noreply.github.com>
AuthorDate: Thu May 28 22:21:32 2026 -0400
Add test coverage for Map-based multi-field sort
Adds OrderBySpec coverage for passing a Map to the sort argument, which
exercises DynamicFinder.applySortForMap() through both list() and dynamic
finders. This multi-field sort path (one direction per field) was
documented in #15599 but had no test coverage.
Assisted-by: claude-code:claude-4.8-opus
---
.../org/grails/datastore/gorm/OrderBySpec.groovy | 36 ++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/grails-datamapping-core-test/src/test/groovy/org/grails/datastore/gorm/OrderBySpec.groovy b/grails-datamapping-core-test/src/test/groovy/org/grails/datastore/gorm/OrderBySpec.groovy
index 094fb642c5..0c22e04859 100644
--- a/grails-datamapping-core-test/src/test/groovy/org/grails/datastore/gorm/OrderBySpec.groovy
+++ b/grails-datamapping-core-test/src/test/groovy/org/grails/datastore/gorm/OrderBySpec.groovy
@@ -68,4 +68,40 @@ class OrderBySpec extends GrailsDataTckSpec<GrailsDataCoreTckManager> {
then:
45 == results[0].age
}
+
+ def 'Test multi-field sort ascending with a Map passed to list()'() {
+ given: 'additional people sharing an age so the secondary sort field is observable'
+ new TestEntity(name: "Amy", age: 40, child: new ChildEntity(name: "Amy Child")).save()
+ new TestEntity(name: "Zoe", age: 40, child: new ChildEntity(name: "Zoe Child")).save()
+
+ when: 'sorting by age ascending and then name ascending'
+ def results = TestEntity.list(sort: [age: 'asc', name: 'asc'])
+
+ then: 'entries with the same age are ordered by name ascending'
+ results*.name == ["Amy", "Bob", "Zoe", "Fred", "Barney", "Frank", "Joe", "Ernie"]
+ }
+
+ def 'Test multi-field sort with mixed directions in a Map passed to list()'() {
+ given: 'additional people sharing an age so the secondary sort field is observable'
+ new TestEntity(name: "Amy", age: 40, child: new ChildEntity(name: "Amy Child")).save()
+ new TestEntity(name: "Zoe", age: 40, child: new ChildEntity(name: "Zoe Child")).save()
+
+ when: 'sorting by age ascending and then name descending'
+ def results = TestEntity.list(sort: [age: 'asc', name: 'desc'])
+
+ then: 'entries with the same age are ordered by name descending'
+ results*.name == ["Zoe", "Bob", "Amy", "Fred", "Barney", "Frank", "Joe", "Ernie"]
+ }
+
+ def 'Test multi-field sort with a Map passed to a dynamic finder'() {
+ given: 'additional people sharing an age so the secondary sort field is observable'
+ new TestEntity(name: "Amy", age: 40, child: new ChildEntity(name: "Amy Child")).save()
+ new TestEntity(name: "Zoe", age: 40, child: new ChildEntity(name: "Zoe Child")).save()
+
+ when: 'sorting by age ascending and then name descending via a dynamic finder'
+ def results = TestEntity.findAllByAgeGreaterThanEquals(40, [sort: [age: 'asc', name: 'desc']])
+
+ then: 'the multi-field Map sort is applied to the dynamic finder results'
+ results*.name == ["Zoe", "Bob", "Amy", "Fred", "Barney", "Frank", "Joe", "Ernie"]
+ }
}