diff options
| author | Mathieu Duckerts-Antoine <dam@odoo.com> | 2020-06-10 09:29:11 +0000 |
|---|---|---|
| committer | Mathieu Duckerts-Antoine <dam@odoo.com> | 2020-06-10 11:57:54 +0000 |
| commit | a758f8f307fe74af93631b77f498db43a845c526 (patch) | |
| tree | 7a46ebe8acff9482adf2150227cb5f9b67a381dc /addons | |
| parent | 4f825e437ad805c6ec77155b81c12a08fd877953 (diff) | |
[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>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/web/static/src/js/core/registry.js | 13 | ||||
| -rw-r--r-- | addons/web/static/tests/core/registry_tests.js | 21 |
2 files changed, 32 insertions, 2 deletions
diff --git a/addons/web/static/src/js/core/registry.js b/addons/web/static/src/js/core/registry.js index cf898c647ca..6089ccc827e 100644 --- a/addons/web/static/src/js/core/registry.js +++ b/addons/web/static/src/js/core/registry.js @@ -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; }); } diff --git a/addons/web/static/tests/core/registry_tests.js b/addons/web/static/tests/core/registry_tests.js index f87238fafb8..fdc437c23ee 100644 --- a/addons/web/static/tests/core/registry_tests.js +++ b/addons/web/static/tests/core/registry_tests.js @@ -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); |
