Skip to content

Commit 6d28243

Browse files
committed
Merge branch '2.1.x' into 2.2.x
2 parents e9f5de7 + c94c133 commit 6d28243

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

grails-plugin-testing/src/main/groovy/grails/test/mixin/web/GroovyPageUnitTestMixin.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.codehaus.groovy.grails.commons.GrailsTagLibClass
2323
import org.codehaus.groovy.grails.commons.TagLibArtefactHandler
2424
import org.codehaus.groovy.grails.commons.metaclass.MetaClassEnhancer
2525
import org.codehaus.groovy.grails.plugins.web.api.TagLibraryApi
26+
import org.codehaus.groovy.grails.web.pages.GroovyPageRequestBinding
2627
import org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine
2728
import org.codehaus.groovy.grails.web.pages.TagLibraryLookup
2829
import org.codehaus.groovy.grails.web.plugins.support.WebMetaUtils;
@@ -60,7 +61,7 @@ class GroovyPageUnitTestMixin extends ControllerUnitTestMixin {
6061
@Before
6162
void bindGrailsWebRequest() {
6263
super.bindGrailsWebRequest()
63-
pageScope = new GroovyPageBinding()
64+
pageScope = new GroovyPageBinding(new GroovyPageRequestBinding(webRequest))
6465
request.setAttribute(GrailsApplicationAttributes.PAGE_SCOPE, pageScope)
6566

6667
}

grails-plugin-testing/src/main/groovy/org/codehaus/groovy/grails/compiler/injection/test/TestForTransformation.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public class TestForTransformation extends TestMixinTransformation {
113113

114114
public static final AnnotationNode TEST_ANNOTATION = new AnnotationNode(new ClassNode(Test.class));
115115
public static final ClassNode GROOVY_TEST_CASE_CLASS = new ClassNode(GroovyTestCase.class);
116+
public static final String VOID_TYPE = "void";
116117

117118
private ResourceLocator resourceLocator;
118119

@@ -236,7 +237,9 @@ public void testFor(ClassNode classNode, ClassExpression ce) {
236237
List<AnnotationNode> existingTestAnnotations = methodNode.getAnnotations(testAnnotationClassNode);
237238
if (isCandidateMethod(methodNode) && (methodNode.getName().startsWith("test") || existingTestAnnotations.size()>0)) {
238239
if (existingTestAnnotations.size()==0) {
239-
methodNode.addAnnotation(TEST_ANNOTATION);
240+
ClassNode returnType = methodNode.getReturnType();
241+
if(returnType.getName().equals(VOID_TYPE))
242+
methodNode.addAnnotation(TEST_ANNOTATION);
240243
}
241244
hasTestMethods = true;
242245
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package grails.test.mixin
2+
3+
import grails.test.mixin.web.GroovyPageUnitTestMixin
4+
import org.junit.Test
5+
6+
/**
7+
* @author Graeme Rocher
8+
*/
9+
@TestMixin(GroovyPageUnitTestMixin)
10+
@TestFor(MyController)
11+
class ControllerAndGroovyPageMixinTests {
12+
13+
// GRAILS-9718
14+
@Test
15+
void testController() {
16+
controller != null
17+
18+
views['/foo/_bar.gsp'] = 'Id: ${params.id}'
19+
20+
params.id = 10
21+
def content = render(template:"/foo/bar")
22+
23+
assert content == 'Id: 10'
24+
}
25+
}

0 commit comments

Comments
 (0)