Skip to content
This repository was archived by the owner on Nov 25, 2022. It is now read-only.

Commit a115c79

Browse files
Add data binding test
This test is testing that auto timestamp properties are by default excluded from mass property binding. We have unit tests in grails-core for this and those tests work on classes that are explicitly marked with @entity in the source code. This test is covering a problem that relates to indetifying a domain class as being a domain class if it is used as a command object. Testing this in a real app (like this one) covers that problem.
1 parent 4dbc3b2 commit a115c79

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

app1/grails-app/domain/functionaltests/Book.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package functionaltests
33
class Book {
44

55
String title
6+
Date lastUpdated
7+
Date dateCreated
68

79
static constraints = {
810
}

app1/src/test/groovy/functionaltests/BookSpec.groovy

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package functionaltests
22
import grails.test.mixin.TestFor
3+
import spock.lang.Issue
34
import spock.lang.Specification
45

56
/**
@@ -12,4 +13,21 @@ class BookSpec extends Specification {
1213
expect:"The book validates"
1314
new Book(title:"The Stand").validate()
1415
}
16+
17+
@Issue('grails/grails-core#10079')
18+
void 'Test that auto-timestamp properties are excluded from mass property binding'() {
19+
given:
20+
def book = new Book()
21+
22+
when:
23+
book.properties = [title: 'Some Title',
24+
dateCreated: 'some value',
25+
lastUpdated: 'some value']
26+
27+
then:
28+
!book.hasErrors()
29+
book.title == 'Some Title'
30+
book.dateCreated == null
31+
book.lastUpdated == null
32+
}
1533
}

0 commit comments

Comments
 (0)