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
|
flash.now.alert = @procedure.errors.full_messages
|
||||||
render 'new'
|
render 'new'
|
||||||
else
|
else
|
||||||
|
@procedure.create_generic_procedure_labels
|
||||||
flash.notice = 'Démarche enregistrée.'
|
flash.notice = 'Démarche enregistrée.'
|
||||||
current_administrateur.instructeur.assign_to_procedure(@procedure)
|
current_administrateur.instructeur.assign_to_procedure(@procedure)
|
||||||
|
|
||||||
|
|
|
@ -295,7 +295,6 @@ class Procedure < ApplicationRecord
|
||||||
after_initialize :ensure_path_exists
|
after_initialize :ensure_path_exists
|
||||||
before_save :ensure_path_exists
|
before_save :ensure_path_exists
|
||||||
after_create :ensure_defaut_groupe_instructeur
|
after_create :ensure_defaut_groupe_instructeur
|
||||||
after_create :create_generic_procedure_labels
|
|
||||||
|
|
||||||
include AASM
|
include AASM
|
||||||
|
|
||||||
|
@ -530,6 +529,7 @@ class Procedure < ApplicationRecord
|
||||||
procedure.closing_notification_en_cours = false
|
procedure.closing_notification_en_cours = false
|
||||||
procedure.template = false
|
procedure.template = false
|
||||||
procedure.monavis_embed = nil
|
procedure.monavis_embed = nil
|
||||||
|
procedure.procedure_labels = procedure_labels.map(&:dup)
|
||||||
|
|
||||||
if !procedure.valid?
|
if !procedure.valid?
|
||||||
procedure.errors.attribute_names.each do |attribute|
|
procedure.errors.attribute_names.each do |attribute|
|
||||||
|
|
|
@ -662,7 +662,7 @@ describe Administrateurs::ProceduresController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'PUT #clone' do
|
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 } }
|
let(:params) { { procedure_id: procedure.id } }
|
||||||
|
|
||||||
subject { put :clone, params: params }
|
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.cloned_from_library).to be_falsey
|
||||||
expect(Procedure.last.notice.attached?).to be_truthy
|
expect(Procedure.last.notice.attached?).to be_truthy
|
||||||
expect(Procedure.last.deliberation.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.'
|
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
|
||||||
|
|
||||||
|
@ -705,6 +709,7 @@ describe Administrateurs::ProceduresController, type: :controller do
|
||||||
|
|
||||||
it 'creates a new procedure and redirect to it' do
|
it 'creates a new procedure and redirect to it' do
|
||||||
expect(response).to redirect_to admin_procedure_path(id: Procedure.last.id)
|
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.'
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -1520,6 +1520,8 @@ describe Instructeurs::DossiersController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'dossier_labels' do
|
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
|
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 }
|
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
|
it 'works' do
|
||||||
|
|
|
@ -639,8 +639,9 @@ describe Instructeurs::ProceduresController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'dossier labels' do
|
context 'dossier labels' do
|
||||||
let!(:dossier) { create(:dossier, :en_construction, groupe_instructeur: gi_2) }
|
let(:procedure) { create(:procedure, :with_labels, instructeurs: [instructeur]) }
|
||||||
let!(:dossier_2) { create(:dossier, :en_construction, groupe_instructeur: gi_2) }
|
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(:statut) { 'tous' }
|
||||||
let(:procedure_label_id) { procedure.find_column(label: 'Labels') }
|
let(:procedure_label_id) { procedure.find_column(label: 'Labels') }
|
||||||
let!(:procedure_presentation) do
|
let!(:procedure_presentation) do
|
||||||
|
|
|
@ -291,6 +291,12 @@ FactoryBot.define do
|
||||||
trait :accuse_lecture do
|
trait :accuse_lecture do
|
||||||
accuse_lecture { true }
|
accuse_lecture { true }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :with_labels do
|
||||||
|
after(:create) do |procedure, _evaluator|
|
||||||
|
procedure.create_generic_procedure_labels
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -272,33 +272,37 @@ describe 'Instructing a dossier:', js: true do
|
||||||
after { DownloadHelpers.clear_downloads }
|
after { DownloadHelpers.clear_downloads }
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'An instructeur can add labels to a dossier' do
|
context 'An instructeur can add labels' do
|
||||||
log_in(instructeur.email, password)
|
let(:procedure) { create(:procedure, :with_labels, :published, instructeurs: [instructeur]) }
|
||||||
|
|
||||||
visit instructeur_dossier_path(procedure, dossier)
|
scenario 'An instructeur can add and remove labels to a dossier' do
|
||||||
click_on 'Ajouter un label'
|
log_in(instructeur.email, password)
|
||||||
|
|
||||||
check 'à relancer', allow_label_click: true
|
visit instructeur_dossier_path(procedure, dossier)
|
||||||
expect(page).to have_css('.fr-badge', text: "à relancer", count: 2)
|
click_on 'Ajouter un label'
|
||||||
expect(dossier.dossier_labels.count).to eq(1)
|
|
||||||
|
|
||||||
expect(page).not_to have_text('Ajouter un label')
|
check 'à relancer', allow_label_click: true
|
||||||
find('span.dropdown button.dropdown-button').click
|
expect(page).to have_css('.fr-tag', text: "à relancer", count: 2)
|
||||||
|
expect(dossier.dossier_labels.count).to eq(1)
|
||||||
|
|
||||||
expect(page).to have_checked_field('à relancer')
|
expect(page).not_to have_text('Ajouter un label')
|
||||||
check 'complet', allow_label_click: true
|
find('span.dropdown button.dropdown-button').click
|
||||||
|
|
||||||
expect(page).to have_css('.fr-badge', text: "complet", count: 2)
|
expect(page).to have_checked_field('à relancer')
|
||||||
expect(dossier.dossier_labels.count).to eq(2)
|
check 'complet', allow_label_click: true
|
||||||
|
|
||||||
find('span.dropdown button.dropdown-button').click
|
expect(page).to have_css('.fr-tag', text: "complet", count: 2)
|
||||||
uncheck 'à relancer', allow_label_click: true
|
expect(dossier.dossier_labels.count).to eq(2)
|
||||||
|
|
||||||
expect(page).to have_unchecked_field('à relancer')
|
find('span.dropdown button.dropdown-button').click
|
||||||
expect(page).to have_checked_field('complet')
|
uncheck 'à relancer', allow_label_click: true
|
||||||
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_unchecked_field('à relancer')
|
||||||
expect(dossier.dossier_labels.count).to eq(1)
|
expect(page).to have_checked_field('complet')
|
||||||
|
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
|
end
|
||||||
|
|
||||||
def log_in(email, password, check_email: true)
|
def log_in(email, password, check_email: true)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
describe "procedure filters" do
|
describe "procedure filters" do
|
||||||
let(:instructeur) { create(:instructeur) }
|
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(:types_de_champ_public) { [{ type: :text }] }
|
||||||
let!(:type_de_champ) { procedure.active_revision.types_de_champ_public.first }
|
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)) }
|
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
|
end
|
||||||
|
|
||||||
describe "Dossier labels" do
|
describe "Dossier labels" do
|
||||||
|
let(:procedure) { create(:procedure, :with_labels) }
|
||||||
|
let(:dossier) { create(:dossier, :en_construction, procedure:) }
|
||||||
context "Dossier without labels" do
|
context "Dossier without labels" do
|
||||||
it 'displays button with text to add label' do
|
it 'displays button with text to add label' do
|
||||||
expect(subject).to have_text("Ajouter un label")
|
expect(subject).to have_text("Ajouter un label")
|
||||||
|
|
Loading…
Reference in a new issue