Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Test shows that plugin doesn't override rollbackFor attribute in @Tra…

  • Loading branch information...
commit ec2a1b107bc8d2284efc6d4e4a7d5c8672436887 1 parent 92318a7
Miro Bezjak authored
4 test/app/plugin-installed/grails-app/controllers/TestController.groovy
View
@@ -34,6 +34,10 @@ class TestController {
invokeTransactionalMethod { notTransactionalService.annotation() }
}
+ def annotationBare = {
+ invokeTransactionalMethod { notTransactionalService.annotationBare() }
+ }
+
private void invokeTransactionalMethod(Closure work) {
try {
work()
9 test/app/plugin-installed/grails-app/services/NotTransactionalService.groovy
View
@@ -34,6 +34,15 @@ class NotTransactionalService {
executeSqlThatCausesException sql
}
+ @Transactional
+ void annotationBare() {
+ new Foo(name: 'xxx').save(failOnError: true, flush: true)
+ new Foo(name: 'yyy').save(failOnError: true, flush: true)
+
+ def sql = new Sql(dataSource)
+ executeSqlThatCausesException sql
+ }
+
private void executeSqlThatCausesException(Sql sql) {
sql.execute """
Some sql statement that causes exception. This one isn't valid sql
12 test/app/plugin-installed/test/integration/AllSpec.groovy
View
@@ -88,4 +88,16 @@ class AllSpec extends IntegrationSpec {
Foo.count() == 0
}
+ def "should not rollback if exception doesnt match one in rollbackFor"() {
+ when:
+ notTransactionalService.annotationBare()
+
+ then:
+ def e = thrown(UndeclaredThrowableException)
+ e.cause.getClass() == SQLException
+ Foo.count() == 2
+ Foo.list()[0].name == 'xxx'
+ Foo.list()[1].name == 'yyy'
+ }
+
}
4 test/app/plugin-not-installed/grails-app/controllers/TestController.groovy
View
@@ -34,6 +34,10 @@ class TestController {
invokeTransactionalMethod { notTransactionalService.annotation() }
}
+ def annotationBare = {
+ invokeTransactionalMethod { notTransactionalService.annotationBare() }
+ }
+
private void invokeTransactionalMethod(Closure work) {
try {
work()
9 test/app/plugin-not-installed/grails-app/services/NotTransactionalService.groovy
View
@@ -34,6 +34,15 @@ class NotTransactionalService {
executeSqlThatCausesException sql
}
+ @Transactional
+ void annotationBare() {
+ new Foo(name: 'xxx').save(failOnError: true, flush: true)
+ new Foo(name: 'yyy').save(failOnError: true, flush: true)
+
+ def sql = new Sql(dataSource)
+ executeSqlThatCausesException sql
+ }
+
private void executeSqlThatCausesException(Sql sql) {
sql.execute """
Some sql statement that causes exception. This one isn't valid sql
12 test/app/plugin-not-installed/test/integration/AllSpec.groovy
View
@@ -90,4 +90,16 @@ class AllSpec extends IntegrationSpec {
Foo.count() == 0
}
+ def "should not rollback if exception doesnt match one in rollbackFor"() {
+ when:
+ notTransactionalService.annotationBare()
+
+ then:
+ def e = thrown(UndeclaredThrowableException)
+ e.cause.getClass() == SQLException
+ Foo.count() == 2
+ Foo.list()[0].name == 'xxx'
+ Foo.list()[1].name == 'yyy'
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.