I'm new to Rails testing and I just want to give it a shot and gradually implement tests for my existing models.
However, I'm currently stuck on what to use for the following case:
I have a project with a volume, which can have multiple donations. each donation has a amount. each donation fills the volume of the project by its amount, until the volume of the project is filled by the donations. The project does not have a dedicated "donated_amount" field.
I have a amount_controller that handles the amount input in the frontend checkout process and the validation of that amount in checkout_validations. The donation itself is saved at the end of the checkout process.
Now there are some special cases for what should happen with the last donation, e.g. if the minimum amount for an donation is more that the residual volume of the project.
How should this be tested? So far, all I've read for validation tests are simple validations of model's attributes, linke username exists, only lowercase usernames etc., which is fairly easy to handle with max. 3 lines of code. But I have not yet found any validation test that includes multiple models.
My understanding right now is that I have to build a project, add donations to this project until the volume is almost filled and then run a test on one last donation. But my validations won't work on an donation, because the amount is supposed to validate earlier in the checkout process.
I'm currently tending towards factory girl, creating factories for the models (which should be able to be related, right?) and then somehow testing for the amount validation.
Is this the right way?
Aucun commentaire:
Enregistrer un commentaire