GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / test / groovy / org / codehaus / groovy / grails / orm / hibernate / WithTransactionMethodTests.groovy
blobfd136295628fcd772ffd80512872ef61b01e8ba1
1 package org.codehaus.groovy.grails.orm.hibernate;
4 class WithTransactionMethodTests extends AbstractGrailsHibernateTests {
6 void testWithTransactionMethod() {
7 def authors = []
8 def domainClass = ga.getDomainClass("Author1")
9 authors << domainClass.newInstance()
10 authors << domainClass.newInstance()
11 authors << domainClass.newInstance()
15 authors[0].name = "Stephen King"
16 authors[1].name = "John Grisham"
17 authors[2].name = "James Patterson"
20 domainClass.clazz.withTransaction { status ->
21 authors[0].save(true)
22 authors[1].save(true)
25 def results = domainClass.clazz.list()
26 assertEquals 2, results.size()
28 domainClass.clazz.withTransaction { status ->
29 authors[2].save(true)
30 status.setRollbackOnly()
33 results = domainClass.clazz.list()
34 assertEquals 2, results.size()
38 void onSetUp() {
39 gcl.parseClass(
40 """
41 class Book1 {
42 Long id
43 Long version
44 static belongsTo = Author1
45 Author1 author
46 String title
47 boolean equals(obj) { title == obj?.title }
48 int hashCode() { title ? title.hashCode() : super.hashCode() }
49 String toString() { title }
51 class Author1 {
52 Long id
53 Long version
54 String name
55 Set books
56 static hasMany = [books:Book1]
57 boolean equals(obj) { name == obj?.name }
58 int hashCode() { name ? name.hashCode() : super.hashCode() }
59 String toString() { name }
61 """
65 void onTearDown() {