First attempt

This commit is contained in:
Guillaume Lazzara 2016-02-02 18:37:38 +01:00
parent cef48fb03c
commit e20de3dba9
16 changed files with 176 additions and 76 deletions

View file

@ -86,7 +86,7 @@ class Admin::ProceduresController < AdminController
private
def create_procedure_params
params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_demarche, :euro_flag, :logo, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id)
params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_demarche, :euro_flag, :logo, :cerfa_flag, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id)
end
def create_module_api_carto_params

View file

@ -23,6 +23,8 @@ class Users::DescriptionController < UsersController
def create
@dossier = current_user_dossier
@procedure = @dossier.procedure
unless @dossier.update_attributes(create_params)
@dossier = @dossier.decorate
@procedure = @dossier.procedure
@ -30,11 +32,13 @@ class Users::DescriptionController < UsersController
flash.now.alert = @dossier.errors.full_messages.join('<br />').html_safe
return render 'show'
end
if @procedure.cerfa_flag?
unless params[:cerfa_pdf].nil?
cerfa = @dossier.cerfa
cerfa.content = params[:cerfa_pdf]
cerfa.save
end
end
unless params[:champs].nil?
@dossier.champs.each do |champ|

View file

@ -25,8 +25,8 @@ class Dossier < ActiveRecord::Base
delegate :types_de_piece_justificative, to: :procedure
delegate :types_de_champ, to: :procedure
before_create :build_default_cerfa
before_save :build_default_cerfa, if: Proc.new { procedure_id_changed? }
after_save :build_default_pieces_justificatives, if: Proc.new { procedure_id_changed? }
after_save :build_default_champs, if: Proc.new { procedure_id_changed? }
@ -188,10 +188,15 @@ class Dossier < ActiveRecord::Base
return composed_scope, dossier
end
def cerfa_available?
procedure.cerfa_flag? && !cerfa.empty?
end
private
def build_default_cerfa
build_cerfa
build_cerfa if procedure.cerfa_flag?
true
end
end

View file

@ -21,12 +21,13 @@
=f.check_box :euro_flag
Afficher le drapeau européen
%br
%h4 Cartographie
.row
.col-md-6.col-lg-6
%h4 Cartographie
= f.fields_for :module_api_carto, @procedure.module_api_carto do |ff|
= f.fields_for :module_api_carto, @procedure.module_api_carto do |ff|
%label
=ff.check_box :use_api_carto, {id: :procedure_module_api_carto_use_api_carto}
Utilisation de la cartographie
@ -40,3 +41,8 @@
%label
= ff.check_box :cadastre
Cadastre
.col-md-6.col-lg-6
%h4 Formulaire / CERFA
%label
=f.check_box :cerfa_flag
Activer l'envoi de formulaire / CERFA

View file

@ -8,7 +8,7 @@
%th{class:'col-lg-6'}
='Formulaire'
%td.col-lg-6.col-md-6
- if !@facade.dossier.cerfa.empty?
- if @facade.dossier.cerfa_available?
- if user_signed_in?
= 'Pièce fournie'
- elsif gestionnaire_signed_in?

View file

@ -49,12 +49,13 @@
%br
//TODO a refactorer
%table{class:'table', style:'width:55%; margin-left:5%'}
- if @procedure.cerfa_flag
%tr
%th{class:'col-lg-6'}
='Formulaire (.pdf / .doc)'
%td{class:'col-lg-5'}
-if !@dossier.cerfa.empty?
-if @dossier.cerfa_available?
%span.btn.btn-sm.btn-file.btn-success
Modifier
%input{type: 'file', name:'cerfa_pdf', id:'cerfa_pdf', accept: ".pdf"}
@ -74,7 +75,7 @@
-else
%span.btn.btn-sm.btn-file.btn-success
Modifier
= file_field_tag "piece_justificative_#{piece_justificative.type}", accept: '.pdf'
= file_f ield_tag "piece_justificative_#{piece_justificative.type}", accept: '.pdf'
%div{style: 'text-align:right'}
%h6 Tous les champs portant un * sont obligatoires.

View file

