PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/tests/model/calculations/count.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 60 lines | 49 code | 11 blank | 0 comment | 0 complexity | 38e75afc2da91552ec4dbfa82e540fd3 MD5 | raw file
 1<cfcomponent extends="wheelsMapping.Test">
 2
 3	<cffunction name="test_count">
 4		<cfset loc.result = model("author").count()>
 5		<cfset assert("loc.result IS 7")>
 6	</cffunction>
 7
 8	<cffunction name="test_count_with_include">
 9		<cfset loc.result = model("author").count(include="posts")>
10		<cfset assert("loc.result IS 7")>
11	</cffunction>
12
13	<cffunction name="test_count_with_where">
14		<cfset loc.result = model("author").count(where="lastName = 'Djurner'")>
15		<cfset assert("loc.result IS 1")>
16	</cffunction>
17
18	<cffunction name="test_count_with_non_matching_where">
19		<cfset loc.result = model("author").count(where="id=0")>
20		<cfset assert("loc.result IS 0")>
21	</cffunction>
22
23	<cffunction name="test_count_with_non_matching_where_and_include">
24		<cfset loc.result = model("author").count(where="id = 0", include="posts")>
25		<cfset assert("loc.result IS 0")>
26	</cffunction>
27
28	<cffunction name="test_count_with_where_and_include">
29		<cfset loc.result = model("author").count(where="lastName = 'Djurner' OR lastName = 'Peters'", include="posts")>
30		<cfset assert("loc.result IS 2")>
31	</cffunction>
32
33	<cffunction name="test_count_with_where_on_included_association">
34		<cfset loc.result = model("author").count(where="title LIKE '%first%' OR title LIKE '%second%' OR title LIKE '%fourth%'", include="posts")>
35		<cfset assert("loc.result IS 2")>
36	</cffunction>
37	
38	<cffunction name="test_dynamic_count">
39		<cfset loc.author = model("author").findOne(where="lastName='Djurner'")>
40		<cfset loc.result = loc.author.postCount()>
41		<cfset assert("loc.result IS 3")>
42	</cffunction>
43
44	<cffunction name="test_dynamic_count_with_where">
45		<cfset loc.author = model("author").findOne(where="lastName='Djurner'")>
46		<cfset loc.result = loc.author.postCount(where="title LIKE '%first%' OR title LIKE '%second%'")>
47		<cfset assert("loc.result IS 2")>
48	</cffunction>
49	
50	<cffunction name="test_count_with_include_soft_deletes">
51		<cftransaction action="begin">
52			<cfset loc.post = model("Post").findOne(where="views=0")>
53			<cfset loc.post.delete(transaction="none")>
54			<cfset loc.count = model("Post").count(property="views", includeSoftDeletes=true)>
55			<cftransaction action="rollback" />
56		</cftransaction>
57		<cfset assert('loc.count eq 4')>
58	</cffunction>	
59	
60</cfcomponent>