Skip to content

Commit

Permalink
Merge pull request #274 from mskeving/query-get
Browse files Browse the repository at this point in the history
Prevent using saved query if new expression doesn't match hash
  • Loading branch information
ericyhwang committed Feb 29, 2020
2 parents 62a0774 + a02856c commit fd5632a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Model/Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Queries.prototype.toJSON = function() {
function Query(model, collectionName, expression, options) {
this.model = model.pass({$query: this});
this.collectionName = collectionName;
this.expression = expression;
this.expression = util.deepCopy(expression);
this.options = options;
this.hash = queryHash(collectionName, expression, options);
this.segments = ['$queries', this.hash];
Expand Down
14 changes: 14 additions & 0 deletions test/Model/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ describe('query', function() {
});
});

describe('Query', function() {
beforeEach('create in-memory backend and model', function() {
this.backend = racer.createBackend();
this.model = this.backend.createModel();
});
it('Uses deep copy of query expression in Query constructor', function() {
var expression = {arrayKey: []};
var query = this.model.query('myCollection', expression);
query.fetch();
expression.arrayKey.push('foo');
expect(query.expression.arrayKey).to.have.length(0);
});
});

describe('idMap', function() {
beforeEach('create in-memory backend and model', function() {
this.backend = racer.createBackend();
Expand Down

0 comments on commit fd5632a

Please sign in to comment.