Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Change property meta data to include functions as well

  • Loading branch information...
commit 4a9692a431f0ef7ca54ce38d9ce0fe81b80b1aed 1 parent 86ab4a7
Moritz Peters authored
Showing with 22 additions and 3 deletions.
  1. +9 −1 lib/nohm.js
  2. +13 −2 test/metaTests.js
10 lib/nohm.js
View
@@ -1,6 +1,7 @@
var h = require(__dirname + '/helpers');
var async = require('async');
var crypto = require('crypto');
+var traverse = require('traverse');
/**
* The Nohm object used for some general configuration and model creation.
@@ -297,6 +298,13 @@ var __updateMeta = function () {
var version_key = Nohm.prefix.meta.version + this.modelName;
var idGenerator_key = Nohm.prefix.meta.idGenerator + this.modelName;
var properties_key = Nohm.prefix.meta.properties + this.modelName;
+ var properties = traverse(self.meta.properties).map(function (x) {
+ if (typeof x === 'function') {
+ return String(x)
+ } else {
+ return x;
+ }
+ });
this.getClient().get(version_key, function (err, db_version) {
if (err) {
@@ -310,7 +318,7 @@ var __updateMeta = function () {
self.getClient().set(idGenerator_key, self.idGenerator.toString(), next);
},
properties: function (next) {
- self.getClient().set(properties_key, JSON.stringify(self.meta.properties), next);
+ self.getClient().set(properties_key, JSON.stringify(properties), next);
}
}, function (err) {
if (err) {
15 test/metaTests.js
View
@@ -4,6 +4,7 @@ var h = require(__dirname + '/helper.js');
var args = require(__dirname + '/testArgs.js');
var redis = args.redis;
var crypto = require('crypto');
+var traverse = require('traverse');
var prefix = args.prefix;
@@ -99,6 +100,16 @@ var createUsers = function(props, modelName, callback) {
var users_created = false;
+var stringify_functions = function (obj) {
+ return traverse(obj).map(function (x) {
+ if (typeof x === 'function') {
+ return String(x)
+ } else {
+ return x;
+ }
+ });
+}
+
exports.meta = {
setUp: function(next) {
@@ -193,14 +204,14 @@ exports.meta = {
function (next) {
redis.get(prefix+':meta:properties:UserMetaMockup', function (err, properties) {
errLogger(err);
- t.same(JSON.stringify(user.meta.properties), properties, 'Properties of the user did not match.');
+ t.same(JSON.stringify(stringify_functions(user.meta.properties)), properties, 'Properties of the user did not match.');
next();
});
},
function (next) {
redis.get(prefix+':meta:properties:CommentMetaMockup', function (err, properties) {
errLogger(err);
- t.same(JSON.stringify(comment.meta.properties), properties, 'Properties of the comment did not match.');
+ t.same(JSON.stringify(stringify_functions(comment.meta.properties)), properties, 'Properties of the comment did not match.');
next();
});
}
Please sign in to comment.
Something went wrong with that request. Please try again.