PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/tests/model/calculations/count.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 60 lines | 49 code | 11 blank | 0 comment | 0 complexity | 38e75afc2da91552ec4dbfa82e540fd3 MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cffunction name="test_count">
  3. <cfset loc.result = model("author").count()>
  4. <cfset assert("loc.result IS 7")>
  5. </cffunction>
  6. <cffunction name="test_count_with_include">
  7. <cfset loc.result = model("author").count(include="posts")>
  8. <cfset assert("loc.result IS 7")>
  9. </cffunction>
  10. <cffunction name="test_count_with_where">
  11. <cfset loc.result = model("author").count(where="lastName = 'Djurner'")>
  12. <cfset assert("loc.result IS 1")>
  13. </cffunction>
  14. <cffunction name="test_count_with_non_matching_where">
  15. <cfset loc.result = model("author").count(where="id=0")>
  16. <cfset assert("loc.result IS 0")>
  17. </cffunction>
  18. <cffunction name="test_count_with_non_matching_where_and_include">
  19. <cfset loc.result = model("author").count(where="id = 0", include="posts")>
  20. <cfset assert("loc.result IS 0")>
  21. </cffunction>
  22. <cffunction name="test_count_with_where_and_include">
  23. <cfset loc.result = model("author").count(where="lastName = 'Djurner' OR lastName = 'Peters'", include="posts")>
  24. <cfset assert("loc.result IS 2")>
  25. </cffunction>
  26. <cffunction name="test_count_with_where_on_included_association">
  27. <cfset loc.result = model("author").count(where="title LIKE '%first%' OR title LIKE '%second%' OR title LIKE '%fourth%'", include="posts")>
  28. <cfset assert("loc.result IS 2")>
  29. </cffunction>
  30. <cffunction name="test_dynamic_count">
  31. <cfset loc.author = model("author").findOne(where="lastName='Djurner'")>
  32. <cfset loc.result = loc.author.postCount()>
  33. <cfset assert("loc.result IS 3")>
  34. </cffunction>
  35. <cffunction name="test_dynamic_count_with_where">
  36. <cfset loc.author = model("author").findOne(where="lastName='Djurner'")>
  37. <cfset loc.result = loc.author.postCount(where="title LIKE '%first%' OR title LIKE '%second%'")>
  38. <cfset assert("loc.result IS 2")>
  39. </cffunction>
  40. <cffunction name="test_count_with_include_soft_deletes">
  41. <cftransaction action="begin">
  42. <cfset loc.post = model("Post").findOne(where="views=0")>
  43. <cfset loc.post.delete(transaction="none")>
  44. <cfset loc.count = model("Post").count(property="views", includeSoftDeletes=true)>
  45. <cftransaction action="rollback" />
  46. </cftransaction>
  47. <cfset assert('loc.count eq 4')>
  48. </cffunction>
  49. </cfcomponent>