add validation presence user for dossier

This commit is contained in:
Tanguy PATTE 2015-09-24 11:17:17 +02:00
parent a91380182d
commit 23d11976a2
19 changed files with 39 additions and 25 deletions

View file

@ -18,7 +18,7 @@ class Users::DossiersController < UsersController
procedure = Procedure.find(params['procedure_id']) procedure = Procedure.find(params['procedure_id'])
@etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params) @etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params)
@entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params) @entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params)
@dossier = Dossier.create @dossier = Dossier.create(user: current_user)
@dossier.draft! @dossier.draft!
@dossier.procedure = procedure @dossier.procedure = procedure

View file

@ -28,7 +28,7 @@ class Dossier < ActiveRecord::Base
validates :montant_projet, presence: true, allow_blank: false, allow_nil: true validates :montant_projet, presence: true, allow_blank: false, allow_nil: true
validates :montant_aide_demande, presence: true, allow_blank: false, allow_nil: true validates :montant_aide_demande, presence: true, allow_blank: false, allow_nil: true
validates :date_previsionnelle, presence: true, allow_blank: false, unless: Proc.new { description.nil? } validates :date_previsionnelle, presence: true, allow_blank: false, unless: Proc.new { description.nil? }
validates :user, presence: true
def retrieve_piece_justificative_by_type(type) def retrieve_piece_justificative_by_type(type)
pieces_justificatives.where(type_de_piece_justificative_id: type).last pieces_justificatives.where(type_de_piece_justificative_id: type).last

View file

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe Backoffice::CommentairesController, type: :controller do describe Backoffice::CommentairesController, type: :controller do
let(:dossier) { create(:dossier) } let(:dossier) { create(:dossier, :with_user) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let(:email_commentaire) { 'test@test.com' } let(:email_commentaire) { 'test@test.com' }
let(:texte_commentaire) { 'Commentaire de test' } let(:texte_commentaire) { 'Commentaire de test' }

View file

@ -1,7 +1,7 @@
require 'rails_helper' require 'rails_helper'
describe Backoffice::DossiersController, type: :controller do describe Backoffice::DossiersController, type: :controller do
let(:dossier) { create(:dossier, :with_entreprise) } let(:dossier) { create(:dossier, :with_entreprise, :with_user) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 10 } let(:bad_dossier_id) { Dossier.count + 10 }
let(:gestionnaire) { create(:gestionnaire) } let(:gestionnaire) { create(:gestionnaire) }

View file

@ -1,7 +1,8 @@
require 'spec_helper' require 'spec_helper'
describe Users::DescriptionController, type: :controller do describe Users::DescriptionController, type: :controller do
let(:dossier) { create(:dossier, :with_procedure) } let(:user) { create(:user) }
let(:dossier) { create(:dossier, :with_procedure, user: user) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 10 } let(:bad_dossier_id) { Dossier.count + 10 }

View file

@ -1,6 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe Users::DossiersController, type: :controller do describe Users::DossiersController, type: :controller do
let(:user) { create(:user) }
describe '.index' do describe '.index' do
subject { get :index } subject { get :index }
context 'when user is not logged in' do context 'when user is not logged in' do
@ -14,7 +15,7 @@ describe Users::DossiersController, type: :controller do
it { is_expected.to have_http_status(:success) } it { is_expected.to have_http_status(:success) }
end end
end end
let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) } let(:dossier) { create(:dossier, :with_entreprise, :with_procedure, user: user) }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let(:siret_not_found) { 999_999_999_999 } let(:siret_not_found) { 999_999_999_999 }
@ -51,10 +52,11 @@ describe Users::DossiersController, type: :controller do
end end
describe 'professionnel fills form' do describe 'professionnel fills form' do
let(:user) { create(:user) }
context 'when pro_dossier_id is empty' do context 'when pro_dossier_id is empty' do
context 'with valid siret ' do context 'with valid siret ' do
before do before do
sign_in create(:user) sign_in user
end end
subject { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last } subject { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last }
@ -69,9 +71,15 @@ describe Users::DossiersController, type: :controller do
end end
it 'links entreprise to dossier' do it 'links entreprise to dossier' do
subject
expect(Entreprise.last.dossier).to eq(Dossier.last) expect(Entreprise.last.dossier).to eq(Dossier.last)
end end
it "links dossier to user" do
subject
expect(Dossier.last.user).to eq(user)
end
it 'creates etablissement for dossier' do it 'creates etablissement for dossier' do
expect { subject }.to change { Etablissement.count }.by(1) expect { subject }.to change { Etablissement.count }.by(1)
end end

