Skip to content

Commit

Permalink
Use extends correctly & consistently
Browse files Browse the repository at this point in the history
- extends clobbers the first argument you pass to it, so that should not be a variable that is used elsewhere, if you're also assigning the value, as it will have unintended side effects.
  • Loading branch information
ErisDS committed Jun 25, 2015
1 parent b3f4bea commit f6322da
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion core/server/api/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ authentication = {
return dataProvider.User.findOne({role: 'Owner', status: 'all'});
}).then(function (ownerUser) {
if (ownerUser) {
return dataProvider.User.setup(setupUser, _.extend(internal, {id: ownerUser.id}));
return dataProvider.User.setup(setupUser, _.extend({id: ownerUser.id}, internal));
} else {
return dataProvider.Role.findOne({name: 'Owner'}).then(function (ownerRole) {
setupUser.roles = [ownerRole.id];
Expand Down
4 changes: 2 additions & 2 deletions core/server/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,9 @@ Post = ghostBookshelf.Model.extend({
var withNext = _.contains(options.include, 'next'),
withPrev = _.contains(options.include, 'previous');

data = _.extend({
data = _.defaults(data || {}, {
status: 'published'
}, data || {});
});

if (data.status === 'all') {
delete data.status;
Expand Down
4 changes: 2 additions & 2 deletions core/server/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ User = ghostBookshelf.Model.extend({

delete data.role;

data = _.extend({
data = _.defaults(data || {}, {
status: 'active'
}, data || {});
});

status = data.status;
delete data.status;
Expand Down
10 changes: 5 additions & 5 deletions core/server/update-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ function updateCheckData() {
ops = [],
mailConfig = config.mail;

ops.push(api.settings.read(_.extend(internal, {key: 'dbHash'})).catch(errors.rejectError));
ops.push(api.settings.read(_.extend(internal, {key: 'activeTheme'})).catch(errors.rejectError));
ops.push(api.settings.read(_.extend(internal, {key: 'activeApps'}))
ops.push(api.settings.read(_.extend({key: 'dbHash'}, internal)).catch(errors.rejectError));
ops.push(api.settings.read(_.extend({key: 'activeTheme'}, internal)).catch(errors.rejectError));
ops.push(api.settings.read(_.extend({key: 'activeApps'}, internal))
.then(function (response) {
var apps = response.settings[0];
try {
Expand Down Expand Up @@ -187,7 +187,7 @@ function updateCheck() {
// No update check
return Promise.resolve();
} else {
return api.settings.read(_.extend(internal, {key: 'nextUpdateCheck'})).then(function then(result) {
return api.settings.read(_.extend({key: 'nextUpdateCheck'}, internal)).then(function then(result) {
var nextUpdateCheck = result.settings[0];

if (nextUpdateCheck && nextUpdateCheck.value && nextUpdateCheck.value > moment().unix()) {
Expand All @@ -204,7 +204,7 @@ function updateCheck() {
}

function showUpdateNotification() {
return api.settings.read(_.extend(internal, {key: 'displayUpdateNotification'})).then(function then(response) {
return api.settings.read(_.extend({key: 'displayUpdateNotification'}, internal)).then(function then(response) {
var display = response.settings[0];

// Version 0.4 used boolean to indicate the need for an update. This special case is
Expand Down
4 changes: 2 additions & 2 deletions core/test/integration/api/api_configuration_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Configuration API', function () {
should.exist(ConfigurationAPI);

it('can browse config', function (done) {
var updatedConfig = _.extend(config, newConfig);
var updatedConfig = _.extend({}, config, newConfig);
config.set(updatedConfig);
ConfigurationAPI.__set__('config', updatedConfig);

Expand All @@ -49,7 +49,7 @@ describe('Configuration API', function () {
});

it('can read config', function (done) {
var updatedConfig = _.extend(config, newConfig);
var updatedConfig = _.extend({}, config, newConfig);
config.set(updatedConfig);
ConfigurationAPI.__set__('config', updatedConfig);

Expand Down
4 changes: 2 additions & 2 deletions core/test/integration/api/api_notifications_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('Notifications API', function () {
var notification = result.notifications[0];

NotificationsAPI.destroy(
_.extend(testUtils.context.internal, {id: notification.id})
_.extend({}, testUtils.context.internal, {id: notification.id})
).then(function (result) {
should.exist(result);
should.exist(result.notifications);
Expand All @@ -143,7 +143,7 @@ describe('Notifications API', function () {
var notification = result.notifications[0];

NotificationsAPI.destroy(
_.extend(testUtils.context.owner, {id: notification.id})
_.extend({}, testUtils.context.owner, {id: notification.id})
).then(function (result) {
should.exist(result);
should.exist(result.notifications);
Expand Down
2 changes: 1 addition & 1 deletion core/test/integration/import_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Import', function () {
describe('Resolves', function () {
beforeEach(testUtils.setup());
beforeEach(function () {
var newConfig = _.extend(config, defaultConfig);
var newConfig = _.extend({}, config, defaultConfig);

migration.__get__('config', newConfig);
config.set(newConfig);
Expand Down
2 changes: 1 addition & 1 deletion core/test/unit/storage_local-file-store_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Local File System Storage', function () {
var image,
overrideConfig = function (newConfig) {
var existingConfig = LocalFileStore.__get__('config'),
updatedConfig = _.extend(existingConfig, newConfig);
updatedConfig = _.extend({}, existingConfig, newConfig);
config.set(updatedConfig);
LocalFileStore.__set__('config', updatedConfig);
};
Expand Down
2 changes: 1 addition & 1 deletion core/test/utils/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function forkGhost(newConfig, envName) {
.then(function (port) {
newConfig.server = newConfig.server || {};
newConfig.server.port = port;
newConfig.url = url.format(_.extend(url.parse(newConfig.url), {port: port, host: null}));
newConfig.url = url.format(_.extend({}, url.parse(newConfig.url), {port: port, host: null}));

var newConfigFile = path.join(config.paths.appRoot, 'config.test' + port + '.js');

Expand Down

0 comments on commit f6322da

Please sign in to comment.