Skip to content

Commit

Permalink
including BaseOutputHref in cache key when calling RenderNamed (fix #183
Browse files Browse the repository at this point in the history
)
  • Loading branch information
AlexCuse committed May 11, 2012
1 parent 38c919a commit 301ba62
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
7 changes: 6 additions & 1 deletion SquishIt.Framework/Base/BundleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public string Render(string renderTo)
private string Render(string renderTo, string key, IRenderer renderer)
{
key = CachePrefix + key;

if(!String.IsNullOrEmpty(BaseOutputHref))
{
key = BaseOutputHref + key;
Expand All @@ -301,7 +302,11 @@ private string Render(string renderTo, string key, IRenderer renderer)
public string RenderNamed(string name)
{
bundleState = GetCachedGroupBundle(name);
var content = bundleCache.GetContent(CachePrefix + name);
//TODO: this sucks
// Revisit https://github.com/jetheredge/SquishIt/pull/155 and https://github.com/jetheredge/SquishIt/issues/183
//hopefully we can find a better way to satisfy both of these requirements
var fullName = (BaseOutputHref ?? "") + CachePrefix + name;
var content = bundleCache.GetContent(fullName);
if(content == null)
{
AsNamed(name, bundleState.Path);
Expand Down
32 changes: 29 additions & 3 deletions SquishIt.Tests/CssBundleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void CanBundleCssSpecifyingOutputLinkPath()
}

[Test]
public void CanBundleCssVaryingOutputBaseHrefRendersIndependantUrl()
public void CanBundleCssVaryingOutputBaseHrefRendersIndependentUrl()
{
//Verify that depending on basehref, we get independantly cached and returned URLs
CSSBundle cssBundle = cssBundleFactory
Expand All @@ -153,7 +153,7 @@ public void CanBundleCssVaryingOutputBaseHrefRendersIndependantUrl()
string tag = cssBundle
.Add("/css/first.css")
.Add("/css/second.css")
.WithOutputBaseHref("http//subdomain.domain.com")
.WithOutputBaseHref("http://subdomain.domain.com")
.Render("/css/output.css");

CSSBundle cssBundleNoBaseHref = cssBundleFactory
Expand All @@ -168,10 +168,36 @@ public void CanBundleCssVaryingOutputBaseHrefRendersIndependantUrl()
.Add("/css/second.css")
.Render("/css/output.css");

Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"http//subdomain.domain.com/css/output.css?r=C33D1225DED9D889876CEE87754EE305\" />", tag);
Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://subdomain.domain.com/css/output.css?r=C33D1225DED9D889876CEE87754EE305\" />", tag);
Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/output.css?r=C33D1225DED9D889876CEE87754EE305\" />", tagNoBaseHref);
}

[Test]
public void RenderNamedUsesOutputBaseHref()
{
//Verify that depending on basehref, we get independantly cached and returned URLs
CSSBundle cssBundle = cssBundleFactory
.WithHasher(hasher)
.WithDebuggingEnabled(false)
.Create();

cssBundleFactory.FileReaderFactory.SetContents(css);

cssBundle
.Add("/css/first.css")
.Add("/css/second.css")
.WithOutputBaseHref("http://subdomain.domain.com")
.AsNamed("leBundle", "/css/output.css");

var tag = cssBundleFactory
.WithHasher(hasher)
.WithDebuggingEnabled(false)
.Create()
.WithOutputBaseHref("http://subdomain.domain.com")
.RenderNamed("leBundle");

Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://subdomain.domain.com/css/output.css?r=C33D1225DED9D889876CEE87754EE305\" />", tag);
}

[Test]
public void CanBundleCssWithQueryStringParameter()
Expand Down
24 changes: 21 additions & 3 deletions SquishIt.Tests/JavaScriptBundleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ public void CanBundleJavaScript()
}

[Test]
public void CanBundleJsVaryingOutputBaseHrefRendersIndependantUrl()
public void CanBundleJsVaryingOutputBaseHrefRendersIndependentUrl()
{
fileReaderFactory.SetContents(javaScript);

string tag = javaScriptBundle
.Add("/js/first.js")
.Add("/js/second.js")
.WithOutputBaseHref("http//subdomain.domain.com")
.WithOutputBaseHref("http://subdomain.domain.com")
.Render("/js/output.js");


Expand All @@ -111,10 +111,28 @@ public void CanBundleJsVaryingOutputBaseHrefRendersIndependantUrl()
.Add("/js/second.js")
.Render("/js/output.js");

Assert.AreEqual("<script type=\"text/javascript\" src=\"http//subdomain.domain.com/js/output.js?r=42C40AB6B5ED5B2868E70CB08201F965\"></script>", tag);
Assert.AreEqual("<script type=\"text/javascript\" src=\"http://subdomain.domain.com/js/output.js?r=42C40AB6B5ED5B2868E70CB08201F965\"></script>", tag);
Assert.AreEqual("<script type=\"text/javascript\" src=\"/js/output.js?r=42C40AB6B5ED5B2868E70CB08201F965\"></script>", tagNoBaseHref);
}

[Test]
public void RenderNamedUsesOutputBaseHref()
{
fileReaderFactory.SetContents(javaScript);

javaScriptBundle
.Add("/js/first.js")
.Add("/js/second.js")
.WithOutputBaseHref("http://subdomain.domain.com")
.AsNamed("leBundle", "/js/output.js");

var tag = javaScriptBundle2
.WithOutputBaseHref("http://subdomain.domain.com")
.RenderNamed("leBundle");

Assert.AreEqual("<script type=\"text/javascript\" src=\"http://subdomain.domain.com/js/output.js?r=42C40AB6B5ED5B2868E70CB08201F965\"></script>", tag);
}

[Test]
public void CanBundleJavaScriptWithQuerystringParameter()
{
Expand Down

0 comments on commit 301ba62

Please sign in to comment.