dossier: remove CommentairesController

This commit is contained in:
Pierre de La Morinerie 2018-09-27 16:19:02 +02:00
parent 0e359653db
commit 3392df0029
9 changed files with 0 additions and 8018 deletions

View file

@ -1,29 +0,0 @@
class CommentairesController < ApplicationController
def create
@commentaire = Commentaire.new
if params[:champ_id]
@commentaire.champ = @commentaire.dossier.champs.find(params[:champ_id])
end
dossier_id = params['dossier_id']
@commentaire.email = current_user.email
@commentaire.dossier = current_user.dossiers.find_by(id: dossier_id) || current_user.invites.find_by!(dossier_id: dossier_id).dossier
@commentaire.file = params["file"]
@commentaire.body = params['texte_commentaire']
if @commentaire.save
flash.notice = "Votre message a été envoyé"
else
flash.alert = "Veuillez rédiger un message ou ajouter une pièce jointe (maximum 20 Mo)"
end
if current_user.email != @commentaire.dossier.user.email
invite = Invite.where(dossier: @commentaire.dossier, email: current_user.email).first
redirect_to url_for(controller: 'users/dossiers/invites', action: :show, id: invite.id)
else
redirect_to users_dossier_recapitulatif_path(params['dossier_id'])
end
end
end

View file

@ -1,3 +0,0 @@
class Users::CommentairesController < CommentairesController
before_action :authenticate_user!
end

View file

@ -1,3 +0,0 @@
class Users::Dossiers::CommentairesController < CommentairesController
before_action :authenticate_user!
end

View file

@ -1,7 +0,0 @@
class CommentaireDecorator < Draper::Decorator
delegate_all
def created_at_fr
created_at.localtime.strftime('%d/%m/%Y - %H:%M')
end
end

View file

@ -134,8 +134,6 @@ Rails.application.routes.draw do
namespace :users do
namespace :dossiers do
resources :invites, only: [:index, :show]
post '/commentaire' => 'commentaires#create'
end
resources :dossiers do
@ -146,7 +144,6 @@ Rails.application.routes.draw do
# TODO: once these pages will be migrated to the new user design, replace these routes by a redirection
get '/recapitulatif' => 'recapitulatif#show'
post '/recapitulatif/initiate' => 'recapitulatif#initiate'
post '/commentaire' => 'commentaires#create'
get '/carte/position' => 'carte#get_position'
post '/carte/qp' => 'carte#get_qp'

View file

@ -1,81 +0,0 @@
require 'spec_helper'
describe Users::CommentairesController, type: :controller do
let(:dossier) { create(:dossier) }
let(:dossier_id) { dossier.id }
let(:email_commentaire) { 'test@test.com' }
let(:texte_commentaire) { 'Commentaire de test' }
before do
allow(ClamavService).to receive(:safe_file?).and_return(true)
end
describe '#POST create' do
context "when user has no access to dossier" do
before do
sign_in create(:user)
end
subject { post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire } }
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
it { expect { subject rescue nil }.to change(Commentaire, :count).by(0) }
end
context "when user is invited on dossier" do
let(:user) { create(:user) }
subject { post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire } }
before do
sign_in user
InviteUser.create(dossier: dossier, user: user, email: user.email, email_sender: "test@test.com")
end
it { expect{ subject }.to change(Commentaire, :count).by(1) }
end
context 'création correct d\'un commentaire' do
subject do
sign_in dossier.user
post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire }
end
it 'depuis la page récapitulatif' do
subject
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
end
it 'Notification email is not send' do
expect(NotificationMailer).not_to receive(:new_answer)
subject
end
end
context 'when document is upload whith a commentaire', vcr: { cassette_name: 'controllers_sers_commentaires_controller_upload_doc' } do
let(:document_upload) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
subject do
sign_in dossier.user
post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire, file: document_upload }
end
it 'clamav check the pj' do
expect(ClamavService).to receive(:safe_file?)
subject
end
describe 'commentaire created' do
let(:commentaire) { Commentaire.last }
before do
subject
end
it 'have a piece justificative reference' do
expect(commentaire.file.present?).to be true
expect(commentaire.file.class).to eq CommentaireFileUploader
end
end
end
end
end

View file

@ -1,44 +0,0 @@
require 'spec_helper'
describe Users::Dossiers::CommentairesController, type: :controller do
let(:dossier) { create(:dossier) }
let(:texte_commentaire) { 'Commentaire de test' }
describe '#POST create' do
subject {
post :create, params: { dossier_id: dossier.id, texte_commentaire: texte_commentaire }
dossier.reload
}
context 'when invite is connected' do
let!(:invite) { create(:invite, :with_user, dossier: dossier) }
before do
sign_in invite.user
end
it do
subject
is_expected.to redirect_to users_dossiers_invite_path(invite.id)
end
it 'should notify user' do
expect(NotificationMailer).to receive(:new_answer).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_later)
subject
end
end
context 'when user is connected' do
before do
sign_in dossier.user
end
it 'do not send a mail to notify user' do
expect(NotificationMailer).to_not receive(:new_answer)
subject
end
end
end
end

View file

@ -1,15 +0,0 @@
require 'spec_helper'
describe CommentaireDecorator do
let(:time) { Time.utc(2008, 9, 1, 10, 5, 0) }
let(:commentaire) { Timecop.freeze(time) { create :commentaire } }
let(:decorator) { commentaire.decorate }
describe 'created_at_fr' do
subject { decorator.created_at_fr }
context 'when created_at have a value' do
it { is_expected.to eq time.localtime.strftime('%d/%m/%Y - %H:%M') }
end
end
end