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

/wheels/tests/model/callbacks/afterFind.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 63 lines | 50 code | 13 blank | 0 comment | 0 complexity | e8de8d733a5a6c9a5f1b3d856510f927 MD5 | raw file
 1<cfcomponent extends="wheelsMapping.Test">
 2
 3	<cffunction name="setup">
 4		<cfset model("post").$registerCallback(type="afterFind", methods="afterFindCallback")>
 5	</cffunction>
 6	
 7	<cffunction name="teardown">
 8		<cfset model("post").$clearCallbacks(type="afterFind")>
 9	</cffunction>
10
11	<cffunction name="test_property_named_method_should_not_clash_with_cfinvoke">
12		<cfset loc.results = model("collisionTest").findAll(returnAs="objects")>
13		<cfset assert("loc.results[1].method IS 'done'")>
14	</cffunction>
15	
16	<cffunction name="test_setting_one_query_record">
17		<cfset loc.posts = model("post").findAll(maxRows=1, order="id DESC")>
18		<cfset assert("loc.posts.views[1] IS 103 AND loc.posts['title'][1] IS 'setTitle'")>
19	</cffunction>
20
21	<cffunction name="test_setting_one_query_record_with_skipped_callback">
22		<cfset loc.posts = model("post").findAll(maxRows=1, order="id DESC")>
23		<cfset assert("loc.posts.views[1] IS 103 AND loc.posts['title'][1] IS 'setTitle'")>
24	</cffunction>
25
26	<cffunction name="test_setting_multiple_query_records">
27		<cfset loc.posts = model("post").findAll(order="id DESC")>
28		<cfset assert("loc.posts.views[1] IS 103 AND loc.posts.views[2] IS 100 AND loc.posts['title'][1] IS 'setTitle'")>
29	</cffunction>
30
31	<cffunction name="test_setting_multiple_query_records_with_skipped_callback">
32		<cfset loc.posts = model("post").findAll(order="id DESC", callbacks=false)>
33		<cfset assert("loc.posts.views[1] IS '3' AND loc.posts.views[2] IS 0 AND loc.posts.title[1] IS 'Title for fourth test post'")>
34	</cffunction>
35
36	<cffunction name="test_setting_property_on_one_object">
37		<cfset loc.post = model("post").findOne()>
38		<cfset assert("loc.post.title IS 'setTitle'")>
39	</cffunction>
40
41	<cffunction name="test_setting_property_on_one_object_with_skipped_callback">
42		<cfset loc.post = model("post").findOne(callbacks=false)>
43		<cfset assert("loc.post.title IS 'Title for first test post'")>
44	</cffunction>
45
46	<cffunction name="test_setting_properties_on_multiple_objects">
47		<cfset loc.posts = model("post").findAll(returnAs="objects")>
48		<cfset assert("loc.posts[1].title IS 'setTitle' AND loc.posts[2].title IS 'setTitle'")>
49	</cffunction>
50
51	<cffunction name="test_setting_properties_on_multiple_objects_with_skipped_callback">
52		<cfset loc.posts = model("post").findAll(returnAs="objects", callbacks=false)>
53		<cfset assert("loc.posts[1].title IS 'Title for first test post' AND loc.posts[2].title IS 'Title for second test post'")>
54	</cffunction>
55
56	<cffunction name="test_creation_of_new_column_and_property">
57		<cfset loc.posts = model("post").findAll(order="id DESC")>
58		<cfset assert("loc.posts.something[1] eq 'hello world'")>
59		<cfset loc.posts = model("post").findAll(returnAs="objects")>
60		<cfset assert("loc.posts[1].something eq 'hello world'")>
61	</cffunction>
62
63</cfcomponent>