create piece jointe when formulaire is linked to dossier
This commit is contained in:
parent
327412fba3
commit
cee8136ecf
9 changed files with 21 additions and 18 deletions
|
@ -11,7 +11,6 @@ class DemandesController < ApplicationController
|
|||
fail "La modification du formulaire n'est pas possible"
|
||||
end
|
||||
dossier.update_attributes(formulaire_id: params[:formulaire])
|
||||
dossier.build_default_pieces_jointes
|
||||
redirect_to url_for(controller: :carte, action: :show, dossier_id: params[:dossier_id])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,6 +12,8 @@ class Dossier < ActiveRecord::Base
|
|||
|
||||
before_create :build_default_cerfa
|
||||
|
||||
after_save :build_default_pieces_jointes, if: Proc.new { formulaire_id_changed? }
|
||||
|
||||
validates :mail_contact, format: { with: /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/ }, unless: 'mail_contact.nil?'
|
||||
|
||||
def retrieve_piece_jointe_by_type(type)
|
||||
|
|
|
@ -112,7 +112,6 @@ describe DescriptionController, type: :controller do
|
|||
|
||||
context 'Sauvegarde du CERFA PDF' do
|
||||
before do
|
||||
dossier.build_default_pieces_jointes
|
||||
post :create, dossier_id: dossier_id,
|
||||
nom_projet: nom_projet,
|
||||
description: description,
|
||||
|
@ -150,7 +149,6 @@ describe DescriptionController, type: :controller do
|
|||
|
||||
context 'Sauvegarde des pièces jointes' do
|
||||
before do
|
||||
dossier.build_default_pieces_jointes
|
||||
post :create, dossier_id: dossier_id,
|
||||
nom_projet: nom_projet,
|
||||
description: description,
|
||||
|
|
|
@ -10,11 +10,5 @@ FactoryGirl.define do
|
|||
dossier.etablissement = etablissement
|
||||
end
|
||||
end
|
||||
|
||||
trait :with_pieces_jointes do
|
||||
after(:build) do |dossier, _evaluator|
|
||||
dossier.build_default_pieces_jointes
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,6 @@ feature '_Commentaires_Flux Admin/Dossier#Show Page' do
|
|||
let(:body) { 'Commentaire de test' }
|
||||
|
||||
before do
|
||||
dossier.build_default_pieces_jointes
|
||||
login_admin
|
||||
visit "/admin/dossiers/#{dossier_id}"
|
||||
end
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'Admin/Dossier#Show Page' do
|
||||
let(:dossier) { create(:dossier, :with_entreprise) }
|
||||
let!(:dossier) { create(:dossier, :with_entreprise) }
|
||||
let(:dossier_id) { dossier.id }
|
||||
|
||||
before do
|
||||
dossier.build_default_pieces_jointes
|
||||
login_admin
|
||||
visit "/admin/dossiers/#{dossier_id}"
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'On the description page' do
|
||||
let!(:dossier) { create(:dossier, :with_entreprise, :with_pieces_jointes) }
|
||||
let!(:dossier) { create(:dossier, :with_entreprise) }
|
||||
before do
|
||||
visit dossier_description_path dossier
|
||||
end
|
||||
|
|
|
@ -5,7 +5,6 @@ feature 'Description#Show Page' do
|
|||
let(:dossier_id) { dossier.id }
|
||||
|
||||
before do
|
||||
dossier.build_default_pieces_jointes
|
||||
visit "/dossiers/#{dossier_id}/description"
|
||||
end
|
||||
|
||||
|
|
|
@ -76,15 +76,28 @@ describe Dossier do
|
|||
end
|
||||
|
||||
describe '#build_default_pieces_jointes' do
|
||||
context 'when dossier is linked to a formualire' do
|
||||
context 'when dossier is linked to a formulaire' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
before do
|
||||
dossier.build_default_pieces_jointes
|
||||
end
|
||||
it 'build all pieces jointes needed' do
|
||||
expect(dossier.pieces_jointes.count).to eq(7)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#save' do
|
||||
subject { create(:dossier, formulaire_id: nil) }
|
||||
context 'when is linked to a formulaire' do
|
||||
it 'creates default pieces jointes' do
|
||||
expect(subject).to receive(:build_default_pieces_jointes)
|
||||
subject.update_attributes(formulaire_id: 1)
|
||||
end
|
||||
end
|
||||
context 'when is not linked to a formulaire' do
|
||||
it 'does not create default pieces jointes' do
|
||||
expect(subject).not_to receive(:build_default_pieces_jointes)
|
||||
subject.update_attributes(description: 'plop')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue