six2six / fixture-factory

Generator fake objects from a template
Apache License 2.0
445 stars 88 forks source link

Order rules by dependencies #72

Closed nykolaslima closed 8 years ago

nykolaslima commented 9 years ago

Today we have the following problem:

Fixture.of(User.class).addTemplate("valid", new Rule() {{
add("email", "${name}@gmail.com");
add("name", random("nykolas", "otavio"));
}};

The above code fails because email depends on name but when email is evaluated, name was not evaluated yet.

@Tavio has solved this problem on Angular-Fixture-Factory(https://github.com/Tavio/angular-fixture-factory) project using Topological sort(http://en.wikipedia.org/wiki/Topological_sorting) https://github.com/Tavio/angular-fixture-factory/blob/master/angular-fixture-factory.js#L264-L312

We can use the same approach here.

Tavio commented 9 years ago

"Beware of bugs in the above code; I have only proved it correct, not tried it." - Knuth, Donald.

ddomingues commented 9 years ago

This issue shouldn't be closed? @nykolaslima

And could you generate a new version with the PR #77?

mahmoudimus commented 8 years ago

This is indeed already merged via #77

nykolaslima commented 8 years ago

Thank you guys.