Is before_save executed after validation?

My user check seems to be done before my before_save block, which is strange to me. I know before_validation , but I'm trying to test my own validator, so the before_validation hook will not let me do this. I also read that testing a private method (my validator) is bad practice. What should I do?

Additional information: we want users to be able to upload a document with a URL or file, but not with both, or with a nickname (xor). My validator checks them. If the user edits a document, the before_save hook deletes the current URL or file. Theoretically, the stream should be:

  • Upload file
  • Confirm and save
  • Download URL
  • before_save, check, save

But in my tests, I get validation errors, assuming that before_save does not occur.

+6
source share
1 answer
 after_initialize ↓ (1) 

 before_validation ↓ (2) after_validation ↓ (3) 

 before_save ↓ (4) 

 before_create ↓ (5) after_create ↓ (6) 

 after_save ↓ (7) 

 after_commit ↓ (8) 
+16
source

Source: https://habr.com/ru/post/984248/


All Articles