adopted-ember-addons / ember-data-factory-guy

Factories and helper functions for (unit, integration, acceptance) testing + development scenarios with Ember Data
MIT License
301 stars 136 forks source link

Passing match to handleCreate results in false positive #81

Closed tonywok closed 9 years ago

tonywok commented 9 years ago

First off, thanks for writing this library. I think it will drastically clean up my tests.

I'm using handleCreate to replace my existing sinon mock. After reading through the docs, I saw the match option. This seems like a really cool feature, but I keep getting false positives when trying to use it.

For example:

TestHelper.handleCreate('project', {match: {name: "Not Tony"}});

I then proceed to write my test code to create an author with the name of "Tony". I would expect that to fail based on the match condition.

Upon closer inspection I saw the code inside MockCreateRequest's calculate method is calling tmpRecord.serialize(matchArgs). Looking at the ember data source, I see this for serialize:

  /*
    Create a JSON representation of the record, using the serialization
    strategy of the store's adapter.

   `serialize` takes an optional hash as a parameter, currently
    supported options are:

   - `includeId`: `true` if the record's ID should be included in the
      JSON representation.

    @method serialize
    @param {Object} options
    @return {Object} an object whose values are primitive JSON values only
  */
  serialize: function(options) {
    return this.store.serialize(this, options);
  },

So, it doesn't seem like the match args are actually going to survive beyond the call to serialize. That would explain my false positive. Am I interpreting your README correctly?

Thanks again :)

ember-data beta 16.1 ember 1.11.3 ember-data-factory-guy 1.0.7 ember-cli 0.2.3

danielspaniel commented 9 years ago

Boy, that is a puzzler @tonywok, because this functionality has been pretty well tested .. and I retested it again today .. kept trying to make this not fail, but it works as expected for me. But maybe you are doing something in model, test, setup that is different? So .. try sending the model, the full test, the factory .. and I can then try and recreate this one. The matchArgs do survive the serialize call, but it was good idea to look there, because it made me wonder "Why am I passing in matchArgs to serialize method in the first place?" .. seems pretty useless thing to do. Turns out .. it was pretty dumb. So I took that out. Maybe you are using a custom serializer for that model that is messing with those options?

tonywok commented 9 years ago

@danielspaniel That could be. It's an old (funny using that word) ember app, so there's lots of work arounds.

I'll take a closer look and resubmit if needed. Thanks.