PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 1ms RepoModel.GetById 40ms app.codeStats 0ms

/wheels/tests/model/callbacks/afterSaving.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 34 lines | 29 code | 5 blank | 0 comment | 0 complexity | 16a57fa14ab560369f8f718af6dc5109 MD5 | raw file
 1<cfcomponent extends="wheelsMapping.Test">
 2
 3	<cffunction name="setup">
 4		<cfset model("tag").$registerCallback(type="afterValidation", methods="callbackThatIncreasesVariable")>
 5		<cfset model("tag").$registerCallback(type="afterValidationOnCreate", methods="callbackThatIncreasesVariable")>
 6		<cfset model("tag").$registerCallback(type="afterValidationOnUpdate", methods="callbackThatIncreasesVariable")>
 7		<cfset model("tag").$registerCallback(type="afterSave", methods="callbackThatIncreasesVariable")>
 8		<cfset model("tag").$registerCallback(type="afterCreate", methods="callbackThatIncreasesVariable")>
 9		<cfset model("tag").$registerCallback(type="afterUpdate", methods="callbackThatIncreasesVariable")>
10		<cfset loc.obj = model("tag").findOne()>
11		<cfset loc.obj.name = "somethingElse">
12	</cffunction>
13	
14	<cffunction name="teardown">
15		<cfset model("tag").$clearCallbacks(type="afterValidation,afterValidationOnCreate,afterValidationOnUpdate,afterSave,afterCreate,afterUpdate")>
16	</cffunction>
17
18	<cffunction name="test_chain_when_saving_existing_object">
19		<cftransaction>
20			<cfset loc.obj.save(transaction="none")>
21			<cftransaction action="rollback"/>
22		</cftransaction>
23		<cfset assert("loc.obj.callbackCount IS 4")>
24	</cffunction>
25
26	<cffunction name="test_chain_when_saving_existing_object_with_all_callbacks_skipped">
27		<cftransaction>
28			<cfset loc.obj.save(transaction="none", callbacks=false)>
29			<cftransaction action="rollback"/>
30		</cftransaction>
31		<cfset assert("NOT StructKeyExists(loc.obj, 'callbackCount')")>
32	</cffunction>
33
34</cfcomponent>