Skip to content

Commit

Permalink
fix: don't modify the passed options object (hoodiehq#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmehner authored and gr2m committed Aug 30, 2016
1 parent 40001d1 commit 7a98915
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ var corsHeaders = require('hapi-cors-headers')
var hoodieServer = require('@hoodie/server').register
var log = require('npmlog')
var PouchDB = require('pouchdb-core')
var cloneDeep = require('lodash').cloneDeep

var registerPlugins = require('./plugins')

function register (server, options, next) {
options = cloneDeep(options)
if (!options.db) {
options.db = {}
}
Expand Down
13 changes: 13 additions & 0 deletions test/integration/server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ test('server with options.db.url lacking auth', function (t) {
})
})

test('does not modify the passed options object', function (t) {
var options = {
db: {
url: 'http://admin:admin@localhost:5984'
}
}

hapiPlugin.register(serverMock, options, function () {})

t.is(options.db.url, 'http://admin:admin@localhost:5984')
t.end()
})

test('server with empty options (#554)', function (t) {
hapiPlugin.register(serverMock, {}, function (error, config) {
t.error(error)
Expand Down

0 comments on commit 7a98915

Please sign in to comment.