Overriding dateCreated for testing in Grails

后端 未结 10 1553
日久生厌
日久生厌 2021-02-12 12:27

Is there any way I can override the value of dateCreated field in my domain class without turning off auto timestamping?

I need to test controller and I ha

10条回答
  •  生来不讨喜
    2021-02-12 13:09

    A simpler solution is to use a SQL query in your integration test to set it as you please after you initialize your object with the other values you want.

    YourDomainClass.executeUpdate(
    """UPDATE YourDomainClass SET dateCreated = :date
    WHERE yourColumn = :something""",
    [date:yourDate, something: yourThing])
    

提交回复
热议问题