/wheels/tests/model/callbacks/afterFindNonLegacy.cfc

http://cfwheels.googlecode.com/ · ColdFusion CFScript · 34 lines · 28 code · 6 blank · 0 comment · 0 complexity · eab4ad0bed7026ed7bcbfe3c2597255b MD5 · raw file

  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cffunction name="setup">
  3. <cfset model("post").$registerCallback(type="afterFind", methods="afterFindCallback")>
  4. </cffunction>
  5. <cffunction name="teardown">
  6. <cfset model("post").$clearCallbacks(type="afterFind")>
  7. </cffunction>
  8. <cffunction name="test_setting_property_on_one_object">
  9. <cfset loc.post = model("post").findOne()>
  10. <cfset assert("loc.post.title IS 'setTitle'")>
  11. </cffunction>
  12. <cffunction name="test_setting_properties_on_multiple_objects">
  13. <cfset loc.postsOrg = model("post").findAll(returnAs="objects", callbacks="false", orderby="views DESC")>
  14. <cfset loc.views1 = loc.postsOrg[1].views + 100>
  15. <cfset loc.views2 = loc.postsOrg[2].views + 100>
  16. <cfset loc.posts = model("post").findAll(returnAs="objects", orderby="views DESC")>
  17. <cfset assert("loc.posts[1].title IS 'setTitle'")>
  18. <cfset assert("loc.posts[2].title IS 'setTitle'")>
  19. <cfset assert("loc.posts[1].views EQ loc.views1")>
  20. <cfset assert("loc.posts[2].views EQ loc.views2")>
  21. </cffunction>
  22. <cffunction name="test_creation_of_new_column_and_property">
  23. <cfset loc.posts = model("post").findAll(order="id DESC")>
  24. <cfset assert("loc.posts.something[1] eq 'hello world'")>
  25. <cfset loc.posts = model("post").findAll(returnAs="objects")>
  26. <cfset assert("loc.posts[1].something eq 'hello world'")>
  27. </cffunction>
  28. </cfcomponent>