-
Notifications
You must be signed in to change notification settings - Fork 42
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
Regression in the Grails 4.0.6 calling response.json in Specification #253
Comments
This error happens also for our application which is on 4.0.5 currently, most of the tests depends on response.json breaks due to this issue. Haven't had time look into this issue. |
This is happening because of the change in #235 which now correctly sets the ModelAndViews in the request attributes. But, we also removed the following line from the
We removed this to avoid calling the Right now, I am not sure what would be the fix for this but I will spend some more time next week figure out a solution. |
@puneetbehl we got hit with this as well when we upgraded grails-view to 2.0.4 - any workaround available as its failing a lot of our test. In addition do you know if its only effecting unit tests? |
@amadfida Yes, it should only affect unit tests because the DispatcherServlet is not executed during the same. |
I have created this /**
* Due to a change in Grails DefaultViewRenderer it does no longer do the actual view rendering to the response
* thus leading to errors in ControllerUnitTests that expect the response being fully written.
* See https://github.com/grails/grails-views/commit/25cab090bfaf6d2264b264c7248680b4f611c806#diff-bab08f900cdc8789160b7e74825cf68433382be9d9a632842136ad2fd91dd46c
*
* Calling renderGsonView() after calling the controller in the unit-test will fix this issue. Not super pretty, but it works.
*/
trait JsonControllerUnitTest implements GrailsWebUnitTest {
void renderGsonView() {
ModelAndView modelView =(request.getAttribute(GrailsApplicationAttributes.CONTROLLER) as Controller)?.modelAndView
modelView?.view?.render(modelView?.model, request, response)
}
} |
When calling
response.json
in a Specification to test a RestfulController thatrespond
with an empty list, an error occurs if you have created a default/object/_object.gson
view such as:Condition failed with Exception:
Without the default GSON view, it works ok.
If you change the grails version to 4.0.5, the test will pass successfully, so this seems to be a regression in 4.0.6.
Task List
Steps to Reproduce
Download the sample application and run:
The key is to call respond for a JSON format without an explicit GSON view to render.
Expected Behaviour
response.json
should succeed and essentially return empty (size == 0) as it does in 4.0.5.Actual Behaviour
An error occurs when
JSON.parse()
is called b/c the output stream has an empty string instead of empty array syntax:""
vs"[]"
. This seems to be a result of the_object.gson
being used, which causes the renderer to follow a different path.Environment Information
Example Application
The text was updated successfully, but these errors were encountered: