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

/wheels/tests/model/properties/toggle.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 45 lines | 38 code | 7 blank | 0 comment | 0 complexity | f42499d208ea9dc0d6acef725135f376 MD5 | raw file
 1<cfcomponent extends="wheelsMapping.Test">
 2
 3	<cffunction name="test_toggle_property_with_save">
 4		<cfset loc.model = model("user").findOne(where="firstName='Chris'") />
 5		<cftransaction action="begin">
 6			<cfset loc.saved = loc.model.toggle("isActive") />
 7			<cftransaction action="rollback" />
 8		</cftransaction>.
 9		<cfset assert('loc.model.isActive eq false and loc.saved eq true') />
10	</cffunction>
11
12	<cffunction name="test_toggle_property_without_save">
13		<cfset loc.model = model("user").findOne(where="firstName='Chris'") />
14		<cfset loc.model.toggle("isActive", false) />
15		<cfset assert('loc.model.isActive eq false') />
16	</cffunction>
17
18	<cffunction name="test_toggle_property_dynamic_method_without_save">
19		<cfset loc.model = model("user").findOne(where="firstName='Chris'") />
20		<cfset loc.model.toggleIsActive(save=false) />
21		<cfset assert('loc.model.isActive eq false') />
22	</cffunction>
23
24	<cffunction name="test_toggle_property_dynamic_method_with_save">
25		<cfset loc.model = model("user").findOne(where="firstName='Chris'") />
26		<cftransaction action="begin">
27			<cfset loc.saved = loc.model.toggleIsActive() />
28			<cftransaction action="rollback" />
29		</cftransaction>
30		<cfset assert('loc.model.isActive eq false and loc.saved eq true') />
31	</cffunction>
32
33	<cffunction name="test_toggle_property_without_save_errors_when_not_existing">
34		<cfset loc.model = model("user").findOne(where="firstName='Chris'") />
35		<cfset loc.error = raised('loc.model.toggle("isMember", false)') />
36		<cfset assert('loc.error eq "Wheels.PropertyDoesNotExist"') />
37	</cffunction>
38
39	<cffunction name="test_toggle_property_without_save_errors_when_not_boolean">
40		<cfset loc.model = model("user").findOne(where="firstName='Chris'") />
41		<cfset loc.error = raised('loc.model.toggle("firstName", false)') />
42		<cfset assert('loc.error eq "Wheels.PropertyIsIncorrectType"') />
43	</cffunction>
44
45</cfcomponent>