model-test.js revision ee8c11237e0fb20d3bfc4329e5e5a2a05b223d9c
var ArrayAssert = Y.ArrayAssert,
ObjectAssert = Y.ObjectAssert,
// -- Global Suite -------------------------------------------------------------
// -- Model Suite --------------------------------------------------------------
// -- Model: Lifecycle ---------------------------------------------------------
name: 'Lifecycle',
'destroy() should destroy the model instance': function () {
};
},
'destroy() should call a callback if provided as the only arg': function () {
method: 'callback',
args : []
});
},
'destroy() should call a callback if provided as the second arg': function () {
method: 'callback',
args : []
});
},
'destroy() should delete the model if the `delete` option is truthy': function () {
var calls = 0,
method: 'callback',
args : []
});
calls += 1;
callback();
};
},
'destroy() should remove the model from all lists': function () {
}
}));
// -- Model: Attributes and Properties -----------------------------------------
name: 'Attributes and Properties',
setUp: function () {
idAttribute: 'customId'
}, {
ATTRS: {
}
});
},
tearDown: function () {
delete this.TestModel;
},
'Attributes should be settable at instantiation time': function () {
},
'Custom id attribute should be settable at instantiation time': function () {
var model;
// We need to set and get the id and customId attributes in various
// orders to ensure there are no issues due to the attributes being
// lazily added.
},
'`_isYUIModel` property should be true': function () {
},
'`id` attribute should be an alias for the custom id attribute': function () {
var calls = 0,
calls += 1;
});
},
'`changed` property should be a hash of attributes that have changed since last save() or load()': function () {
},
'clientId attribute should be automatically generated': function () {
},
'`lastChange` property should contain attributes that changed in the last `change` event': function () {
},
'`lists` property should be an array of ModelList instances that contain this model': function () {
var calls = 0,
lists = [
];
function onChange() {
calls += 1;
}
}
}));
// -- Model: Methods -----------------------------------------------------------
name: 'Methods',
setUp: function () {
ATTRS: {
}
});
},
tearDown: function () {
delete this.TestModel;
},
'generateClientId() should generate a unique client id': function () {
},
'getAsHTML() should return an HTML-escaped attribute value': function () {
var value = '<div id="foo">hello!</div>',
},
'getAsURL() should return a URL-encoded attribute value': function () {
var value = 'foo & bar = baz',
},
'isModified() should return true if the model is new': function () {
},
'isModified() should return true if the model has changed since it was last saved': function () {
},
'isNew() should return true if the model is new': function () {
},
'load() should delegate to sync()': function () {
var calls = 0,
opts = {};
calls += 1;
callback();
};
},
'load() should reset this.changed when loading succeeds': function () {
},
'load() should be chainable and should call the callback if one was provided': function () {
var calls = 0,
calls += 1;
}));
calls += 1;
}));
},
'parse() should parse a JSON string and return an object': function () {
},
'parse() should not try to parse non-strings': function () {
},
'save() should delegate to sync()': function () {
var calls = 0,
opts = {};
calls += 1;
// Give the model an id so it will no longer be new.
};
calls += 1;
};
},
'save() should reset this.changed when saving succeeds': function () {
},
'save() should be chainable and should call the callback if one was provided': function () {
var calls = 0,
calls += 1;
}));
calls += 1;
}));
},
'set() should set the value of a single attribute': function () {
},
'setAttrs() should set the values of multiple attributes': function () {
},
'sync() should just call the supplied callback by default': function () {
var calls = 0,
calls += 1;
});
},
"toJSON() should return a copy of the model's attributes, minus excluded ones": function () {
// When there's a custom id attribute, the 'id' attribute should be
// excluded.
idAttribute: 'customId'
}, {
ATTRS: {
}
});
},
'undo() should revert the previous change to the model': function () {
},
'undo() should revert only the specified attributes when attributes are specified': function () {
},
'undo() should pass options to setAttrs()': function () {
var calls = 0,
calls += 1;
});
},
'undo() should do nothing when there is no previous change to revert': function () {
});
},
'validate() should only be called on save()': function () {
var calls = 0,
calls += 1;
callback();
};
},
'a validation failure should abort a save() call': function () {
var calls = 0,
errors = 0,
saveCallbacks = 0;
calls += 1;
callback('OMG invalid!');
};
};
errors += 1;
});
saveCallbacks += 1;
});
},
'validate() should be backwards compatible with the 3.4.x synchronous style': function () {
var errors = 0,
saves = 0,
errors += 1;
});
saves += 1;
});
return 'No no no!';
}
};
}
}));
// -- Model: Events ------------------------------------------------------------
name: 'Events',
setUp: function () {
ATTRS: {
}
});
},
tearDown: function () {
delete this.TestModel;
},
'`change` event should contain coalesced attribute changes': function () {
var calls = 0,
calls += 1;
});
foo: 'foo',
bar: 'bar'
}, {src: 'test'});
},
'`change` event should not fire when the _silent_ option is truthy': function () {
});
},
'`change` event facade should contain options passed to set()/setAttrs()': function () {
var calls = 0,
calls += 1;
});
foo: 'foo',
bar: 'bar'
src: 'test',
foo: 'bar'
});
},
'`error` event should fire when validation fails': function () {
var calls = 0,
callback('ERROR. ERROR. DOES NOT COMPUTE.');
};
calls += 1;
});
},
'`error` event should fire when parsing fails': function () {
var calls = 0,
calls += 1;
});
},
'`error` event should fire when a load operation fails': function () {
var calls = 0,
calls += 1;
});
};
},
'`error` event should fire when a save operation fails': function () {
var calls = 0,
calls += 1;
});
};
},
'`load` event should fire after a successful load operation': function () {
var calls = 0,
calls += 1;
Assert.areSame('bar', model.get('foo'), 'load event should fire after attribute changes are applied');
});
callback(null, '{"foo": "bar"}');
};
});
},
'`save` event should fire after a successful save operation': function () {
var calls = 0,
calls += 1;
Assert.areSame('bar', model.get('foo'), 'save event should fire after attribute changes are applied');
});
callback(null, '{"foo": "bar"}');
};
});
}
}));
}, '@VERSION@', {
});