/wheels/tests/model/properties/accessibleproperties.cfc

http://cfwheels.googlecode.com/ · ColdFusion CFScript · 37 lines · 33 code · 4 blank · 0 comment · 0 complexity · cba559664a4d47e45279f5999e21e40b MD5 · raw file

  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cffunction name="test_all_properties_can_be_set_by_default">
  3. <cfset loc.model = model("author") />
  4. <cfset loc.model = duplicate(loc.model)>
  5. <cfset loc.properties = { firstName = "James", lastName = "Gibson" } />
  6. <cfset loc.model = loc.model.new(properties=loc.properties) />
  7. <cfset assert('StructKeyExists(loc.model, "firstName") eq true') />
  8. <cfset assert('StructKeyExists(loc.model, "lastName") eq true') />
  9. </cffunction>
  10. <cffunction name="test_all_other_properties_cannot_be_set_except_accessible_properties">
  11. <cfset loc.model = model("post") />
  12. <cfset loc.model = duplicate(loc.model)>
  13. <cfset loc.model.accessibleProperties(properties="views") />
  14. <cfset loc.properties = { views = "2000", averageRating = 4.9, body = "This is the body", title = "this is the title" } />
  15. <cfset loc.model = loc.model.new(properties=loc.properties) />
  16. <cfset assert('StructKeyExists(loc.model, "averageRating") eq false') />
  17. <cfset assert('StructKeyExists(loc.model, "body") eq false') />
  18. <cfset assert('StructKeyExists(loc.model, "title") eq false') />
  19. <cfset assert('StructKeyExists(loc.model, "views") eq true') />
  20. </cffunction>
  21. <cffunction name="test_all_other_properties_can_be_set_directly">
  22. <cfset loc.model = model("post") />
  23. <cfset loc.model = duplicate(loc.model)>
  24. <cfset loc.model.accessibleProperties(propertyName="views") />
  25. <cfset loc.model = loc.model.new() />
  26. <cfset loc.model.averageRating = 4.9 />
  27. <cfset loc.model.body = "This is the body" />
  28. <cfset loc.model.title = "this is the title" />
  29. <cfset assert('StructKeyExists(loc.model, "averageRating") eq true') />
  30. <cfset assert('StructKeyExists(loc.model, "body") eq true') />
  31. <cfset assert('StructKeyExists(loc.model, "title") eq true') />
  32. </cffunction>
  33. </cfcomponent>