ajout de la procédure à la création d'un dossier

This commit is contained in:
Xavier J 2015-09-22 11:24:03 +02:00
parent 632c19bc48
commit 94cfa8a139
3 changed files with 27 additions and 44 deletions

View file

@ -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

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150922082416) do
ActiveRecord::Schema.define(version: 20150922085811) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -47,6 +47,8 @@ ActiveRecord::Schema.define(version: 20150922082416) do
t.boolean "dossier_termine"
t.integer "procedure_id"
t.date "date_previsionnelle"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree
@ -108,7 +110,7 @@ ActiveRecord::Schema.define(version: 20150922082416) 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"

View file

@ -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