Skip to content
This repository was archived by the owner on Mar 10, 2025. It is now read-only.

Commit 2773ae9

Browse files
committed
Added cleanup in the test
1 parent 34f2a4f commit 2773ae9

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

grails-datastore-gorm-neo4j/src/test/groovy/grails/gorm/tests/assignedid/OneToManyCreateSpec.groovy

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,32 @@ import spock.lang.Specification
1111
/**
1212
* Created by graemerocher on 14/03/2017.
1313
*/
14-
class OneToManyCreateSpec extends Specification{
14+
class OneToManyCreateSpec extends Specification {
1515
// tag::setup[]
1616
@Shared @AutoCleanup Neo4jDatastore datastore = new Neo4jDatastore(getClass().getPackage())
1717
// end::setup[]
1818

1919
@Rollback
2020
void "test save one-to-many"() {
2121
given:
22+
List<Owner> deleteOwners = []
2223
// tag::save[]
23-
new Owner(name:"Fred")
24+
deleteOwners << new Owner(name:"Fred")
2425
.addToPets(name: "Dino")
2526
.addToPets(name: "Joe")
2627
.save()
27-
new Owner(name:"Barney")
28+
deleteOwners << new Owner(name:"Barney")
2829
.addToPets(name: "Hoppy")
2930
.save(flush:true)
3031
// end::save[]
3132
Owner.withSession { it.clear() }
33+
3234
expect:
3335
Owner.count == 2
3436
Owner.findByName("Fred").pets.size() == 2
3537
Owner.findByName("Barney").pets.size() == 1
38+
39+
cleanup:
40+
Owner.deleteAll(deleteOwners)
3641
}
3742
}

grails-datastore-gorm-neo4j/src/test/groovy/grails/gorm/tests/cypher/OneToManyCreateSpec.groovy

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,24 @@ class OneToManyCreateSpec extends Specification {
1414
void "test save one-to-many"() {
1515
given:
1616
// tag::save[]
17-
new Owner(name:"Fred")
17+
Owner owner = new Owner(name:"David")
1818
.addToPets(name: "Dino")
1919
.save(flush:true)
2020
.discard()
2121
// end::save[]
2222
expect:
2323
Owner.count == 1
2424
Owner.first().pets.size() == 1
25+
26+
cleanup:
27+
Owner.deleteAll(owner)
2528
}
2629

2730
@Rollback
2831
void "test save one-to-many with dynamic attributes"() {
2932

3033
given:
31-
def owner = new Owner(name: "Fred")
34+
def owner = new Owner(name: "John")
3235
.addToPets(name: "Dino")
3336
owner.age = 40
3437
owner
@@ -38,6 +41,10 @@ class OneToManyCreateSpec extends Specification {
3841
expect:
3942
Owner.count == 1
4043
Owner.first().pets.size() == 1
44+
Owner.first().name == "John"
4145
Owner.first().age == 40
46+
47+
cleanup:
48+
Owner.deleteAll(owner)
4249
}
4350
}

0 commit comments

Comments
 (0)