Skip to content
Browse files

test for GRAILS-3077

  • Loading branch information...
1 parent dd84a79 commit d65c13a2f4648d5a6fb0b3747b48686e379261ee @graemerocher graemerocher committed Jul 22, 2009
Showing with 63 additions and 0 deletions.
  1. +63 −0 grails/src/test/org/codehaus/groovy/grails/web/binding/BindToEnumTests.groovy
View
63 grails/src/test/org/codehaus/groovy/grails/web/binding/BindToEnumTests.groovy
@@ -0,0 +1,63 @@
+package org.codehaus.groovy.grails.web.binding
+
+import org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerTests
+
+/**
+ * @author Graeme Rocher
+ * @since 1.1
+ */
+
+public class BindToEnumTests extends AbstractGrailsControllerTests{
+
+ protected void onSetUp() {
+ gcl.parseClass('''
+import grails.persistence.*
+
+@Entity
+class RoleHolder {
+
+ EnumRole role
+
+ static constraints = {
+ role nullable:true
+ }
+}
+
+enum EnumRole {
+ USER, ADMINISTRATOR, EDITOR
+}
+
+class EnumBindingController {
+
+ def save = {
+ def h = new RoleHolder(params)
+ [holder:h]
+ }
+}
+
+''')
+ }
+
+
+ void testBindBlankValueToEnum() {
+ def controller = ga.getControllerClass("EnumBindingController").newInstance()
+
+ controller.params.role = ""
+
+ def model = controller.save()
+
+ assertNull "should have been null", model.holder.role
+ }
+
+ void testBindValueToEnum() {
+ def controller = ga.getControllerClass("EnumBindingController").newInstance()
+
+ controller.params.role = "USER"
+
+ def model = controller.save()
+
+ assertEquals "USER", model.holder.role.toString()
+
+ }
+
+}

0 comments on commit d65c13a

Please sign in to comment.
Something went wrong with that request. Please try again.