PageRenderTime 34ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wheels/tests/model/crud/updates.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 92 lines | 82 code | 10 blank | 0 comment | 0 complexity | 32aedfd5677a8733735aadba1b3c75b3 MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cffunction name="test_update">
  3. <cftransaction action="begin">
  4. <cfset loc.author = model("Author").findOne()>
  5. <cfset loc.author.update(firstName="Kermit", lastName="Frog")>
  6. <cfset loc.allKermits = model("Author").findAll(where="firstName='Kermit' AND lastName='Frog'")>
  7. <cftransaction action="rollback" />
  8. </cftransaction>
  9. <cfset assert('loc.allKermits.recordcount eq 1')>
  10. </cffunction>
  11. <cffunction name="test_dynamic_update_with_named_argument">
  12. <cftransaction action="begin">
  13. <cfset loc.author = model("author").findOne(where="firstName='Andy'")>
  14. <cfset loc.profile = model("profile").findOne(where="bio LIKE 'ColdFusion Developer'")>
  15. <cfset loc.author.setProfile(profile=loc.profile)>
  16. <cfset loc.updatedProfile = model("profile").findByKey(loc.profile.id)>
  17. <cftransaction action="rollback" />
  18. </cftransaction>
  19. <cfset assert("loc.updatedProfile.authorId IS loc.author.id")>
  20. </cffunction>
  21. <cffunction name="test_dynamic_update_with_unnamed_argument">
  22. <cftransaction action="begin">
  23. <cfset loc.author = model("author").findOne(where="firstName='Andy'")>
  24. <cfset loc.profile = model("profile").findOne(where="bio LIKE 'ColdFusion Developer'")>
  25. <cfset loc.author.setProfile(loc.profile)>
  26. <cfset loc.updatedProfile = model("profile").findByKey(loc.profile.id)>
  27. <cftransaction action="rollback" />
  28. </cftransaction>
  29. <cfset assert("loc.updatedProfile.authorId IS loc.author.id")>
  30. </cffunction>
  31. <cffunction name="test_update_one">
  32. <cftransaction action="begin">
  33. <cfset model("Author").updateOne(where="firstName='Andy'", firstName="Kermit", lastName="Frog")>
  34. <cfset loc.allKermits = model("Author").findAll(where="firstName='Kermit' AND lastName='Frog'")>
  35. <cftransaction action="rollback" />
  36. </cftransaction>
  37. <cfset assert('loc.allKermits.recordcount eq 1')>
  38. </cffunction>
  39. <cffunction name="test_update_one_for_soft_deleted_records">
  40. <cftransaction action="begin">
  41. <cfset loc.post = model("Post").deleteOne(where="views=0")>
  42. <cfset model("Post").updateOne(where="views=0", title="This is a new title", includeSoftDeletes=true)>
  43. <cfset loc.changedPosts = model("Post").findAll(where="title='This is a new title'", includeSoftDeletes=true)>
  44. <cftransaction action="rollback" />
  45. </cftransaction>
  46. <cfset assert('loc.changedPosts.recordcount eq 1')>
  47. </cffunction>
  48. <cffunction name="test_update_by_key">
  49. <cftransaction action="begin">
  50. <cfset loc.author = model("Author").findOne()>
  51. <cfset model("Author").updateByKey(key=loc.author.id, firstName="Kermit", lastName="Frog")>
  52. <cfset loc.allKermits = model("Author").findAll(where="firstName='Kermit' AND lastName='Frog'")>
  53. <cftransaction action="rollback" />
  54. </cftransaction>
  55. <cfset assert('loc.allKermits.recordcount eq 1')>
  56. </cffunction>
  57. <cffunction name="test_update_by_key_for_soft_deleted_records">
  58. <cftransaction action="begin">
  59. <cfset loc.post = model("Post").findOne(where="views=0")>
  60. <cfset model("Post").updateByKey(key=loc.post.id, title="This is a new title", includeSoftDeletes=true)>
  61. <cfset loc.changedPosts = model("Post").findAll(where="title='This is a new title'", includeSoftDeletes=true)>
  62. <cftransaction action="rollback" />
  63. </cftransaction>
  64. <cfset assert('loc.changedPosts.recordcount eq 1')>
  65. </cffunction>
  66. <cffunction name="test_update_all">
  67. <cftransaction action="begin">
  68. <cfset model("Author").updateAll(firstName="Kermit", lastName="Frog")>
  69. <cfset loc.allKermits = model("Author").findAll(where="firstName='Kermit' AND lastName='Frog'")>
  70. <cftransaction action="rollback" />
  71. </cftransaction>
  72. <cfset assert('loc.allKermits.recordcount eq 7')>
  73. </cffunction>
  74. <cffunction name="test_update_all_for_soft_deleted_records">
  75. <cftransaction action="begin">
  76. <cfset model("Post").updateAll(title="This is a new title", includeSoftDeletes=true)>
  77. <cfset loc.changedPosts = model("Post").findAll(where="title='This is a new title'", includeSoftDeletes=true)>
  78. <cftransaction action="rollback" />
  79. </cftransaction>
  80. <cfset assert('loc.changedPosts.recordcount eq 4')>
  81. </cffunction>
  82. </cfcomponent>