{"action":"created","issue":{"url":"https://api.github.com/repos/hapijs/hapi/issues/2702","repository_url":"https://api.github.com/repos/hapijs/hapi","labels_url":"https://api.github.com/repos/hapijs/hapi/issues/2702/labels{/name}","comments_url":"https://api.github.com/repos/hapijs/hapi/issues/2702/comments","events_url":"https://api.github.com/repos/hapijs/hapi/issues/2702/events","html_url":"https://github.com/hapijs/hapi/issues/2702","id":100557634,"number":2702,"title":"Override an existing decoration","user":{"login":"aymericbeaumet","id":569243,"avatar_url":"https://avatars.githubusercontent.com/u/569243?v=3","gravatar_id":"","url":"https://api.github.com/users/aymericbeaumet","html_url":"https://github.com/aymericbeaumet","followers_url":"https://api.github.com/users/aymericbeaumet/followers","following_url":"https://api.github.com/users/aymericbeaumet/following{/other_user}","gists_url":"https://api.github.com/users/aymericbeaumet/gists{/gist_id}","starred_url":"https://api.github.com/users/aymericbeaumet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aymericbeaumet/subscriptions","organizations_url":"https://api.github.com/users/aymericbeaumet/orgs","repos_url":"https://api.github.com/users/aymericbeaumet/repos","events_url":"https://api.github.com/users/aymericbeaumet/events{/privacy}","received_events_url":"https://api.github.com/users/aymericbeaumet/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hapijs/hapi/labels/request","name":"request","color":"c7def8"}],"state":"closed","locked":false,"assignee":{"login":"hueniverse","id":56631,"avatar_url":"https://avatars.githubusercontent.com/u/56631?v=3","gravatar_id":"","url":"https://api.github.com/users/hueniverse","html_url":"https://github.com/hueniverse","followers_url":"https://api.github.com/users/hueniverse/followers","following_url":"https://api.github.com/users/hueniverse/following{/other_user}","gists_url":"https://api.github.com/users/hueniverse/gists{/gist_id}","starred_url":"https://api.github.com/users/hueniverse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hueniverse/subscriptions","organizations_url":"https://api.github.com/users/hueniverse/orgs","repos_url":"https://api.github.com/users/hueniverse/repos","events_url":"https://api.github.com/users/hueniverse/events{/privacy}","received_events_url":"https://api.github.com/users/hueniverse/received_events","type":"User","site_admin":false},"assignees":[{"login":"hueniverse","id":56631,"avatar_url":"https://avatars.githubusercontent.com/u/56631?v=3","gravatar_id":"","url":"https://api.github.com/users/hueniverse","html_url":"https://github.com/hueniverse","followers_url":"https://api.github.com/users/hueniverse/followers","following_url":"https://api.github.com/users/hueniverse/following{/other_user}","gists_url":"https://api.github.com/users/hueniverse/gists{/gist_id}","starred_url":"https://api.github.com/users/hueniverse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hueniverse/subscriptions","organizations_url":"https://api.github.com/users/hueniverse/orgs","repos_url":"https://api.github.com/users/hueniverse/repos","events_url":"https://api.github.com/users/hueniverse/events{/privacy}","received_events_url":"https://api.github.com/users/hueniverse/received_events","type":"User","site_admin":false}],"milestone":null,"comments":3,"created_at":"2015-08-12T14:36:32Z","updated_at":"2016-09-27T14:39:14Z","closed_at":"2015-08-12T15:20:31Z","body":"It is currently not possible to override an existing decoration. For example the following code will fail (by design):\r\n\r\n```javascript\r\nvar Hapi = require('hapi');\r\nvar server = new Hapi.Server();\r\nserver.decorate('request', 'foobar', function DBConnection() {});\r\nserver.decorate('request', 'foobar', function DBConnectionMock() {}); // expected override\r\n```\r\n\r\n```\r\n/private/tmp/hapidecoration/node_modules/hapi/node_modules/hoek/lib/index.js:723\r\n    throw new Error(msgs.join(' ') || 'Unknown error');\r\n          ^\r\nError: Request interface decoration already defined: foobar\r\n    at Object.exports.assert (/private/tmp/hapidecoration/node_modules/hapi/node_modules/hoek/lib/index.js:723:11)\r\n    at internals.Generator.decorate (/private/tmp/hapidecoration/node_modules/hapi/lib/request.js:50:10)\r\n    at internals.Plugin.decorate (/private/tmp/hapidecoration/node_modules/hapi/lib/plugin.js:300:37)\r\n    at Object.<anonymous> (/private/tmp/hapidecoration/index.js:4:8)\r\n    at Module._compile (module.js:460:26)\r\n    at Object.Module._extensions..js (module.js:478:10)\r\n    at Module.load (module.js:355:32)\r\n    at Function.Module._load (module.js:310:12)\r\n    at Function.Module.runMain (module.js:501:10)\r\n    at startup (node.js:129:16)\r\n```\r\n\r\nI would like to be able to redefine an existing decoration, mainly for testing purpose so as to mock DB connections, etc.\r\n\r\nMaybe adding an option would make sense:\r\n\r\n```javascript\r\nserver.decorate('request', 'foobar', function DBConnectionMock() {}, { force: true });\r\n```"},"comment":{"url":"https://api.github.com/repos/hapijs/hapi/issues/comments/249884779","html_url":"https://github.com/hapijs/hapi/issues/2702#issuecomment-249884779","issue_url":"https://api.github.com/repos/hapijs/hapi/issues/2702","id":249884779,"user":{"login":"danielo515","id":2270425,"avatar_url":"https://avatars.githubusercontent.com/u/2270425?v=3","gravatar_id":"","url":"https://api.github.com/users/danielo515","html_url":"https://github.com/danielo515","followers_url":"https://api.github.com/users/danielo515/followers","following_url":"https://api.github.com/users/danielo515/following{/other_user}","gists_url":"https://api.github.com/users/danielo515/gists{/gist_id}","starred_url":"https://api.github.com/users/danielo515/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielo515/subscriptions","organizations_url":"https://api.github.com/users/danielo515/orgs","repos_url":"https://api.github.com/users/danielo515/repos","events_url":"https://api.github.com/users/danielo515/events{/privacy}","received_events_url":"https://api.github.com/users/danielo515/received_events","type":"User","site_admin":false},"created_at":"2016-09-27T14:39:14Z","updated_at":"2016-09-27T14:39:14Z","body":"> It is currently not possible to override an existing decoration. For example the following code will fail (by design):\r\n> \r\n> var Hapi = require('hapi');\r\n> var server = new Hapi.Server();\r\n> server.decorate('request', 'foobar', function DBConnection() {});\r\n> server.decorate('request', 'foobar', function DBConnectionMock() {}); // expected override\r\n\r\nSorry, if this is just for testing purposes I don't understand why do you need to decorate the server twice. Why don't just decorate it with the mocked version?"}}
{"actor":{"display_login":"danielo515"}}