PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/wheels/tests/model/properties/toggle.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 45 lines | 38 code | 7 blank | 0 comment | 0 complexity | f42499d208ea9dc0d6acef725135f376 MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cffunction name="test_toggle_property_with_save">
  3. <cfset loc.model = model("user").findOne(where="firstName='Chris'") />
  4. <cftransaction action="begin">
  5. <cfset loc.saved = loc.model.toggle("isActive") />
  6. <cftransaction action="rollback" />
  7. </cftransaction>.
  8. <cfset assert('loc.model.isActive eq false and loc.saved eq true') />
  9. </cffunction>
  10. <cffunction name="test_toggle_property_without_save">
  11. <cfset loc.model = model("user").findOne(where="firstName='Chris'") />
  12. <cfset loc.model.toggle("isActive", false) />
  13. <cfset assert('loc.model.isActive eq false') />
  14. </cffunction>
  15. <cffunction name="test_toggle_property_dynamic_method_without_save">
  16. <cfset loc.model = model("user").findOne(where="firstName='Chris'") />
  17. <cfset loc.model.toggleIsActive(save=false) />
  18. <cfset assert('loc.model.isActive eq false') />
  19. </cffunction>
  20. <cffunction name="test_toggle_property_dynamic_method_with_save">
  21. <cfset loc.model = model("user").findOne(where="firstName='Chris'") />
  22. <cftransaction action="begin">
  23. <cfset loc.saved = loc.model.toggleIsActive() />
  24. <cftransaction action="rollback" />
  25. </cftransaction>
  26. <cfset assert('loc.model.isActive eq false and loc.saved eq true') />
  27. </cffunction>
  28. <cffunction name="test_toggle_property_without_save_errors_when_not_existing">
  29. <cfset loc.model = model("user").findOne(where="firstName='Chris'") />
  30. <cfset loc.error = raised('loc.model.toggle("isMember", false)') />
  31. <cfset assert('loc.error eq "Wheels.PropertyDoesNotExist"') />
  32. </cffunction>
  33. <cffunction name="test_toggle_property_without_save_errors_when_not_boolean">
  34. <cfset loc.model = model("user").findOne(where="firstName='Chris'") />
  35. <cfset loc.error = raised('loc.model.toggle("firstName", false)') />
  36. <cfset assert('loc.error eq "Wheels.PropertyIsIncorrectType"') />
  37. </cffunction>
  38. </cfcomponent>