v1.18.x
Barış Soner Uşaklı 6 years ago
parent da1a90a470
commit 250e8c01ff

@ -1,6 +1,7 @@
'use strict'; 'use strict';
var meta = require('./meta'); var meta = require('./meta');
var pubsub = require('./pubsub');
function expandObjBy(obj1, obj2) { function expandObjBy(obj1, obj2) {
var key; var key;
@ -68,6 +69,8 @@ function Settings(hash, version, defCfg, callback, forceUpdate, reset) {
this.hash = hash; this.hash = hash;
this.version = version || this.version; this.version = version || this.version;
this.defCfg = defCfg; this.defCfg = defCfg;
var self = this;
if (reset) { if (reset) {
this.reset(callback); this.reset(callback);
} else { } else {
@ -75,6 +78,11 @@ function Settings(hash, version, defCfg, callback, forceUpdate, reset) {
this.checkStructure(callback, forceUpdate); this.checkStructure(callback, forceUpdate);
}); });
} }
pubsub.on('action:settings.set.' + hash, function (data) {
try {
self.cfg._ = JSON.parse(data._);
} catch (err) {}
});
} }
Settings.prototype.hash = ''; Settings.prototype.hash = '';

@ -193,7 +193,6 @@ describe('Search', function () {
query: 'xxxxxxxxxxxxxx', query: 'xxxxxxxxxxxxxx',
}, function (err, data) { }, function (err, data) {
assert.ifError(err); assert.ifError(err);
console.log(data);
assert(Array.isArray(data.posts)); assert(Array.isArray(data.posts));
assert(!data.matchCount); assert(!data.matchCount);
done(); done();

@ -0,0 +1,38 @@
'use strict';
var assert = require('assert');
var nconf = require('nconf');
var db = require('./mocks/databasemock');
var settings = require('../src/settings');
describe('settings v3', function () {
var settings1;
var settings2;
it('should create a new settings object', function (done) {
settings1 = new settings('my-plugin', '1.0', { foo: 1, bar: { derp: 2 } }, done);
});
it('should get the saved settings ', function (done) {
assert.equal(settings1.get('foo'), 1);
assert.equal(settings1.get('bar.derp'), 2);
done();
});
it('should create a new settings instance for same key', function (done) {
settings2 = new settings('my-plugin', '1.0', { foo: 1, bar: { derp: 2 } }, done);
});
it('should pass change between settings object over pubsub', function (done) {
settings1.set('foo', 3);
settings1.persist(function (err) {
assert.ifError(err);
// give pubsub time to complete
setTimeout(function () {
assert.equal(settings2.get('foo'), 3);
done();
}, 500);
});
});
});
Loading…
Cancel
Save