PageRenderTime 61ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/wheels/tests/model/callbacks/afterFind.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 63 lines | 50 code | 13 blank | 0 comment | 0 complexity | e8de8d733a5a6c9a5f1b3d856510f927 MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  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_property_named_method_should_not_clash_with_cfinvoke">
  9. <cfset loc.results = model("collisionTest").findAll(returnAs="objects")>
  10. <cfset assert("loc.results[1].method IS 'done'")>
  11. </cffunction>
  12. <cffunction name="test_setting_one_query_record">
  13. <cfset loc.posts = model("post").findAll(maxRows=1, order="id DESC")>
  14. <cfset assert("loc.posts.views[1] IS 103 AND loc.posts['title'][1] IS 'setTitle'")>
  15. </cffunction>
  16. <cffunction name="test_setting_one_query_record_with_skipped_callback">
  17. <cfset loc.posts = model("post").findAll(maxRows=1, order="id DESC")>
  18. <cfset assert("loc.posts.views[1] IS 103 AND loc.posts['title'][1] IS 'setTitle'")>
  19. </cffunction>
  20. <cffunction name="test_setting_multiple_query_records">
  21. <cfset loc.posts = model("post").findAll(order="id DESC")>
  22. <cfset assert("loc.posts.views[1] IS 103 AND loc.posts.views[2] IS 100 AND loc.posts['title'][1] IS 'setTitle'")>
  23. </cffunction>
  24. <cffunction name="test_setting_multiple_query_records_with_skipped_callback">
  25. <cfset loc.posts = model("post").findAll(order="id DESC", callbacks=false)>
  26. <cfset assert("loc.posts.views[1] IS '3' AND loc.posts.views[2] IS 0 AND loc.posts.title[1] IS 'Title for fourth test post'")>
  27. </cffunction>
  28. <cffunction name="test_setting_property_on_one_object">
  29. <cfset loc.post = model("post").findOne()>
  30. <cfset assert("loc.post.title IS 'setTitle'")>
  31. </cffunction>
  32. <cffunction name="test_setting_property_on_one_object_with_skipped_callback">
  33. <cfset loc.post = model("post").findOne(callbacks=false)>
  34. <cfset assert("loc.post.title IS 'Title for first test post'")>
  35. </cffunction>
  36. <cffunction name="test_setting_properties_on_multiple_objects">
  37. <cfset loc.posts = model("post").findAll(returnAs="objects")>
  38. <cfset assert("loc.posts[1].title IS 'setTitle' AND loc.posts[2].title IS 'setTitle'")>
  39. </cffunction>
  40. <cffunction name="test_setting_properties_on_multiple_objects_with_skipped_callback">
  41. <cfset loc.posts = model("post").findAll(returnAs="objects", callbacks=false)>
  42. <cfset assert("loc.posts[1].title IS 'Title for first test post' AND loc.posts[2].title IS 'Title for second test post'")>
  43. </cffunction>
  44. <cffunction name="test_creation_of_new_column_and_property">
  45. <cfset loc.posts = model("post").findAll(order="id DESC")>
  46. <cfset assert("loc.posts.something[1] eq 'hello world'")>
  47. <cfset loc.posts = model("post").findAll(returnAs="objects")>
  48. <cfset assert("loc.posts[1].something eq 'hello world'")>
  49. </cffunction>
  50. </cfcomponent>