Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

payload of handleFind limited to record's typeKey #82

Closed
tonywok opened this issue May 6, 2015 · 5 comments
Closed

payload of handleFind limited to record's typeKey #82

tonywok opened this issue May 6, 2015 · 5 comments

Comments

@tonywok
Copy link

tonywok commented May 6, 2015

The API I'm working with uses single table inheritance. For example, we have a base task model, and various subclasses.

In my test I'm trying to do a handleFind(task). That task happens to be of type paper-editor-task. The factory guy method mapFind will always return a json payload keyed to the pluralized version of the model name resulting in paperEditorTasks. My ember app expects tasks.

As a workaround I've monkey patched the FactoryGuy code. Would you consider supporting this? Perhaps as an option to handleFind? Or maybe by looking into the model's serializer instead of always using record.constructor.typeKey.

@danielspaniel
Copy link
Collaborator

Best thing you can do is do fork this project, make the code how you like it, write tests to prove it works, send me a pull request, and away you go with your new version of factory-guy ..

Or you could alway override mapFind:

 FactoryGuyTestHelper.reopen({
  mapFind:function(modelName, json){
    var responseJson = {};
    if (modelName === 'paper-editor-task') {
      modelName = 'task';
    } 
    responseJson[Ember.String.pluralize(modelName)] = json;
    return responseJson;
  }
});

which is alittle bit funky .. but works.

@tonywok
Copy link
Author

tonywok commented May 7, 2015

@danielspaniel Heh, that's exactly what I have right now :)

I was just wondering if it was something you were interested in supporting before I sent you a PR demanding you merge it :P

pairing added a commit to Aperta-project/Aperta that referenced this issue May 7, 2015
@danielspaniel
Copy link
Collaborator

Sure, I would support some way to modify that modelName .. but I am not sure how you are going to do it .. kind of tricky to do in a generic way .. ( I think ) .. but if you can figure it out .. I will merge it .. ( if you have it tested properly )

@danielspaniel
Copy link
Collaborator

@tonywok, v2.0.1 removes mapFind from the creation of json .. so if you upgrade, you have to find another path to fix these kinds of issues, but I refactored things to use serializer to create the keys, so maybe it will have fixed itself in this new version? not sure.

@tonywok
Copy link
Author

tonywok commented Sep 2, 2015

@danielspaniel I'll let my previous client know so they can address accordingly. Thanks for the update :)

@tonywok tonywok closed this as completed Sep 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants