Skip to content

Commit

Permalink
resolves #253
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-boivin committed Jan 25, 2015
1 parent 997894d commit 5f8e3eb
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 4 deletions.
18 changes: 18 additions & 0 deletions core/api.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,21 @@
<cfreturn output />
</cffunction>

<cffunction name="throwExceptionIfURIDoesntBeginWithForwardSlash" output="false" access="private" returntype="void">
<cfargument name="uri" type="string" required="true">
<cfargument name="beanName" type="string" required="true">

<cfset var uriDoesntBeginWithForwardSlash = left(arguments.uri,1) neq "/">

<cfif uriDoesntBeginWithForwardSlash>
<cfthrow
message="URI doesn't begin with a forward slash."
detail="The URI (#arguments.uri#) for `#arguments.beanName#` should begin with a forward slash."
errorcode="taffy.resources.URIDoesntBeginWithForwardSlash"
/>
</cfif>
</cffunction>

<cffunction name="cacheBeanMetaData" access="private" output="false">
<cfargument name="factory" required="true" />
<cfargument name="beanList" type="string" required="true" />
Expand Down Expand Up @@ -998,6 +1013,9 @@
errorcode="taffy.resources.DuplicateUriPattern"
/>
</cfif>

<cfset throwExceptionIfURIDoesntBeginWithForwardSlash(local.uri, local.beanName)>

<cfset local.endpoints[local.metaInfo.uriRegex] = { beanName = local.cachedBeanName, tokens = local.metaInfo.tokens, methods = structNew(), srcURI = local.uri } />
<cfif structKeyExists(local.cfcMetadata, "functions")>
<cfloop array="#local.cfcMetadata.functions#" index="local.f">
Expand Down
8 changes: 7 additions & 1 deletion dashboard/dashboard.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,16 @@
and arrayLen(application._taffy.status.skippedResources) gt 0>
<cfoutput>
<cfloop from="1" to="#arrayLen(application._taffy.status.skippedResources)#" index="local.i">

<cfset local.err = application._taffy.status.skippedResources[local.i] />
<cfset local.exceptionHasErrorCode = structKeyExists(local.err, "Exception") AND structKeyExists(local.err.Exception, "ErrorCode")>
<cfset local.errorCode = local.exceptionHasErrorCode and local.err.Exception.ErrorCode>

<div class="alert alert-warning">
<cfif structKeyExists(local.err, "Exception") AND structKeyExists(local.err.Exception, "ErrorCode") AND local.err.Exception.ErrorCode EQ "taffy.resources.DuplicateUriPattern">
<cfif local.errorCode EQ "taffy.resources.DuplicateUriPattern">
<strong class="label label-warning"><cfoutput>#local.err.resource#</cfoutput></strong> contains a conflicting URI.
<cfelseif local.errorcode EQ "taffy.resources.URIDoesntBeginWithForwardSlash">
<strong class="label label-warning"><cfoutput>#local.err.resource#</cfoutput></strong> should have a URI that begins with a forward slash.
<cfelse>
<strong class="label label-warning"><cfoutput>#local.err.resource#</cfoutput></strong> contains a syntax error.
<cfif structKeyExists(local.err.exception, 'tagContext')>
Expand Down
7 changes: 7 additions & 0 deletions tests/resources/uriAliasDoesntBeginWithForwardSlash.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<cfcomponent extends="taffy.core.resource" taffy:uri="/uriWithForwardSlash{,},uriAliasWithoutFowardSlash">

<cffunction name="get">
<cfreturn noData() />
</cffunction>

</cfcomponent>
7 changes: 7 additions & 0 deletions tests/resources/uriDoesntBeginWithForwardSlash.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<cfcomponent extends="taffy.core.resource" taffy:uri="uriWithoutForwardSlash">

<cffunction name="get">
<cfreturn noData() />
</cffunction>

</cfcomponent>
4 changes: 1 addition & 3 deletions tests/tests/TestConflict.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
}

function conflicting_URIs_get_skipped() {
assertEquals(1, arrayLen(application._taffy.status.skippedResources), "Conflicting URIs not showing in errors");
var err = application._taffy.status.skippedResources[1];
assertEquals("taffy.resources.DuplicateUriPattern", local.err.Exception.ErrorCode);
assertTrue(checkIfOneSkippedRessourceContainsExpectedException("errorCode", "taffy.resources.DuplicateUriPattern"), "Conflicting URIs not showing in errors");
}
</cfscript>

Expand Down
8 changes: 8 additions & 0 deletions tests/tests/TestCore.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -603,4 +603,12 @@
<cfset assertTrue(local.uploadResult.statusCode eq "200 OK", "Did not return status 200") />
</cffunction>

<cffunction name="throws_exception_when_ressource_uri_doesnt_begin_with_forward_slash">
<cfset assertTrue(checkIfOneSkippedRessourceContainsExpectedException("detail", "The URI (uriWithoutForwardSlash) for `uriDoesntBeginWithForwardSlash` should begin with a forward slash."), "Uri without forward slash not showing in errors")>
</cffunction>

<cffunction name="throws_exception_when_alias_ressource_uri_doesnt_begin_with_forward_slash">
<cfset assertTrue(checkIfOneSkippedRessourceContainsExpectedException("detail", "The URI (uriAliasWithoutFowardSlash) for `uriAliasDoesntBeginWithForwardSlash` should begin with a forward slash."), "Uri alias without forward slash not showing in errors")>
</cffunction>

</cfcomponent>
16 changes: 16 additions & 0 deletions tests/tests/base.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,20 @@
<cfreturn local.result />
</cffunction>

<cffunction name="checkIfOneSkippedRessourceContainsExpectedException" access="private" output="false" returntype="boolean">
<cfargument name="exceptionAttributeName" type="string" required="true" />
<cfargument name="expectedValue" type="string" required="true" />
<cfset var skippedRessource = "">
<cfset var expectedExceptionAttributeValueFound = 0>

<cfloop array="#application._taffy.status.skippedResources#" index="skippedRessource">
<cfset expectedExceptionAttributeValueFound = structKeyExists(skippedRessource.exception, arguments.exceptionAttributeName) and skippedRessource.exception[arguments.exceptionAttributeName] is arguments.expectedValue>
<cfif expectedExceptionAttributeValueFound>
<cfbreak>
</cfif>
</cfloop>

<cfreturn expectedExceptionAttributeValueFound>
</cffunction>

</cfcomponent>

0 comments on commit 5f8e3eb

Please sign in to comment.