grails 4.0.3 integration-test: if setup() calls another method for saving to database, the change does not persist

Viewed 23

assuming the existence of a "User"-class with a "name"-field - the following test will fail:

@Integration
@Rollback
class MySpec extends Specification {

    def createUser(String name) {
        User user = new User(name: name).save(failOnError: true, flush: true)
    }

    def setup() {
        createUser('Daonald')
        assert User.findByName('Daonald')   // passes
    }

    def cleanup() {
    }

    void 'data does NOT persist'() {
        expect:
        assert User.findByName('Daonald')   //fails, data does not persist
    }
}

while the following test will pass:

@Integration
@Rollback
class MySpec extends Specification {

    def setup() {
        User user = new User(name: name).save(failOnError: true, flush: true)
        assert User.findByName('Daonald')   // passes
    }

    def cleanup() {
    }

    void 'data does persist'() {
        expect:
        assert User.findByName('Daonald')   //passes
    }
}

it seems to not be possible to use the setup()-method for calling other methods to save data. is it a bug or intended behavior?

0 Answers
Related