View file

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe DossierDecorator do describe DossierDecorator do
let(:dossier) { create(:dossier) } let(:dossier) { create(:dossier, :with_user) }
subject { dossier.decorate } subject { dossier.decorate }
describe 'last_update' do describe 'last_update' do
subject { Timecop.freeze(Time.new(2015, 12, 24, 14, 10)) { super().last_update } } subject { Timecop.freeze(Time.new(2015, 12, 24, 14, 10)) { super().last_update } }

View file

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
feature 'add commentaire on backoffice' do feature 'add commentaire on backoffice' do
let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) } let(:dossier) { create(:dossier, :with_entreprise, :with_procedure, :with_user) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let!(:commentaire) { create(:commentaire, dossier: dossier, email: 'toto@toto.com') } let!(:commentaire) { create(:commentaire, dossier: dossier, email: 'toto@toto.com') }
let(:email_commentaire) { 'test@test.com' } let(:email_commentaire) { 'test@test.com' }

View file

@ -2,7 +2,7 @@ require 'spec_helper'
feature 'when gestionnaire come to /backoffice and is not authenticated' do feature 'when gestionnaire come to /backoffice and is not authenticated' do
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let!(:dossier) { create(:dossier, procedure: procedure) } let!(:dossier) { create(:dossier, :with_user, procedure: procedure) }
before do before do
visit backoffice_path visit backoffice_path
end end

View file

@ -1,7 +1,8 @@
require 'spec_helper' require 'spec_helper'
feature 'Admin/Dossier#Show Page' do feature 'Admin/Dossier#Show Page' do
let!(:dossier) { create(:dossier, :with_entreprise, :with_procedure) } let(:user) { create(:user) }
let!(:dossier) { create(:dossier, :with_entreprise, :with_procedure, user: user) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
before do before do

View file

@ -2,7 +2,7 @@ require 'spec_helper'
feature 'on backoffice page' do feature 'on backoffice page' do
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure) } let!(:dossier) { create(:dossier, :with_user, :with_entreprise, procedure: procedure) }
before do before do
visit backoffice_path visit backoffice_path
end end

View file

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
feature 'On the description page' do feature 'On the description page' do
let!(:dossier) { create(:dossier, :with_entreprise, :with_procedure) } let!(:dossier) { create(:dossier, :with_entreprise, :with_procedure, :with_user) }
before do before do
visit users_dossier_description_path dossier visit users_dossier_description_path dossier
end end

View file

@ -1,7 +1,8 @@
require 'spec_helper' require 'spec_helper'
feature 'Description#Show Page' do feature 'Description#Show Page' do
let(:dossier) { create(:dossier, :with_procedure) } let(:user) { create(:user) }
let(:dossier) { create(:dossier, :with_procedure, user: user) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
before do before do
@ -89,7 +90,8 @@ feature 'Description#Show Page' do
description: 'Description de test', description: 'Description de test',
montant_projet: 12_000, montant_projet: 12_000,
montant_aide_demande: 3000, montant_aide_demande: 3000,
date_previsionnelle: '20/01/2016') date_previsionnelle: '20/01/2016',
user: user)
end end
scenario 'Nom du projet' do scenario 'Nom du projet' do

View file

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
feature 'user is on description page' do feature 'user is on description page' do
let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) } let(:dossier) { create(:dossier, :with_entreprise, :with_procedure, :with_user) }
before do before do
visit users_dossier_description_path dossier visit users_dossier_description_path dossier
end end

View file

