Skip to content

Commit a235759

Browse files
committed
Merge branch '3.0.x'
2 parents 5234669 + 0432f2d commit a235759

File tree

3 files changed

+96
-3
lines changed

3 files changed

+96
-3
lines changed

grails-bootstrap/src/main/groovy/org/grails/config/CodeGenConfig.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class CodeGenConfig implements Cloneable, ConfigMap {
198198
}
199199

200200
protected <T> T convertToOtherTypes(Object value, Class<T> requiredType) {
201-
throw new RuntimeException("conversion to $requiredType.name not implemented")
201+
throw new RuntimeException("conversion of $value to $requiredType.name not implemented")
202202
}
203203

204204
public Object navigate(String... path) {

grails-core/src/main/groovy/org/grails/transaction/transform/TransactionalTransform.groovy

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,14 @@ class TransactionalTransform implements ASTTransformation{
117117
if (!md.isSynthetic() && Modifier.isPublic(modifiers) && !Modifier.isAbstract(modifiers) && !Modifier.isStatic(modifiers)) {
118118
if(hasExcludedAnnotation(md)) continue
119119

120-
if( methodName.contains('$') && !methodName.startsWith('$spock') ) continue
120+
def startsWithSpock = methodName.startsWith('$spock')
121+
if( methodName.contains('$') && !startsWithSpock) continue
122+
123+
if(startsWithSpock && methodName.endsWith('proc') ) continue
124+
125+
if(md.getAnnotations().any { AnnotationNode an -> an.classNode.name == "org.spockframework.runtime.model.DataProviderMetadata"}) {
126+
continue
127+
}
121128

122129
if(METHOD_NAME_EXCLUDES.contains(methodName)) continue
123130

@@ -129,7 +136,7 @@ class TransactionalTransform implements ASTTransformation{
129136
if(hasAnnotation(md, DelegatingMethod.class)) continue
130137
weaveTransactionalMethod(source, classNode, annotationNode, md);
131138
}
132-
else if("setup".equals(methodName) && isSpockTest(classNode)) {
139+
else if(("setup".equals(methodName) || "cleanup".equals(methodName)) && isSpockTest(classNode)) {
133140
def requiresNewTransaction = new AnnotationNode(annotationNode.classNode)
134141
requiresNewTransaction.addMember("propagation", new PropertyExpression(new ClassExpression(ClassHelper.make(Propagation.class)), "REQUIRES_NEW"))
135142
weaveTransactionalMethod(source, classNode, requiresNewTransaction, md, "execute")

grails-test-suite-uber/src/test/groovy/grails/transaction/TransactionalTransformSpec.groovy

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import org.codehaus.groovy.control.MultipleCompilationErrorsException
2121
import org.springframework.beans.factory.annotation.Autowired
2222
import org.springframework.beans.factory.annotation.Qualifier
2323
import org.springframework.transaction.PlatformTransactionManager
24+
import org.springframework.util.ReflectionUtils
2425

2526
import javax.annotation.PostConstruct
2627
import javax.sql.DataSource
@@ -60,6 +61,10 @@ class TransactionalTransformSpec extends Specification {
6061
6162
}
6263
64+
def cleanup() {
65+
66+
}
67+
6368
void "my test method"() {
6469
expect:
6570
1 == 1
@@ -72,10 +77,91 @@ class TransactionalTransformSpec extends Specification {
7277
TransactionManagerAware.isAssignableFrom(mySpec)
7378
mySpec.getDeclaredMethod('setup')
7479
mySpec.getDeclaredMethod('$tt__setup', TransactionStatus)
80+
mySpec.getDeclaredMethod('cleanup')
81+
mySpec.getDeclaredMethod('$tt__cleanup', TransactionStatus)
82+
7583
mySpec.getDeclaredMethod('$spock_feature_0_0')
7684
mySpec.getDeclaredMethod('$tt__$spock_feature_0_0', TransactionStatus)
7785
}
7886

87+
void "Test @Rollback when applied to Spock specifications and where blocks"() {
88+
when:"A new instance of a class with a @Transactional method is created that subclasses another transactional class"
89+
Class mySpec = new GroovyShell().evaluate('''
90+
import grails.test.mixin.integration.Integration
91+
import grails.transaction.Rollback
92+
import spock.lang.Specification
93+
94+
@Integration
95+
@Rollback
96+
class DemoSpec extends Specification {
97+
98+
def "test toUpperCase"() {
99+
given:
100+
def result = value.toUpperCase()
101+
102+
expect:
103+
result == expectedResult
104+
105+
where:
106+
value | expectedResult
107+
'King Crimson' | 'KING CRIMSON\'
108+
'Riverside' | 'RIVERSIDE\'
109+
}
110+
}
111+
DemoSpec
112+
''')
113+
114+
then:"It implements TransactionManagerAware"
115+
TransactionManagerAware.isAssignableFrom(mySpec)
116+
mySpec.getDeclaredMethod('$spock_feature_0_0', Object, Object)
117+
mySpec.getDeclaredMethod('$spock_feature_0_0proc', Object, Object)
118+
mySpec.getDeclaredMethod('$spock_feature_0_0prov0')
119+
120+
!ReflectionUtils.findMethod(mySpec, '$tt__$spock_feature_0_0prov0', TransactionStatus)
121+
ReflectionUtils.findMethod(mySpec, '$tt__$spock_feature_0_0', Object, Object, TransactionStatus)
122+
!ReflectionUtils.findMethod(mySpec, '$tt__$spock_feature_0_0proc', Object, Object, TransactionStatus)
123+
}
124+
125+
void "Test @Rollback when applied to Spock specifications on a method and where blocks"() {
126+
when:"A new instance of a class with a @Transactional method is created that subclasses another transactional class"
127+
Class mySpec = new GroovyShell().evaluate('''
128+
import grails.test.mixin.integration.Integration
129+
import grails.transaction.Rollback
130+
import spock.lang.Specification
131+
132+
@Integration
133+
134+
class DemoSpec extends Specification {
135+
136+
@Rollback
137+
def "test toUpperCase"() {
138+
given:
139+
def result = value.toUpperCase()
140+
141+
expect:
142+
result == expectedResult
143+
144+
where:
145+
value | expectedResult
146+
'King Crimson' | 'KING CRIMSON\'
147+
'Riverside' | 'RIVERSIDE\'
148+
}
149+
}
150+
DemoSpec
151+
''')
152+
153+
then:"It implements TransactionManagerAware"
154+
TransactionManagerAware.isAssignableFrom(mySpec)
155+
mySpec.getDeclaredMethod('$spock_feature_0_0', Object, Object)
156+
mySpec.getDeclaredMethod('$spock_feature_0_0proc', Object, Object)
157+
mySpec.getDeclaredMethod('$spock_feature_0_0prov0')
158+
159+
!ReflectionUtils.findMethod(mySpec, '$tt__$spock_feature_0_0prov0', TransactionStatus)
160+
ReflectionUtils.findMethod(mySpec, '$tt__$spock_feature_0_0', Object, Object, TransactionStatus)
161+
!ReflectionUtils.findMethod(mySpec, '$tt__$spock_feature_0_0proc', Object, Object, TransactionStatus)
162+
}
163+
164+
79165
@Issue('#701')
80166
void "Test @Transactional with a datasource specified isn't TransactionManager aware, but has appropriate autowired and qualifier"() {
81167
when:"A new instance of a class with a @Transactional method is created that subclasses another transactional class"

0 commit comments

Comments
 (0)