Grails

Integration test - Calling render(template:'template') from a controller on a template with <g:sortableColumn> throws exception

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.2-M4
  • Fix Version/s: 1.2 final
  • Component/s: Testing
  • Labels:
    None
  • Testcase included:
    yes

Description

In my integration test, I get the above error when using "render(template:'/trip/list')" but not when using "render(view:'list')"

TripController.groovy
================
class TripController {
def list = { render(template:'/trip/list', model:[tripInstanceList: Trip.list(params), tripInstanceTotal: Trip.count()]) }
}

The above runs fine, with "grails run-app". However, "grails test-app" fails (happens in Grails 1.1 and Grails 1.2M4):

TripControllerTests.groovy
===================
class TripControllerTests extends GroovyTestCase {
void testList() { def tripController = new TripController() tripController.list() }
}

Error:
====

Error executing tag <g:sortableColumn>: org.codehaus.groovy.grails.web.mapping.exceptions.UrlMappingException: Unable to create URL for mapping [/(*)/(*)?/(*)?] and parameters [{sort=id, order=asc, action=list}]. Parameter [controller] is required, but was not specified! (F:/work/test_project/test-app/grails-app/views/trip/_list.gsp:5)

org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException: Error executing tag : org.codehaus.groovy.grails.web.mapping.exceptions.UrlMappingException: Unable to create URL for mapping [/(*)/(*)?/(*)?] and parameters [{sort=id, order=asc, action=list}]
. Parameter [controller] is required, but was not specified! (F:/work/test_project/test-app/grails-app/views/trip/_list.gsp:5)

However,

def list = { render(view:'list', model:[tripInstanceList: Trip.list(params), tripInstanceTotal: Trip.count()]) }

works, as does

def list = { [tripInstanceList: Trip.list(params), tripInstanceTotal: Trip.count()] }

Activity

Hide
Lari Hotari added a comment - - edited

There is a workaround. Set the controller name manually in your test.

import org.springframework.web.context.request.RequestContextHolder
.
.
.
RequestContextHolder.currentRequestAttributes().controllerName = "somecontroller"
Show
Lari Hotari added a comment - - edited There is a workaround. Set the controller name manually in your test.
import org.springframework.web.context.request.RequestContextHolder
.
.
.
RequestContextHolder.currentRequestAttributes().controllerName = "somecontroller"
Hide
Luke Daley added a comment -

I am pretty sure I have introduced this regression in the change to the GrailsTestSuite code.

Show
Luke Daley added a comment - I am pretty sure I have introduced this regression in the change to the GrailsTestSuite code.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: