Skip to content

Commit

Permalink
Fix for Issue DarthFubuMVC#193 - don't trim a url's trailing slash if…
Browse files Browse the repository at this point in the history
… the url is only a slash ('/')
  • Loading branch information
KevM committed Nov 18, 2011
1 parent 125c3a4 commit 6c4a4da
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/FubuMVC.Core/Http/AspNet/AspNetCurrentHttpRequest.cs
Expand Up @@ -36,9 +36,9 @@ public string ToFullUrl(string url)
url = "~/" + url.TrimStart('/');
}

var absoluteUrl = VirtualPathUtility.ToAbsolute(url);


return VirtualPathUtility.ToAbsolute(url).TrimEnd('/');
return (absoluteUrl != "/") ? absoluteUrl.TrimEnd('/') : absoluteUrl;
}

public string HttpMethod()
Expand Down
18 changes: 15 additions & 3 deletions src/FubuMVC.HelloSpark/Controllers/Air/AirController.cs
@@ -1,10 +1,12 @@
namespace FubuMVC.HelloSpark.Controllers.Air
using FubuCore;

namespace FubuMVC.HelloSpark.Controllers.Air
{
public class AirController
{
public AirViewModel TakeABreath()
public AirViewModel TakeABreath(AirRequest request)
{
return new AirViewModel { Text = "Take a breath?" };
return new AirViewModel { Text = "Take a {0} breath?".ToFormat(request.Type) };
}

public BreatheViewModel Breathe(AirInputModel model)
Expand All @@ -17,6 +19,16 @@ public BreatheViewModel Breathe(AirInputModel model)
}
}

public class AirRequest
{
public AirRequest()
{
Type = "deep";
}

public string Type { get; set; }
}

public class AirInputModel
{
public bool TakeABreath { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/FubuMVC.HelloSpark/HelloSparkRegistry.cs
Expand Up @@ -22,7 +22,7 @@ public HelloSparkRegistry()
ApplyHandlerConventions();

Routes
.HomeIs<AirController>(c => c.TakeABreath())
.HomeIs<AirRequest>()
.IgnoreControllerNamespaceEntirely()
.IgnoreMethodSuffix("Command")
.IgnoreMethodSuffix("Query")
Expand Down
3 changes: 3 additions & 0 deletions src/FubuMVC.HelloSpark/Shared/Application.spark
Expand Up @@ -17,5 +17,8 @@
<div>no footer by default</div>
</use>
</div>

<p>You can always !{this.LinkTo<FubuMVC.HelloSpark.Controllers.Air.AirRequest>().Text("go home")}.
</p>
</body>
</html>
14 changes: 13 additions & 1 deletion src/FubuMVC.Tests/Urls/UrlRegistryIntegrationTester.cs
Expand Up @@ -43,7 +43,7 @@ public void SetUp()


registry.ResolveTypes(x => x.AddStrategy<UrlModelForwarder>());

registry.Routes.HomeIs<DefaultModel>();

graph = registry.BuildGraph();

Expand All @@ -63,6 +63,12 @@ public void retrieve_a_url_for_a_model_simple_case()
{
urls.UrlFor(new Model1()).ShouldEqual("http://server/fubu/one/m1");
}

[Test]
public void retrieve_a_url_for_the_default_model()
{
urls.UrlFor(new DefaultModel()).ShouldEqual("http://server/fubu");
}

[Test]
public void retrieve_a_url_for_a_inferred_model_simple_case()
Expand Down Expand Up @@ -279,6 +285,11 @@ public void M5(Model3 input)

[UrlRegistryCategory("different")]
public void M4(UrlModel model) { }

public string Default(DefaultModel model)
{
return "welcome to the default view";
}
}

public class TwoController
Expand Down Expand Up @@ -313,6 +324,7 @@ public class Model4{}
public class Model5{}
public class Model6{}
public class Model7{}
public class DefaultModel { }
public class ModelWithNoChain{}
public class ModelWithoutNewUrl{}

Expand Down

0 comments on commit 6c4a4da

Please sign in to comment.