Lines Matching refs:model
1 YUI.add('model-list-test', function (Y) {
21 this.list = new Y.ModelList({model: Y.Model});
29 var model = new Y.Model();
31 this.list.add(model);
32 Assert.areSame(this.list, model.lists[0]);
35 ArrayAssert.isEmpty(model.lists);
57 'ModelList instances should have a `model` property that defaults to Y.Model': function () {
58 Assert.areSame(Y.Model, this.list.model);
61 '`model` property should be customizable on init': function () {
63 list = new Y.ModelList({model: CustomModel});
65 Assert.areSame(CustomModel, list.model);
68 '`model` property should evaluate a string to a namespaced class on `Y`': function () {
72 model: 'CustomModel'
77 Assert.areSame(Y.CustomModel, list.model);
80 '`model` property should support deeply-nested names': function () {
84 model: 'Foo.Bar.CustomModel'
89 Assert.areSame(Y.Foo.Bar.CustomModel, list.model);
109 return new this.TestList({model: modelClass || this.TestModel});
124 'add() should add a model to the list': function () {
126 model = this.createModel(),
129 Assert.areSame(model, list.add(model));
170 model = iframe.contentWindow.iframeModel;
172 list.add(model);
174 Assert.areSame(model, list.item(0));
184 list.comparator = function (model) {
185 return model.get('foo');
193 'create() should create or update a model, then add it to the list': function () {
195 model = this.createModel();
197 Assert.areSame(model, list.create(model));
221 model = this.createModel();
223 model.sync = function (action, options, callback) {
227 list.create(model, function (err) {
238 model = iframe.contentWindow.iframeModel;
240 list.create(model);
242 Assert.areSame(model, list.item(0));
252 filtered = list.filter(function (model, i, myList) {
253 var foo = model.get('foo');
255 Assert.areSame(model, list.item(i), 'model should be the first arg and item index the second');
282 filtered = list.filter({asList: true}, function (model, i, myList) {
283 var foo = model.get('foo');
285 Assert.areSame(model, list.item(i), 'model should be the first arg and item index the second');
293 Assert.areSame(list.model, filtered.model, 'filtered list should have the same `model` property as the original list');
347 'getByClientId() should look up a model by its clientId': function () {
349 model = list.add({});
351 Assert.areSame(model, list.getByClientId(model.get('clientId')));
355 'getById() should look up a model by its id': function () {
357 model = list.add({id: 'foo'});
359 Assert.areSame(model, list.getById(model.get('id')));
365 model = list.add({id: 0});
367 Assert.areSame(model, list.getById(0));
380 model = list.add({customId: 'foo'});
382 Assert.areSame(model, list.getById(model.get('customId')));
385 'invoke() should call the named method on every model in the list': function () {
396 'item() should return the model at the specified index': function () {
483 'map() should execute a function on every model in the list and return an array of return values': function () {
490 results = list.map(function (model) {
492 return model.get('foo');
515 'remove() should remove a single model from the list': function () {
567 list.comparator = function (model) {
568 return model.get('bar');
607 model = iframe.contentWindow.iframeModel;
609 list.reset([model]);
611 Assert.areSame(model, list.item(0));
629 list.comparator = function (model) {
630 return model.get('foo');
657 'toJSON() should return an array of model hashes': function () {
683 return new this.TestList({model: modelClass || this.TestModel});
698 '`add` event should fire when a model is added': function () {
701 model = this.createModel();
706 Assert.areSame(model, e.model);
711 list.add(model, {src: 'test'});
741 '`add` event should not fire when a model is added silently': function () {
757 model = list.add({});
762 Assert.areSame(model, e.target);
766 model.set('foo', 'foo').set('bar', 'bar');
771 '`create` event should fire when a model is created': function () {
774 model = this.createModel();
778 Assert.areSame(model, e.model, 'Model should be passed in the event facade.');
785 list.create(model);
793 model = this.createModel();
800 list.create(model, {src: 'foo'});
808 model = list.add({});
810 model.validate = function (hash, callback) {
819 Assert.areSame(model, e.target);
823 model.set('foo', 'invalid');
824 model.save();
829 '`error` event should fire when a model with a duplicate clientId is added': function () {
832 model = this.createModel(),
838 Assert.areSame(model, e.model);
842 list.add([model, model2]);
843 list.add(model, {src: 'test'});
849 '`error` event should fire when a model with a duplicate id is added': function () {
852 model = this.createModel(),
856 model.set('id', 0);
861 Assert.areSame(model3, e.model);
864 list.add([model, model2]);
871 "`error` event should fire when a model that isn't in the list is removed": function () {
874 model = this.createModel();
879 Assert.areSame(model, e.model);
883 list.add(model);
884 list.remove(model);
885 list.remove(model, {src: 'test'});
954 list.comparator = function (model) {
955 return model.get('clientId');
967 list.comparator = function (model) {
968 return model.get('bar');
976 Y.Array.each(e.models, function (model) {
977 values.push(model.get('bar'));
1039 '`remove` event should fire when a model is removed': function () {
1042 model = list.add({});
1047 Assert.areSame(model, e.model);
1052 list.remove(model, {src: 'test'});
1082 '`remove` event should not fire when a model is removed silently': function () {
1099 requires: ['model-list', 'test']