Skip to content
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

handleFindAll not playing well with handleUpdate #128

Closed
eliotpiering opened this issue Sep 3, 2015 · 4 comments · Fixed by #129
Closed

handleFindAll not playing well with handleUpdate #128

eliotpiering opened this issue Sep 3, 2015 · 4 comments · Fixed by #129

Comments

@eliotpiering
Copy link
Contributor

I'm trying to write integration tests for an index page. One test involves updating one of the items on the index page. Basically I haven't been able to get this to work.:

TestHelper.handleFindAll('connection', 1); 
//trying to handle a update of the connection that was returned from the findAll
TestHelper.handleUpdate('connection', 1); 

handleFindAll doesn't seem to put the records in the store so when handleUpdate calls

model = store.peekRecord(type, id);

it returns null and errors out later on.

I have instead tried using makeList to create the records, which works with handleUpdate but then my tests fail when the route fails to load all the 'connections' because the query has not been mocked out.

I have also tried to pass the result of makeList to handleFindAll but that also doesn't seem to work.

Am I missing something simple here, or is there another strategy I should be using? Or is this a bug?

It would be nice if handleFindAll loaded the records it creates into the store so that we could interact with them afterwards.

I just updated to version 2.0.1 of FactoryGuy and using ember and ember-data 2.0.0. I was experiencing the same issue in version 1.13 of FactoryGuy as well.

@danielspaniel
Copy link
Collaborator

@eliotpiering, this is a really interesting problem .. I would not quite call it a bug, but maybe an interesting use case, because handleFindAll does actually populate the records .. just AFTER the findAll query has returned ( once that promise is completed in other words ).
what you are doing is trying to mock the update BEFORE that findAll has returned ( if you understand my meaning ) .. which you probably do.

Here is example of what you have to do to make this work:

    Ember.run(function () {
      var done = assert.async();
      TestHelper.handleFindAll('user', 2);

      FactoryGuy.getStore().findAll('user').then(function (users) {

        TestHelper.handleUpdate('user', 1);

        var user = FactoryGuy.getStore().peekRecord('user',1);
        user.set('name', 'BOB').save();

        done();
      });
    });

This of course is contrived because its not a real world scenario .. but if you give me an idea of what you are doing .. in your test .. I can try and do better at getting the mocks right in your testing scenario
but my guess is it will be something like this: ( pseudo codeish )

 TestHelper.handleFindAll('user', 2);
  visit('users') 
  andThen(function() {
    TestHelper.handleUpdate('user', 1);
    # now update the user
    fillIn('input.user', 'BOB');
    click('#save-that-sucker')

@eliotpiering
Copy link
Contributor Author

Ahh yes, this last code example made it perfectly clear. I see my mistake now. I just updated my tests and it is working properly. I don't think anything should be different, it makes total sense the way it currently works, but maybe something about handleFindAll populating records after the request resolves in the readme would be helpful. I'll make a pull request for the docs later today. Thanks for the quick response and the great library.

@danielspaniel
Copy link
Collaborator

your welcome @eliotpiering, and yes, it's something I have done in my tests a few times so I think your right that it would be nice to document. In that pull request @eliotpiering, if you want to be a rock star, could you create a test in the acceptance directory ( that you can point to and that people can see when they click on it .. like I did in doc's with some of the other tests ( user.js etc. ) .. that shows the idea too.
This kind of thing I think ( real example ) .. helps a ton, and thanks for offering to help with PR. It's always nice to get help.

@eliotpiering
Copy link
Contributor Author

sure no problem, will do shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants