PageRenderTime 39ms CodeModel.GetById 36ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/tests/model/associations/belongsTo.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 45 lines | 38 code | 7 blank | 0 comment | 0 complexity | 702655153d68eb9dc5acf4acb9285c6e MD5 | raw file
 1<cfcomponent extends="wheelsMapping.Test">
 2
 3	<cffunction name="test_getting_parent">
 4		<cfset loc.obj = model("post").findOne(order="id")>
 5		<cfset loc.dynamicResult = loc.obj.author()>
 6		<cfset loc.coreResult = model("author").findByKey(loc.obj.authorId)>
 7		<cfset assert("loc.dynamicResult.key() IS loc.coreResult.key()")>
 8		<cfset loc.dynamicResult = loc.obj.author(select="lastName", returnAs="query")>
 9		<cfset loc.coreResult = model("author").findByKey(key=loc.obj.authorId, select="lastName", returnAs="query")>
10		<cfset assert("IsQuery(loc.dynamicResult) AND ListLen(loc.dynamicResult.columnList) IS 1 AND IsQuery(loc.coreResult) AND ListLen(loc.coreResult.columnList) IS 1 AND loc.dynamicResult.lastName IS loc.coreResult.lastName")>
11	</cffunction>
12
13	<cffunction name="test_checking_if_parent_exists">
14		<cfset loc.obj = model("post").findOne(order="id")>
15		<cfset loc.dynamicResult = loc.obj.hasAuthor()>
16		<cfset loc.coreResult = model("author").exists(loc.obj.authorId)>
17		<cfset assert("loc.dynamicResult IS loc.coreResult")>
18	</cffunction>
19
20	<cffunction name="test_getting_parent_on_new_object">
21		<cfset loc.authorByFind = model("author").findOne(order="id")>
22		<cfset loc.newPost = model("post").new(authorId=loc.authorByFind.id)>
23		<cfset loc.authorByAssociation = loc.newPost.author()>
24		<cfset assert("loc.authorByFind.key() IS loc.authorByAssociation.key()")>
25	</cffunction>
26
27	<cffunction name="test_checking_if_parent_exists_on_new_object">
28		<cfset loc.authorByFind = model("author").findOne(order="id")>
29		<cfset loc.newPost = model("post").new(authorId=loc.authorByFind.id)>
30		<cfset loc.authorExistsByAssociation = loc.newPost.hasAuthor()>
31		<cfset assert("loc.authorExistsByAssociation IS true")>
32	</cffunction>
33	
34	<cffunction name="test_getting_parent_on_combined_key_model">
35		<cfset loc.combikey = model("combikey").findOne()>
36		<cfset loc.user = loc.combikey.user()>
37		<cfset assert("IsObject(loc.user)")>
38	</cffunction>
39
40	<cffunction name="test_getting_parent_with_join_key">
41		<cfset loc.obj = model("author").findOne(order="id", include="user")>
42		<cfset assert('loc.obj.firstName eq loc.obj.user.firstName')>
43	</cffunction>
44
45</cfcomponent>