PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/wheels/tests/model/validations/skip_validations.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 85 lines | 77 code | 8 blank | 0 comment | 0 complexity | f36dd2b569968b67c58ac1a0af06e53f MD5 | raw file
 1<cfcomponent extends="wheelsMapping.Test">
 2
 3	<cffunction name="setup">
 4		<cfset loc.user = model("user")>
 5		<cfset loc.args = {username="myusername", password="mypassword", firstname="myfirstname", lastname="mylastname"}>
 6	</cffunction>
 7
 8	<cffunction name="test_can_create_new_record_validation_execute">
 9		<cftransaction>
10			<cfset loc.u = loc.user.new(loc.args)>
11			<cfset loc.e = loc.u.isnew()>
12			<cfset loc.r = loc.u.save()>
13			<cftransaction action="rollback" />
14		</cftransaction>
15		<cfset assert('loc.e eq true')>
16		<cfset assert('loc.r eq true')>
17	</cffunction>
18
19	<cffunction name="test_cannot_create_new_record_validation_execute">
20		<cftransaction>
21			<cfset loc.args.username = "1">
22			<cfset loc.u = loc.user.new(loc.args)>
23			<cfset loc.e = loc.u.isnew()>
24			<cfset loc.r = loc.u.save()>
25			<cftransaction action="rollback" />
26		</cftransaction>
27		<cfset assert('loc.e eq true')>
28		<cfset assert('loc.r eq false')>
29	</cffunction>
30
31	<cffunction name="test_can_create_new_record_validation_skipped">
32		<cftransaction>
33			<cfset loc.args.username = "1">
34			<cfset loc.u = loc.user.new(loc.args)>
35			<cfset loc.e = loc.u.isnew()>
36			<cfset loc.r = loc.u.save(validate="false")>
37			<cftransaction action="rollback" />
38		</cftransaction>
39		<cfset assert('loc.e eq true')>
40		<cfset assert('loc.r eq true')>
41	</cffunction>
42
43	<cffunction name="test_can_update_existing_record_validation_execute">
44		<cftransaction>
45			<cfset loc.u = loc.user.findOne(where="lastname = 'Petruzzi'")>
46			<cfset loc.p = loc.u.properties()>
47			<cfset loc.r = loc.u.update(loc.args)>
48			<cfset loc.e = loc.u.isnew()>
49			<cfset loc.u.update(loc.p)>
50			<cftransaction action="rollback" />
51		</cftransaction>
52		<cfset assert('loc.e eq false')>
53		<cfset assert('loc.r eq true')>
54	</cffunction>
55
56	<cffunction name="test_cannot_update_existing_record_validation_execute">
57		<cftransaction>
58			<cfset loc.args.password = "1">
59			<cfset loc.u = loc.user.findOne(where="lastname = 'Petruzzi'")>
60			<cfset loc.p = loc.u.properties()>
61			<cfset loc.r = loc.u.update(loc.args)>
62			<cfset loc.e = loc.u.isnew()>
63			<cfset loc.u.update(loc.p)>
64			<cftransaction action="rollback" />
65		</cftransaction>
66		<cfset assert('loc.e eq false')>
67		<cfset assert('loc.r eq false')>
68	</cffunction>
69
70	<cffunction name="test_cant_update_existing_record_validation_skipped">
71		<cftransaction>
72			<cfset loc.args.password = "1">
73			<cfset loc.u = loc.user.findOne(where="lastname = 'Petruzzi'")>
74			<cfset loc.p = loc.u.properties()>
75			<cfset loc.u.setProperties(loc.args)>
76			<cfset loc.e = loc.u.isnew()>
77			<cfset loc.r = loc.u.save(validate="false")>
78			<cfset loc.u.update(loc.p)>
79			<cftransaction action="rollback" />
80		</cftransaction>
81		<cfset assert('loc.e eq false')>
82		<cfset assert('loc.r eq true')>
83	</cffunction>
84
85</cfcomponent>