I have a Submission model that belongs_to two different models: Student and Quiz.
Student and Quiz each individually belong_to a Course.
When a student sends a Submission for a quiz, it is assumed that the Quiz must be for the same Course that the Student is in. I want to write a validation for that.
First question: How can I write a validation to ensure that two related records (Student and Quiz) have the same, common parent?
Second question: How can I make a Submission factory that, when given no arguments, will create a Submission that passes that validation?
For the model validation, I used:
Is that reasonable? Is there a more Rails-y way to express that?