refactor demandes controller

This commit is contained in:
Tanguy PATTE 2015-08-17 17:08:13 +02:00
parent c38a9f4498
commit ef69fa453c
6 changed files with 27 additions and 15 deletions

View file

@ -1,13 +1,14 @@
class DemandesController < ApplicationController
def show
@dossier = Dossier.find(params[:dossier_id])
@evenement_vie = EvenementVie.for_admi_facile
@evenements_vie = EvenementVie.for_admi_facile
end
def choice
def update
@dossier = Dossier.find(params[:dossier_id])
@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

View file

@ -2,4 +2,8 @@ class Formulaire < ActiveRecord::Base
has_many :types_piece_jointe
has_many :dossiers
belongs_to :evenement_vie
def self.for_admi_facile
where(use_admi_facile: true)
end
end

View file

@ -2,15 +2,14 @@
='Type de demande'
%br
= form_tag(url_for({controller: :demandes, action: :choice}), class: 'form-inline', method: 'POST') do
%div{style:'text-align:center'}
= form_tag(url_for({controller: :demandes, action: :update}), class: 'form-inline', method: 'POST') do
%div.center
%select{name:'formulaire', id: 'formulaire', class:'form-control'}
-@evenement_vie.each do |ev|
%optgroup{:label => ev.nom}
- Formulaire.where(evenement_vie: ev.id, use_admi_facile: true).each do |form|
%option{value: form.id}
- @evenements_vie.each do |evenement_vie|
%optgroup{label: evenement_vie.nom}
- evenement_vie.formulaires.for_admi_facile.each do |formulaire|
%option{value: formulaire.id}
&nbsp;&nbsp;
=form.nom
=formulaire.nom
%br
=render partial: 'layouts/etape_suivante'

View file

@ -26,7 +26,8 @@ Rails.application.routes.draw do
resources :dossiers do
get '/demande' => 'demandes#show'
post '/demande' => 'demandes#choice'
post '/demande' => 'demandes#update'
get '/carte/position' => 'carte#get_position'
get '/carte' => 'carte#show'

View file

@ -14,8 +14,8 @@ RSpec.describe DemandesController, type: :controller do
describe 'POST #choice' do
context 'dans tous les cas on affiche la carte' do
it {
post :choice, :dossier_id => dossier_id, :type_demande => '1'
expect(response).to redirect_to("/dossiers/#{dossier_id}/carte")
post :update, :dossier_id => dossier_id, :type_demande => '1'
expect(response).to redirect_to(controller: :carte, action: :show, dossier_id: dossier_id)
}
end
end

View file

@ -23,4 +23,11 @@ describe Formulaire do
it { is_expected.to have_db_column(:mail_pj) }
it { is_expected.to have_db_column(:use_admi_facile) }
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