Skip to content

Commit

Permalink
Merge pull request #163 from offirgolan/leaky-state-in-tests
Browse files Browse the repository at this point in the history
Fix leaky state with nested objects
  • Loading branch information
offirgolan committed Apr 14, 2016
2 parents 09eabe4 + 2cbbf61 commit 284dab7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions addon/validations/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,19 @@ function createValidationsClass(inheritedValidationsClass, validations = {}) {
set(lastObject, '_model', model);
}
});
},

destroy() {
this._super(...arguments);
validatableAttributes.forEach(attribute => {
// Remove model reference from nested objects
const path = attribute.split('.');
const lastObject = get(this, path.slice(0, path.length - 1).join('.'));

if (!isNone(get(lastObject, '_model'))) {
set(lastObject, '_model', null);
}
});
}
});

Expand Down Expand Up @@ -259,6 +272,9 @@ function createValidationsClass(inheritedValidationsClass, validations = {}) {
const validatableAttrs = get(this, 'validatableAttributes');
const debouncedValidations = get(this, '_debouncedValidations');

// Initiate attrs destroy to cleanup any remaining model references
this.get('attrs').destroy();

// Cancel all debounced timers
validatableAttrs.forEach(attr => {
const attrCache = get(debouncedValidations, attr);
Expand Down

0 comments on commit 284dab7

Please sign in to comment.