Integration tests with ember-testing: preloading data from fixtures


#1

Hi there. I am trying to setup ember-testing so that the app is in the state that it appears in production. In production I am using an initializer to preload the current user’s record and set the contents of a currentUser controller. This will not work inside my tests. I have swapped out the REST adapter for the fixture adapter for testing, but I need to preload one record before the tests begin. How can I do this? I imagine that this is a pretty common requirement, but I can’t find an example anywhere. Using QUnit and ember-testing (the standard).


#2

You may already be using this, but when using the fixture adapter you just add an array of objects to App.MyModel.FIXTURES and away you go.

Here’s a small demo JSBin.

I am probably missing your point though…


#3

Hi there! Thanks for taking the time to reply. Yep, I have my fixtures loading as normal, although I am generating their content dynamically. My issue is with setting the content of a ‘currentUserController’ to one of the user records before the tests begin. In the application itself I am using an initializer to do this, but this won’t work in testing as I understand it because the tests themselves will control when the app is ready. I can’t use any async methods to load the content of the controller, so I’m wondering what the best way is. The app’s currentUser initializer looks like this:

Ember.Application.initializer({
  name: 'currentUser',
  initialize: function(container) {
    App.deferReadiness();
    var controller, store, currentUser, currentUserId;
    store = container.lookup('store:main');
    currentUserId = $.cookie('_app_current_user_id');
    $.removeCookie('_app_current_user_id');
    Ember.$.getJSON("/people/" + currentUserId + ".json", function(json) {
      var id = json.person.id;
      var store = DS.get("defaultStore");
      var adapter = store.adapterForType(App.Person);
      adapter.didFindRecord(store, App.Person, json, id);
      var currentUser = App.Person.find(id);
      controller = container.lookup('controller:currentUser').set('content', currentUser);
      App.advanceReadiness();
    });
  }
});