Skip to content

Commit

Permalink
Fixed subsequent rescue error pointed out by mrardon
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrpcic committed Jun 3, 2011
1 parent 789ecff commit cc78b64
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 67 deletions.
6 changes: 3 additions & 3 deletions path.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ var Path = {
match.run();
} else {
if (Path.routes.rescue !== null) {
if (Path.routes[Path.routes.previous].do_exit !== null) {
Path.routes[Path.routes.previous].do_exit();
var previous_route = Path.match(Path.routes.previous);
if (previous_route != null && previous_route.do_exit !== null) {
previous_route.do_exit();
}

Path.routes.rescue();
}
}
Expand Down
2 changes: 1 addition & 1 deletion path.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 33 additions & 31 deletions tests/path.js.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
<script type="text/javascript" src="../path.js"></script>
<script type="text/javascript">
var hrefs = [
"#A",
"#A",
"#B",
"#C",
"#D",
"#D1",
"#D2",
"#E/params/1/parse",
"#E/params/2/parse",
"#E/params/3/check",
"#F",
"#F",
"#G"
];
var index = 0;
Expand Down Expand Up @@ -68,7 +69,7 @@
update("C[exit]");
});

// No map for #D. This checks that our rescue method works.
// No map for #D1 or #D2. This checks that our rescue method works, and works multiple times in succession.

