Permalink
Browse files

GRAILS-1984 - improve id handling in ctor

Domain class identifiers should be assignable via a Map constructor if marked with "bindable: true".
  • Loading branch information...
1 parent 27690dd commit 47ce4b528171f11fd7934c52444b0d2c62e16895 @jeffbrown jeffbrown committed Jun 25, 2012
@@ -2,6 +2,16 @@ package databinding
class DatabindingController {
+ def createWidgetWithNonBindableId() {
+ def w = new WidgetWithNonBindableId(params)
+ render "Name is ${w.name} and id is ${w.id}."
+ }
+
+ def createWidgetWithBindableId() {
+ def w = new WidgetWithBindableId(params)
+ render "Name is ${w.name} and id is ${w.id}."
+ }
+
def coTest(MyCommandObject co) {
render "Title: ${co.title}, Widget Name: ${co.widget?.name}, State: ${co.state}, Zip: ${co.zip}"
}
@@ -0,0 +1,9 @@
+package databinding
+
+class WidgetWithBindableId {
+ String name
+
+ static constraints = {
+ id bindable: true
+ }
+}
@@ -0,0 +1,5 @@
+package databinding
+
+class WidgetWithNonBindableId {
+ String name
+}
@@ -0,0 +1,29 @@
+package grails.functional.tests.gorm
+
+import grails.functional.tests.BaseApplicationSpec;
+import groovy.lang.MetaClass;
+
+class IdBindingSpec extends BaseApplicationSpec {
+
+ void 'Test a non bindable id'() {
+ when:
+ go 'databinding/createWidgetWithNonBindableId?name=Joe&id=42'
+
+ then:
+ statusCode == 200
+ $(text: contains('Name is Joe and id is null.'))
+ }
+
+ void 'Test a bindable id'() {
+ when:
+ go 'databinding/createWidgetWithBindableId?name=Joe&id=42'
+
+ then:
+ $(text: contains('Name is Joe and id is 42.'))
+ }
+
+ @Override
+ public String getApplication() {
+ 'kitchen_sink_app'
+ }
+}

0 comments on commit 47ce4b5

Please sign in to comment.