refactor demandes controller
This commit is contained in:
parent
c38a9f4498
commit
ef69fa453c
6 changed files with 27 additions and 15 deletions
|
@ -1,13 +1,14 @@
|
||||||
class DemandesController < ApplicationController
|
class DemandesController < ApplicationController
|
||||||
def show
|
def show
|
||||||
@dossier = Dossier.find(params[:dossier_id])
|
@dossier = Dossier.find(params[:dossier_id])
|
||||||
@evenement_vie = EvenementVie.for_admi_facile
|
@evenements_vie = EvenementVie.for_admi_facile
|
||||||
end
|
end
|
||||||
|
|
||||||
def choice
|
def update
|
||||||
@dossier = Dossier.find(params[:dossier_id])
|
@dossier = Dossier.find(params[:dossier_id])
|
||||||
@dossier.update_attributes(formulaire_id: params[:formulaire])
|
@dossier.update_attributes(formulaire_id: params[:formulaire])
|
||||||
|
|
||||||
redirect_to url_for( { controller: :carte, action: :show, :dossier_id => params[:dossier_id] } )
|
redirect_to url_for(controller: :carte, action: :show, dossier_id: params[:dossier_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,4 +2,8 @@ class Formulaire < ActiveRecord::Base
|
||||||
has_many :types_piece_jointe
|
has_many :types_piece_jointe
|
||||||
has_many :dossiers
|
has_many :dossiers
|
||||||
belongs_to :evenement_vie
|
belongs_to :evenement_vie
|
||||||
|
|
||||||
|
def self.for_admi_facile
|
||||||
|
where(use_admi_facile: true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,15 +2,14 @@
|
||||||
='Type de demande'
|
='Type de demande'
|
||||||
|
|
||||||
%br
|
%br
|
||||||
= form_tag(url_for({controller: :demandes, action: :choice}), class: 'form-inline', method: 'POST') do
|
= form_tag(url_for({controller: :demandes, action: :update}), class: 'form-inline', method: 'POST') do
|
||||||
|
%div.center
|
||||||
%div{style:'text-align:center'}
|
|
||||||
%select{name:'formulaire', id: 'formulaire', class:'form-control'}
|
%select{name:'formulaire', id: 'formulaire', class:'form-control'}
|
||||||
-@evenement_vie.each do |ev|
|
- @evenements_vie.each do |evenement_vie|
|
||||||
%optgroup{:label => ev.nom}
|
%optgroup{label: evenement_vie.nom}
|
||||||
- Formulaire.where(evenement_vie: ev.id, use_admi_facile: true).each do |form|
|
- evenement_vie.formulaires.for_admi_facile.each do |formulaire|
|
||||||
%option{value: form.id}
|
%option{value: formulaire.id}
|
||||||
|
|
||||||
=form.nom
|
=formulaire.nom
|
||||||
%br
|
%br
|
||||||
=render partial: 'layouts/etape_suivante'
|
=render partial: 'layouts/etape_suivante'
|
|
@ -26,7 +26,8 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
resources :dossiers do
|
resources :dossiers do
|
||||||
get '/demande' => 'demandes#show'
|
get '/demande' => 'demandes#show'
|
||||||
post '/demande' => 'demandes#choice'
|
post '/demande' => 'demandes#update'
|
||||||
|
|
||||||
|
|
||||||
get '/carte/position' => 'carte#get_position'
|
get '/carte/position' => 'carte#get_position'
|
||||||
get '/carte' => 'carte#show'
|
get '/carte' => 'carte#show'
|
||||||
|
|
|
@ -14,8 +14,8 @@ RSpec.describe DemandesController, type: :controller do
|
||||||
describe 'POST #choice' do
|
describe 'POST #choice' do
|
||||||
context 'dans tous les cas on affiche la carte' do
|
context 'dans tous les cas on affiche la carte' do
|
||||||
it {
|
it {
|
||||||
post :choice, :dossier_id => dossier_id, :type_demande => '1'
|
post :update, :dossier_id => dossier_id, :type_demande => '1'
|
||||||
expect(response).to redirect_to("/dossiers/#{dossier_id}/carte")
|
expect(response).to redirect_to(controller: :carte, action: :show, dossier_id: dossier_id)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,4 +23,11 @@ describe Formulaire do
|
||||||
it { is_expected.to have_db_column(:mail_pj) }
|
it { is_expected.to have_db_column(:mail_pj) }
|
||||||
it { is_expected.to have_db_column(:use_admi_facile) }
|
it { is_expected.to have_db_column(:use_admi_facile) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.for_admi_facile' do
|
||||||
|
it 'retruns Formulaire where use_admi_facile is true' do
|
||||||
|
expect(Formulaire.for_admi_facile.size).to eq(Formulaire.where(use_admi_facile: true).count)
|
||||||
|
expect(Formulaire.for_admi_facile).to include(Formulaire.where(use_admi_facile: true).first)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
Reference in a new issue