[FIX] web: don't forget initial registry entries

The entries comming from the optional parameter 'mapping' passed at the
instantiation of a registry were never considered when returning the
registry keys or entries. This is no longer the case.

closes odoo/odoo#52768

X-original-commit: e094ddd0ffaf3357e64ca5941ffc2e0454c24ab7
Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
This commit is contained in:
Mathieu Duckerts-Antoine
2020-06-10 11:57:54 +00:00
parent 4f825e437a
commit a758f8f307
2 changed files with 32 additions and 2 deletions
+11 -2
View File
@@ -68,7 +68,12 @@ var Registry = Class.extend({
* @returns {Object}
*/
entries: function () {
return Object.create(this.map);
var entries = {};
var keys = this.keys();
for (var i = 0; i < keys.length; i++) {
entries[keys[i]] = this.map[keys[i]];
}
return entries;
},
/**
* Returns the value associated to the given key.
@@ -105,7 +110,11 @@ var Registry = Class.extend({
keys: function () {
var self = this;
if (!this._sortedKeys) {
this._sortedKeys = _.sortBy(Object.keys(this.map), function (key) {
var keys = [];
for (var key in this.map) {
keys.push(key);
}
this._sortedKeys = _.sortBy(keys, function (key) {
return self._scoreMapping[key] || 0;
});
}
@@ -19,6 +19,27 @@ QUnit.module('core', {}, function () {
assert.strictEqual(registry.get('foo'), foo);
});
QUnit.test('get initial keys', function (assert) {
assert.expect(1);
var registry = new Registry({ a: 1, });
assert.deepEqual(
registry.keys(),
['a'],
"keys on prototype should be returned"
);
});
QUnit.test('get initial entries', function (assert) {
assert.expect(1);
var registry = new Registry({ a: 1, });
assert.deepEqual(
registry.entries(),
{ a: 1, },
"entries on prototype should be returned"
);
});
QUnit.test('multiget', function (assert) {
assert.expect(1);