DEFRA / ruby-services-team

Guides, info and issue management for the Ruby Services team
Other
1 stars 3 forks source link

Improve factorybot factories #5

Open Cruikshanks opened 5 years ago

Cruikshanks commented 5 years ago

In recent changes there is a shared smell amongst the team that we have not been consistent with how we are using factories.

In some cases we have defined traits, in other places we are using a base trait and then specifying the additional properties we want set either within the factory or in the unit tests themselves.

So we need to complete a review of our factories and ensure we are doing these things

It is highly recommended that you have one factory for each class that provides the simplest set of attributes necessary to create an instance of that class. If you're creating ActiveRecord objects, that means that you should only provide attributes that are required through validations and that do not have defaults. Other factories can be created through inheritance to cover common scenarios for each class.

Cruikshanks commented 5 years ago

Since this issue was raised our agreement on how we use factories has evolved. The work still needs to be done but when we come to this tests should be reviewed beforehand.