Path.map("#E/params/:id/parse").to(function(){
update("E[action](parse id=" + this.params['id'] + ")");
Expand All @@ -80,32 +81,32 @@

Path.map("#E/params/:id/check").to(function(){
update("E[action](check id=" + this.params['id'] + ")");
});

Path.map("#E/params/:id/check").exit(function(){
update("E[exit](check)");
});

Path.map("#E/params/:id/check").exit(function(){
update("E[exit](check)");
});

Path.map("#F").enter(function(){
update("F[enter]");
}).to(function(){
update("F[action]");
});

Path.map("#G").enter(function(){
update("G[enter 1]");
}).enter(function(){
update("G[enter 2]");
}).enter([
function(){
update("G[enter 3]");
},
function(){
update("G[enter 4]");
return false;
}
]).to(function(){
update("G[action - NOT HIT]");
});

Path.map("#G").enter(function(){
update("G[enter 1]");
}).enter(function(){
update("G[enter 2]");
}).enter([
function(){
update("G[enter 3]");
},
function(){
update("G[enter 4]");
return false;
}
]).to(function(){
update("G[action - NOT HIT]");
});

Path.rescue(function(){
Expand Down Expand Up @@ -146,25 +147,26 @@ <h2>Test Suite</h2>
<tr><td>B[action]</td> <td>True action of B, as it is looped</td></tr>
<tr><td>C[action]</td> <td>True action of C</td></tr>
<tr><td>C[exit]</td> <td>Exit method of C, as we move to next route</td></tr>
<tr><td>RESCUE</td> <td>Rescue a route that wasn't found</td></tr>
<tr><td>RESCUE</td> <td>Rescue a route that wasn't found (D1)</td></tr>
<tr><td>RESCUE</td> <td>Rescue a route that wasn't found (D2)</td></tr>
<tr><td>E[enter](parse)</td> <td>Enter method of a param parsed route</td></tr>
<tr><td>E[action](parse id=1)</td> <td>True action of the route, with param of id=1</td></tr>
<tr><td>E[enter](parse)</td> <td>Enter method of the same route again</td></tr>
<tr><td>E[action](parse id=2)</td> <td>True action of the route, with param of id=2</td></tr>
<tr><td>E[action](check id=3)</td> <td>True action of the next route, with param id=3</td></tr>
<tr><td>E[action](check id=3)</td> <td>True action of the next route, with param id=3</td></tr>
<tr><td>E[exit](check)</td> <td>Exit method of parameterized route</td></tr>
<tr><td>F[enter]</td> <td>Enter method of F again, our final route</td></tr>
<tr><td>F[action]</td> <td>True action of F, our final route</td></tr>
<tr><td>G[enter 1]</td> <td>First enter method of G</td></tr>
<tr><td>G[enter 2]</td> <td>Second enter method of G</td></tr>
<tr><td>G[enter 3]</td> <td>Third enter method of G</td></tr>
<tr><td>F[action]</td> <td>True action of F, our final route</td></tr>
<tr><td>G[enter 1]</td> <td>First enter method of G</td></tr>
<tr><td>G[enter 2]</td> <td>Second enter method of G</td></tr>
<tr><td>G[enter 3]</td> <td>Third enter method of G</td></tr>
<tr><td>G[enter 4]</td> <td>Last enter method of G - Returns false, stops execution</td></tr>
</table>

</div><br /><br />
<div id="console">
<h3>Expected</h3>
<div id="expected">F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::E[enter](parse)::E[action](parse id=1)::E[enter](parse)::E[action](parse id=2)::E[action](check id=3)::E[exit](check)::F[enter]::F[action]::G[enter 1]::G[enter 2]::G[enter 3]::G[enter 4]</div>
<div id="expected">F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse)::E[action](parse id=1)::E[enter](parse)::E[action](parse id=2)::E[action](check id=3)::E[exit](check)::F[enter]::F[action]::G[enter 1]::G[enter 2]::G[enter 3]::G[enter 4]</div>
<h3>Actual</h3>
<div id="actual"></div>
<h3>Grade</h3>
Expand Down
66 changes: 34 additions & 32 deletions tests/path.min.js.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
<script type="text/javascript" src="../path.min.js"></script>
<script type="text/javascript">
var hrefs = [
"#A",
"#A",
"#B",
"#C",
"#D",
"#D1",
"#D2",
"#E/params/1/parse",
"#E/params/2/parse",
"#E/params/3/check",
"#F",
"#F",
"#G"
];
var index = 0;
Expand Down Expand Up @@ -68,7 +69,7 @@
update("C[exit]");
});

// No map for #D. This checks that our rescue method works.
// No map for #D1 or #D2. This checks that our rescue method works, and works multiple times in succession.

Path.map("#E/params/:id/parse").to(function(){
update("E[action](parse id=" + this.params['id'] + ")");
Expand All @@ -80,32 +81,32 @@

Path.map("#E/params/:id/check").to(function(){
update("E[action](check id=" + this.params['id'] + ")");
});

Path.map("#E/params/:id/check").exit(function(){
update("E[exit](check)");
});

Path.map("#E/params/:id/check").exit(function(){
update("E[exit](check)");
});

Path.map("#F").enter(function(){
update("F[enter]");
}).to(function(){
update("F[action]");
});

Path.map("#G").enter(function(){
update("G[enter 1]");
}).enter(function(){
update("G[enter 2]");
}).enter([
function(){
update("G[enter 3]");
},
function(){
update("G[enter 4]");
return false;
}
]).to(function(){
update("G[action - NOT HIT]");
});

Path.map("#G").enter(function(){
update("G[enter 1]");
}).enter(function(){
update("G[enter 2]");
}).enter([
function(){
update("G[enter 3]");
},
function(){
update("G[enter 4]");
return false;
}
]).to(function(){
update("G[action - NOT HIT]");
});

Path.rescue(function(){
Expand Down Expand Up @@ -146,29 +147,30 @@ <h2>Test Suite</h2>
<tr><td>B[action]</td> <td>True action of B, as it is looped</td></tr>
<tr><td>C[action]</td> <td>True action of C</td></tr>
<tr><td>C[exit]</td> <td>Exit method of C, as we move to next route</td></tr>
<tr><td>RESCUE</td> <td>Rescue a route that wasn't found</td></tr>
<tr><td>RESCUE</td> <td>Rescue a route that wasn't found (D1)</td></tr>
<tr><td>RESCUE</td> <td>Rescue a route that wasn't found (D2)</td></tr>
<tr><td>E[enter](parse)</td> <td>Enter method of a param parsed route</td></tr>
<tr><td>E[action](parse id=1)</td> <td>True action of the route, with param of id=1</td></tr>
<tr><td>E[enter](parse)</td> <td>Enter method of the same route again</td></tr>
<tr><td>E[action](parse id=2)</td> <td>True action of the route, with param of id=2</td></tr>
<tr><td>E[action](check id=3)</td> <td>True action of the next route, with param id=3</td></tr>
<tr><td>E[action](check id=3)</td> <td>True action of the next route, with param id=3</td></tr>
<tr><td>E[exit](check)</td> <td>Exit method of parameterized route</td></tr>
<tr><td>F[enter]</td> <td>Enter method of F again, our final route</td></tr>
<tr><td>F[action]</td> <td>True action of F, our final route</td></tr>
<tr><td>G[enter 1]</td> <td>First enter method of G</td></tr>
<tr><td>G[enter 2]</td> <td>Second enter method of G</td></tr>
<tr><td>G[enter 3]</td> <td>Third enter method of G</td></tr>
<tr><td>F[action]</td> <td>True action of F, our final route</td></tr>
<tr><td>G[enter 1]</td> <td>First enter method of G</td></tr>
<tr><td>G[enter 2]</td> <td>Second enter method of G</td></tr>
<tr><td>G[enter 3]</td> <td>Third enter method of G</td></tr>
<tr><td>G[enter 4]</td> <td>Last enter method of G - Returns false, stops execution</td></tr>
</table>

</div><br /><br />
<div id="console">
<h3>Expected</h3>
<div id="expected">F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::E[enter](parse)::E[action](parse id=1)::E[enter](parse)::E[action](parse id=2)::E[action](check id=3)::E[exit](check)::F[enter]::F[action]::G[enter 1]::G[enter 2]::G[enter 3]::G[enter 4]</div>
<div id="expected">F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse)::E[action](parse id=1)::E[enter](parse)::E[action](parse id=2)::E[action](check id=3)::E[exit](check)::F[enter]::F[action]::G[enter 1]::G[enter 2]::G[enter 3]::G[enter 4]</div>
<h3>Actual</h3>
<div id="actual"></div>
<h3>Grade</h3>
<div id="grade"></div>
</div>
</body>
</html>
</html>

0 comments on commit cc78b64

Please sign in to comment.