mercredi 25 mars 2015

Does before_save run after validations?

My custom validation seems to run before my before_save block, which is odd to me. I'm aware of before_validation, but I'm trying to test my custom validator, so a before_validation hook wouldn't allow me to. I've also read that testing a private method (my validator) is bad practice. What should I do?


More info: We want users to be able to upload a Document with either a URL or File, but not both or none (xor). My validator checks the xor of these. If a user edits a Document, the before_save hook removes the current URL or File. In theory, the flow should be:



  1. Upload file

  2. Validate and save

  3. Upload URL

  4. before_save, validate, save


But in my tests, I get validation errors, suggesting that the before_save is not occurring.


Aucun commentaire:

Enregistrer un commentaire