tech(lint): rubocopify
This commit is contained in:
parent
d4c74b5621
commit
4042d51d1a
5 changed files with 26 additions and 19 deletions
|
@ -2,7 +2,6 @@
|
|||
|
||||
module Instructeurs
|
||||
class CommentairesController < ProceduresController
|
||||
|
||||
def destroy
|
||||
result = CommentaireService.soft_delete(current_instructeur, params.permit(:dossier_id, :id))
|
||||
if result.status
|
||||
|
|
|
@ -23,12 +23,12 @@ class CommentaireService
|
|||
|
||||
def soft_delete(user, params)
|
||||
commentaire = Dossier.find(params[:dossier_id])
|
||||
.commentaires
|
||||
.find(params[:id])
|
||||
.commentaires
|
||||
.find(params[:id])
|
||||
if commentaire.sent_by?(user)
|
||||
commentaire.piece_jointe.purge_later if commentaire.piece_jointe.attached?
|
||||
commentaire.piece_jointe.purge_later if commentaire.piece_jointe.attached?
|
||||
commentaire.update!(body: I18n.t('views.shared.commentaires.destroy.deleted_body'),
|
||||
deleted_at: Time.now.utc)
|
||||
deleted_at: Time.zone.now.utc)
|
||||
OpenStruct.new(status: true)
|
||||
else
|
||||
OpenStruct.new(status: false,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
describe Instructeurs::CommentairesController, type: :controller do
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
let(:procedure) { create(:procedure, :published, :for_individual, instructeurs: [instructeur]) }
|
||||
|
@ -7,7 +8,7 @@ describe Instructeurs::CommentairesController, type: :controller do
|
|||
before { sign_in(instructeur.user) }
|
||||
|
||||
describe 'destroy' do
|
||||
let(:commentaire) { create(:commentaire, instructeur: instructeur, dossier: dossier)}
|
||||
let(:commentaire) { create(:commentaire, instructeur: instructeur, dossier: dossier) }
|
||||
subject { delete :destroy, params: { dossier_id: dossier.id, procedure_id: procedure.id, id: commentaire.id } }
|
||||
it 'redirect to dossier' do
|
||||
expect(subject).to redirect_to(messagerie_instructeur_dossier_path(dossier.procedure, dossier))
|
||||
|
|
|
@ -33,7 +33,6 @@ describe CommentaireService do
|
|||
expect(commentaire.piece_jointe.attached?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '.soft_delete' do
|
||||
|
@ -64,8 +63,12 @@ describe CommentaireService do
|
|||
context 'when commentaire does not belongs to instructeur' do
|
||||
let(:user) { create(:instructeur) }
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:params) { { dossier_id: dossier.id,
|
||||
id: create(:commentaire, dossier: dossier, instructeur: create(:instructeur)).id } }
|
||||
let(:params) {
|
||||
{
|
||||
dossier_id: dossier.id,
|
||||
id: create(:commentaire, dossier: dossier, instructeur: create(:instructeur)).id
|
||||
}
|
||||
}
|
||||
it 'returns error struct' do
|
||||
expect(subject.status).to eq(false)
|
||||
end
|
||||
|
@ -83,21 +86,25 @@ describe CommentaireService do
|
|||
instructeur: user,
|
||||
piece_jointe: fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf'))
|
||||
end
|
||||
let(:params) { { dossier_id: dossier.id,
|
||||
id: commentaire.id } }
|
||||
let(:params) {
|
||||
{
|
||||
dossier_id: dossier.id,
|
||||
id: commentaire.id
|
||||
}
|
||||
}
|
||||
it 'returns error struct' do
|
||||
expect(subject.status).to eq(true)
|
||||
end
|
||||
it 'sets commentaire.body to deleted message' do
|
||||
allow(commentaire.piece_jointe).to receive(:purge_later)
|
||||
expect{ subject}.to change { commentaire.reload.body}.from(an_instance_of(String)).to("Message supprimé")
|
||||
expect { subject }.to change { commentaire.reload.body }.from(an_instance_of(String)).to("Message supprimé")
|
||||
end
|
||||
it 'sets commentaire.body to deleted message' do
|
||||
expect{ subject}.to change { commentaire.reload.body}.from(an_instance_of(String)).to("Message supprimé")
|
||||
expect { subject }.to change { commentaire.reload.body }.from(an_instance_of(String)).to("Message supprimé")
|
||||
end
|
||||
it 'set deleted_at' do
|
||||
Timecop.freeze do
|
||||
expect{ subject}.to change { commentaire.reload.deleted_at}.from(nil).to(Time.now.utc)
|
||||
expect { subject }.to change { commentaire.reload.deleted_at }.from(nil).to(Time.zone.now.utc)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,31 +57,31 @@ describe 'shared/dossiers/messages/message.html.haml', type: :view do
|
|||
context 'on a procedure where commentaire had been written by connected instructeur' do
|
||||
let(:commentaire) { create(:commentaire, instructeur: instructeur, body: 'Second message') }
|
||||
|
||||
it { is_expected.to have_selector("form[action=\"#{form_url}\"]")}
|
||||
it { is_expected.to have_selector("form[action=\"#{form_url}\"]") }
|
||||
end
|
||||
|
||||
context 'on a procedure where commentaire had been written by connected instructeur and deleted' do
|
||||
let(:commentaire) { create(:commentaire, instructeur: instructeur, body: 'Second message', deleted_at: 2.days.ago) }
|
||||
|
||||
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]")}
|
||||
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]") }
|
||||
end
|
||||
|
||||
context 'on a procedure where commentaire had been written by connected an user' do
|
||||
let(:commentaire) { create(:commentaire, email: create(:user).email, body: 'Second message') }
|
||||
|
||||
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]")}
|
||||
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]") }
|
||||
end
|
||||
|
||||
context 'on a procedure where commentaire had been written by connected an expert' do
|
||||
let(:commentaire) { create(:commentaire, expert: create(:expert), body: 'Second message') }
|
||||
|
||||
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]")}
|
||||
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]") }
|
||||
end
|
||||
|
||||
context 'on a procedure where commentaire had been written another instructeur' do
|
||||
let(:commentaire) { create(:commentaire, instructeur: create(:instructeur), body: 'Second message') }
|
||||
|
||||
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]")}
|
||||
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]") }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue