six2six / fixture-factory

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

Allows override properties with collection attribute #89

Open acarvalho opened 8 years ago

aparra commented 8 years ago

Hey @acarvalho. Thank you very much for your contribution. We really appreciate it.

Now we need to have a little chat about this feature. Well, I particularly don't like the approach to override multiple functions in a collection:

Student student = Fixture.from(Student.class).gimme("valid", new Rule() {{
  add("addresses[0].id", 123456L);
  add("addresses[0].city.name", "BH");
  add("addresses[0].city.neighborhoods[0].name", "Santa Efigênia");
  add("addresses[1].id", 123457L);
  add("addresses[2].id", 123458L);
}});

I prefer override all the list in this case, I guess this way is more maintainable:

Student student = Fixture.from(Student.class).gimme("valid", new Rule() {{
  add("addresses", Fixture.from(Address.class).gimme(3, "from-bh"));
}});

But I am talking about this specific usage. Please let me know more about how you are using it.

cc/ @ahirata @nykolaslima

acarvalho commented 7 years ago

Hey @aparra, thanks for your answer.

The idea of this new feature is not to override multiple functions in a collection but rather to override one single function in a collection inside others collections. Take a look at the code below.

 Student student = Fixture.from(Student.class).gimme("valid", new Rule() {{
   add("addresses[0].city.neighborhoods[0].name", "Santa Efigênia");
 }});

To override a name, today in the library, I need to create a new template for address, city and neighborhoods. If these templates were used in other tests that's ok but most of the time these templates are used only in a specific test.

I think that the function of an override attribute in a template was created to avoid the creation of unnecessary templates to keep the code clean. But this does not work for collections. So this PR is to allow this.

Any question just ping me.

Cheers,

cc/ @ahirata @nykolaslima