0

I have an Ember route that fetches it's model from the store (ember-data) and then needs to reload it from the server to populate attributes that were not sent on the index action.

To implement this, I added an afterModel hook into the router, and called model.reload(). In the UI, it works brilliantly; the index action loads all the items with partial data, and clicking into the detail requests the rest of the attributes from the server.

However, when I attempt to run integration tests using capybara-webkit or selenium, the route does not transition. The url changes, but the new view is not rendered.

I placed console.log statements in the model, afterModel, and setupController actions in the route; the model action does not appear to fire. However, if I remove the afterModel hook from the router, model still does not fire, but the route transitions properly. As a user in a web browser, model, afterModel, and setupController all fire, and the route transitions with a fully populated model.

Router code:

Prm.LeadRoute = Ember.Route.extend
  setupController: (controller, model) ->
    console.log 'setupController'
    @controllerFor('newNote').set('model', @store.createRecord('note'))
    @controllerFor('newCustomLeadEmail').set('model', @store.createRecord('customLeadEmail'))
    @controllerFor('newLeadQuote').set('model', @store.createRecord('leadQuote'))
    console.log model
    console.log model.get('id')
    model.reload()
    controller.set('model', model)

  model: (params) ->
    console.log 'model'
    selectedLead = @store.find('lead', params.lead_id)
    @controllerFor('property').set('selectedLead', selectedLead)
    selectedLead

  afterModel: (model) ->
    console.log 'afterModel'
    model.reload()

  deactivate: ->
    @controllerFor('property').set('selectedLead', null)

EDIT: Here's the 'transition code'. It's nothing special; we're just clicking a link and letting the Ember router handle the url:

<h2 {{action 'selectLead' lead}}>
  {{#linkTo 'lead' lead}}{{unbound bookingRequestName}}{{/linkTo}}
</h2>
Stuart
  • 644
  • 1
  • 6
  • 13
  • Will you show the transition code? Are you running in testing mode? There's a good chance it's not running in the run loop which may be why the remainder of the code isn't executing. – Kingpin2k Nov 22 '13 at 23:42
  • @kingpin2k I added the transition code. I don't think Ember is in testing mode; it's a Capybara integration test with Rails, so capybara-webkit spins up a server and exercises the entire page. Also, the transition works perfectly fine as long as the `afterModel` hook isn't present. – Stuart Nov 23 '13 at 18:05

0 Answers0