PageRenderTime 21ms CodeModel.GetById 10ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/wheels/tests/model/crud/deletes.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 173 lines | 156 code | 17 blank | 0 comment | 0 complexity | e8fe57572e97e9a9f987732d294054c9 MD5 | raw file
  1<cfcomponent extends="wheelsMapping.Test">
  2 
  3 	<cffunction name="test_delete">
  4		<cftransaction action="begin">
  5			<cfset loc.author = model("Author").findOne()>
  6			<cfset loc.author.delete()>
  7			<cfset loc.allAuthors = model("Author").findAll()>
  8			<cftransaction action="rollback" />
  9		</cftransaction>
 10		<cfset assert('loc.allAuthors.recordcount eq 6')>
 11	</cffunction>
 12
 13 	<cffunction name="test_soft_delete">
 14		<cftransaction action="begin">
 15			<cfset loc.post = model("Post").findOne()>
 16			<cfset loc.post.delete()>
 17			<cfset loc.postsWithoutSoftDeletes = model("Post").findAll()>
 18			<cfset loc.postsWithSoftDeletes = model("Post").findAll(includeSoftDeletes=true)>
 19			<cftransaction action="rollback" />
 20		</cftransaction>
 21		<cfset assert('loc.postsWithoutSoftDeletes.recordcount eq 3 AND loc.postsWithSoftDeletes.recordcount eq 4')>
 22	</cffunction>
 23
 24 	<cffunction name="test_permanent_delete">
 25		<cftransaction action="begin">
 26			<cfset loc.post = model("Post").findOne()>
 27			<cfset loc.post.delete(softDelete=false)>
 28			<cfset loc.postsWithoutSoftDeletes = model("Post").findAll()>
 29			<cfset loc.postsWithSoftDeletes = model("Post").findAll(includeSoftDeletes=true)>
 30			<cftransaction action="rollback" />
 31		</cftransaction>
 32		<cfset assert('loc.postsWithoutSoftDeletes.recordcount eq 3 AND loc.postsWithSoftDeletes.recordcount eq 3')>
 33	</cffunction>
 34
 35 	<cffunction name="test_permanent_delete_of_soft_deleted_records">
 36		<cftransaction action="begin">
 37			<cfset loc.post = model("Post").findOne()>
 38			<cfset loc.post.delete()>
 39			<cfset loc.softDeletedPost = model("Post").findByKey(key=loc.post.id, includeSoftDeletes=true)>
 40			<cfset loc.softDeletedPost.delete(includeSoftDeletes=true, softDelete=false)>
 41			<cfset loc.postsWithoutSoftDeletes = model("Post").findAll()>
 42			<cfset loc.postsWithSoftDeletes = model("Post").findAll(includeSoftDeletes=true)>
 43			<cftransaction action="rollback" />
 44		</cftransaction>
 45		<cfset assert('loc.postsWithoutSoftDeletes.recordcount eq 3 AND loc.postsWithSoftDeletes.recordcount eq 3')>
 46	</cffunction>
 47
 48 	<cffunction name="test_delete_by_key">
 49		<cftransaction action="begin">
 50			<cfset loc.post = model("Author").findOne()>
 51			<cfset model("Author").deleteByKey(loc.post.id)>
 52			<cfset loc.allAuthors = model("Author").findAll()>
 53			<cftransaction action="rollback" />
 54		</cftransaction>
 55		<cfset assert('loc.allAuthors.recordcount eq 6')>
 56	</cffunction>
 57
 58 	<cffunction name="test_soft_delete_by_key">
 59		<cftransaction action="begin">
 60			<cfset loc.post = model("Post").findOne()>
 61			<cfset model("Post").deleteByKey(loc.post.id)>
 62			<cfset loc.postsWithoutSoftDeletes = model("Post").findAll(includeSoftDeletes=false)>
 63			<cfset loc.postsWithSoftDeletes = model("Post").findAll(includeSoftDeletes=true)>
 64			<cftransaction action="rollback" />
 65		</cftransaction>
 66		<cfset assert('loc.postsWithoutSoftDeletes.recordcount eq 3 AND loc.postsWithSoftDeletes.recordcount eq 4')>
 67	</cffunction>
 68
 69 	<cffunction name="test_permanent_delete_by_key">
 70		<cftransaction action="begin">
 71			<cfset loc.post = model("Post").findOne()>
 72			<cfset model("Post").deleteByKey(key=loc.post.id, softDelete=false)>
 73			<cfset loc.postsWithoutSoftDeletes = model("Post").findAll()>
 74			<cfset loc.postsWithSoftDeletes = model("Post").findAll(includeSoftDeletes=true)>
 75			<cftransaction action="rollback" />
 76		</cftransaction>
 77		<cfset assert('loc.postsWithoutSoftDeletes.recordcount eq 3 AND loc.postsWithSoftDeletes.recordcount eq 3')>
 78	</cffunction>
 79
 80 	<cffunction name="test_permanent_delete_by_key_of_soft_deleted_records">
 81		<cftransaction action="begin">
 82			<cfset loc.post = model("Post").findOne()>
 83			<cfset model("Post").deleteOne(where="id=#loc.post.id#")>
 84			<cfset model("Post").deleteOne(where="id=#loc.post.id#", includeSoftDeletes=true, softDelete=false)>
 85			<cfset loc.postsWithoutSoftDeletes = model("Post").findAll()>
 86			<cfset loc.postsWithSoftDeletes = model("Post").findAll(includeSoftDeletes=true)>
 87			<cftransaction action="rollback" />
 88		</cftransaction>
 89		<cfset assert('loc.postsWithoutSoftDeletes.recordcount eq 3 AND loc.postsWithSoftDeletes.recordcount eq 3')>
 90	</cffunction>
 91 
 92 	<cffunction name="test_delete_one">
 93		<cftransaction action="begin">
 94			<cfset model("Author").deleteOne()>
 95			<cfset loc.allAuthors = model("Author").findAll()>
 96			<cftransaction action="rollback" />
 97		</cftransaction>
 98		<cfset assert('loc.allAuthors.recordcount eq 6')>
 99	</cffunction>
100
101 	<cffunction name="test_soft_delete_one">
102		<cftransaction action="begin">
103			<cfset model("Post").deleteOne()>
104			<cfset loc.postsWithoutSoftDeletes = model("Post").findAll()>
105			<cfset loc.postsWithSoftDeletes = model("Post").findAll(includeSoftDeletes=true)>
106			<cftransaction action="rollback" />
107		</cftransaction>
108		<cfset assert('loc.postsWithoutSoftDeletes.recordcount eq 3 AND loc.postsWithSoftDeletes.recordcount eq 4')>
109	</cffunction>
110
111 	<cffunction name="test_permanent_delete_one">
112		<cftransaction action="begin">
113			<cfset model("Post").deleteOne(softDelete=false)>
114			<cfset loc.postsWithoutSoftDeletes = model("Post").findAll()>
115			<cfset loc.postsWithSoftDeletes = model("Post").findAll(includeSoftDeletes=true)>
116			<cftransaction action="rollback" />
117		</cftransaction>
118		<cfset assert('loc.postsWithoutSoftDeletes.recordcount eq 3 AND loc.postsWithSoftDeletes.recordcount eq 3')>
119	</cffunction>
120
121 	<cffunction name="test_permanent_delete_one_of_soft_deleted_records">
122		<cftransaction action="begin">
123			<cfset loc.post = model("Post").findOne()>
124			<cfset model("Post").deleteOne(where="id=#loc.post.id#")>
125			<cfset model("Post").deleteOne(where="id=#loc.post.id#", includeSoftDeletes=true, softDelete=false)>
126			<cfset loc.postsWithoutSoftDeletes = model("Post").findAll()>
127			<cfset loc.postsWithSoftDeletes = model("Post").findAll(includeSoftDeletes=true)>
128			<cftransaction action="rollback" />
129		</cftransaction>
130		<cfset assert('loc.postsWithoutSoftDeletes.recordcount eq 3 AND loc.postsWithSoftDeletes.recordcount eq 3')>
131	</cffunction>
132
133 	<cffunction name="test_delete_all">
134		<cftransaction action="begin">
135			<cfset model("Author").deleteAll()>
136			<cfset loc.allAuthors = model("Author").findAll()>
137			<cftransaction action="rollback" />
138		</cftransaction>
139		<cfset assert('loc.allAuthors.recordcount eq 0')>
140	</cffunction>
141
142 	<cffunction name="test_soft_delete_all">
143		<cftransaction action="begin">
144			<cfset model("Post").deleteAll()>
145			<cfset loc.postsWithoutSoftDeletes = model("Post").findAll()>
146			<cfset loc.postsWithSoftDeletes = model("Post").findAll(includeSoftDeletes=true)>
147			<cftransaction action="rollback" />
148		</cftransaction>
149		<cfset assert('loc.postsWithoutSoftDeletes.recordcount eq 0 AND loc.postsWithSoftDeletes.recordcount eq 4')>
150	</cffunction>
151
152 	<cffunction name="test_permanent_delete_all">
153		<cftransaction action="begin">
154			<cfset model("Post").deleteAll(softDelete=false)>
155			<cfset loc.postsWithoutSoftDeletes = model("Post").findAll()>
156			<cfset loc.postsWithSoftDeletes = model("Post").findAll(includeSoftDeletes=true)>
157			<cftransaction action="rollback" />
158		</cftransaction>
159		<cfset assert('loc.postsWithoutSoftDeletes.recordcount eq 0 AND loc.postsWithSoftDeletes.recordcount eq 0')>
160	</cffunction>
161
162 	<cffunction name="test_permanent_delete_all_of_soft_deleted_records">
163		<cftransaction action="begin">
164			<cfset model("Post").deleteAll()>
165			<cfset model("Post").deleteAll(includeSoftDeletes=true, softDelete=false)>
166			<cfset loc.postsWithoutSoftDeletes = model("Post").findAll()>
167			<cfset loc.postsWithSoftDeletes = model("Post").findAll(includeSoftDeletes=true)>
168			<cftransaction action="rollback" />
169		</cftransaction>
170		<cfset assert('loc.postsWithoutSoftDeletes.recordcount eq 0 AND loc.postsWithSoftDeletes.recordcount eq 0')>
171	</cffunction>
172
173</cfcomponent>