PageRenderTime 153ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/tests/model/validations/skip_validations.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 85 lines | 77 code | 8 blank | 0 comment | 0 complexity | f36dd2b569968b67c58ac1a0af06e53f MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cffunction name="setup">
  3. <cfset loc.user = model("user")>
  4. <cfset loc.args = {username="myusername", password="mypassword", firstname="myfirstname", lastname="mylastname"}>
  5. </cffunction>
  6. <cffunction name="test_can_create_new_record_validation_execute">
  7. <cftransaction>
  8. <cfset loc.u = loc.user.new(loc.args)>
  9. <cfset loc.e = loc.u.isnew()>
  10. <cfset loc.r = loc.u.save()>
  11. <cftransaction action="rollback" />
  12. </cftransaction>
  13. <cfset assert('loc.e eq true')>
  14. <cfset assert('loc.r eq true')>
  15. </cffunction>
  16. <cffunction name="test_cannot_create_new_record_validation_execute">
  17. <cftransaction>
  18. <cfset loc.args.username = "1">
  19. <cfset loc.u = loc.user.new(loc.args)>
  20. <cfset loc.e = loc.u.isnew()>
  21. <cfset loc.r = loc.u.save()>
  22. <cftransaction action="rollback" />
  23. </cftransaction>
  24. <cfset assert('loc.e eq true')>
  25. <cfset assert('loc.r eq false')>
  26. </cffunction>
  27. <cffunction name="test_can_create_new_record_validation_skipped">
  28. <cftransaction>
  29. <cfset loc.args.username = "1">
  30. <cfset loc.u = loc.user.new(loc.args)>
  31. <cfset loc.e = loc.u.isnew()>
  32. <cfset loc.r = loc.u.save(validate="false")>
  33. <cftransaction action="rollback" />
  34. </cftransaction>
  35. <cfset assert('loc.e eq true')>
  36. <cfset assert('loc.r eq true')>
  37. </cffunction>
  38. <cffunction name="test_can_update_existing_record_validation_execute">
  39. <cftransaction>
  40. <cfset loc.u = loc.user.findOne(where="lastname = 'Petruzzi'")>
  41. <cfset loc.p = loc.u.properties()>
  42. <cfset loc.r = loc.u.update(loc.args)>
  43. <cfset loc.e = loc.u.isnew()>
  44. <cfset loc.u.update(loc.p)>
  45. <cftransaction action="rollback" />
  46. </cftransaction>
  47. <cfset assert('loc.e eq false')>
  48. <cfset assert('loc.r eq true')>
  49. </cffunction>
  50. <cffunction name="test_cannot_update_existing_record_validation_execute">
  51. <cftransaction>
  52. <cfset loc.args.password = "1">
  53. <cfset loc.u = loc.user.findOne(where="lastname = 'Petruzzi'")>
  54. <cfset loc.p = loc.u.properties()>
  55. <cfset loc.r = loc.u.update(loc.args)>
  56. <cfset loc.e = loc.u.isnew()>
  57. <cfset loc.u.update(loc.p)>
  58. <cftransaction action="rollback" />
  59. </cftransaction>
  60. <cfset assert('loc.e eq false')>
  61. <cfset assert('loc.r eq false')>
  62. </cffunction>
  63. <cffunction name="test_cant_update_existing_record_validation_skipped">
  64. <cftransaction>
  65. <cfset loc.args.password = "1">
  66. <cfset loc.u = loc.user.findOne(where="lastname = 'Petruzzi'")>
  67. <cfset loc.p = loc.u.properties()>
  68. <cfset loc.u.setProperties(loc.args)>
  69. <cfset loc.e = loc.u.isnew()>
  70. <cfset loc.r = loc.u.save(validate="false")>
  71. <cfset loc.u.update(loc.p)>
  72. <cftransaction action="rollback" />
  73. </cftransaction>
  74. <cfset assert('loc.e eq false')>
  75. <cfset assert('loc.r eq true')>
  76. </cffunction>
  77. </cfcomponent>