-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow customization of auto timestamp dateCreated and lastUpdated pro…
…perties
- Loading branch information
1 parent
5646c30
commit d67e1ca
Showing
3 changed files
with
99 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
grails-datastore-gorm-tck/src/main/groovy/grails/gorm/tests/CustomAutotimeStampSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package grails.gorm.tests | ||
|
||
import grails.persistence.Entity | ||
|
||
class CustomAutotimeStampSpec extends GormDatastoreSpec{ | ||
|
||
void "Test when the auto timestamp properties are customized, they are correctly set"() { | ||
when:"An entity is persisted" | ||
def r = new RecordCustom(name: "Test") | ||
r.save(flush:true) | ||
session.clear() | ||
r = RecordCustom.get(r.id) | ||
|
||
then:"the custom lastUpdated and dateCreated are set" | ||
r.modified != null && r.modified < new Date() | ||
r.created != null && r.created < new Date() | ||
|
||
when:"An entity is modified" | ||
Date previousCreated = r.created | ||
Date previousModified = r.modified | ||
r.name = "Test 2" | ||
r.save(flush:true) | ||
session.clear() | ||
r = RecordCustom.get(r.id) | ||
|
||
then:"the custom lastUpdated property is updated and dateCreated is not" | ||
r.modified != null && previousModified > r.modified | ||
previousCreated == r.created | ||
} | ||
@Override | ||
List getDomainClasses() { | ||
[RecordCustom] | ||
} | ||
} | ||
|
||
@Entity | ||
class RecordCustom { | ||
Long id | ||
String name | ||
Date created | ||
Date modified | ||
|
||
static mapping = { | ||
dateCreated 'created' | ||
lastUpdated 'modified' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters