Skip to content

eagerInject doesn't add the model to the list after HTTP success #186

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

Closed
elado opened this issue Sep 22, 2014 · 2 comments
Closed

eagerInject doesn't add the model to the list after HTTP success #186

elado opened this issue Sep 22, 2014 · 2 comments
Assignees
Milestone

Comments

@elado
Copy link

elado commented Sep 22, 2014

Article.bindAll(scope, 'articles', {});
Article.findAll({});
Article.create({title: "a"}, {eagerInject: true}).then(function () {
  console.log("AFTER", Article.filter());
});
$timeout(function () { // timeout because the first inject is in a promise
  console.log("BEFORE", Article.filter());
});

// log:
// BEFORE [Article]
// AFTER []

I faked sleep on the server on insert. Seems like the initial object is injected to the list but when HTTP is done it's not there anymore.

@jmdobry
Copy link
Member

jmdobry commented Sep 22, 2014

Was there an error? Try adding the catch to see.

This test passes... https://github.com/jmdobry/angular-data/blob/master/test/integration/datastore/async_methods/create.test.js#L229

@elado
Copy link
Author

elado commented Sep 22, 2014

No error but it's not joining the array. The test should also check it's being added to the array:

  it('should eager inject', function () {
    $httpBackend.expectPOST('http://test.angular-cache.com/organization/77/user').respond(200, {
      organizationId: 77,
      id: 88
    });

    var eagerUser;

    DS.create('user', {
      organizationId: 77
    }, { eagerInject: true }).then(function (user) {
      var eagerUserAfterHTTP = DS.filter('user')[0]; // currently undefined
      assert.isDefined(eagerUserAfterHTTP);
      assert.equal(user, eagerUserAfterHTTP);

      assert.equal(user.id, 88);
      assert.isTrue(eagerUser === user);
    }, function () {
      fail('Should not have succeeded!');
    });

    $rootScope.$apply();


    eagerUser = DS.filter('user')[0];
    assert.isDefined(eagerUser);
    assert.equal(eagerUser.organizationId, 77);
    assert.notEqual(eagerUser.id, 88);

    $httpBackend.flush();
  });

@jmdobry jmdobry added this to the 1.0.0-rc.2 milestone Sep 22, 2014
@jmdobry jmdobry self-assigned this Sep 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants