[#25,model][xs]: turns out the hack to allow simple arguments to Field ctor does *not* work.
This commit is contained in:
@@ -96,8 +96,7 @@ my.Field = Backbone.Model.extend({
|
|||||||
initialize: function(data) {
|
initialize: function(data) {
|
||||||
// if a hash not passed in the first argument is set as value for key 0
|
// if a hash not passed in the first argument is set as value for key 0
|
||||||
if ('0' in data) {
|
if ('0' in data) {
|
||||||
this.set({id: data['0']});
|
throw new Error('Looks like you did not pass a proper hash with id to Field constructor');
|
||||||
this.unset('0');
|
|
||||||
}
|
}
|
||||||
if (this.attributes.label == null) {
|
if (this.attributes.label == null) {
|
||||||
this.set({label: this.id});
|
this.set({label: this.id});
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ test('Field: basics', function () {
|
|||||||
});
|
});
|
||||||
equal(field.attributes.label, 'My label', 'Field label should be set from id but not if explicitly provided');
|
equal(field.attributes.label, 'My label', 'Field label should be set from id but not if explicitly provided');
|
||||||
|
|
||||||
var field = new recline.Model.Field('x');
|
raises(function() {
|
||||||
equal(field.id, 'x', 'Set of id from single argumentst to ctor');
|
var field = new recline.Model.Field('xxx');
|
||||||
equal(field.attributes.id, 'x', 'Set of id from single argumentst to ctor');
|
},
|
||||||
ok(!('0' in field.toJSON()), 'Should have removed artificially created 0 key in attributes');
|
'should throw an error if not passed in a hash with id'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
})(this.jQuery);
|
})(this.jQuery);
|
||||||
|
|||||||
Reference in New Issue
Block a user