+ module('model - create');
+
+ asyncTest("create/read/delete/read (ok)", function() {
+ var TOKEN = new Date().getTime();
+ var c1 = new ContactModel({
+ contact_type: "Individual",
+ first_name: "George" + TOKEN,
+ last_name: "Anon" + TOKEN
+ });
+ equal(c1.isSaved(), false, "");
+
+ // Create the new contact
+ c1.save({}, {
+ error: onUnexpectedError,
+ success: function() {
+ equal(c1.get("first_name"), "George" + TOKEN, "save() should return new first name");
+ equal(c1.isSaved(), true, "");
+
+ // Fetch the newly created contact
+ var c2 = new ContactModel({id: c1.get('id')});
+ equal(c2.isSaved(), true, "");
+ c2.fetch({
+ error: onUnexpectedError,
+ success: function() {
+ equal(c2.get("first_name"), c1.get("first_name"), "fetch() should return first name");
+ equal(c2.isSaved(), true, "");
+
+ // Destroy the newly created contact
+ c2.destroy({
+ error: onUnexpectedError,
+ success: function() {
+ equal(c2.isSaved(), true, "");
+
+ // Attempt (but fail) to fetch the deleted contact
+ var c3 = new ContactModel({id: c1.get('id')});
+ equal(c3.isSaved(), true, "");
+ c3.fetch({
+ success: onUnexpectedSuccess,
+ error: function(model, error) {
+ assertApiError(error);
+ start();
+ }
+ }); // fetch
+ }
+ }); // destroy
+ }
+ }); // fetch
+ }
+ }); // save
+ });