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

/wheels/tests/model/crud/updates.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 92 lines | 82 code | 10 blank | 0 comment | 0 complexity | 32aedfd5677a8733735aadba1b3c75b3 MD5 | raw file
 1<cfcomponent extends="wheelsMapping.Test">
 2
 3 	<cffunction name="test_update">
 4		<cftransaction action="begin">
 5			<cfset loc.author = model("Author").findOne()>
 6			<cfset loc.author.update(firstName="Kermit", lastName="Frog")>
 7			<cfset loc.allKermits = model("Author").findAll(where="firstName='Kermit' AND lastName='Frog'")>
 8			<cftransaction action="rollback" />
 9		</cftransaction>
10		<cfset assert('loc.allKermits.recordcount eq 1')>
11	</cffunction>
12
13 	<cffunction name="test_dynamic_update_with_named_argument">
14		<cftransaction action="begin">
15			<cfset loc.author = model("author").findOne(where="firstName='Andy'")>
16			<cfset loc.profile = model("profile").findOne(where="bio LIKE 'ColdFusion Developer'")>
17			<cfset loc.author.setProfile(profile=loc.profile)>
18			<cfset loc.updatedProfile = model("profile").findByKey(loc.profile.id)>
19			<cftransaction action="rollback" />
20		</cftransaction>
21		<cfset assert("loc.updatedProfile.authorId IS loc.author.id")>
22	</cffunction>
23
24 	<cffunction name="test_dynamic_update_with_unnamed_argument">
25		<cftransaction action="begin">
26			<cfset loc.author = model("author").findOne(where="firstName='Andy'")>
27			<cfset loc.profile = model("profile").findOne(where="bio LIKE 'ColdFusion Developer'")>
28			<cfset loc.author.setProfile(loc.profile)>
29			<cfset loc.updatedProfile = model("profile").findByKey(loc.profile.id)>
30			<cftransaction action="rollback" />
31		</cftransaction>
32		<cfset assert("loc.updatedProfile.authorId IS loc.author.id")>
33	</cffunction>
34
35 	<cffunction name="test_update_one">
36		<cftransaction action="begin">
37			<cfset model("Author").updateOne(where="firstName='Andy'", firstName="Kermit", lastName="Frog")>
38			<cfset loc.allKermits = model("Author").findAll(where="firstName='Kermit' AND lastName='Frog'")>
39			<cftransaction action="rollback" />
40		</cftransaction>
41		<cfset assert('loc.allKermits.recordcount eq 1')>
42	</cffunction>
43
44 	<cffunction name="test_update_one_for_soft_deleted_records">
45		<cftransaction action="begin">
46			<cfset loc.post = model("Post").deleteOne(where="views=0")>
47			<cfset model("Post").updateOne(where="views=0", title="This is a new title", includeSoftDeletes=true)>
48			<cfset loc.changedPosts = model("Post").findAll(where="title='This is a new title'", includeSoftDeletes=true)>
49			<cftransaction action="rollback" />
50		</cftransaction>
51		<cfset assert('loc.changedPosts.recordcount eq 1')>
52	</cffunction>
53
54 	<cffunction name="test_update_by_key">
55		<cftransaction action="begin">
56			<cfset loc.author = model("Author").findOne()>
57			<cfset model("Author").updateByKey(key=loc.author.id, firstName="Kermit", lastName="Frog")>
58			<cfset loc.allKermits = model("Author").findAll(where="firstName='Kermit' AND lastName='Frog'")>
59			<cftransaction action="rollback" />
60		</cftransaction>
61		<cfset assert('loc.allKermits.recordcount eq 1')>
62	</cffunction>
63
64 	<cffunction name="test_update_by_key_for_soft_deleted_records">
65		<cftransaction action="begin">
66			<cfset loc.post = model("Post").findOne(where="views=0")>
67			<cfset model("Post").updateByKey(key=loc.post.id, title="This is a new title", includeSoftDeletes=true)>
68			<cfset loc.changedPosts = model("Post").findAll(where="title='This is a new title'", includeSoftDeletes=true)>
69			<cftransaction action="rollback" />
70		</cftransaction>
71		<cfset assert('loc.changedPosts.recordcount eq 1')>
72	</cffunction>
73
74 	<cffunction name="test_update_all">
75		<cftransaction action="begin">
76			<cfset model("Author").updateAll(firstName="Kermit", lastName="Frog")>
77			<cfset loc.allKermits = model("Author").findAll(where="firstName='Kermit' AND lastName='Frog'")>
78			<cftransaction action="rollback" />
79		</cftransaction>
80		<cfset assert('loc.allKermits.recordcount eq 7')>
81	</cffunction>
82
83 	<cffunction name="test_update_all_for_soft_deleted_records">
84		<cftransaction action="begin">
85			<cfset model("Post").updateAll(title="This is a new title", includeSoftDeletes=true)>
86			<cfset loc.changedPosts = model("Post").findAll(where="title='This is a new title'", includeSoftDeletes=true)>
87			<cftransaction action="rollback" />
88		</cftransaction>
89		<cfset assert('loc.changedPosts.recordcount eq 4')>
90	</cffunction>
91
92</cfcomponent>