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

/wheels/tests/model/calculations/average.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 59 lines | 46 code | 13 blank | 0 comment | 0 complexity | 435146e479371fb9d3f22c23178f1569 MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="wheelsMapping.Test">
  2. <!--- integers --->
  3. <cffunction name="test_average_with_integer">
  4. <cfset loc.result = model("post").average(property="views")>
  5. <cfset assert("loc.result IS 3.25")>
  6. </cffunction>
  7. <cffunction name="test_average_with_integer_with_non_matching_where">
  8. <cfset loc.result = model("post").average(property="views", where="id=0")>
  9. <cfset assert("loc.result IS ''")>
  10. </cffunction>
  11. <cffunction name="test_average_with_integer_with_distinct">
  12. <cfset loc.result = model("post").average(property="views", distinct="true")>
  13. <cfset assert("DecimalFormat(loc.result) IS DecimalFormat(2.66666666667)")>
  14. </cffunction>
  15. <cffunction name="test_average_with_integer_with_ifNull">
  16. <cfset loc.result = model("post").average(property="views", where="id=0", ifNull=0)>
  17. <cfset assert("loc.result IS 0")>
  18. </cffunction>
  19. <!--- floats --->
  20. <cffunction name="test_average_with_float">
  21. <cfset loc.result = model("post").average(property="averageRating")>
  22. <cfset assert("DecimalFormat(loc.result) IS DecimalFormat(3.47)")>
  23. </cffunction>
  24. <cffunction name="test_average_with_float_with_non_matching_where">
  25. <cfset loc.result = model("post").average(property="averageRating", where="id=0")>
  26. <cfset assert("loc.result IS ''")>
  27. </cffunction>
  28. <cffunction name="test_average_with_float_with_distinct">
  29. <cfset loc.result = model("post").average(property="averageRating", distinct="true")>
  30. <cfset assert("DecimalFormat(loc.result) IS DecimalFormat(3.4)")>
  31. </cffunction>
  32. <cffunction name="test_average_with_float_with_ifNull">
  33. <cfset loc.result = model("post").average(property="averageRating", where="id=0", ifNull=0)>
  34. <cfset assert("loc.result IS 0")>
  35. </cffunction>
  36. <!--- include deleted records --->
  37. <cffunction name="test_average_with_include_soft_deletes">
  38. <cftransaction action="begin">
  39. <cfset loc.post = model("Post").findOne(where="views=0")>
  40. <cfset loc.post.delete(transaction="none")>
  41. <cfset loc.average = model("Post").average(property="views", includeSoftDeletes=true)>
  42. <cftransaction action="rollback" />
  43. </cftransaction>
  44. <cfset assert('loc.average eq 3.25')>
  45. </cffunction>
  46. </cfcomponent>