move validation in model for dossier
This commit is contained in:
parent
bab43c5cd3
commit
e5e2fef8ae
5 changed files with 82 additions and 28 deletions
|
@ -70,29 +70,46 @@ describe DescriptionController, type: :controller do
|
|||
end
|
||||
|
||||
context 'Attribut(s) manquant(s)' do
|
||||
it 'nom_projet manquant' do
|
||||
post :create, dossier_id: dossier_id, nom_projet: '', description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle, mail_contact: mail_contact
|
||||
expect(response).to redirect_to("/dossiers/#{dossier_id}/description/error")
|
||||
subject {
|
||||
post :create,
|
||||
dossier_id: dossier_id,
|
||||
nom_projet: nom_projet,
|
||||
description: description,
|
||||
montant_projet: montant_projet,
|
||||
montant_aide_demande: montant_aide_demande,
|
||||
date_previsionnelle: date_previsionnelle,
|
||||
mail_contact: mail_contact
|
||||
}
|
||||
before { subject }
|
||||
|
||||
context 'nom_projet empty' do
|
||||
let(:nom_projet) { '' }
|
||||
it { is_expected.to render_template(:show) }
|
||||
it { expect(flash[:alert]).to be_present }
|
||||
end
|
||||
|
||||
it 'description manquante' do
|
||||
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: '', montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle, mail_contact: mail_contact
|
||||
expect(response).to redirect_to("/dossiers/#{dossier_id}/description/error")
|
||||
context 'description empty' do
|
||||
let(:description) { '' }
|
||||
it { is_expected.to render_template(:show) }
|
||||
it { expect(flash[:alert]).to be_present }
|
||||
end
|
||||
|
||||
it 'montant_projet manquant' do
|
||||
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: '', montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle, mail_contact: mail_contact
|
||||
expect(response).to redirect_to("/dossiers/#{dossier_id}/description/error")
|
||||
context 'montant_projet empty' do
|
||||
let(:montant_projet) { '' }
|
||||
it { is_expected.to render_template(:show) }
|
||||
it { expect(flash[:alert]).to be_present }
|
||||
end
|
||||
|
||||
it 'montant_aide_demande manquant' do
|
||||
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: '', date_previsionnelle: date_previsionnelle, mail_contact: mail_contact
|
||||
expect(response).to redirect_to("/dossiers/#{dossier_id}/description/error")
|
||||
context 'montant_aide_demande empty' do
|
||||
let(:montant_aide_demande) { '' }
|
||||
it { is_expected.to render_template(:show) }
|
||||
it { expect(flash[:alert]).to be_present }
|
||||
end
|
||||
|
||||
it 'date_previsionnelle manquante' do
|
||||
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: '', mail_contact: mail_contact
|
||||
expect(response).to redirect_to("/dossiers/#{dossier_id}/description/error")
|
||||
context 'date_previsionnelle empty' do
|
||||
let(:date_previsionnelle) { '' }
|
||||
it { is_expected.to render_template(:show) }
|
||||
it { expect(flash[:alert]).to be_present }
|
||||
end
|
||||
|
||||
it 'mail_contact manquant' do
|
||||
|
|
|
@ -32,8 +32,30 @@ describe Dossier do
|
|||
end
|
||||
|
||||
describe 'validation' do
|
||||
it { is_expected.to allow_value('tanguy@plop.com').for(:mail_contact) }
|
||||
it { is_expected.not_to allow_value('tanguyplop.com').for(:mail_contact) }
|
||||
context 'mail_contact' do
|
||||
it { is_expected.to allow_value('tanguy@plop.com').for(:mail_contact) }
|
||||
it { is_expected.not_to allow_value('tanguyplop.com').for(:mail_contact) }
|
||||
end
|
||||
context 'nom_projet' do
|
||||
it { is_expected.to allow_value(nil).for(:nom_projet) }
|
||||
it { is_expected.not_to allow_value('').for(:nom_projet) }
|
||||
it { is_expected.to allow_value('mon super projet').for(:nom_projet) }
|
||||
end
|
||||
context 'description' do
|
||||
it { is_expected.to allow_value(nil).for(:description) }
|
||||
it { is_expected.not_to allow_value('').for(:description) }
|
||||
it { is_expected.to allow_value('ma superbe description').for(:description) }
|
||||
end
|
||||
context 'montant_projet' do
|
||||
it { is_expected.to allow_value(nil).for(:montant_projet) }
|
||||
it { is_expected.not_to allow_value('').for(:montant_projet) }
|
||||
it { is_expected.to allow_value(124324).for(:montant_projet) }
|
||||
end
|
||||
context 'montant_aide_demande' do
|
||||
it { is_expected.to allow_value(nil).for(:montant_aide_demande) }
|
||||
it { is_expected.not_to allow_value('').for(:montant_aide_demande) }
|
||||
it { is_expected.to allow_value(124324).for(:montant_aide_demande) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'methods' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue