Custom adapter using snapshot attributes other than adapterOptions and record dont' work
artinboghosian opened this issue · 3 comments
Our app has several custom adapters that use attributes on the snapshot such as attr
or belongsTo
which are part of DS.Snapshot
but not part of the makeFakeSnapshot
method which returns an object with adapterOptions
and record
only. So anytime we want to mock with a model that uses other DS.Snapshot properties or methods in it's adapter we get errors such as: snapshot.attr is not a function
.
One specific instance is our Photo model:
models/photo.js
export default Model.extend({
url: attr(),
parent_id: attr(),
parent_type: attr()
}
It has a custom adapter for generating the URL for deleting a record.
adapters/photo.js
export default ApplicationAdapter.extend({
urlForDeleteRecord(id, modelName, snapshot) {
let url = this._super(...arguments);
let parentId = snapshot.attr('parent_id');
let parentType = snapshot.attr('parent_type');
return `${url}?parent_id=${parentId}&parent_type=${parentType}`;
}
});
Any call to mockDelete(photo) in a test will result in snapshot.attr is not a function
. Is there any way around this issue or does the fake snapshot need to mimic functionality of DS.Snapshot in it's entirety to support use cases such as this?
i guess your right, that fake snapshot is missing attr and other methods ( very true ).
if you make a PR for fixing this ( and I am thinking that adding those methods that do same thing ) OR using the ember-data snapshot model ( not sure if that is even possible ) that will solve it and I would be up for that
@danielspaniel I've opted to instead make mockDelete behave the same as mockUpdate when creating a fake snapshot by passing the record like mockUpdate. These two methods are dealing with persisted records and thus should behave the same anyways when it comes to arguments + snapshot generation.
v 3.6.4 has the PR