Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Test of extending a model
- Faction = Model.extend ->
- attributes ["name", "description", "members"]
- validates "name", presence: true, type: "String"
- validates "description", presence: true, length: 25, type: "String"
- validates "members", type: "Array(String)"
- # Test of create
- newFaction = Faction.create name: "TheForgotten", description: "The forgotten people of middle earth.", members: ["Tim"]
- # Test of read
- otherFaction = Faction.find name: "Blah"
- # Test of update
- newFaction.name = "Foo"
- newFaction.save()
- # Test of destroy
- newFaction.destroy()
- ----------------
- var Faction, newFaction, otherFaction;
- Faction = Model.extend(function() {
- attributes(["name", "description", "members"]);
- validates("name", {
- presence: true,
- type: "String"
- });
- validates("description", {
- presence: true,
- length: 25,
- type: "String"
- });
- return validates("members", {
- type: "Array(String)"
- });
- });
- newFaction = Faction.create({
- name: "TheForgotten",
- description: "The forgotten people of middle earth.",
- members: ["Tim"]
- });
- otherFaction = Faction.find({
- name: "Blah"
- });
- newFaction.name = "Foo";
- newFaction.save();
- newFaction.destroy();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement