From a75e04701f7154594181365dfd265073513d00de Mon Sep 17 00:00:00 2001 From: Rufus Pollock Date: Sat, 18 Feb 2012 08:11:38 +0000 Subject: [PATCH] [#25,model][xs]: turns out the hack to allow simple arguments to Field ctor does *not* work. --- src/model.js | 3 +-- test/model.test.js | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) 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);