PageRenderTime 313ms CodeModel.GetById 171ms app.highlight 1ms RepoModel.GetById 140ms app.codeStats 0ms

/wheels/tests/model/calculations/average.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 59 lines | 46 code | 13 blank | 0 comment | 0 complexity | 435146e479371fb9d3f22c23178f1569 MD5 | raw file
 1<cfcomponent extends="wheelsMapping.Test">
 2
 3	<!--- integers --->
 4
 5	<cffunction name="test_average_with_integer">
 6		<cfset loc.result = model("post").average(property="views")>
 7		<cfset assert("loc.result IS 3.25")>
 8	</cffunction>
 9
10	<cffunction name="test_average_with_integer_with_non_matching_where">
11		<cfset loc.result = model("post").average(property="views", where="id=0")>
12		<cfset assert("loc.result IS ''")>
13	</cffunction>
14
15	<cffunction name="test_average_with_integer_with_distinct">
16		<cfset loc.result = model("post").average(property="views", distinct="true")>
17		<cfset assert("DecimalFormat(loc.result) IS DecimalFormat(2.66666666667)")>
18	</cffunction>
19
20	<cffunction name="test_average_with_integer_with_ifNull">
21		<cfset loc.result = model("post").average(property="views", where="id=0", ifNull=0)>
22		<cfset assert("loc.result IS 0")>
23	</cffunction>	
24
25	<!--- floats --->
26
27	<cffunction name="test_average_with_float">
28		<cfset loc.result = model("post").average(property="averageRating")>
29		<cfset assert("DecimalFormat(loc.result) IS DecimalFormat(3.47)")>
30	</cffunction>
31
32	<cffunction name="test_average_with_float_with_non_matching_where">
33		<cfset loc.result = model("post").average(property="averageRating", where="id=0")>
34		<cfset assert("loc.result IS ''")>
35	</cffunction>
36
37	<cffunction name="test_average_with_float_with_distinct">
38		<cfset loc.result = model("post").average(property="averageRating", distinct="true")>
39		<cfset assert("DecimalFormat(loc.result) IS DecimalFormat(3.4)")>
40	</cffunction>
41
42	<cffunction name="test_average_with_float_with_ifNull">
43		<cfset loc.result = model("post").average(property="averageRating", where="id=0", ifNull=0)>
44		<cfset assert("loc.result IS 0")>
45	</cffunction>
46	
47	<!--- include deleted records --->
48	
49	<cffunction name="test_average_with_include_soft_deletes">
50		<cftransaction action="begin">
51			<cfset loc.post = model("Post").findOne(where="views=0")>
52			<cfset loc.post.delete(transaction="none")>
53			<cfset loc.average = model("Post").average(property="views", includeSoftDeletes=true)>
54			<cftransaction action="rollback" />
55		</cftransaction>
56		<cfset assert('loc.average eq 3.25')>
57	</cffunction>
58
59</cfcomponent>