diff --git a/app/controllers/dossiers_controller.rb b/app/controllers/dossiers_controller.rb index b4a885bea..af8b3245a 100644 --- a/app/controllers/dossiers_controller.rb +++ b/app/controllers/dossiers_controller.rb @@ -14,7 +14,8 @@ class DossiersController < ApplicationController @entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params) @dossier = Dossier.create - @dossier.procedure_id + @dossier.procedure = Procedure.find(params['procedure_id']) + @dossier.save @entreprise.dossier = @dossier @entreprise.save diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 8587ece27..a8aa195cb 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -2,4 +2,8 @@ class Procedure < ActiveRecord::Base has_many :types_de_piece_justificative has_many :dossiers belongs_to :evenement_vie + + validates :libelle, presence: true, allow_blank: false, allow_nil: false + validates :description, presence: true, allow_blank: false, allow_nil: false + validates :lien_demarche, presence: true, allow_blank: false, allow_nil: false end diff --git a/db/schema.rb b/db/schema.rb index e4519d4bd..8bff94a8e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -110,7 +110,7 @@ ActiveRecord::Schema.define(version: 20150922085811) do t.integer "type_de_piece_justificative_id" end - add_index "pieces_justificatives", ["type_de_piece_justificative_id"], name: "index_pieces_justificatives_on_type_de_piece_justificative_id", using: :btree + add_index "pieces_justificatives", ["type_de_piece_justificative_id"], name: "index_pieces_justificatives_on_type_piece_jointe_id", using: :btree create_table "procedures", force: :cascade do |t| t.string "libelle" diff --git a/spec/controllers/dossiers_controller_spec.rb b/spec/controllers/dossiers_controller_spec.rb index d8bb095cf..78f650b53 100644 --- a/spec/controllers/dossiers_controller_spec.rb +++ b/spec/controllers/dossiers_controller_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' RSpec.describe DossiersController, type: :controller do - let(:dossier) { create(:dossier, :with_entreprise) } + let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) } let(:dossier_id) { dossier.id } let(:siret_not_found) { 999_999_999_999 } @@ -37,7 +37,7 @@ RSpec.describe DossiersController, type: :controller do context 'when pro_dossier_id is empty' do context 'with valid siret ' do before do - post :create, siret: siret, pro_dossier_id: '' + post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last end it 'create a dossier' do @@ -45,7 +45,7 @@ RSpec.describe DossiersController, type: :controller do end it 'creates entreprise' do - expect { post :create, siret: siret, pro_dossier_id: '' }.to change { Entreprise.count }.by(1) + expect { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last }.to change { Entreprise.count }.by(1) end it 'links entreprise to dossier' do @@ -53,7 +53,7 @@ RSpec.describe DossiersController, type: :controller do end it 'creates etablissement for dossier' do - expect { post :create, siret: siret, pro_dossier_id: '' }.to change { Etablissement.count }.by(1) + expect { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last }.to change { Etablissement.count }.by(1) end it 'links etablissement to dossier' do @@ -63,6 +63,10 @@ RSpec.describe DossiersController, type: :controller do it 'links etablissement to entreprise' do expect(Etablissement.last.entreprise).to eq(Entreprise.last) end + + it 'links procedure to dossier' do + expect(Dossier.last.procedure).to eq(Procedure.last) + end end context 'with non existant siret' do @@ -77,30 +81,6 @@ RSpec.describe DossiersController, type: :controller do end end end - # context 'when pro_dossier_id is not empty' do - # let!(:dossier) { create(:dossier, :with_entreprise) } - # subject { post :create, siret: dossier.siret, pro_dossier_id: 99_999_999_999 } - # - # context 'when dossier not found' do - # it 'redirects to start with error_dossier' do - # expect(subject).to redirect_to(controller: :start, action: :error_dossier) - # end - # end - # context 'when dossier found' do - # context 'when siret match' do - # subject { post :create, siret: dossier.siret, pro_dossier_id: dossier.id } - # it 'redirects to controller recapitulatif' do - # expect(subject).to redirect_to(controller: :recapitulatif, action: :show, dossier_id: dossier.id) - # end - # end - # context 'when siret does not match' do - # subject { post :create, siret: '11111111111111', pro_dossier_id: dossier.id } - # it 'redirects to start with action error_dossier' do - # expect(subject).to redirect_to(controller: :start, action: :error_dossier) - # end - # end - # end - # end end end diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index a22438bda..9ce01635f 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -1,5 +1,7 @@ FactoryGirl.define do factory :procedure do + libelle 'Demande de subvention' + description 'Description demande de subvention' lien_demarche 'http://localhost' libelle 'Demande de subvention' description "Demande de subvention à l'intention des associations" diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 74b6491ed..5f05ec267 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -13,4 +13,24 @@ describe Procedure do it { is_expected.to have_db_column(:direction) } it { is_expected.to have_db_column(:test) } end + + describe 'validation' do + context 'libelle' do + it { is_expected.not_to allow_value(nil).for(:libelle) } + it { is_expected.not_to allow_value('').for(:libelle) } + it { is_expected.to allow_value('Demande de subvention').for(:libelle) } + end + + context 'description' do + it { is_expected.not_to allow_value(nil).for(:description) } + it { is_expected.not_to allow_value('').for(:description) } + it { is_expected.to allow_value('Description Demande de subvention').for(:description) } + end + + context 'lien_demarche' do + it { is_expected.not_to allow_value(nil).for(:lien_demarche) } + it { is_expected.not_to allow_value('').for(:lien_demarche) } + it { is_expected.to allow_value('http://localhost').for(:lien_demarche) } + end + end end