Skip to content

Commit 7cc3c68

Browse files
author
graeme
committed
fixes for failing tests
git-svn-id: https://svn.codehaus.org/grails/trunk@5753 1cfb16fd-6d17-0410-8ff1-b7e8e1e2867d
1 parent 7e51071 commit 7cc3c68

File tree

5 files changed

+90
-16
lines changed

5 files changed

+90
-16
lines changed

.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<classpathentry kind="lib" path="lib/dom4j-1.6.1.jar"/>
3434
<classpathentry kind="lib" path="lib/ehcache-1.2.4.jar"/>
3535
<classpathentry kind="lib" path="lib/ejb3-persistence.jar"/>
36-
<classpathentry kind="lib" path="lib/gant-0.3.3.jar"/>
36+
<classpathentry kind="lib" path="lib/gant-0.3.4-SNAPSHOT.jar"/>
3737
<classpathentry kind="lib" path="lib/groovy-all-1.1-rc-1-SNAPSHOT.jar"/>
3838
<classpathentry kind="lib" path="lib/hibernate-annotations.jar"/>
3939
<classpathentry kind="lib" path="lib/hsqldb-1.8.0.5.jar"/>

src/groovy/org/codehaus/groovy/grails/plugins/web/filters/DefaultGrailsFiltersClass.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ class DefaultGrailsFiltersClass extends AbstractInjectableGrailsClass implement
4646
class Loader {
4747
def filters = []
4848

49-
def methodMissing(String name, args) {
49+
def methodMissing(String methodName, args) {
5050
if(args) {
5151

5252
def fc = new FilterConfig(name:methodName)
53-
delegate.filters << fc
53+
filters << fc
5454

5555
if(args[0] instanceof Closure) {
5656
def closure = args[0]

src/web/org/codehaus/groovy/grails/web/mapping/DefaultUrlMappingInfo.java

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616

1717
import groovy.lang.Closure;
1818
import org.codehaus.groovy.grails.web.mapping.exceptions.UrlMappingException;
19-
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap;
2019
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest;
20+
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
2121
import org.springframework.web.context.request.RequestContextHolder;
2222

23-
import java.util.Collections;
24-
import java.util.Iterator;
25-
import java.util.Map;
23+
import java.util.*;
2624

2725
/**
2826
* A Class that implements the UrlMappingInfo interface and holds information established from a matched
@@ -39,14 +37,14 @@ public class DefaultUrlMappingInfo implements UrlMappingInfo {
3937
private Map params = Collections.EMPTY_MAP;
4038
private Object controllerName;
4139
private Object actionName;
40+
private Object id;
4241
private static final String ID_PARAM = "id";
43-
private String id;
4442
private UrlMappingData urlData;
4543
private Object viewName;
4644

4745
private DefaultUrlMappingInfo(Map params, UrlMappingData urlData) {
4846
this.params = Collections.unmodifiableMap(params);
49-
this.id = (String)params.get(ID_PARAM);
47+
this.id = params.get(ID_PARAM);
5048
this.urlData = urlData;
5149
}
5250

@@ -79,9 +77,31 @@ public String toString() {
7977
* @param dispatchParams The Map instance
8078
*/
8179
protected void populateParamsForMapping(Map dispatchParams) {
82-
for (Iterator j = this.params.keySet().iterator(); j.hasNext();) {
80+
Collection keys = this.params.keySet();
81+
keys = DefaultGroovyMethods.toList(keys);
82+
Collections.sort((List)keys, new Comparator() {
83+
84+
public int compare(Object leftKey, Object rightKey) {
85+
Object leftValue = params.get(leftKey);
86+
Object rightValue = params.get(rightKey);
87+
boolean leftIsClosure = leftValue instanceof Closure;
88+
boolean rightIsClosure = rightValue instanceof Closure;
89+
if(leftIsClosure && rightIsClosure) return 0;
90+
else if(leftIsClosure && !rightIsClosure) return 1;
91+
else if(rightIsClosure && !leftIsClosure) return -1;
92+
return 0;
93+
}
94+
});
95+
for (Iterator j = keys.iterator(); j.hasNext();) {
96+
8397
String name = (String) j.next();
84-
dispatchParams.put(name, this.params.get(name));
98+
Object param = this.params.get(name);
99+
if(param instanceof Closure) {
100+
param = evaluateNameForValue(param);
101+
}
102+
103+
dispatchParams.put(name, param);
104+
85105
}
86106
}
87107

@@ -108,7 +128,7 @@ public String getViewName() {
108128
}
109129

110130
public String getId() {
111-
return id;
131+
return evaluateNameForValue(this.id);
112132
}
113133

114134
private String evaluateNameForValue(Object value) {

test/groovy/org/codehaus/groovy/grails/validation/ConstraintsBuilderTests.groovy

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package org.codehaus.groovy.grails.validation
22

33
import org.codehaus.groovy.grails.commons.test.*
44
import org.codehaus.groovy.grails.commons.metaclass.*
5-
import org.springframework.validation.BindException;
5+
import org.springframework.validation.BindException
6+
import org.springframework.validation.Errors;
67

78
class ConstraintsBuilderTests extends AbstractGrailsMockTests {
89

@@ -46,6 +47,48 @@ class ConstraintsBuilderTests extends AbstractGrailsMockTests {
4647
assert !errors.hasErrors()
4748
}
4849

50+
51+
void testURLValidation() {
52+
def theClass = ga.getDomainClass("Site")
53+
54+
def instance = theClass.newInstance()
55+
def validator = configureValidator(theClass, instance)
56+
57+
def errors = validateInstance(instance, validator)
58+
59+
assert !errors.hasErrors()
60+
61+
instance.url = new URL("http://grails.org")
62+
errors = validateInstance(instance, validator)
63+
assert !errors.hasErrors()
64+
65+
instance.url = new URL("http://localhost:8080/tau_gwi_00/clif/cb/19")
66+
errors = validateInstance(instance, validator)
67+
assert !errors.hasErrors()
68+
69+
}
70+
71+
Errors validateInstance(instance, validator) {
72+
def errors = new BindException(instance, instance.class.name)
73+
validator.validate(instance, errors, true)
74+
return errors
75+
}
76+
77+
GrailsDomainClassValidator configureValidator(theClass, instance) {
78+
def metaClass = new ExpandoMetaClass(theClass.clazz)
79+
def errorsProp = null
80+
def setter = { Object obj -> errorsProp = obj }
81+
metaClass.setErrors = setter
82+
metaClass.initialize()
83+
instance.metaClass = metaClass
84+
def validator = new GrailsDomainClassValidator()
85+
86+
validator.domainClass = theClass
87+
validator.messageSource = createMessageSource()
88+
theClass.validator = validator
89+
return validator
90+
}
91+
4992
public void onSetUp() {
5093
gcl.parseClass('''
5194
class Book {
@@ -58,6 +101,14 @@ class Book {
58101
totalSales(min:0)
59102
60103
}
104+
}
105+
class Site {
106+
Long id
107+
Long version
108+
URL url
109+
static constraints = {
110+
url(url:true, nullable:true)
111+
}
61112
}
62113
''')
63114
}

test/groovy/org/codehaus/groovy/grails/web/mapping/DynamicActionNameEvaluatingTests.groovy

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ mappings {
1212
action = { "${params.test}" }
1313
}
1414
"/$controller/$action?/$id?" {
15-
controller = { params.controller }
16-
action = { params.action }
17-
id = { params.id }
15+
ctrl = { params.controller }
16+
act = { params.action }
17+
identity = { params.id }
1818
}
1919
}
2020
'''
@@ -84,8 +84,11 @@ mappings {
8484
assert info
8585
info.configure(webRequest)
8686
assertEquals "book", info.controllerName
87+
assertEquals "book", webRequest.params.ctrl
8788
assertEquals "show", info.actionName
89+
assertEquals "show", webRequest.params.act
8890
assertEquals "1", info.id
91+
assertEquals "1", webRequest.params.identity
8992

9093
}
9194

0 commit comments

Comments
 (0)