Merge pull request #7365 from tchak/fix-messages-expert
fix(expert): expert should be allowed to delete messages
This commit is contained in:
commit
7003014831
3 changed files with 45 additions and 19 deletions
|
@ -124,6 +124,12 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def authenticate_instructeur_or_expert!
|
||||||
|
if !instructeur_signed_in? && !expert_signed_in?
|
||||||
|
redirect_to new_user_session_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def authenticate_administrateur!
|
def authenticate_administrateur!
|
||||||
if !administrateur_signed_in?
|
if !administrateur_signed_in?
|
||||||
redirect_to new_user_session_path
|
redirect_to new_user_session_path
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
module Instructeurs
|
module Instructeurs
|
||||||
class CommentairesController < ProceduresController
|
class CommentairesController < ApplicationController
|
||||||
|
before_action :authenticate_instructeur_or_expert!
|
||||||
after_action :mark_messagerie_as_read
|
after_action :mark_messagerie_as_read
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|
|
@ -1,36 +1,55 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
describe Instructeurs::CommentairesController, type: :controller do
|
describe Instructeurs::CommentairesController, type: :controller do
|
||||||
|
let(:expert) { create(:expert) }
|
||||||
let(:instructeur) { create(:instructeur) }
|
let(:instructeur) { create(:instructeur) }
|
||||||
let(:procedure) { create(:procedure, :published, :for_individual, instructeurs: [instructeur]) }
|
let(:procedure) { create(:procedure, :published, :for_individual, instructeurs: [instructeur]) }
|
||||||
let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
|
let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
|
||||||
render_views
|
render_views
|
||||||
|
|
||||||
before { sign_in(instructeur.user) }
|
context 'as instructeur' do
|
||||||
|
before { sign_in(instructeur.user) }
|
||||||
|
|
||||||
describe 'destroy' do
|
describe 'destroy' do
|
||||||
render_views
|
context 'when it works' do
|
||||||
|
let(:commentaire) { create(:commentaire, instructeur: instructeur, dossier: dossier) }
|
||||||
|
subject { delete :destroy, params: { dossier_id: dossier.id, procedure_id: procedure.id, id: commentaire.id }, format: :turbo_stream }
|
||||||
|
|
||||||
context 'when it works' do
|
it 'respond with OK and flash' do
|
||||||
let(:commentaire) { create(:commentaire, instructeur: instructeur, dossier: dossier) }
|
expect(subject).to have_http_status(:ok)
|
||||||
subject { delete :destroy, params: { dossier_id: dossier.id, procedure_id: procedure.id, id: commentaire.id }, format: :turbo_stream }
|
expect(subject.body).to include('Message supprimé')
|
||||||
|
expect(subject.body).to include('alert-success')
|
||||||
|
expect(subject.body).to include('Votre message a été supprimé')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'respond with OK and flash' do
|
context 'when dossier had been discarded' do
|
||||||
expect(subject).to have_http_status(:ok)
|
let(:commentaire) { create(:commentaire, instructeur: instructeur, dossier: dossier, discarded_at: 2.hours.ago) }
|
||||||
expect(subject.body).to include('Message supprimé')
|
subject { delete :destroy, params: { dossier_id: dossier.id, procedure_id: procedure.id, id: commentaire.id }, format: :turbo_stream }
|
||||||
expect(subject.body).to include('alert-success')
|
|
||||||
expect(subject.body).to include('Votre message a été supprimé')
|
it 'respond with OK and flash' do
|
||||||
|
expect(subject).to have_http_status(:ok)
|
||||||
|
expect(subject.body).to include('alert-danger')
|
||||||
|
expect(subject.body).to include('Ce message a déjà été supprimé')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when dossier had been discarded' do
|
context 'as expert' do
|
||||||
let(:commentaire) { create(:commentaire, instructeur: instructeur, dossier: dossier, discarded_at: 2.hours.ago) }
|
before { sign_in(expert.user) }
|
||||||
subject { delete :destroy, params: { dossier_id: dossier.id, procedure_id: procedure.id, id: commentaire.id }, format: :turbo_stream }
|
|
||||||
|
|
||||||
it 'respond with OK and flash' do
|
describe 'destroy' do
|
||||||
expect(subject).to have_http_status(:ok)
|
context 'when it works' do
|
||||||
expect(subject.body).to include('alert-danger')
|
let(:commentaire) { create(:commentaire, expert: expert, dossier: dossier) }
|
||||||
expect(subject.body).to include('Ce message a déjà été supprimé')
|
subject { delete :destroy, params: { dossier_id: dossier.id, procedure_id: procedure.id, id: commentaire.id }, format: :turbo_stream }
|
||||||
|
|
||||||
|
it 'respond with OK and flash' do
|
||||||
|
expect(subject).to have_http_status(:ok)
|
||||||
|
expect(subject.body).to include('Message supprimé')
|
||||||
|
expect(subject.body).to include('alert-success')
|
||||||
|
expect(subject.body).to include('Votre message a été supprimé')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue