PageRenderTime 34ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/wheels/tests/model/nestedproperties/one_to_many.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 50 lines | 45 code | 5 blank | 0 comment | 0 complexity | 29cfb9b248b215916ae6a0b9e5a3b892 MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cffunction name="setup">
  3. <cfset loc.gallery = model("gallery")>
  4. <cfset loc.photo = model("photo")>
  5. <cfset loc.user = model("user")>
  6. <cfset loc.testGallery = $setTestObjects()>
  7. </cffunction>
  8. <cffunction name="test_add_children_via_object_array">
  9. <cftransaction>
  10. <cfset assert("loc.testGallery.save()")>
  11. <cfset loc.testGallery = loc.gallery.findOneByTitle(value="Nested Properties Gallery", include="photos")>
  12. <cfset assert("IsArray(loc.testGallery.photos)")>
  13. <cfset assert("ArrayLen(loc.testGallery.photos) eq 3")>
  14. <cftransaction action="rollback"/>
  15. </cftransaction>
  16. </cffunction>
  17. <cffunction name="test_delete_children_via_object_array">
  18. <cftransaction>
  19. <cfset assert("loc.testGallery.save()")>
  20. <cfset loc.testGallery = loc.gallery.findOneByTitle(value="Nested Properties Gallery", include="photos")>
  21. <cfloop array="#loc.testGallery.photos#" index="loc.i">
  22. <cfset loc.i._delete = true>
  23. </cfloop>
  24. <cfset loc.testGallery.save()>
  25. <cfset assert("IsArray(loc.testGallery.photos)")>
  26. <cfset assert("ArrayLen(loc.testGallery.photos) eq 0")>
  27. <cftransaction action="rollback"/>
  28. </cftransaction>
  29. </cffunction>
  30. <cffunction name="$setTestObjects" access="private" hint="Sets up test gallery/gallery photo objects.">
  31. <!--- User --->
  32. <cfset loc.u = loc.user.findOneByLastName("Petruzzi")>
  33. <!--- Gallery --->
  34. <cfset loc.params = {userId=loc.u.id, title="Nested Properties Gallery", description="A gallery testing nested properties."}>
  35. <cfset loc.g = loc.gallery.new(loc.params)>
  36. <cfset
  37. loc.g.photos = [
  38. loc.photo.new(userId=loc.u.id, filename="Nested Properties Photo Test 1", DESCRIPTION1="test photo 1 for nested properties gallery"),
  39. loc.photo.new(userId=loc.u.id, filename="Nested Properties Photo Test 2", DESCRIPTION1="test photo 2 for nested properties gallery"),
  40. loc.photo.new(userId=loc.u.id, filename="Nested Properties Photo Test 3", DESCRIPTION1="test photo 3 for nested properties gallery")
  41. ]
  42. >
  43. <cfreturn loc.g>
  44. </cffunction>
  45. </cfcomponent>