Permalink
Browse files

Merge pull request #63 from guspower/master

Adding 'from' functionality to default rendering of one-to-one/many-to-one/many-to-many
  • Loading branch information...
2 parents 2cc51c2 + e5a565e commit 7c441c2680caf24e5fe0880a3c7594da5f80277d Rob Fletcher committed Mar 22, 2012
@@ -340,7 +340,7 @@ class FormFieldsTagLib implements GrailsApplicationAware {
private String renderAssociationInput(Map model, Map attrs) {
attrs.name = "${model.prefix?:''}${model.property}.id"
attrs.id = (model.prefix?:'')+model.property
- attrs.from = model.persistentProperty.referencedPropertyType.list()
+ attrs.from = attrs.from ?: model.persistentProperty.referencedPropertyType.list()
attrs.optionKey = "id" // TODO: handle alternate id names
if (model.persistentProperty.manyToMany) {
attrs.multiple = ""
@@ -29,6 +29,8 @@ class DefaultInputRenderingSpec extends Specification {
people*.save(validate: false)
}
+ private List<Person> getSimpsons() { people.findAll { it.name.contains("Simpson")} }
+
def "input for a #type.simpleName property matches '#outputPattern'"() {
given:
def model = [type: type, property: "prop", constraints: [:], persistentProperty: basicProperty]
@@ -342,6 +344,28 @@ class DefaultInputRenderingSpec extends Specification {
Set | manyToManyProperty | "many-to-many"
}
+ def "input for a #description property is a select containing only entries specified in from parameter"() {
+ given:
+ def model = [type: type, property: "prop", constraints: [:], persistentProperty: persistentProperty]
+
+ when:
+ def output = tagLib.renderDefaultInput(model, [from: simpsons])
+
+ then:
+ output =~ /select name="prop.id"/
+ output =~ /id="prop"/
+ simpsons.every {
+ output =~ /option value="$it.id" >$it.name/
+ }
+ !output.contains("Monty Burns")
+
+ where:
+ type | persistentProperty | description
+ Person | oneToOneProperty | "one-to-one"
+ Person | manyToOneProperty | "many-to-one"
+ Set | manyToManyProperty | "many-to-many"
+ }
+
def "select for a #description property with a value of #value has the correct option selected"() {
given:
def model = [type: type, property: "prop", constraints: [:], persistentProperty: persistentProperty, value: value]

0 comments on commit 7c441c2

Please sign in to comment.