Grails

Method assertForwardUrlMapping in GrailsUrlMappingsTestCase ignores the param assertions

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.2-M2
  • Fix Version/s: 1.4-M1
  • Component/s: Testing
  • Labels:
    None

Description

With the following mapping:

"/user/$idText?"{
    controller = "user"
    action = "publicProfile"
}

The following assert should fail, but it doesn't:

assertForwardUrlMapping("/user", controller: "user", action: "publicProfile") {
	idText = "1234"
}

The problem is that the method assertForwardUrlMapping doesn't check the params assertions. I have checked it debugging the code, and I think that the problem exactly is in the line 170 of the GrailsUrlMappingsTestCase:

if(!controllers.containsKey(actual) && mappingInfos.size() > 1) return

In all the cases the code checks if the "actual" value is a controller. For the cases of actions (in my case "publicProfile") the return sentence is executed and the sentences that really check the param assertions (later in the code) are never executed.

I think that the solution is to make the check only if we are talking about a controller:

if(key == "controller" && !controllers.containsKey(actual) && mappingInfos.size() > 1) return

BTW, in the line 187 of the same file (GrailsUrlMappingsTestCase), the assertEquals compares "value.toString()" and "mapping.params[name]". When the value is null (for instance, to check that an specific param is not set) the assertion fails. I think that the solution is to compare "value.toString()" with "mapping.params[name].toString()". I changed the code, I tested it and it ran ok.

Activity

Hide
Marcin Erdmann added a comment - - edited

Attached a really simple test project that shows the issue. The bug is still there in 1.3.7

Show
Marcin Erdmann added a comment - - edited Attached a really simple test project that shows the issue. The bug is still there in 1.3.7

People

Vote (1)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: