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

Sequences and calculated attributes don't work in buildLists when attributes are specified #26

Closed
RustyToms opened this issue May 27, 2014 · 0 comments

Comments

@RustyToms
Copy link
Contributor

This is a great library that I have found very useful! However, I often like to create lists of objects with unique attributes. Unfortunately, when attributes are set using buildList the sequences no longer work. All the objects have identical values, even if they are sequences or calculated using functions. This is because the attributes have been mutated and include all the attributes of the first object. It appears that these attributes have been passed in, and are set on all subsequent objects. This only happens if attributes are specified, because if attributes are not specified the attribute variable here is set to a new, empty object for each object created.

To reproduce the error:

Factory.define('test')
  .sequence('id')
  .attr('random', function() {
    return Math.floor(Math.random() * 100);
  })
  .attr('constant', 'same');

// this produces 4 objects with different ids and 'random' attributes 
Factory.buildList('test', 4);

// this produces 4 objects with identical attributes
Factory.buildList('test', 4, {constant: 'different'});

I am submitting a pull request with a simple fix

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

No branches or pull requests

1 participant