This commit is contained in:
Chris Tavares 2013-07-31 23:51:57 -07:00
Родитель 06a3529b51
Коммит 78ad101ad5
2 изменённых файлов: 35 добавлений и 4 удалений

Просмотреть файл

@ -65,14 +65,21 @@ function Config(parent, defaultEnvVar, customizer) {
return this;
};
config.get = function (setting) {
config.getRaw = function (setting) {
if (!settings.hasOwnProperty(setting)) {
if (parent) {
return parent.get(setting);
return parent.getRaw(setting);
}
return undefined;
}
return settings[setting]();
return settings[setting];
};
config.get = function (setting) {
var args = Array.prototype.slice.apply(arguments);
var getter = this.getRaw(setting);
if (!getter) { return undefined; }
return getter.apply(this, args);
};
config.has = function (setting) {

Просмотреть файл

@ -393,6 +393,30 @@ describe('Setting getters', function () {
var spy = sinon.spy(getter);
c.set('setting', spy);
c.get('setting').should.equal(spy);
spy.callCount.should.equal(0);
spy.callCount.should.equal(0);
});
it('should be invoked with parameters that are passed on get call', function () {
var spy = sinon.spy(function () { return 'a value'; });
c.setFunc('setting', spy);
c.get('setting', 1, 3, 'hello').should.equal('a value');
spy.calledWithExactly('setting', 1, 3, 'hello').should.be.true;
});
it('should be invoked with config that get was called on as context', function () {
var c2 = c('child');
var spy = sinon.spy(function (s, n1) { return 'a value for ' + s + ' is ' + n1; });
c.setFunc('setting', spy);
c2.get('setting', 37, 42).should.equal('a value for setting is 37');
spy.alwaysCalledOn(c2).should.be.true;
});
it('should be able to request other values from config', function () {
c.setFunc('root', function () { return 'root: ' + this.get('child'); });
c.set('child', 'child value');
c.get('root').should.equal('root: child value');
});
});