models: require belong_to associations on commentaire
This commit is contained in:
parent
32e55a6d37
commit
dd1bed9340
3 changed files with 9 additions and 11 deletions
|
@ -12,7 +12,7 @@
|
||||||
# user_id :bigint
|
# user_id :bigint
|
||||||
#
|
#
|
||||||
class Commentaire < ApplicationRecord
|
class Commentaire < ApplicationRecord
|
||||||
belongs_to :dossier, inverse_of: :commentaires, touch: true
|
belongs_to :dossier, inverse_of: :commentaires, touch: true, optional: false
|
||||||
|
|
||||||
belongs_to :user, optional: true
|
belongs_to :user, optional: true
|
||||||
belongs_to :instructeur, optional: true
|
belongs_to :instructeur, optional: true
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :commentaire do
|
factory :commentaire do
|
||||||
body { 'plop' }
|
association :dossier, :en_construction
|
||||||
|
|
||||||
before(:create) do |commentaire, _evaluator|
|
body { 'plop' }
|
||||||
if !commentaire.dossier
|
|
||||||
commentaire.dossier = create :dossier, :en_construction
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
trait :with_file do
|
trait :with_file do
|
||||||
piece_jointe { Rack::Test::UploadedFile.new('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
|
piece_jointe { Rack::Test::UploadedFile.new('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
|
||||||
|
|
|
@ -34,15 +34,17 @@ describe ActiveStorage::DownloadableFile do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when there is a message with no attachment' do
|
context 'when there is a message with no attachment' do
|
||||||
let(:commentaire) { create(:commentaire) }
|
before do
|
||||||
let(:dossier) { commentaire.dossier }
|
dossier.commentaires << build(:commentaire, dossier: dossier)
|
||||||
|
end
|
||||||
|
|
||||||
it { expect(list.length).to eq 0 }
|
it { expect(list.length).to eq 0 }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when there is a message with an attachment' do
|
context 'when there is a message with an attachment' do
|
||||||
let(:commentaire) { create(:commentaire, :with_file) }
|
before do
|
||||||
let(:dossier) { commentaire.dossier }
|
dossier.commentaires << build(:commentaire, :with_file, dossier: dossier)
|
||||||
|
end
|
||||||
|
|
||||||
it { expect(list.length).to eq 1 }
|
it { expect(list.length).to eq 1 }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue