Permalink
Browse files

Fix #44 (Defining new methods creates undefined _super_)

  • Loading branch information...
1 parent 39568fa commit 8898af58726b09b305f69c1420f6675c24da7eff @maritz committed Feb 21, 2012
Showing with 13 additions and 2 deletions.
  1. +3 −1 lib/nohm.js
  2. +10 −1 test/featureTests.js
View
@@ -191,7 +191,9 @@ Nohm.prototype.getClient = function () {
var addMethods = function (methods) {
for (var name in methods) {
if (methods.hasOwnProperty(name) && typeof(methods[name]) === 'function') {
- this['_super_'+name] = this[name];
+ if (this[name]) {
+ this['_super_'+name] = this[name];
+ }
this[name] = methods[name].bind(this);
}
}
View
@@ -666,15 +666,24 @@ exports.methods = function (t) {
exports.methodsSuper = function (t) {
var user = new UserMockup();
- t.expect(3);
+ t.expect(4);
t.same(typeof(user.prop), 'function', 'Overwriting a method in a model definition did not create that method on a new instance.');
+ t.same(typeof(user._super_prop), 'function', 'Overwriting a method in a model definition did not create the _super_ method on a new instance.');
t.same(user.prop('super'), user.p('name'), 'The super test method did not work properly.');
user.prop('name', 'methodTest');
t.same(user.p('name'), 'methodTest', 'The super test method did not properly handle arguments');
t.done();
};
+exports["no super method if none needed"] = function (t) {
+ var user = new UserMockup();
+ t.expect(1);
+
+ t.ok(!user.hasOwnProperty('_super_test'), 'Defining a method that does not overwrite a nohm method created a _super_.');
+ t.done();
+};
+
exports.uniqueDefaultOverwritten = function (t) {
var user = new UserMockup();
var user2 = new UserMockup();

0 comments on commit 8898af5

Please sign in to comment.