@ -0,0 +1,5 @@
class AddCerfaFlagToProcedure < ActiveRecord::Migration
def change
add_column :procedures, :cerfa_flag, :boolean, :default => false
end
end

View file

@ -11,8 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160121110603) do
ActiveRecord::Schema.define(version: 20160127162841) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -190,6 +189,7 @@ ActiveRecord::Schema.define(version: 20160121110603) do
t.boolean "archived", default: false
t.boolean "euro_flag", default: false
t.string "logo"
t.boolean "cerfa_flag", default: false
end
create_table "quartier_prioritaires", force: :cascade do |t|

View file

@ -2,7 +2,8 @@ require 'spec_helper'
describe Users::DescriptionController, type: :controller do
let(:user) { create(:user) }
let(:dossier) { create(:dossier, :with_procedure, user: user) }
let(:procedure) { create(:procedure, cerfa_flag: true) }
let(:dossier) { create(:dossier, procedure: procedure, user: user) }
let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 10 }
@ -119,6 +120,7 @@ describe Users::DescriptionController, type: :controller do
end
end
context 'Quand la procédure accepte les CERFA' do
context 'Sauvegarde du CERFA PDF' do
before do
post :create, dossier_id: dossier_id,
@ -151,6 +153,24 @@ describe Users::DescriptionController, type: :controller do
# TODO à écrire
end
end
end
context 'Quand la procédure n\'accepte pas les CERFA' do
context 'Sauvegarde du CERFA PDF' do
let!(:procedure) { create(:procedure) }
before do
post :create, dossier_id: dossier_id,
nom_projet: nom_projet,
description: description,
cerfa_pdf: cerfa_pdf
dossier.reload
end
context 'un CERFA PDF est envoyé' do
it { expect(dossier.cerfa_available?).to be_falsey }
end
end
end
context 'Sauvegarde des champs' do
let(:champs_dossier) { dossier.champs }

View file

@ -4,6 +4,12 @@ FactoryGirl.define do
description "Ma super description"
state 'draft'
association :user, factory:[:user]
unless procedure
before(:create) do |dossier, _evaluator|
procedure = create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ)
dossier.procedure = procedure
end
end
trait :with_entreprise do
after(:build) do |dossier, _evaluator|
@ -15,7 +21,7 @@ FactoryGirl.define do
end
trait :with_procedure do
after(:build) do |dossier, _evaluator|
before(:create) do |dossier, _evaluator|
procedure = create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ)
dossier.procedure = procedure
end

View file

@ -1,7 +1,8 @@
require 'spec_helper'
feature 'user is on description page' do
let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) }
let!(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, cerfa_flag: true) }
let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure) }
before do
visit users_dossier_description_path dossier
@ -42,7 +43,7 @@ feature 'user is on description page' do
context 'when he adds a piece_justificative and submit form' do
before do
file_input_id = 'piece_justificative_' + dossier.pieces_justificatives.first.type.to_s
attach_file(file_input_id, File.path('spec/support/files/dossierPDF.pdf'))
attach_file(file_inp ut_id, File.path('spec/support/files/dossierPDF.pdf'))
click_on('Soumettre mon dossier')
dossier.reload
end

View file

@ -4,7 +4,7 @@ feature 'user access to the list of his dossier' do
let(:user) { create(:user) }
let!(:last_updated_dossier) { create(:dossier, :with_procedure, user: user, state: 'replied')}
let!(:dossier1) { create(:dossier, :with_procedure, user: user, nom_projet: 'mon permier dossier', state: 'replied') }
let!(:dossier1) { create(:dossier, user: user, nom_projet: 'mon permier dossier', state: 'replied') }
let!(:dossier2) { create(:dossier, nom_projet: 'mon deuxième dossier') }
before do

View file

