adopted-ember-addons/ember-data-factory-guy

Snapshot record in any of Store mocks is empty

cinkonaap opened this issue · 3 comments

I've been writing a test for a model with adapter that requires snapshot.record model instance in multiple urlFor* methods. I couldn't make it work, because record was always empty.

After looking at the source code, it seems like this.model is never set. Maybe I am overlooking something, but still would be glad to discuss and help to fix that.

https://github.com/danielspaniel/ember-data-factory-guy/blob/5bd3a4b6122a5e172fac3492d9ed02351be8224a/addon/mocks/mock-store-request.js#L48

the => this.model is the model that you are mocking so it might be empty .. it just depends how you do the mock. so if you do

let user = make('user');
mockUpdate(user);

than this.model will be that user you are mocking

whereas if you just do

mockUpdate('user');

this.model will be nil

you are welcome to try and fix it. I just can't think of how to do a fix when you have no real model.

I am using a model created with a make method, so we are talking about such scenario:

let user = make('user');
mockFindRecord(user);

However, I think model instance is never passed to any of MockRequest classes (only modelName), so it's not available even if full model is used:

https://github.com/danielspaniel/ember-data-factory-guy/blob/master/addon/mocks/exposed-request-functions.js#L87

Ok, interesting .. I think you can fix that then. Can you make the PR with the fix ? ( and make a test for that ).