Merge branch 'develop' into staging
This commit is contained in:
commit
72315254b0
18 changed files with 102 additions and 36 deletions
|
@ -19,7 +19,7 @@ class Admin::TypesDeChampController < AdminController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_params
|
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
|
end
|
||||||
|
|
||||||
def move_up
|
def move_up
|
||||||
|
|
|
@ -4,8 +4,7 @@ class Users::DescriptionController < UsersController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@dossier = current_user_dossier
|
@dossier = current_user_dossier.decorate
|
||||||
@dossier = @dossier.decorate
|
|
||||||
|
|
||||||
@procedure = @dossier.procedure
|
@procedure = @dossier.procedure
|
||||||
@champs = @dossier.ordered_champs
|
@champs = @dossier.ordered_champs
|
||||||
|
@ -24,10 +23,10 @@ class Users::DescriptionController < UsersController
|
||||||
def create
|
def create
|
||||||
@dossier = current_user_dossier
|
@dossier = current_user_dossier
|
||||||
@procedure = @dossier.procedure
|
@procedure = @dossier.procedure
|
||||||
|
@champs = @dossier.ordered_champs
|
||||||
|
|
||||||
unless @dossier.update_attributes(create_params)
|
unless @dossier.update_attributes(create_params)
|
||||||
@dossier = @dossier.decorate
|
@dossier = @dossier.decorate
|
||||||
@procedure = @dossier.procedure
|
|
||||||
|
|
||||||
flash.now.alert = @dossier.errors.full_messages.join('<br />').html_safe
|
flash.now.alert = @dossier.errors.full_messages.join('<br />').html_safe
|
||||||
return render 'show'
|
return render 'show'
|
||||||
|
@ -47,6 +46,12 @@ class Users::DescriptionController < UsersController
|
||||||
unless params[:champs].nil?
|
unless params[:champs].nil?
|
||||||
@dossier.champs.each do |champ|
|
@dossier.champs.each do |champ|
|
||||||
champ.value = params[:champs]["'#{champ.id}'"]
|
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
|
champ.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
class Champ < ActiveRecord::Base
|
class Champ < ActiveRecord::Base
|
||||||
belongs_to :dossier
|
belongs_to :dossier
|
||||||
belongs_to :type_de_champ
|
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
|
end
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
class CerfaSerializer < ActiveModel::Serializer
|
class CerfaSerializer < ActiveModel::Serializer
|
||||||
|
|
||||||
attributes :content_url => :url
|
attributes :created_at,
|
||||||
|
:content_url => :url
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
|
@ -1,5 +1,6 @@
|
||||||
class PieceJustificativeSerializer < ActiveModel::Serializer
|
class PieceJustificativeSerializer < ActiveModel::Serializer
|
||||||
attributes :content_url => :url
|
attributes :created_at,
|
||||||
|
:content_url => :url
|
||||||
|
|
||||||
has_one :type_de_piece_justificative
|
has_one :type_de_piece_justificative
|
||||||
end
|
end
|
|
@ -9,6 +9,11 @@
|
||||||
.form-group
|
.form-group
|
||||||
%h4 Description
|
%h4 Description
|
||||||
= ff.text_area :description, class: 'form-control description', placeholder: 'Description'
|
= ff.text_area :description, class: 'form-control description', placeholder: 'Description'
|
||||||
|
.form-group
|
||||||
|
%h4 Obligatoire ?
|
||||||
|
.center
|
||||||
|
= ff.check_box :mandatory, placeholder: 'Obligatoire ?'
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
= ff.hidden_field :order_place, value: ff.index
|
= ff.hidden_field :order_place, value: ff.index
|
||||||
= ff.hidden_field :id
|
= ff.hidden_field :id
|
||||||
|
|
|
@ -26,11 +26,15 @@
|
||||||
-if champ.type_champ == 'checkbox'
|
-if champ.type_champ == 'checkbox'
|
||||||
%h4{style:'margin-left:15px;'}
|
%h4{style:'margin-left:15px;'}
|
||||||
= champ.libelle
|
= champ.libelle
|
||||||
|
- if champ.mandatory?
|
||||||
|
= '*'
|
||||||
%input{type: 'hidden', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", value: ''}
|
%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')}
|
%input{type: 'checkbox', style:'margin-left: 15px;', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", checked: ('checked' if champ.value == 'on')}
|
||||||
-else
|
-else
|
||||||
%h4
|
%h4
|
||||||
= champ.libelle
|
= champ.libelle
|
||||||
|
- if champ.mandatory?
|
||||||
|
= '*'
|
||||||
|
|
||||||
-if champ.type_champ == 'textarea'
|
-if champ.type_champ == 'textarea'
|
||||||
%textarea.form-control{name:"champs['#{champ.id}']",
|
%textarea.form-control{name:"champs['#{champ.id}']",
|
||||||
|
@ -62,7 +66,7 @@
|
||||||
- if @procedure.cerfa_flag
|
- if @procedure.cerfa_flag
|
||||||
%tr
|
%tr
|
||||||
%th{class:'col-lg-6'}
|
%th{class:'col-lg-6'}
|
||||||
='Formulaire (.pdf / .doc / .docx / .xls / .xlsx)'
|
='Formulaire'
|
||||||
|
|
||||||
%td{class:'col-lg-5'}
|
%td{class:'col-lg-5'}
|
||||||
-if @dossier.cerfa_available?
|
-if @dossier.cerfa_available?
|
||||||
|
|
5
db/migrate/20160314160801_add_created_at_to_cerfa.rb
Normal file
5
db/migrate/20160314160801_add_created_at_to_cerfa.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddCreatedAtToCerfa < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :cerfas, :created_at, :datetime
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddCreatedAtToPieceJustificative < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :pieces_justificatives, :created_at, :datetime
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddMandatoryToTypeDeChamps < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :types_de_champ, :mandatory, :boolean, default: false
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -70,6 +70,7 @@ ActiveRecord::Schema.define(version: 20160314102523) do
|
||||||
create_table "cerfas", force: :cascade do |t|
|
create_table "cerfas", force: :cascade do |t|
|
||||||
t.string "content"
|
t.string "content"
|
||||||
t.integer "dossier_id"
|
t.integer "dossier_id"
|
||||||
|
t.datetime "created_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "cerfas", ["dossier_id"], name: "index_cerfas_on_dossier_id", using: :btree
|
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.string "content"
|
||||||
t.integer "dossier_id"
|
t.integer "dossier_id"
|
||||||
t.integer "type_de_piece_justificative_id"
|
t.integer "type_de_piece_justificative_id"
|
||||||
|
t.datetime "created_at"
|
||||||
end
|
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_de_piece_justificative_id", using: :btree
|
||||||
|
@ -242,6 +244,7 @@ ActiveRecord::Schema.define(version: 20160314102523) do
|
||||||
t.integer "order_place"
|
t.integer "order_place"
|
||||||
t.integer "procedure_id"
|
t.integer "procedure_id"
|
||||||
t.text "description"
|
t.text "description"
|
||||||
|
t.boolean "mandatory", default: false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "types_de_piece_justificative", force: :cascade do |t|
|
create_table "types_de_piece_justificative", force: :cascade do |t|
|
||||||
|
|
|
@ -37,6 +37,7 @@ describe Admin::TypesDeChampController, type: :controller do
|
||||||
let(:description) { 'titi' }
|
let(:description) { 'titi' }
|
||||||
let(:order_place) { '' }
|
let(:order_place) { '' }
|
||||||
let(:types_de_champ_id) { '' }
|
let(:types_de_champ_id) { '' }
|
||||||
|
let(:mandatory) { 'on' }
|
||||||
|
|
||||||
let(:procedure_params) do
|
let(:procedure_params) do
|
||||||
{ types_de_champ_attributes:
|
{ types_de_champ_attributes:
|
||||||
|
@ -46,7 +47,8 @@ describe Admin::TypesDeChampController, type: :controller do
|
||||||
type_champ: type_champ,
|
type_champ: type_champ,
|
||||||
description: description,
|
description: description,
|
||||||
order_place: order_place,
|
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.libelle).to eq('mon libelle') }
|
||||||
it { expect(subject.type_champ).to eq('text') }
|
it { expect(subject.type_champ).to eq('text') }
|
||||||
it { expect(subject.description).to eq('titi') }
|
it { expect(subject.description).to eq('titi') }
|
||||||
# it { expect(subject.order_place).to eq('0') }
|
it { expect(subject.mandatory).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when type_de_champ already exist' do
|
context 'when type_de_champ already exist' do
|
||||||
|
@ -78,6 +80,7 @@ describe Admin::TypesDeChampController, type: :controller do
|
||||||
let(:type_champ) { 'text' }
|
let(:type_champ) { 'text' }
|
||||||
let(:description) { 'citrouille' }
|
let(:description) { 'citrouille' }
|
||||||
let(:order_place) { '0' }
|
let(:order_place) { '0' }
|
||||||
|
let(:mandatory) { 'on' }
|
||||||
before do
|
before do
|
||||||
request
|
request
|
||||||
procedure.reload
|
procedure.reload
|
||||||
|
@ -86,7 +89,8 @@ describe Admin::TypesDeChampController, type: :controller do
|
||||||
it { expect(subject.libelle).to eq('toto') }
|
it { expect(subject.libelle).to eq('toto') }
|
||||||
it { expect(subject.type_champ).to eq('text') }
|
it { expect(subject.type_champ).to eq('text') }
|
||||||
it { expect(subject.description).to eq('citrouille') }
|
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
|
||||||
end
|
end
|
||||||
context 'when procedure is not found' do
|
context 'when procedure is not found' do
|
||||||
|
|
|
@ -172,6 +172,7 @@ describe API::V1::DossiersController do
|
||||||
subject { super().first }
|
subject { super().first }
|
||||||
|
|
||||||
it { expect(subject.keys.include?(:url)).to be_truthy }
|
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 }
|
it { expect(subject.keys.include?(:type_de_piece_justificative)).to be_truthy }
|
||||||
|
|
||||||
describe 'type de piece justificative' do
|
describe 'type de piece justificative' do
|
||||||
|
@ -242,6 +243,7 @@ describe API::V1::DossiersController do
|
||||||
|
|
||||||
subject { super()[:cerfa] }
|
subject { super()[:cerfa] }
|
||||||
|
|
||||||
|
it { expect(subject[:created_at]).not_to be_nil }
|
||||||
it { expect(subject[:url]).to match /^http:\/\/.*downloads.*_CERFA\.pdf$/ }
|
it { expect(subject[:url]).to match /^http:\/\/.*downloads.*_CERFA\.pdf$/ }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ describe Users::DescriptionController, type: :controller do
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, cerfa_flag: true) }
|
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(:dossier_id) { dossier.id }
|
||||||
let(:bad_dossier_id) { Dossier.count + 10000 }
|
let(:bad_dossier_id) { Dossier.count + 10000 }
|
||||||
|
@ -178,7 +178,7 @@ describe Users::DescriptionController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Sauvegarde des champs' do
|
describe 'Sauvegarde des champs' do
|
||||||
let(:champs_dossier) { dossier.champs }
|
let(:champs_dossier) { dossier.champs }
|
||||||
let(:dossier_champs_first) { 'test value' }
|
let(:dossier_champs_first) { 'test value' }
|
||||||
|
|
||||||
|
@ -194,11 +194,20 @@ describe Users::DescriptionController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(dossier.champs.first.value).to eq(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 value is empty' do
|
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(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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,14 @@ FactoryGirl.define do
|
||||||
end
|
end
|
||||||
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
|
trait :with_two_type_de_piece_justificative do
|
||||||
after(:build) do |procedure, _evaluator|
|
after(:build) do |procedure, _evaluator|
|
||||||
rib = create(:type_de_piece_justificative, :rib)
|
rib = create(:type_de_piece_justificative, :rib)
|
||||||
|
|
|
@ -4,5 +4,6 @@ FactoryGirl.define do
|
||||||
description 'description de votre projet'
|
description 'description de votre projet'
|
||||||
type_champ 'textarea'
|
type_champ 'textarea'
|
||||||
order_place 1
|
order_place 1
|
||||||
|
mandatory false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,7 @@ require 'spec_helper'
|
||||||
describe Cerfa do
|
describe Cerfa do
|
||||||
describe 'database columns' do
|
describe 'database columns' do
|
||||||
it { is_expected.to have_db_column(:content) }
|
it { is_expected.to have_db_column(:content) }
|
||||||
|
it { is_expected.to have_db_column(:created_at) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'associations' do
|
describe 'associations' do
|
||||||
|
|
|
@ -3,6 +3,7 @@ require 'spec_helper'
|
||||||
describe PieceJustificative do
|
describe PieceJustificative do
|
||||||
describe 'database columns' do
|
describe 'database columns' do
|
||||||
it { is_expected.to have_db_column(:content) }
|
it { is_expected.to have_db_column(:content) }
|
||||||
|
it { is_expected.to have_db_column(:created_at) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'associations' do
|
describe 'associations' do
|
||||||
|
|
Loading…
Reference in a new issue