Advertisement
Guest User

Untitled

a guest
May 6th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Test of extending a model
  2. Faction = Model.extend ->
  3.   attributes ["name", "description", "members"]
  4.  
  5.   validates "name", presence: true, type: "String"
  6.   validates "description", presence: true, length: 25, type: "String"
  7.   validates "members", type: "Array(String)"
  8.  
  9. # Test of create
  10. newFaction = Faction.create name: "TheForgotten", description: "The forgotten people of middle earth.", members: ["Tim"]
  11.  
  12. # Test of read
  13. otherFaction = Faction.find name: "Blah"
  14.  
  15. # Test of update
  16. newFaction.name = "Foo"
  17. newFaction.save()
  18.  
  19. # Test of destroy
  20. newFaction.destroy()
  21.  
  22. ----------------
  23.  
  24. var Faction, newFaction, otherFaction;
  25. Faction = Model.extend(function() {
  26.   attributes(["name", "description", "members"]);
  27.   validates("name", {
  28.     presence: true,
  29.     type: "String"
  30.   });
  31.   validates("description", {
  32.     presence: true,
  33.     length: 25,
  34.     type: "String"
  35.   });
  36.   return validates("members", {
  37.     type: "Array(String)"
  38.   });
  39. });
  40. newFaction = Faction.create({
  41.   name: "TheForgotten",
  42.   description: "The forgotten people of middle earth.",
  43.   members: ["Tim"]
  44. });
  45. otherFaction = Faction.find({
  46.   name: "Blah"
  47. });
  48. newFaction.name = "Foo";
  49. newFaction.save();
  50. newFaction.destroy();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement