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

/wheels/tests/model/nestedproperties/one_to_many.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 50 lines | 45 code | 5 blank | 0 comment | 0 complexity | 29cfb9b248b215916ae6a0b9e5a3b892 MD5 | raw file
 1<cfcomponent extends="wheelsMapping.Test">
 2
 3	<cffunction name="setup">
 4		<cfset loc.gallery = model("gallery")>
 5		<cfset loc.photo = model("photo")>
 6		<cfset loc.user = model("user")>
 7		<cfset loc.testGallery = $setTestObjects()>
 8	</cffunction>
 9
10	<cffunction name="test_add_children_via_object_array">
11		<cftransaction>
12			<cfset assert("loc.testGallery.save()")>
13			<cfset loc.testGallery = loc.gallery.findOneByTitle(value="Nested Properties Gallery", include="photos")>
14			<cfset assert("IsArray(loc.testGallery.photos)")>
15			<cfset assert("ArrayLen(loc.testGallery.photos) eq 3")>
16			<cftransaction action="rollback"/>
17		</cftransaction>
18	</cffunction>
19
20	<cffunction name="test_delete_children_via_object_array">
21		<cftransaction>
22			<cfset assert("loc.testGallery.save()")>
23			<cfset loc.testGallery = loc.gallery.findOneByTitle(value="Nested Properties Gallery", include="photos")>
24			<cfloop array="#loc.testGallery.photos#" index="loc.i">
25				<cfset loc.i._delete = true>
26			</cfloop>
27			<cfset loc.testGallery.save()>
28			<cfset assert("IsArray(loc.testGallery.photos)")>
29			<cfset assert("ArrayLen(loc.testGallery.photos) eq 0")>
30			<cftransaction action="rollback"/>
31		</cftransaction>
32	</cffunction>
33
34	<cffunction name="$setTestObjects" access="private" hint="Sets up test gallery/gallery photo objects.">
35		<!--- User --->
36		<cfset loc.u = loc.user.findOneByLastName("Petruzzi")>
37		<!--- Gallery --->
38		<cfset loc.params = {userId=loc.u.id, title="Nested Properties Gallery", description="A gallery testing nested properties."}>
39		<cfset loc.g = loc.gallery.new(loc.params)>
40		<cfset
41			loc.g.photos = [
42				loc.photo.new(userId=loc.u.id, filename="Nested Properties Photo Test 1", DESCRIPTION1="test photo 1 for nested properties gallery"),
43				loc.photo.new(userId=loc.u.id, filename="Nested Properties Photo Test 2", DESCRIPTION1="test photo 2 for nested properties gallery"),
44				loc.photo.new(userId=loc.u.id, filename="Nested Properties Photo Test 3", DESCRIPTION1="test photo 3 for nested properties gallery")
45			]
46		>
47		<cfreturn loc.g>
48	</cffunction>
49
50</cfcomponent>