diff --git a/src/model.js b/src/model.js index 5db70c7a..b00871b0 100644 --- a/src/model.js +++ b/src/model.js @@ -96,8 +96,7 @@ my.Field = Backbone.Model.extend({ initialize: function(data) { // if a hash not passed in the first argument is set as value for key 0 if ('0' in data) { - this.set({id: data['0']}); - this.unset('0'); + throw new Error('Looks like you did not pass a proper hash with id to Field constructor'); } if (this.attributes.label == null) { this.set({label: this.id}); diff --git a/test/model.test.js b/test/model.test.js index 41d50ab4..a4773dd3 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -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'); - var field = new recline.Model.Field('x'); - equal(field.id, 'x', 'Set of id from single argumentst to ctor'); - 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'); + raises(function() { + var field = new recline.Model.Field('xxx'); + }, + 'should throw an error if not passed in a hash with id' + ); }); })(this.jQuery);