create generic label for procedure in controller instead of using a hook
This commit is contained in:
parent
f68f4c88eb
commit
e723c9e365
9 changed files with 46 additions and 25 deletions
|
@ -108,6 +108,7 @@ module Administrateurs
|
|||
flash.now.alert = @procedure.errors.full_messages
|
||||
render 'new'
|
||||
else
|
||||
@procedure.create_generic_procedure_labels
|
||||
flash.notice = 'Démarche enregistrée.'
|
||||
current_administrateur.instructeur.assign_to_procedure(@procedure)
|
||||
|
||||
|
|
|
@ -295,7 +295,6 @@ class Procedure < ApplicationRecord
|
|||
after_initialize :ensure_path_exists
|
||||
before_save :ensure_path_exists
|
||||
after_create :ensure_defaut_groupe_instructeur
|
||||
after_create :create_generic_procedure_labels
|
||||
|
||||
include AASM
|
||||
|
||||
|
@ -530,6 +529,7 @@ class Procedure < ApplicationRecord
|
|||
procedure.closing_notification_en_cours = false
|
||||
procedure.template = false
|
||||
procedure.monavis_embed = nil
|
||||
procedure.procedure_labels = procedure_labels.map(&:dup)
|
||||
|
||||
if !procedure.valid?
|
||||
procedure.errors.attribute_names.each do |attribute|
|
||||
|
|
|
@ -662,7 +662,7 @@ describe Administrateurs::ProceduresController, type: :controller do
|
|||
end
|
||||
|
||||
describe 'PUT #clone' do
|
||||
let(:procedure) { create(:procedure, :with_notice, :with_deliberation, administrateur: admin) }
|
||||
let(:procedure) { create(:procedure, :with_notice, :with_deliberation, :with_labels, administrateur: admin) }
|
||||
let(:params) { { procedure_id: procedure.id } }
|
||||
|
||||
subject { put :clone, params: params }
|
||||
|
@ -684,6 +684,10 @@ describe Administrateurs::ProceduresController, type: :controller do
|
|||
expect(Procedure.last.cloned_from_library).to be_falsey
|
||||
expect(Procedure.last.notice.attached?).to be_truthy
|
||||
expect(Procedure.last.deliberation.attached?).to be_truthy
|
||||
expect(Procedure.last.procedure_labels.present?).to be_truthy
|
||||
expect(Procedure.last.procedure_labels.first.procedure_id).to eq(Procedure.last.id)
|
||||
expect(procedure.procedure_labels.first.procedure_id).to eq(procedure.id)
|
||||
|
||||
expect(flash[:notice]).to have_content 'Démarche clonée. Pensez à vérifier la présentation et choisir le service à laquelle cette démarche est associée.'
|
||||
end
|
||||
|
||||
|
@ -705,6 +709,7 @@ describe Administrateurs::ProceduresController, type: :controller do
|
|||
|
||||
it 'creates a new procedure and redirect to it' do
|
||||
expect(response).to redirect_to admin_procedure_path(id: Procedure.last.id)
|
||||
expect(Procedure.last.procedure_labels.present?).to be_truthy
|
||||
expect(flash[:notice]).to have_content 'Démarche clonée. Pensez à vérifier la présentation et choisir le service à laquelle cette démarche est associée.'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1520,6 +1520,8 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
describe 'dossier_labels' do
|
||||
let(:procedure) { create(:procedure, :with_labels, instructeurs: [instructeur]) }
|
||||
let!(:dossier) { create(:dossier, :en_construction, procedure:) }
|
||||
context 'it create dossier labels' do
|
||||
subject { post :dossier_labels, params: { procedure_id: procedure.id, dossier_id: dossier.id, procedure_label_id: [ProcedureLabel.first.id] }, format: :turbo_stream }
|
||||
it 'works' do
|
||||
|
|
|
@ -639,8 +639,9 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
end
|
||||
|
||||
context 'dossier labels' do
|
||||
let!(:dossier) { create(:dossier, :en_construction, groupe_instructeur: gi_2) }
|
||||
let!(:dossier_2) { create(:dossier, :en_construction, groupe_instructeur: gi_2) }
|
||||
let(:procedure) { create(:procedure, :with_labels, instructeurs: [instructeur]) }
|
||||
let!(:dossier) { create(:dossier, :en_construction, procedure:, groupe_instructeur: gi_2) }
|
||||
let!(:dossier_2) { create(:dossier, :en_construction, procedure:, groupe_instructeur: gi_2) }
|
||||
let(:statut) { 'tous' }
|
||||
let(:procedure_label_id) { procedure.find_column(label: 'Labels') }
|
||||
let!(:procedure_presentation) do
|
||||
|
|
|
@ -291,6 +291,12 @@ FactoryBot.define do
|
|||
trait :accuse_lecture do
|
||||
accuse_lecture { true }
|
||||
end
|
||||
|
||||
trait :with_labels do
|
||||
after(:create) do |procedure, _evaluator|
|
||||
procedure.create_generic_procedure_labels
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -272,14 +272,17 @@ describe 'Instructing a dossier:', js: true do
|
|||
after { DownloadHelpers.clear_downloads }
|
||||
end
|
||||
|
||||
scenario 'An instructeur can add labels to a dossier' do
|
||||
context 'An instructeur can add labels' do
|
||||
let(:procedure) { create(:procedure, :with_labels, :published, instructeurs: [instructeur]) }
|
||||
|
||||
scenario 'An instructeur can add and remove labels to a dossier' do
|
||||
log_in(instructeur.email, password)
|
||||
|
||||
visit instructeur_dossier_path(procedure, dossier)
|
||||
click_on 'Ajouter un label'
|
||||
|
||||
check 'à relancer', allow_label_click: true
|
||||
expect(page).to have_css('.fr-badge', text: "à relancer", count: 2)
|
||||
expect(page).to have_css('.fr-tag', text: "à relancer", count: 2)
|
||||
expect(dossier.dossier_labels.count).to eq(1)
|
||||
|
||||
expect(page).not_to have_text('Ajouter un label')
|
||||
|
@ -288,7 +291,7 @@ describe 'Instructing a dossier:', js: true do
|
|||
expect(page).to have_checked_field('à relancer')
|
||||
check 'complet', allow_label_click: true
|
||||
|
||||
expect(page).to have_css('.fr-badge', text: "complet", count: 2)
|
||||
expect(page).to have_css('.fr-tag', text: "complet", count: 2)
|
||||
expect(dossier.dossier_labels.count).to eq(2)
|
||||
|
||||
find('span.dropdown button.dropdown-button').click
|
||||
|
@ -296,10 +299,11 @@ describe 'Instructing a dossier:', js: true do
|
|||
|
||||
expect(page).to have_unchecked_field('à relancer')
|
||||
expect(page).to have_checked_field('complet')
|
||||
expect(page).to have_css('.fr-badge', text: "à relancer", count: 1)
|
||||
expect(page).to have_css('.fr-badge', text: "complet", count: 2)
|
||||
expect(page).to have_css('.fr-tag', text: "à relancer", count: 1)
|
||||
expect(page).to have_css('.fr-tag', text: "complet", count: 2)
|
||||
expect(dossier.dossier_labels.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
def log_in(email, password, check_email: true)
|
||||
visit new_user_session_path
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
describe "procedure filters" do
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
let(:procedure) { create(:procedure, :published, types_de_champ_public:, instructeurs: [instructeur]) }
|
||||
let(:procedure) { create(:procedure, :published, :with_labels, types_de_champ_public:, instructeurs: [instructeur]) }
|
||||
let(:types_de_champ_public) { [{ type: :text }] }
|
||||
let!(:type_de_champ) { procedure.active_revision.types_de_champ_public.first }
|
||||
let!(:new_unfollow_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) }
|
||||
|
|
|
@ -219,6 +219,8 @@ describe 'instructeurs/dossiers/show', type: :view do
|
|||
end
|
||||
|
||||
describe "Dossier labels" do
|
||||
let(:procedure) { create(:procedure, :with_labels) }
|
||||
let(:dossier) { create(:dossier, :en_construction, procedure:) }
|
||||
context "Dossier without labels" do
|
||||
it 'displays button with text to add label' do
|
||||
expect(subject).to have_text("Ajouter un label")
|
||||
|
|
Loading…
Reference in a new issue