@ -63,13 +63,27 @@ describe Dossier do
end
describe 'creation' do
describe 'Procedure accepts cerfa upload' do
let(:procedure) { create(:procedure, cerfa_flag: true) }
let(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, user: user) }
it 'create default cerfa' do
expect { described_class.create(user: user) }.to change { Cerfa.count }.by(1)
expect { subject.to change(Cerfa.count).by(1) }
expect { subject.cerfa_available.to be_truthy }
end
it 'link cerfa to dossier' do
dossier = described_class.create
expect(dossier.cerfa).to eq(Cerfa.last)
expect { subject.cerfa.to eq(Cerfa.last) }
end
end
describe 'Procedure does not accept cerfa upload' do
let(:procedure) { create(:procedure, cerfa_flag: false) }
let(:dossier) { create(:dossier, :with_entreprise, :with_procedure, user: user) }
it 'default cerfa is not created' do
expect { subject.to change(Cerfa.count).by(0) }
expect { subject.cerfa.to eq(nil) }
expect { subject.cerfa_available.to be_falsey }
end
end
end
@ -104,20 +118,21 @@ describe Dossier do
end
describe '#save' do
subject { create(:dossier, procedure_id: nil, user: user) }
subject { build(:dossier, procedure: procedure, user: user) }
let!(:procedure) { create(:procedure) }
context 'when is linked to a procedure' do
it 'creates default pieces justificatives' do
expect(subject).to receive(:build_default_pieces_justificatives)
subject.update_attributes(procedure_id: procedure.id)
subject.save
end
it 'creates default champs' do
expect(subject).to receive(:build_default_champs)
subject.update_attributes(procedure_id: procedure.id)
subject.save
end
end
context 'when is not linked to a procedure' do
subject { create(:dossier, procedure: procedure, user: user) }
it 'does not create default pieces justificatives' do
expect(subject).not_to receive(:build_default_pieces_justificatives)
subject.update_attributes(description: 'plop')
@ -504,4 +519,26 @@ describe Dossier do
end
end
end
describe '#cerfa_available?' do
let(:procedure) { create(:procedure, cerfa_flag: cerfa_flag) }
let(:dossier) { create(:dossier, procedure: procedure)}
context 'Procedure accepts CERFA' do
let(:cerfa_flag) { true }
context 'when cerfa is not uploaded' do
it { expect(dossier.cerfa_available?).to be_falsey }
end
context 'when cerfa is uploaded' do
let(:dossier_with_cerfa) { create(:dossier, procedure: procedure) }
before do
allow_any_instance_of(Cerfa).to receive(:empty?).and_return(false)
end
it { expect(dossier_with_cerfa.cerfa_available?).to be_truthy }
end
end
context 'Procedure does not accept CERFA' do
let(:cerfa_flag) { false }
it { expect(dossier.cerfa_available?).to be_falsey }
end
end
end

View file

@ -17,6 +17,7 @@ describe Procedure do
it { is_expected.to have_db_column(:test) }
it { is_expected.to have_db_column(:euro_flag) }
it { is_expected.to have_db_column(:logo) }
it { is_expected.to have_db_column(:cerfa_flag) }
end
describe 'validation' do

View file

@ -2,7 +2,9 @@ require 'spec_helper'
describe 'users/description/show.html.haml', type: :view do
let(:user) { create(:user) }
let(:dossier) { create(:dossier, :with_procedure, user: user) }
let(:cerfa_flag) { true }
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, cerfa_flag: cerfa_flag) }
let(:dossier) { create(:dossier, procedure: procedure, user: user) }
let(:dossier_id) { dossier.id }
before do
@ -125,4 +127,15 @@ describe 'users/description/show.html.haml', type: :view do
end
end
end
context 'Envoi des CERFA désactivé' do
let!(:cerfa_flag) { false }
before do
render
end
it { expect(rendered).to_not have_css("#cerfa_flag") }
it { expect(rendered).to_not have_selector('input[type=file][name=cerfa_pdf][id=cerfa_pdf]') }
end
end

View file

@ -3,8 +3,9 @@ require 'spec_helper'
describe 'users/dossiers/new.html.haml', type: :view do
let(:user) { create(:user) }
let(:euro_flag) { false }
let(:cerfa_flag) { false }
let(:logo) { '' }
let(:procedure) { create(:procedure, euro_flag: euro_flag, logo: logo) }
let(:procedure) { create(:procedure, euro_flag: euro_flag, cerfa_flag: cerfa_flag, logo: logo) }
let!(:dossier) { create(:dossier, procedure: procedure, user: user).decorate }
before do