add attachment when instructor asking for a review
This commit is contained in:
parent
cb811df94f
commit
b32ed88f9b
6 changed files with 27 additions and 4 deletions
|
@ -23,6 +23,7 @@ module CreateAvisConcern
|
|||
{
|
||||
email: email,
|
||||
introduction: create_avis_params[:introduction],
|
||||
introduction_file: create_avis_params[:introduction_file],
|
||||
claimant: current_instructeur,
|
||||
dossier: dossier,
|
||||
confidentiel: confidentiel
|
||||
|
@ -43,7 +44,6 @@ module CreateAvisConcern
|
|||
sent_emails_addresses << avis.email_to_display
|
||||
end
|
||||
end
|
||||
|
||||
flash.notice = "Une demande d'avis a été envoyée à #{sent_emails_addresses.uniq.join(", ")}"
|
||||
end
|
||||
|
||||
|
@ -61,6 +61,6 @@ module CreateAvisConcern
|
|||
end
|
||||
|
||||
def create_avis_params
|
||||
params.require(:avis).permit(:introduction, :confidentiel, :invite_linked_dossiers, emails: [])
|
||||
params.require(:avis).permit(:introduction_file, :introduction, :confidentiel, :invite_linked_dossiers, emails: [])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,6 +6,7 @@ class Avis < ApplicationRecord
|
|||
belongs_to :claimant, class_name: 'Instructeur'
|
||||
|
||||
has_one_attached :piece_justificative_file
|
||||
has_one_attached :introduction_file
|
||||
|
||||
validates :email, format: { with: Devise.email_regexp, message: "n'est pas valide" }, allow_nil: true
|
||||
validates :claimant, presence: true
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
%span.date Demande d'avis envoyée le #{l(@avis.created_at, format: '%d/%m/%y')}
|
||||
%p.introduction= @avis.introduction
|
||||
|
||||
- if @avis.introduction_file.attached?
|
||||
= render partial: 'shared/attachment/show', locals: { attachment: @avis.introduction_file.attachment }
|
||||
%br/
|
||||
|
||||
= form_for @avis, url: instructeur_avis_path(@avis), html: { class: 'form' } do |f|
|
||||
= f.text_area :answer, rows: 3, placeholder: 'Votre avis', required: true
|
||||
= render 'shared/attachment/edit',
|
||||
|
|
|
@ -5,6 +5,12 @@
|
|||
= form_for avis, url: url, html: { class: 'form' } do |f|
|
||||
= f.email_field :emails, placeholder: 'Adresses email, séparées par des virgules', required: true, multiple: true, onchange: "javascript:DS.replaceSemicolonByComma(event);"
|
||||
= f.text_area :introduction, rows: 3, value: avis.introduction || 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true
|
||||
%p.tab-title Ajouter une pièce jointe
|
||||
.form-group
|
||||
= render 'shared/attachment/edit',
|
||||
{ form: f,
|
||||
attached_file: avis.introduction_file,
|
||||
user_can_destroy: true }
|
||||
|
||||
- if linked_dossiers.present?
|
||||
= f.check_box :invite_linked_dossiers, {}, true, false
|
||||
|
|
|
@ -126,7 +126,9 @@ describe Instructeurs::AvisController, type: :controller do
|
|||
let(:invite_linked_dossiers) { nil }
|
||||
|
||||
before do
|
||||
post :create_avis, params: { id: previous_avis.id, avis: { emails: emails, introduction: intro, confidentiel: asked_confidentiel, invite_linked_dossiers: invite_linked_dossiers } }
|
||||
@introduction_file = Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf')
|
||||
post :create_avis, params: { id: previous_avis.id, avis: { emails: emails, introduction: intro, confidentiel: asked_confidentiel, invite_linked_dossiers: invite_linked_dossiers, introduction_file: @introduction_file } }
|
||||
created_avis.reload
|
||||
end
|
||||
|
||||
context 'when an invalid email' do
|
||||
|
@ -139,6 +141,16 @@ describe Instructeurs::AvisController, type: :controller do
|
|||
it { expect(Avis.last).to eq(previous_avis) }
|
||||
end
|
||||
|
||||
context 'ask review with attachment' do
|
||||
let(:previous_avis_confidentiel) { false }
|
||||
let(:asked_confidentiel) { false }
|
||||
let(:emails) { ["toto@totomail.com"] }
|
||||
|
||||
it { expect(created_avis.introduction_file).to be_attached }
|
||||
it { expect(created_avis.introduction_file.filename).to eq("piece_justificative_0.pdf") }
|
||||
it { expect(flash.notice).to eq("Une demande d'avis a été envoyée à toto@totomail.com") }
|
||||
end
|
||||
|
||||
context 'with multiple emails' do
|
||||
let(:asked_confidentiel) { false }
|
||||
let(:previous_avis_confidentiel) { false }
|
||||
|
|
|
@ -113,7 +113,7 @@ feature 'Inviting an expert:' do
|
|||
expect(page).to have_text('Cet avis est confidentiel')
|
||||
|
||||
fill_in 'avis_answer', with: 'Ma réponse d’expert : c’est un oui.'
|
||||
find('.attachment input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/RIB.pdf')
|
||||
find('.attachment input[name="avis[piece_justificative_file]"]').attach_file(Rails.root + 'spec/fixtures/files/RIB.pdf')
|
||||
click_on 'Envoyer votre avis'
|
||||
|
||||
expect(page).to have_content('Votre réponse est enregistrée')
|
||||
|
|
Loading…
Reference in a new issue