Skip to content

"Domain.build(save:false)" saves immediately #115

Description

@koji-k

Hi,
I use Grails 3.3.8 and build-test-data:3.3.1

I worte following Integration test code. comments explain this problem.

def sample () {
    setup:

    assert RoomType.count == 0 // it will be "0". no problem.

    RoomType roomType1 = RoomType.build(save: false)

    assert roomType1.id == null // no problem.

    assert RoomType.count == 0 // this test fails... RoomType.count returns "1"
}

so, Grails's test report shows such as following message.

Condition not satisfied:

RoomType.count == 0 // this test fails... RoomType.count returns "1"
         |     |
         1     false

I think that the following actions are originally correct:

  • RomoType.build(save: false) creates a instance of RoomType domain of Grails.
  • But not save into data store(I use H2 for Integration test), because be specified save: false in build method.

However, like a above my sample code, that instance saves immediately.

Is this behavior correct? or i understand it wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions