fix(bulk_messages): destroy bulk messages with procedures

This commit is contained in:
Paul Chavard 2021-12-09 12:20:22 +01:00
parent 78784d1c62
commit c7b1dc7f87
5 changed files with 20 additions and 1 deletions

View file

@ -15,6 +15,7 @@ class GroupeInstructeur < ApplicationRecord
has_many :instructeurs, through: :assign_tos
has_many :dossiers
has_and_belongs_to_many :exports, dependent: :destroy
has_and_belongs_to_many :bulk_messages, dependent: :destroy
validates :label, presence: { message: 'doit être renseigné' }, allow_nil: false
validates :label, uniqueness: { scope: :procedure, message: 'existe déjà' }

View file

@ -0,0 +1,10 @@
FactoryBot.define do
factory :bulk_message do
body { 'bonjour' }
dossier_count { 1 }
dossier_state { Dossier.states.fetch(:brouillon) }
sent_at { 1.day.ago }
instructeur { association :instructeur }
groupe_instructeurs { [association(:groupe_instructeur, strategy: :build)] }
end
end

View file

@ -8,5 +8,9 @@ FactoryBot.define do
trait :default do
label { GroupeInstructeur::DEFAUT_LABEL }
end
trait :with_bulk_message do
bulk_messages { [association(:bulk_message, strategy: :build)] }
end
end
end

View file

@ -72,6 +72,10 @@ FactoryBot.define do
end
end
trait :with_bulk_message do
groupe_instructeurs { [association(:groupe_instructeur, :default, :with_bulk_message, procedure: instance, strategy: :build)] }
end
trait :with_logo do
logo { Rack::Test::UploadedFile.new('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
end

View file

@ -1115,7 +1115,7 @@ describe Procedure do
end
describe "#destroy" do
let(:procedure) { create(:procedure, :closed, :with_type_de_champ) }
let(:procedure) { create(:procedure, :closed, :with_type_de_champ, :with_bulk_message) }
before do
procedure.discard!