Add auto champs objects at a dossier (same as PJ)
Add dynamic of Champs on the description page Rename model 'Champs' to 'Champ'
This commit is contained in:
parent
56eccf55df
commit
27dbd3a878
14 changed files with 103 additions and 81 deletions
|
@ -2,6 +2,7 @@ FactoryGirl.define do
|
|||
factory :dossier do
|
||||
nom_projet "Demande de subvention dans le cadre d'accompagnement d'enfant à l'étranger"
|
||||
state 'draft'
|
||||
|
||||
trait :with_entreprise do
|
||||
after(:build) do |dossier, _evaluator|
|
||||
etablissement = create(:etablissement)
|
||||
|
@ -13,7 +14,7 @@ FactoryGirl.define do
|
|||
|
||||
trait :with_procedure do
|
||||
after(:build) do |dossier, _evaluator|
|
||||
procedure = create(:procedure, :with_two_type_de_piece_justificative)
|
||||
procedure = create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champs)
|
||||
dossier.procedure = procedure
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Champs do
|
||||
describe Champ do
|
||||
describe 'database columns' do
|
||||
it { is_expected.to have_db_column(:value) }
|
||||
end
|
|
@ -28,6 +28,7 @@ describe Dossier do
|
|||
it { is_expected.to delegate_method(:siren).to(:entreprise) }
|
||||
it { is_expected.to delegate_method(:siret).to(:etablissement) }
|
||||
it { is_expected.to delegate_method(:types_de_piece_justificative).to(:procedure) }
|
||||
it { is_expected.to delegate_method(:types_de_champs).to(:procedure) }
|
||||
end
|
||||
|
||||
describe 'validation' do
|
||||
|
@ -91,12 +92,27 @@ describe Dossier do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#build_default_champs' do
|
||||
context 'when dossier is linked to a procedure' do
|
||||
let(:dossier) { create(:dossier, :with_procedure, user: user) }
|
||||
it 'build all champs needed' do
|
||||
expect(dossier.champs.count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#save' do
|
||||
subject { create(:dossier, procedure_id: nil, 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: 1)
|
||||
subject.update_attributes(procedure_id: procedure.id)
|
||||
end
|
||||
|
||||
it 'creates default champs' do
|
||||
expect(subject).to receive(:build_default_champs)
|
||||
subject.update_attributes(procedure_id: procedure.id)
|
||||
end
|
||||
end
|
||||
context 'when is not linked to a procedure' do
|
||||
|
@ -104,6 +120,11 @@ describe Dossier do
|
|||
expect(subject).not_to receive(:build_default_pieces_justificatives)
|
||||
subject.update_attributes(description: 'plop')
|
||||
end
|
||||
|
||||
it 'does not create default champss' do
|
||||
expect(subject).not_to receive(:build_default_champs)
|
||||
subject.update_attributes(description: 'plop')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ describe TypeDeChamps do
|
|||
|
||||
describe 'associations' do
|
||||
it { is_expected.to belong_to(:procedure) }
|
||||
it { is_expected.to have_many(:champs) }
|
||||
it { is_expected.to have_many(:champ) }
|
||||
end
|
||||
|
||||
describe 'validation' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue