All Downloads are FREE. Search and download functionalities are using the official Maven repository.

grails.gorm.tests.SaveAllSpec.groovy Maven / Gradle / Ivy

There is a newer version: 2023.0.1
Show newest version
package grails.gorm.tests

class SaveAllSpec extends GormDatastoreSpec {

    def "Test that many objects can be saved at once using multiple arguments"() {
        given:
            def bob = new Person(firstName:"Bob", lastName:"Builder")
            def fred = new Person(firstName:"Fred", lastName:"Flintstone")
            def joe = new Person(firstName:"Joe", lastName:"Doe")

            Person.saveAll(bob, fred, joe)

        when:
            def total = Person.count()
            def results = Person.list()
        then:
            total == 3
            results.every { it.id != null } == true
    }

    def "Test that many objects can be saved at once using a list"() {
        given:
            def bob = new Person(firstName:"Bob", lastName:"Builder")
            def fred = new Person(firstName:"Fred", lastName:"Flintstone")
            def joe = new Person(firstName:"Joe", lastName:"Doe")

            Person.saveAll([bob, fred, joe])

        when:
            def total = Person.count()
            def results = Person.list()
        then:
            total == 3
            results.every { it.id != null } == true
    }

    def "Test that many objects can be saved at once using an iterable"() {
        given:
            def bob = new Person(firstName:"Bob", lastName:"Builder")
            def fred = new Person(firstName:"Fred", lastName:"Flintstone")
            def joe = new Person(firstName:"Joe", lastName:"Doe")

            Vector personVector = new Vector()
            personVector.add(bob)
            personVector.add(fred)
            personVector.add(joe)

            Person.saveAll(personVector)

        when:
            def total = Person.count()
            def results = Person.list()
        then:
            total == 3
            results.every { it.id != null } == true
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy