Skip to content

Commit

Permalink
Add third argument temp to nohm.model(). If set to true the model d…
Browse files Browse the repository at this point in the history
…efinition will not be stored and cannot be used with nohm.factory().
  • Loading branch information
maritz committed Jul 13, 2012
1 parent 4a9692a commit bc216ed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/nohm.js
Expand Up @@ -50,7 +50,7 @@ var models = {};
* @param {Object} Option This is an object containing the actual model definitions. These are: properties, methods (optional) and the client (optional) to be used. * @param {Object} Option This is an object containing the actual model definitions. These are: properties, methods (optional) and the client (optional) to be used.
* @static * @static
*/ */
Nohm.model = function (name, options) { Nohm.model = function (name, options, temp) {
if ( ! name ) { if ( ! name ) {
this.logError('When creating a new model you have to provide a name!'); this.logError('When creating a new model you have to provide a name!');
} }
Expand Down Expand Up @@ -92,7 +92,9 @@ Nohm.model = function (name, options) {
instance.remove(cb); instance.remove(cb);
}; };


models[name] = obj; if ( ! temp) {
models[name] = obj;
}


return obj; return obj;
}; };
Expand Down
19 changes: 19 additions & 0 deletions test/featureTests.js
Expand Up @@ -956,3 +956,22 @@ exports["no key left behind"] = function (t) {
} }
); );
}; };

exports["temporary model definitions"] = function (t) {
t.expect(2);
var user = nohm.factory('UserMockup');
var user2 = nohm.factory('UserMockup');

var TempUserMockup = nohm.model('UserMockup', {
properties: {
well_shit: {
type: 'string'
}
}
}, true);
var new_user = new TempUserMockup();

t.deepEqual(user.allProperties(), user2.allProperties(), 'HURASDASF');
t.notDeepEqual(user.allProperties(), new_user.allProperties(), 'HURASDASF');
t.done();
};

0 comments on commit bc216ed

Please sign in to comment.