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

Returning inherited models of various types

未關閉
#231 6 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
JavaScript
星號
298
分支
136
PR 合併指標
30 天內沒有已合併 PR

描述

Hello!

I ran into a problem while writing tests for our application. We have a certain backend route that can return various models inherited from a single base model. When I tried to mock it, I found out that the mock replaces the types of the supplied model instances with the type specified as the modelName for the mock, so the data aren't loaded properly.

To illustrate this, I wrote a simple test based on your test setup:

``` javascript
test("mock returns inherited models with proper types", function(assert) {
const smallHat = make('small-hat');
const bigHat = make('big-hat');
let mock = mockQuery('hat', { size: 'all' }).returns({ models: [smallHat, bigHat] });
let responseData = mock.responseJson.data;
equal(responseData[0].type, 'small-hat');
equal(responseData[1].type, 'big-hat');
});
```

As it turned out, the data type specified in the JSON is `'hat'` in both cases.

I would greatly appreciate your suggestions on handling this situation.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。