@ -3,7 +3,7 @@ require 'spec_helper'
feature 'user access to the list of his dossier' do feature 'user access to the list of his dossier' do
let(:user) { create(:user) } let(:user) { create(:user) }
let!(:dossier1) { create(:dossier) } let!(:dossier1) { create(:dossier, :with_user) }
before do before do
visit root_path visit root_path
page.find_by_id('user_email').set user.email page.find_by_id('user_email').set user.email

View file

@ -1,6 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe Dossier do describe Dossier do
let(:user) { create(:user) }
describe 'database columns' do describe 'database columns' do
it { is_expected.to have_db_column(:description) } it { is_expected.to have_db_column(:description) }
it { is_expected.to have_db_column(:autorisation_donnees) } it { is_expected.to have_db_column(:autorisation_donnees) }
@ -54,7 +55,7 @@ describe Dossier do
end end
describe 'methods' do describe 'methods' do
let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) } let(:dossier) { create(:dossier, :with_entreprise, :with_procedure, user: user) }
let(:entreprise) { dossier.entreprise } let(:entreprise) { dossier.entreprise }
let(:etablissement) { dossier.etablissement } let(:etablissement) { dossier.etablissement }
@ -71,7 +72,7 @@ describe Dossier do
describe 'creation' do describe 'creation' do
it 'create default cerfa' do it 'create default cerfa' do
expect { described_class.create }.to change { Cerfa.count }.by(1) expect { described_class.create(user: user) }.to change { Cerfa.count }.by(1)
end end
it 'link cerfa to dossier' do it 'link cerfa to dossier' do
@ -94,7 +95,7 @@ describe Dossier do
describe '#build_default_pieces_justificatives' do describe '#build_default_pieces_justificatives' do
context 'when dossier is linked to a procedure' do context 'when dossier is linked to a procedure' do
let(:dossier) { create(:dossier, :with_procedure) } let(:dossier) { create(:dossier, :with_procedure, user: user) }
it 'build all pieces justificatives needed' do it 'build all pieces justificatives needed' do
expect(dossier.pieces_justificatives.count).to eq(2) expect(dossier.pieces_justificatives.count).to eq(2)
end end
@ -102,7 +103,7 @@ describe Dossier do
end end
describe '#save' do describe '#save' do
subject { create(:dossier, procedure_id: nil) } subject { create(:dossier, procedure_id: nil, user: user) }
context 'when is linked to a procedure' do context 'when is linked to a procedure' do
it 'creates default pieces justificatives' do it 'creates default pieces justificatives' do
expect(subject).to receive(:build_default_pieces_justificatives) expect(subject).to receive(:build_default_pieces_justificatives)

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe 'backoffice/index.html.haml', type: :view do describe 'backoffice/index.html.haml', type: :view do
let!(:procedure) { create(:procedure) } let!(:procedure) { create(:procedure) }
let!(:decorated_dossier) { create(:dossier, procedure: procedure).decorate } let!(:decorated_dossier) { create(:dossier, :with_user, procedure: procedure).decorate }
before do before do
assign(:dossiers, [decorated_dossier]) assign(:dossiers, [decorated_dossier])
render render

View file

@ -1,7 +1,8 @@
require 'spec_helper' require 'spec_helper'
describe 'dossiers/show.html.haml', type: :view do describe 'dossiers/show.html.haml', type: :view do
let(:dossier) { create(:dossier, :with_entreprise) } let(:user) { create(:user) }
let(:dossier) { create(:dossier, :with_entreprise, user: user) }
before do before do
assign(:dossier, dossier) assign(:dossier, dossier)

View file

@ -3,8 +3,8 @@ require 'spec_helper'
describe 'users/dossiers/index.html.haml', type: :view do describe 'users/dossiers/index.html.haml', type: :view do
describe 'list dossiers' do describe 'list dossiers' do
let(:dossier1) { create(:dossier).decorate } let(:dossier1) { create(:dossier, :with_user).decorate }
let(:dossier2) { create(:dossier).decorate } let(:dossier2) { create(:dossier, :with_user).decorate }
before do before do
assign(:dossiers, [dossier1, dossier2]) assign(:dossiers, [dossier1, dossier2])
render render