{"action":"created","issue":{"url":"https://api.github.com/repos/colonyamerican/mock-knex/issues/13","repository_url":"https://api.github.com/repos/colonyamerican/mock-knex","labels_url":"https://api.github.com/repos/colonyamerican/mock-knex/issues/13/labels{/name}","comments_url":"https://api.github.com/repos/colonyamerican/mock-knex/issues/13/comments","events_url":"https://api.github.com/repos/colonyamerican/mock-knex/issues/13/events","html_url":"https://github.com/colonyamerican/mock-knex/pull/13","id":106988080,"number":13,"title":"Failing tests showing unmock not reverting to original client","user":{"login":"techniq","id":177476,"avatar_url":"https://avatars.githubusercontent.com/u/177476?v=3","gravatar_id":"","url":"https://api.github.com/users/techniq","html_url":"https://github.com/techniq","followers_url":"https://api.github.com/users/techniq/followers","following_url":"https://api.github.com/users/techniq/following{/other_user}","gists_url":"https://api.github.com/users/techniq/gists{/gist_id}","starred_url":"https://api.github.com/users/techniq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/techniq/subscriptions","organizations_url":"https://api.github.com/users/techniq/orgs","repos_url":"https://api.github.com/users/techniq/repos","events_url":"https://api.github.com/users/techniq/events{/privacy}","received_events_url":"https://api.github.com/users/techniq/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":18,"created_at":"2015-09-17T13:42:52Z","updated_at":"2016-08-10T20:28:00Z","closed_at":"2016-08-10T20:28:00Z","pull_request":{"url":"https://api.github.com/repos/colonyamerican/mock-knex/pulls/13","html_url":"https://github.com/colonyamerican/mock-knex/pull/13","diff_url":"https://github.com/colonyamerican/mock-knex/pull/13.diff","patch_url":"https://github.com/colonyamerican/mock-knex/pull/13.patch"},"body":"I ran into an issue where 1 of my tests was failing that was expecting the actual database and not the mock (but ran after the tests using a mock).  After digging around, I found that `mockDb.unmock(knex)` was not restoring the original `knex.client` correctly.  The issue is due to [this line](https://github.com/colonyamerican/mock-knex/blob/master/lib/platforms/knex/0.8/index.js#L6) where it is expected that `db._oldClient` is a clone of `db.client` but it is instead just another reference to the same object and those getting mocked directly.\r\n\r\nI attempted to use lodash's shallow copy `_.clone(...)` to fix the issue by shallow cloning `db.client` and `db.client.Runner` like so...\r\n\r\n```js\r\n  mock: function mockDatabase(db) {\r\n    if (! db._oldClient) {\r\n      db._oldClient = db.client;\r\n    }\r\n\r\n    db.client = _.clone(db.client);\r\n    db.client.Runner = _.clone(db.client.Runner);\r\n\r\n    makeClient(db.client);\r\n  },\r\n```\r\n\r\n...but doing so just causes the `should revert a single adapter back to the original` test to hang on `mod.mock(db)` and I'm struggling to understand why.  I'm not sure if it would be better to instead restore all the patched functions in `client.js` (`client.acquireConnection`, `client.releaseConnection`, `client.prototype._query`, etc)."},"comment":{"url":"https://api.github.com/repos/colonyamerican/mock-knex/issues/comments/238993365","html_url":"https://github.com/colonyamerican/mock-knex/pull/13#issuecomment-238993365","issue_url":"https://api.github.com/repos/colonyamerican/mock-knex/issues/13","id":238993365,"user":{"login":"jbrumwell","id":413363,"avatar_url":"https://avatars.githubusercontent.com/u/413363?v=3","gravatar_id":"","url":"https://api.github.com/users/jbrumwell","html_url":"https://github.com/jbrumwell","followers_url":"https://api.github.com/users/jbrumwell/followers","following_url":"https://api.github.com/users/jbrumwell/following{/other_user}","gists_url":"https://api.github.com/users/jbrumwell/gists{/gist_id}","starred_url":"https://api.github.com/users/jbrumwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbrumwell/subscriptions","organizations_url":"https://api.github.com/users/jbrumwell/orgs","repos_url":"https://api.github.com/users/jbrumwell/repos","events_url":"https://api.github.com/users/jbrumwell/events{/privacy}","received_events_url":"https://api.github.com/users/jbrumwell/received_events","type":"User","site_admin":false},"created_at":"2016-08-10T20:28:00Z","updated_at":"2016-08-10T20:28:00Z","body":"This is properly tested now in `release/0.3.3` if you have time to test it that would be great :)"}}
{"actor":{"display_login":"jbrumwell"}}