Grails
  1. Grails
  2. GRAILS-8700

Calling g:render more than once in the same unit test renders the same template repeatedly

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0 final
    • Fix Version/s: 2.0.1
    • Component/s: Testing, View technologies
    • Labels:
      None
    • Testcase included:
      yes

      Description

      In a unit test that directly or indirectly calls g:render more than once the template used for the first call is used for all subsequent calls as well regardless of the template requested. The model passed to the render tag is handled correctly on each occasion.

      Please see attached project that has a single unit test that demonstrates the problem.

        Activity

        Hide
        Robert Fletcher added a comment - - edited

        Using a debugger shows that this is not caused by key collision in GroovyPagesTemplateRenderer.findAndCacheTemplate as I initially suspected.

        Show
        Robert Fletcher added a comment - - edited Using a debugger shows that this is not caused by key collision in GroovyPagesTemplateRenderer.findAndCacheTemplate as I initially suspected.
        Hide
        Robert Fletcher added a comment -

        The collision is further on. In GroovyPagesTemplateEngine.createTemplate a cache key is generated using:

        establishPageName(resource, getPathForResource(resource))
        

        which when passed an instance of org.springframework.core.io.ByteArrayResource will always return the same value: "resource loaded from byte array".

        I think this can be fixed by modifying GroovyPageUnitTestResourceLoader.getResource to use the 2 argument form of the ByteArrayResource constructor so that a unique description is assigned to the resource rather than the default "resource loaded from byte array" string.

        Show
        Robert Fletcher added a comment - The collision is further on. In GroovyPagesTemplateEngine.createTemplate a cache key is generated using: establishPageName(resource, getPathForResource(resource)) which when passed an instance of org.springframework.core.io.ByteArrayResource will always return the same value: "resource loaded from byte array" . I think this can be fixed by modifying GroovyPageUnitTestResourceLoader.getResource to use the 2 argument form of the ByteArrayResource constructor so that a unique description is assigned to the resource rather than the default "resource loaded from byte array" string.
        Show
        Robert Fletcher added a comment - Fix in master: https://github.com/grails/grails-core/commit/c1d7cd2c56d381147ebf20d8511b96e529aa8cd5 Fix in 2.0.x: https://github.com/grails/grails-core/commit/6456613813e779d64f4b5890197f012162518f67

          People

          • Assignee:
            Robert Fletcher
            Reporter:
            Robert Fletcher
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development