Permalink
Browse files

Merge pull request #58 from erdi/GRAILS-5222.

fix for GRAILS-5222
  • Loading branch information...
graemerocher committed May 4, 2011
2 parents 64294d5 + c6ea74f commit 97d35e89130edf4d961e4bb7aa6dacdba115841f
@@ -162,23 +162,25 @@ class GrailsUrlMappingsTestCase extends GroovyTestCase {
mappingInfos = mappingsHolder.matchAll(url)
}
if (mappingInfos.size() == 0) throw new IllegalArgumentException("url '$url' did not match any mappings")
mappingInfos.find {mapping ->
def mappingMatched = mappingInfos.any {mapping ->
mapping.configure(webRequest)
for (key in assertionKeys) {
if (assertions.containsKey(key)) {
def expected = assertions[key]
def actual = mapping."${key}Name"
// if this is not a match and there are still more potential matches try the next one
if (!controllers.containsKey(actual) && mappingInfos.size() > 1) return
if (key == "view") {
if (actual[0] == "/") actual = actual.substring(1)
if (expected[0] == "/") expected = expected.substring(1)
switch (key) {
case "controller":
if (actual && !controllers.containsKey(actual)) return false
break
case "view":
if (actual[0] == "/") actual = actual.substring(1)
if (expected[0] == "/") expected = expected.substring(1)
break
case "action":
if (key == "action" && actual == null) actual = getDefaultAction(assertions.controller)
break
}
if (key == "action" && actual == null) actual = getDefaultAction(assertions.controller)
assertEquals("Url mapping $key assertion for '$url' failed", expected, actual)
}
@@ -192,8 +194,10 @@ class GrailsUrlMappingsTestCase extends GroovyTestCase {
assertEquals("Url mapping '$name' parameter assertion for '$url' failed", value.toString(), mapping.params[name])
}
}
true
return true
}
if (!mappingMatched) throw new IllegalArgumentException("url '$url' did not match any mappings")
}
void assertReverseUrlMapping(assertions, url) {
@@ -265,6 +265,13 @@ class GrailsUrlMappingsTestCaseTests extends GrailsUnitTestCase {
test.testSuperClassMapping()
}
void testGrails5222() {
def test = new Grails5222TestCase()
test.grailsApplication = mockApplication
test.setUp()
test.testShouldFailOnInvalidParameterValueForAlias()
}
private void checkFailures(TestResult result) {
result.errors().each { TestFailure failure ->
println ">> Error: ${failure.toString()}"
@@ -344,6 +351,21 @@ class MultipleMappingsTestCase extends GrailsUrlMappingsTestCase {
}
}
class Grails5222TestCase extends GrailsUrlMappingsTestCase {
static mappings = {
"/$controller/$action?/$id?" {}
"/alias/$param1/"(controller: "grailsUrlMappingsTestCaseFake", action: "action1")
}
void testShouldFailOnInvalidParameterValueForAlias() {
shouldFail(ComparisonFailure) {
assertForwardUrlMapping("/alias/param1value", controller: "grailsUrlMappingsTestCaseFake", action: "action1") {
param1 = "invalidparam1value"
}
}
}
}
class TestInternalUrlMappings {
static mappings = {
"/showPerson/$personName"(controller:'grailsUrlMappingsTestCaseFake', action:'action1')

0 comments on commit 97d35e8

Please sign in to comment.