You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by jd...@apache.org on 2026/04/08 04:44:51 UTC
(grails-core) branch expandedTests/GRAILS-10683 created (now 4348ccf2ff)
This is an automated email from the ASF dual-hosted git repository.
jdaugherty pushed a change to branch expandedTests/GRAILS-10683
in repository https://gitbox.apache.org/repos/asf/grails-core.git
at 4348ccf2ff GRAILS-10683 - improve rendering empty collections
This branch includes the following new commits:
new 4348ccf2ff GRAILS-10683 - improve rendering empty collections
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: GRAILS-10683 - improve rendering empty collections
Posted by jd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jdaugherty pushed a commit to branch expandedTests/GRAILS-10683
in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit 4348ccf2fff4ada5f0451f879b6dee537f84939b
Author: Jeff Scott Brown <jb...@gopivotal.com>
AuthorDate: Thu Feb 13 09:19:26 2014 -0600
GRAILS-10683 - improve rendering empty collections
---
.../plugins/web/rest/api/ControllersRestApi.groovy | 9 +++++++-
.../grails/rest/web/RespondMethodSpec.groovy | 26 +++++++++++++++++++++-
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/grails-plugin-rest/src/main/groovy/org/grails/plugins/web/rest/api/ControllersRestApi.groovy b/grails-plugin-rest/src/main/groovy/org/grails/plugins/web/rest/api/ControllersRestApi.groovy
index 0601253731..a8d30a55e2 100644
--- a/grails-plugin-rest/src/main/groovy/org/grails/plugins/web/rest/api/ControllersRestApi.groovy
+++ b/grails-plugin-rest/src/main/groovy/org/grails/plugins/web/rest/api/ControllersRestApi.groovy
@@ -141,7 +141,14 @@ class ControllersRestApi {
return render(controller,[status: statusCode ?: 404 ])
}
-
+ if(value instanceof Collection &&
+ value.size() == 0 &&
+ mimeType &&
+ mimeType != MimeType.ALL &&
+ mimeType != MimeType.HTML) {
+ return render(controller,[status: statusCode ?: HttpStatus.NO_CONTENT.value() ])
+ }
+
final valueType = value.getClass()
if (registry.isContainerType(valueType)) {
renderer = registry.findContainerRenderer(mimeType,valueType, value)
diff --git a/grails-test-suite-web/src/test/groovy/grails/rest/web/RespondMethodSpec.groovy b/grails-test-suite-web/src/test/groovy/grails/rest/web/RespondMethodSpec.groovy
index f8a59d0fbf..2fa5c1af35 100644
--- a/grails-test-suite-web/src/test/groovy/grails/rest/web/RespondMethodSpec.groovy
+++ b/grails-test-suite-web/src/test/groovy/grails/rest/web/RespondMethodSpec.groovy
@@ -22,11 +22,12 @@ import grails.test.mixin.Mock
import grails.test.mixin.TestFor
import org.codehaus.groovy.grails.plugins.web.mimes.MimeTypesFactoryBean
-import org.codehaus.groovy.grails.web.mime.MimeType
import org.codehaus.groovy.grails.support.proxy.ProxyHandler
+import org.codehaus.groovy.grails.web.mime.MimeType
import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes
import org.springframework.web.servlet.ModelAndView
+import spock.lang.Issue
import spock.lang.Specification
@TestFor(BookController)
@@ -232,6 +233,29 @@ class RespondMethodSpec extends Specification{
modelAndView.model.extra == true
modelAndView.viewName == 'showWithModel'
}
+
+ @Issue('GRAILS-10683')
+ void "Test responding to a REST call with an empty collection"() {
+
+ when:"The respond method is used to render an empty collection in XML"
+ response.format = 'xml'
+ controller.index()
+
+ then:"The response status should be 204"
+ response.status == 204
+ !model
+ response.contentType == null
+ }
+
+ @Issue('GRAILS-10683')
+ void "Test responding to an HTML call with an empty collection"() {
+ when:"The respond method is used to render an empty collection in HTML"
+ response.format = 'html'
+ controller.index()
+
+ then:"The response status should be 200"
+ response.status == 200
+ }
}
@Artefact("Controller")