Skip to content

Commit

Permalink
Resolves #147 for 1.3 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Tuttle committed Aug 10, 2013
1 parent fafec75 commit 8e78d38
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
27 changes: 22 additions & 5 deletions core/factory.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<cfscript>
//bean cache
this.beans = structNew();
this.transients = structNew();
//functionality
function init(){
return this;
Expand All @@ -10,18 +11,29 @@
function containsBean(beanName){
return beanExists(arguments.beanName);
}
function beanExists(beanName){
return structKeyExists(this.beans, arguments.beanName);
function beanExists(beanName, includeTransients = true){
return structKeyExists(this.beans, arguments.beanName) or (includeTransients and transientExists(arguments.beanName));
}
function transientExists(beanName){
return structKeyExists(this.transients, arguments.beanName);
}
function getBean(beanName){
if (beanExists(arguments.beanName)){
if (beanExists(arguments.beanName, false)){
return this.beans[arguments.beanName];
}else if (transientExists(arguments.beanName)){
return createObject('component', this.transients[arguments.beanName]);
}else{
throwError(message="Bean name '#arguments.beanName#' not found.", type="Taffy.Factory.BeanNotFound");
}
}
function getBeanList(){
return structKeyList(this.beans);
var combined = structKeyList(this.beans);
var trans = structKeyList(this.transients);
if (len(combined) and len(trans)){
combined = combined & ",";
}
combined = combined & trans;
return combined;
}
</cfscript>
<cffunction name="loadBeansFromPath" access="public" output="false" returnType="void">
Expand All @@ -46,7 +58,12 @@
<cfset local.beanName = filePathToBeanName(local.beanQuery.directory, local.beanquery.name, arguments.resourcesBasePath) />
<cfset local.beanPath = filePathToBeanPath(local.beanQuery.directory, local.beanquery.name, arguments.resourcesPath, arguments.resourcesBasePath) />
<cftry>
<cfset this.beans[local.beanName] = createObject("component", local.beanPath) />
<cfset local.objBean = createObject("component", local.beanPath) />
<cfif isInstanceOf(local.objBean, "taffy.core.baseRepresentation")>
<cfset this.transients[local.beanName] = local.beanPath />
<cfelse>
<cfset this.beans[local.beanName] = local.objBean />
</cfif>
<cfcatch>
<!--- skip cfc's with errors, but save info about them for display in the dashboard --->
<cfset local.err = structNew() />
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/EchoMethodTunnelMember.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<cfset var echo = {} />
<cfset echo.actualMethod = "get" />

<cfreturn representationOf(echo).withStatus(200) />
<cfreturn representationOf(echo) />
</cffunction>

<cffunction name="put">
Expand Down
12 changes: 12 additions & 0 deletions tests/tests/TestFactory.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,17 @@
assertTrue( ArrayLen(application._taffy.status.skippedResources) eq 0, "Expected skipped resources array to be empty but it wasn't" );
}

function treats_CRCs_as_transients(){
var local = {};
//this resource+method explicitly sets response status of 999
local.result = apiCall("get", "/echo/2.json", "foo=bar");
debug(local.result);
assertEquals(999, local.result.responseHeader.status_code);
//this resource+method usees the default response status => 200=passing test, 999=failing test
local.result = apiCall("get", "/echo/tunnel/2.json", "foo=bar");
debug(local.result);
assertEquals(200, local.result.responseHeader.status_code);
}

</cfscript>
</cfcomponent>

0 comments on commit 8e78d38

Please sign in to comment.