forked from grails/grails
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9f637f
commit 05fb1c0
Showing
3 changed files
with
82 additions
and
7 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
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
66 changes: 66 additions & 0 deletions
66
...ls/src/test/org/codehaus/groovy/grails/web/binding/BindToObjectWithEmbeddableTests.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,66 @@ | |||
package org.codehaus.groovy.grails.web.binding | |||
|
|||
import org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerTests | |||
|
|||
/** | |||
* @author Graeme Rocher | |||
* @since 1.1 | |||
*/ | |||
|
|||
public class BindToObjectWithEmbeddableTests extends AbstractGrailsControllerTests{ | |||
|
|||
protected void onSetUp() { | |||
gcl.parseClass(''' | |||
import grails.persistence.* | |||
@Entity | |||
class Person { | |||
static embedded = ['address'] | |||
String name | |||
int age | |||
Address address = new Address() | |||
} | |||
class Address { | |||
String street | |||
String street2 | |||
String city | |||
String state | |||
String zip | |||
static constraints = { | |||
street2(nullable:true) | |||
} | |||
} | |||
class PersonController { | |||
def save = { | |||
def p = new Person(params) | |||
[person:p] | |||
} | |||
} | |||
''') | |||
} | |||
|
|||
|
|||
void testBindToObjectWithEmbedded() { | |||
def controller = ga.getControllerClass("PersonController").newInstance() | |||
|
|||
controller.params.name = "Joe" | |||
controller.params.age= "45" | |||
controller.params.'address.city' = 'Brighton' | |||
|
|||
def model = controller.save() | |||
|
|||
assertEquals "Joe", model.person.name | |||
assertEquals 45, model.person.age | |||
assertEquals "Brighton", model.person.address.city | |||
|
|||
} | |||
|
|||
} |