models: require belong_to associations on champ

- Make `champ.dossier` a requirement;
- Move the dossier_id assignation to `before_validation` (otherwise
the record is invalid, and never gets saved);
- Allow specs to only build the champ (instead of saving it to the
database), which bypasses the requirement to have a dossier.
This commit is contained in:
Pierre de La Morinerie 2020-07-20 15:18:44 +00:00
parent eb22dc9d8f
commit 6328011f60
13 changed files with 318 additions and 274 deletions

View file

@ -2,7 +2,7 @@ RSpec.describe VirusScannerJob, type: :job do
include ActiveJob::TestHelper
let(:champ) do
champ = create(:champ, :piece_justificative)
champ = create(:champ_piece_justificative)
champ.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
champ.save
champ