ember.jsember-cli-mirage

Ember Relationships Are Not Respecting Model Custom Adapter in Test Environment


In my Ember.js app I have a model Company with a custom adapter that points to an API. I also have a User model with a custom adapter that points to a different API and a belongsTo relationship with Company (via a user#companyId attribute).

When manually exercising the app, all references to a Company in the code seem to send requests to the correct endpoint defined in the Company's custom adapter. However when running tests (both unit and acceptance tests), direct queries for a company this.store.find... hit the correct endpoint (company-host.com/api/companies/1), but references to a Company through its relationship with a User user.company are pointing to the User adapter's host and namespace (user-host.com/api/companies/1).

I'm new to Ember and any help or insight would be appreciated.


Solution

  • When you call user.company, it will use the findBelongsTo method of your user adapter, taking the host and namespace from user adapter. To fix this, you will need to override the findBelongsTo method to call findRecord of your company adapter with the correct id.