A procedure has a default groupe instructeur
This commit is contained in:
parent
f296318072
commit
115d91387c
4 changed files with 31 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
||||||
class GroupeInstructeur < ApplicationRecord
|
class GroupeInstructeur < ApplicationRecord
|
||||||
|
DEFAULT_LABEL = 'défaut'
|
||||||
belongs_to :procedure
|
belongs_to :procedure
|
||||||
end
|
end
|
||||||
|
|
|
@ -74,6 +74,7 @@ class Procedure < ApplicationRecord
|
||||||
before_save :update_juridique_required
|
before_save :update_juridique_required
|
||||||
before_save :update_durees_conservation_required
|
before_save :update_durees_conservation_required
|
||||||
before_create :ensure_path_exists
|
before_create :ensure_path_exists
|
||||||
|
after_create :ensure_default_groupe_instructeur
|
||||||
|
|
||||||
include AASM
|
include AASM
|
||||||
|
|
||||||
|
@ -477,6 +478,10 @@ class Procedure < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def defaut_groupe_instructeur
|
||||||
|
groupe_instructeurs.find_by(label: GroupeInstructeur::DEFAULT_LABEL)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def move_type_de_champ_attributes(types_de_champ, type_de_champ, new_index)
|
def move_type_de_champ_attributes(types_de_champ, type_de_champ, new_index)
|
||||||
|
@ -566,4 +571,10 @@ class Procedure < ApplicationRecord
|
||||||
self.path = SecureRandom.uuid
|
self.path = SecureRandom.uuid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ensure_default_groupe_instructeur
|
||||||
|
if self.groupe_instructeurs.empty?
|
||||||
|
groupe_instructeurs.create(label: GroupeInstructeur::DEFAULT_LABEL)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
namespace :after_party do
|
||||||
|
desc 'Deployment task: create_default_groupe_instructeur'
|
||||||
|
task create_default_groupe_instructeur: :environment do
|
||||||
|
Procedure.find_each do |procedure|
|
||||||
|
procedure.groupe_instructeurs.create(label: GroupeInstructeur::DEFAULT_LABEL)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Update task as completed. If you remove the line below, the task will
|
||||||
|
# run with every deploy (or every time you call after_party:run).
|
||||||
|
AfterParty::TaskRecord.create version: '20190819142551'
|
||||||
|
end
|
||||||
|
end
|
|
@ -882,4 +882,11 @@ describe Procedure do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.ensure_a_groupe_instructeur_exists' do
|
||||||
|
let!(:procedure) { create(:procedure) }
|
||||||
|
|
||||||
|
it { expect(procedure.groupe_instructeurs.count).to eq(1) }
|
||||||
|
it { expect(procedure.groupe_instructeurs.first.label).to eq(GroupeInstructeur::DEFAULT_LABEL) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue