Merge branch 'develop' into staging

This commit is contained in:
Xavier J 2016-03-15 17:20:57 +01:00
commit 72315254b0
18 changed files with 102 additions and 36 deletions

View file

@ -19,7 +19,7 @@ class Admin::TypesDeChampController < AdminController
end
def update_params
params.require(:procedure).permit(types_de_champ_attributes: [:libelle, :description, :order_place, :type_champ, :id])
params.require(:procedure).permit(types_de_champ_attributes: [:libelle, :description, :order_place, :type_champ, :id, :mandatory])
end
def move_up

View file

@ -4,8 +4,7 @@ class Users::DescriptionController < UsersController
end
def show
@dossier = current_user_dossier
@dossier = @dossier.decorate
@dossier = current_user_dossier.decorate
@procedure = @dossier.procedure
@champs = @dossier.ordered_champs
@ -24,10 +23,10 @@ class Users::DescriptionController < UsersController
def create
@dossier = current_user_dossier
@procedure = @dossier.procedure
@champs = @dossier.ordered_champs
unless @dossier.update_attributes(create_params)
@dossier = @dossier.decorate
@procedure = @dossier.procedure
flash.now.alert = @dossier.errors.full_messages.join('<br />').html_safe
return render 'show'
@ -47,6 +46,12 @@ class Users::DescriptionController < UsersController
unless params[:champs].nil?
@dossier.champs.each do |champ|
champ.value = params[:champs]["'#{champ.id}'"]
if champ.mandatory? && (champ.value.nil? || champ.value.blank?)
flash.now.alert = "Le champ #{champ.libelle} doit être rempli."
return render 'show'
end
champ.save
end
end

View file

@ -1,5 +1,10 @@
class Champ < ActiveRecord::Base
belongs_to :dossier
belongs_to :type_de_champ
delegate :libelle, :type_champ, :order_place, to: :type_de_champ
delegate :libelle, :type_champ, :order_place, :mandatory, to: :type_de_champ
def mandatory?
mandatory
end
end

View file

@ -1,5 +1,7 @@
class CerfaSerializer < ActiveModel::Serializer
attributes :content_url => :url
attributes :created_at,
:content_url => :url
end

View file

@ -1,5 +1,6 @@
class PieceJustificativeSerializer < ActiveModel::Serializer
attributes :content_url => :url
attributes :created_at,
:content_url => :url
has_one :type_de_piece_justificative
end

View file

@ -9,6 +9,11 @@
.form-group
%h4 Description
= ff.text_area :description, class: 'form-control description', placeholder: 'Description'
.form-group
%h4 Obligatoire ?
.center
= ff.check_box :mandatory, placeholder: 'Obligatoire ?'
.form-group
= ff.hidden_field :order_place, value: ff.index
= ff.hidden_field :id

View file

@ -26,11 +26,15 @@
-if champ.type_champ == 'checkbox'
%h4{style:'margin-left:15px;'}
= champ.libelle
- if champ.mandatory?
= '*'
%input{type: 'hidden', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", value: ''}
%input{type: 'checkbox', style:'margin-left: 15px;', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", checked: ('checked' if champ.value == 'on')}
-else
%h4
= champ.libelle
- if champ.mandatory?
= '*'
-if champ.type_champ == 'textarea'
%textarea.form-control{name:"champs['#{champ.id}']",
@ -62,7 +66,7 @@
- if @procedure.cerfa_flag
%tr
%th{class:'col-lg-6'}
='Formulaire (.pdf / .doc / .docx / .xls / .xlsx)'
='Formulaire'
%td{class:'col-lg-5'}
-if @dossier.cerfa_available?

View file

@ -0,0 +1,5 @@
class AddCreatedAtToCerfa < ActiveRecord::Migration
def change
add_column :cerfas, :created_at, :datetime
end
end

View file

@ -0,0 +1,5 @@
class AddCreatedAtToPieceJustificative < ActiveRecord::Migration
def change
add_column :pieces_justificatives, :created_at, :datetime
end
end

View file

@ -0,0 +1,5 @@
class AddMandatoryToTypeDeChamps < ActiveRecord::Migration
def change
add_column :types_de_champ, :mandatory, :boolean, default: false
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160314102523) do
ActiveRecord::Schema.define(version: 20160315101245) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -70,6 +70,7 @@ ActiveRecord::Schema.define(version: 20160314102523) do
create_table "cerfas", force: :cascade do |t|
t.string "content"
t.integer "dossier_id"
t.datetime "created_at"
end
add_index "cerfas", ["dossier_id"], name: "index_cerfas_on_dossier_id", using: :btree
@ -198,6 +199,7 @@ ActiveRecord::Schema.define(version: 20160314102523) do
t.string "content"
t.integer "dossier_id"
t.integer "type_de_piece_justificative_id"
t.datetime "created_at"
end
add_index "pieces_justificatives", ["type_de_piece_justificative_id"], name: "index_pieces_justificatives_on_type_de_piece_justificative_id", using: :btree
@ -242,6 +244,7 @@ ActiveRecord::Schema.define(version: 20160314102523) do
t.integer "order_place"
t.integer "procedure_id"
t.text "description"
t.boolean "mandatory", default: false
end
create_table "types_de_piece_justificative", force: :cascade do |t|

View file

@ -37,6 +37,7 @@ describe Admin::TypesDeChampController, type: :controller do
let(:description) { 'titi' }
let(:order_place) { '' }
let(:types_de_champ_id) { '' }
let(:mandatory) { 'on' }
let(:procedure_params) do
{ types_de_champ_attributes:
@ -46,7 +47,8 @@ describe Admin::TypesDeChampController, type: :controller do
type_champ: type_champ,
description: description,
order_place: order_place,
id: types_de_champ_id
id: types_de_champ_id,
mandatory: mandatory
}
}
}
@ -67,7 +69,7 @@ describe Admin::TypesDeChampController, type: :controller do
it { expect(subject.libelle).to eq('mon libelle') }
it { expect(subject.type_champ).to eq('text') }
it { expect(subject.description).to eq('titi') }
# it { expect(subject.order_place).to eq('0') }
it { expect(subject.mandatory).to be_truthy }
end
context 'when type_de_champ already exist' do
@ -78,6 +80,7 @@ describe Admin::TypesDeChampController, type: :controller do
let(:type_champ) { 'text' }
let(:description) { 'citrouille' }
let(:order_place) { '0' }
let(:mandatory) { 'on' }
before do
request
procedure.reload
@ -86,7 +89,8 @@ describe Admin::TypesDeChampController, type: :controller do
it { expect(subject.libelle).to eq('toto') }
it { expect(subject.type_champ).to eq('text') }
it { expect(subject.description).to eq('citrouille') }
# it { expect(subject.order_place).to eq(0) }
it { expect(subject.order_place).to eq(0) }
it { expect(subject.order_place).to be_truthy }
end
end
context 'when procedure is not found' do

View file

@ -172,6 +172,7 @@ describe API::V1::DossiersController do
subject { super().first }
it { expect(subject.keys.include?(:url)).to be_truthy }
it { expect(subject[:created_at]).not_to be_nil }
it { expect(subject.keys.include?(:type_de_piece_justificative)).to be_truthy }
describe 'type de piece justificative' do
@ -242,6 +243,7 @@ describe API::V1::DossiersController do
subject { super()[:cerfa] }
it { expect(subject[:created_at]).not_to be_nil }
it { expect(subject[:url]).to match /^http:\/\/.*downloads.*_CERFA\.pdf$/ }
end

View file

@ -4,7 +4,7 @@ describe Users::DescriptionController, type: :controller do
let(:user) { create(:user) }
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, cerfa_flag: true) }
let!(:dossier) { create(:dossier, procedure: procedure, user: user) }
let(:dossier) { create(:dossier, procedure: procedure, user: user) }
let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 10000 }
@ -178,7 +178,7 @@ describe Users::DescriptionController, type: :controller do
end
end
context 'Sauvegarde des champs' do
describe 'Sauvegarde des champs' do
let(:champs_dossier) { dossier.champs }
let(:dossier_champs_first) { 'test value' }
@ -194,16 +194,25 @@ describe Users::DescriptionController, type: :controller do
end
it { expect(dossier.champs.first.value).to eq(dossier_champs_first) }
it { expect(response).to redirect_to users_dossier_recapitulatif_path }
context 'when champs value is empty' do
let(:dossier_champs_first) { 'test value' }
let(:dossier_champs_first) { '' }
it { expect(dossier.champs.first.value).to eq(dossier_champs_first) }
it { expect(response).to redirect_to users_dossier_recapitulatif_path }
context 'when champs is mandatory' do
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ_mandatory, cerfa_flag: true) }
it { expect(response).not_to redirect_to users_dossier_recapitulatif_path }
it { expect(flash[:alert]).to be_present }
end
end
end
context 'Sauvegarde des pièces justificatives' do
let(:all_pj_type){ dossier.procedure.type_de_piece_justificative_ids }
let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids }
before do
post :create, {dossier_id: dossier_id,
nom_projet: nom_projet,

View file

@ -27,6 +27,14 @@ FactoryGirl.define do
end
end
trait :with_type_de_champ_mandatory do
after(:build) do |procedure, _evaluator|
type_de_champ = create(:type_de_champ, mandatory: true)
procedure.types_de_champ << type_de_champ
end
end
trait :with_two_type_de_piece_justificative do
after(:build) do |procedure, _evaluator|
rib = create(:type_de_piece_justificative, :rib)

View file

@ -4,5 +4,6 @@ FactoryGirl.define do
description 'description de votre projet'
type_champ 'textarea'
order_place 1
mandatory false
end
end

View file

@ -3,6 +3,7 @@ require 'spec_helper'
describe Cerfa do
describe 'database columns' do
it { is_expected.to have_db_column(:content) }
it { is_expected.to have_db_column(:created_at) }
end
describe 'associations' do

View file

@ -3,6 +3,7 @@ require 'spec_helper'
describe PieceJustificative do
describe 'database columns' do
it { is_expected.to have_db_column(:content) }
it { is_expected.to have_db_column(:created_at) }
end
describe 'associations' do