Hi All,
I am trying to write a functional test for a simple CRUD controller which is in a subfolder (ColdRoute namespaced).
I have run into an issue where testing a namespaced controller won't run the controller filters..
Eg.. Controller Snippet:
<cfcomponent extends="Controller" output="false">
<cffunction name="init">
<cfset filters(through="getOwner")>
</cffunction>
<cffunction name="index">
<cfset categories = model("Category").findAll(where="ownerid = #owner.ownerid#")>
</cffunction>
</cfcomponent>
Functional Test (Note controller="admin.categories"):
<cffunction name="test_index_displays_category_listing">
<!--- setup some params for the tests --->
<cfset loc.params = {controller="admin.categories", action="index"}>
<!--- create an instance of the controller --->
<cfset loc.controller = controller("admin.categories", loc.params)>
<!--- process the action of the controller --->
<cfset loc.controller.$processAction()>
<!--- get copy of the code the view generated --->
<cfset loc.response = loc.controller.response()>
<!--- make sure this string is displayed --->
<cfset loc.string = '<h2>Categories</h2>'>
<cfset assert('loc.response contains loc.string')>
</cffunction>
The test result suggests that the getOwner filter is not being run.
CategoriesTest INDEX DISPLAYS CATEGORY LISTING Error
variable [owner] doesn't exist
Categories.cfc line 28
When I move the Categories controller out of the /controllers/admin and back into the root /controllers folder.. the test passes and all is rosey!
Has anyone else got this combination working correctly? Could this be a wheels or coldroute bug?
Some more info:
- Railo 4.0.4.001
- OSX
- controllers/admin/Categories.cfc extends controllers/admin/Controller.cfc which extends /controllers/Controller.cfc
- get getOwner function is in the /controllers/Controller.cfc
- only the Categories.cfc has an init method
- I have also tried controller="admin/categories" in the test
- If I hack my controller and call getOwner() in the index function, the test passes.
Any thoughts appreciated.
Regards,
Adam