Skip to content

Commit

Permalink
Added cleanup in the test
Browse files Browse the repository at this point in the history
  • Loading branch information
puneetbehl committed May 5, 2023
1 parent 34f2a4f commit 2773ae9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,32 @@ import spock.lang.Specification
/**
* Created by graemerocher on 14/03/2017.
*/
class OneToManyCreateSpec extends Specification{
class OneToManyCreateSpec extends Specification {
// tag::setup[]
@Shared @AutoCleanup Neo4jDatastore datastore = new Neo4jDatastore(getClass().getPackage())
// end::setup[]

@Rollback
void "test save one-to-many"() {
given:
List<Owner> deleteOwners = []
// tag::save[]
new Owner(name:"Fred")
deleteOwners << new Owner(name:"Fred")
.addToPets(name: "Dino")
.addToPets(name: "Joe")
.save()
new Owner(name:"Barney")
deleteOwners << new Owner(name:"Barney")
.addToPets(name: "Hoppy")
.save(flush:true)
// end::save[]
Owner.withSession { it.clear() }

expect:
Owner.count == 2
Owner.findByName("Fred").pets.size() == 2
Owner.findByName("Barney").pets.size() == 1

cleanup:
Owner.deleteAll(deleteOwners)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@ class OneToManyCreateSpec extends Specification {
void "test save one-to-many"() {
given:
// tag::save[]
new Owner(name:"Fred")
Owner owner = new Owner(name:"David")
.addToPets(name: "Dino")
.save(flush:true)
.discard()
// end::save[]
expect:
Owner.count == 1
Owner.first().pets.size() == 1

cleanup:
Owner.deleteAll(owner)
}

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

given:
def owner = new Owner(name: "Fred")
def owner = new Owner(name: "John")
.addToPets(name: "Dino")
owner.age = 40
owner
Expand All @@ -38,6 +41,10 @@ class OneToManyCreateSpec extends Specification {
expect:
Owner.count == 1
Owner.first().pets.size() == 1
Owner.first().name == "John"
Owner.first().age == 40

cleanup:
Owner.deleteAll(owner)
}
}

0 comments on commit 2773ae9

Please sign in to comment.