Merge branch 'develop' into staging
This commit is contained in:
commit
8c5aaa84e6
66 changed files with 1001 additions and 213 deletions
|
@ -184,7 +184,7 @@ div.pagination {
|
|||
|
||||
.alert.alert-success.move_up,
|
||||
.alert.alert-danger.siret{
|
||||
position: absolute;
|
||||
position: fixed;
|
||||
top: 0px;
|
||||
left: 0;
|
||||
height: 52px;
|
||||
|
|
|
@ -4,16 +4,19 @@ class Admin::TypesDeChampController < AdminController
|
|||
|
||||
def destroy
|
||||
@procedure.types_de_champ.destroy(params[:id])
|
||||
create_facade
|
||||
render 'show', format: :js
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render json: { message: 'Champ not found' }, status: 404
|
||||
end
|
||||
|
||||
def show
|
||||
create_facade
|
||||
end
|
||||
|
||||
def update
|
||||
@procedure.update_attributes(update_params)
|
||||
create_facade
|
||||
flash.now.notice = 'Modifications sauvegardées'
|
||||
render 'show', format: :js
|
||||
end
|
||||
|
@ -21,12 +24,13 @@ class Admin::TypesDeChampController < AdminController
|
|||
def update_params
|
||||
params
|
||||
.require(:procedure)
|
||||
.permit(types_de_champ_attributes: [:libelle, :description, :order_place, :type_champ, :id, :mandatory])
|
||||
.permit(types_de_champ_attributes: [:libelle, :description, :order_place, :type_champ, :id, :mandatory, :type])
|
||||
end
|
||||
|
||||
def move_up
|
||||
index = params[:index].to_i - 1
|
||||
if @procedure.switch_types_de_champ index
|
||||
create_facade
|
||||
render 'show', format: :js
|
||||
else
|
||||
render json: {}, status: 400
|
||||
|
@ -35,9 +39,16 @@ class Admin::TypesDeChampController < AdminController
|
|||
|
||||
def move_down
|
||||
if @procedure.switch_types_de_champ params[:index].to_i
|
||||
create_facade
|
||||
render 'show', format: :js
|
||||
else
|
||||
render json: {}, status: 400
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_facade
|
||||
@types_de_champ_facade = AdminTypesDeChampFacades.new false, @procedure
|
||||
end
|
||||
end
|
55
app/controllers/admin/types_de_champ_private_controller.rb
Normal file
55
app/controllers/admin/types_de_champ_private_controller.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
class Admin::TypesDeChampPrivateController < AdminController
|
||||
before_action :retrieve_procedure
|
||||
before_action :procedure_locked?
|
||||
|
||||
def destroy
|
||||
@procedure.types_de_champ_private.destroy(params[:id])
|
||||
create_facade
|
||||
render 'admin/types_de_champ/show', format: :js
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render json: { message: 'Champ not found' }, status: 404
|
||||
end
|
||||
|
||||
def show
|
||||
create_facade
|
||||
render 'admin/types_de_champ/show'
|
||||
end
|
||||
|
||||
def update
|
||||
@procedure.update_attributes(update_params)
|
||||
create_facade
|
||||
flash.now.notice = 'Modifications sauvegardées'
|
||||
render 'admin/types_de_champ/show', format: :js
|
||||
end
|
||||
|
||||
def update_params
|
||||
params
|
||||
.require(:procedure)
|
||||
.permit(types_de_champ_private_attributes: [:libelle, :description, :order_place, :type_champ, :id, :mandatory, :type])
|
||||
end
|
||||
|
||||
def move_up
|
||||
index = params[:index].to_i - 1
|
||||
if @procedure.switch_types_de_champ_private index
|
||||
create_facade
|
||||
render 'admin/types_de_champ/show', format: :js
|
||||
else
|
||||
render json: {}, status: 400
|
||||
end
|
||||
end
|
||||
|
||||
def move_down
|
||||
if @procedure.switch_types_de_champ_private params[:index].to_i
|
||||
create_facade
|
||||
render 'admin/types_de_champ/show', format: :js
|
||||
else
|
||||
render json: {}, status: 400
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_facade
|
||||
@types_de_champ_facade = AdminTypesDeChampFacades.new true, @procedure
|
||||
end
|
||||
end
|
|
@ -14,6 +14,7 @@ class Backoffice::DossiersController < ApplicationController
|
|||
|
||||
def show
|
||||
create_dossier_facade params[:id]
|
||||
@champs = @facade.champs_private unless @facade.nil?
|
||||
end
|
||||
|
||||
def search
|
||||
|
|
19
app/controllers/backoffice/private_formulaires_controller.rb
Normal file
19
app/controllers/backoffice/private_formulaires_controller.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
class Backoffice::PrivateFormulairesController < ApplicationController
|
||||
before_action :authenticate_gestionnaire!
|
||||
|
||||
def update
|
||||
dossier = current_gestionnaire.dossiers.find(params[:dossier_id])
|
||||
|
||||
unless params[:champs].nil?
|
||||
champs_service_errors = ChampsService.save_formulaire dossier.champs_private, params
|
||||
|
||||
if champs_service_errors.empty?
|
||||
flash[:notice] = "Formulaire enregistré"
|
||||
else
|
||||
flash[:alert] = (champs_service_errors.inject('') { |acc, error| acc+= error[:message]+'<br>' }).html_safe
|
||||
end
|
||||
end
|
||||
|
||||
render 'backoffice/dossiers/formulaire_private', formats: :js
|
||||
end
|
||||
end
|
|
@ -43,23 +43,11 @@ class Users::DescriptionController < UsersController
|
|||
end
|
||||
|
||||
unless params[:champs].nil?
|
||||
@dossier.champs.each do |champ|
|
||||
champ.value = params[:champs]["'#{champ.id}'"]
|
||||
champs_service_errors = ChampsService.save_formulaire @dossier.champs, params
|
||||
|
||||
if champ.type_champ == 'datetime'
|
||||
champ.value = params[:champs]["'#{champ.id}'"]+
|
||||
' ' +
|
||||
params[:time_hour]["'#{champ.id}'"] +
|
||||
':' +
|
||||
params[:time_minute]["'#{champ.id}'"]
|
||||
end
|
||||
|
||||
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
|
||||
unless champs_service_errors.empty?
|
||||
flash.now.alert = (champs_service_errors.inject('') {|acc, error| acc+= error[:message]+'<br>' }).html_safe
|
||||
return render 'show'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -19,11 +19,9 @@ class Users::RecapitulatifController < UsersController
|
|||
def submit
|
||||
create_dossier_facade
|
||||
|
||||
@facade.dossier.next_step! 'user', 'submit'
|
||||
@facade.dossier.submit!
|
||||
flash.notice = 'Dossier déposé avec succès.'
|
||||
|
||||
NotificationMailer.dossier_submitted(@facade.dossier).deliver_now!
|
||||
|
||||
render 'show'
|
||||
end
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
|
||||
class TypeDeChampDecorator < Draper::Decorator
|
||||
|
||||
delegate_all
|
||||
|
||||
def button_up params
|
||||
h.link_to '', params[:url], class: up_classes, id: "btn_up_#{params[:index]}", remote: true, method: :post if display_up_button?(params[:index])
|
||||
h.link_to '', params[:url], class: up_classes, id: "btn_up_#{params[:index]}", remote: true, method: :post if display_up_button?(params[:index], params[:private])
|
||||
end
|
||||
|
||||
def button_down params
|
||||
h.link_to '', params[:url], class: down_classes, id: "btn_down_#{params[:index]}", remote: true, method: :post if display_down_button?(params[:index])
|
||||
h.link_to '', params[:url], class: down_classes, id: "btn_down_#{params[:index]}", remote: true, method: :post if display_down_button?(params[:index], params[:private])
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -23,15 +24,19 @@ class TypeDeChampDecorator < Draper::Decorator
|
|||
%w(btn btn-default form-control fa)
|
||||
end
|
||||
|
||||
def display_up_button?(index)
|
||||
!(index == 0 || count_type_de_champ < 2)
|
||||
def display_up_button?(index, private)
|
||||
!(index == 0 || count_type_de_champ(private) < 2)
|
||||
end
|
||||
|
||||
def display_down_button?(index)
|
||||
(index + 1) < count_type_de_champ
|
||||
def display_down_button?(index, private)
|
||||
(index + 1) < count_type_de_champ(private)
|
||||
end
|
||||
|
||||
def count_type_de_champ
|
||||
@count_type_de_champ ||= procedure.types_de_champ.count
|
||||
def count_type_de_champ private
|
||||
if private
|
||||
@count_type_de_champ ||= procedure.types_de_champ_private.count
|
||||
else
|
||||
@count_type_de_champ ||= procedure.types_de_champ.count
|
||||
end
|
||||
end
|
||||
end
|
3
app/decorators/type_de_champ_private_decorator.rb
Normal file
3
app/decorators/type_de_champ_private_decorator.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class TypeDeChampPrivateDecorator < TypeDeChampDecorator
|
||||
|
||||
end
|
48
app/facades/admin_types_de_champ_facades.rb
Normal file
48
app/facades/admin_types_de_champ_facades.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
class AdminTypesDeChampFacades
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
def initialize private, procedure
|
||||
@private = private
|
||||
@procedure = procedure
|
||||
end
|
||||
|
||||
def private
|
||||
@private
|
||||
end
|
||||
|
||||
def active
|
||||
@private ? 'Champs privés' : 'Champs'
|
||||
end
|
||||
|
||||
def url
|
||||
@private ? admin_procedure_types_de_champ_private_path(@procedure) : admin_procedure_types_de_champ_path(@procedure)
|
||||
end
|
||||
|
||||
def types_de_champ
|
||||
@private ? @procedure.types_de_champ_private_ordered.decorate : @procedure.types_de_champ_ordered.decorate
|
||||
end
|
||||
|
||||
def new_type_de_champ
|
||||
@private ? TypeDeChampPrivate.new.decorate : TypeDeChampPublic.new.decorate
|
||||
end
|
||||
|
||||
def fields_for_var
|
||||
@private ? :types_de_champ_private : :types_de_champ
|
||||
end
|
||||
|
||||
def move_up_url ff
|
||||
@private ? move_up_admin_procedure_types_de_champ_private_path(@procedure, ff.index) : move_up_admin_procedure_types_de_champ_path(@procedure, ff.index)
|
||||
end
|
||||
|
||||
def move_down_url ff
|
||||
@private ? move_down_admin_procedure_types_de_champ_private_path(@procedure, ff.index) : move_down_admin_procedure_types_de_champ_path(@procedure, ff.index)
|
||||
end
|
||||
|
||||
def delete_url ff
|
||||
@private ? admin_procedure_type_de_champ_private_path(@procedure, ff.object.id) : admin_procedure_type_de_champ_path(@procedure, ff.object.id)
|
||||
end
|
||||
|
||||
def add_button_id
|
||||
@private ? :add_type_de_champ_private : :add_type_de_champ
|
||||
end
|
||||
end
|
|
@ -46,6 +46,10 @@ class DossierFacades
|
|||
@dossier.invites
|
||||
end
|
||||
|
||||
def champs_private
|
||||
@dossier.ordered_champs_private
|
||||
end
|
||||
|
||||
def commentaires_files
|
||||
PieceJustificative.where(dossier_id: @dossier.id, type_de_piece_justificative_id: nil)
|
||||
end
|
||||
|
|
3
app/models/champ_private.rb
Normal file
3
app/models/champ_private.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class ChampPrivate < Champ
|
||||
|
||||
end
|
3
app/models/champ_public.rb
Normal file
3
app/models/champ_public.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class ChampPublic < Champ
|
||||
|
||||
end
|
|
@ -13,7 +13,8 @@ class Dossier < ActiveRecord::Base
|
|||
has_many :cerfa, dependent: :destroy
|
||||
|
||||
has_many :pieces_justificatives, dependent: :destroy
|
||||
has_many :champs, dependent: :destroy
|
||||
has_many :champs, class_name: 'ChampPublic', dependent: :destroy
|
||||
has_many :champs_private, class_name: 'ChampPrivate', dependent: :destroy
|
||||
has_many :quartier_prioritaires, dependent: :destroy
|
||||
has_many :cadastres, dependent: :destroy
|
||||
has_many :commentaires, dependent: :destroy
|
||||
|
@ -47,7 +48,11 @@ class Dossier < ActiveRecord::Base
|
|||
|
||||
def build_default_champs
|
||||
procedure.types_de_champ.each do |type_de_champ|
|
||||
Champ.create(type_de_champ_id: type_de_champ.id, dossier_id: id)
|
||||
ChampPublic.create(type_de_champ_id: type_de_champ.id, dossier_id: id)
|
||||
end
|
||||
|
||||
procedure.types_de_champ_private.each do |type_de_champ|
|
||||
ChampPrivate.create(type_de_champ_id: type_de_champ.id, dossier_id: id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -55,6 +60,10 @@ class Dossier < ActiveRecord::Base
|
|||
champs.joins(', types_de_champ').where("champs.type_de_champ_id = types_de_champ.id AND types_de_champ.procedure_id = #{procedure.id}").order('order_place')
|
||||
end
|
||||
|
||||
def ordered_champs_private
|
||||
champs_private.joins(', types_de_champ').where("champs.type_de_champ_id = types_de_champ.id AND types_de_champ.procedure_id = #{procedure.id}").order('order_place')
|
||||
end
|
||||
|
||||
def ordered_commentaires
|
||||
commentaires.order(created_at: :desc)
|
||||
end
|
||||
|
@ -207,4 +216,11 @@ class Dossier < ActiveRecord::Base
|
|||
def total_commentaire
|
||||
self.commentaires.size
|
||||
end
|
||||
|
||||
def submit!
|
||||
self.deposit_datetime= DateTime.now
|
||||
|
||||
next_step! 'user', 'submit'
|
||||
NotificationMailer.dossier_submitted(self).deliver_now!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class Procedure < ActiveRecord::Base
|
||||
has_many :types_de_piece_justificative, dependent: :destroy
|
||||
has_many :types_de_champ, dependent: :destroy
|
||||
has_many :types_de_champ, class_name: 'TypeDeChampPublic', dependent: :destroy
|
||||
has_many :types_de_champ_private, dependent: :destroy
|
||||
has_many :dossiers
|
||||
|
||||
has_one :procedure_path, dependent: :destroy
|
||||
|
@ -17,6 +18,7 @@ class Procedure < ActiveRecord::Base
|
|||
accepts_nested_attributes_for :types_de_champ,:reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true
|
||||
accepts_nested_attributes_for :types_de_piece_justificative, :reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true
|
||||
accepts_nested_attributes_for :module_api_carto
|
||||
accepts_nested_attributes_for :types_de_champ_private
|
||||
|
||||
mount_uploader :logo, ProcedureLogoUploader
|
||||
|
||||
|
@ -35,6 +37,10 @@ class Procedure < ActiveRecord::Base
|
|||
types_de_champ.order(:order_place)
|
||||
end
|
||||
|
||||
def types_de_champ_private_ordered
|
||||
types_de_champ_private.order(:order_place)
|
||||
end
|
||||
|
||||
def types_de_piece_justificative_ordered
|
||||
types_de_piece_justificative.order(:order_place)
|
||||
end
|
||||
|
@ -51,6 +57,10 @@ class Procedure < ActiveRecord::Base
|
|||
switch_list_order(types_de_champ_ordered, index_of_first_element)
|
||||
end
|
||||
|
||||
def switch_types_de_champ_private index_of_first_element
|
||||
switch_list_order(types_de_champ_private_ordered, index_of_first_element)
|
||||
end
|
||||
|
||||
def switch_types_de_piece_justificative index_of_first_element
|
||||
switch_list_order(types_de_piece_justificative_ordered, index_of_first_element)
|
||||
end
|
||||
|
|
3
app/models/type_de_champ_private.rb
Normal file
3
app/models/type_de_champ_private.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class TypeDeChampPrivate < TypeDeChamp
|
||||
|
||||
end
|
3
app/models/type_de_champ_public.rb
Normal file
3
app/models/type_de_champ_public.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class TypeDeChampPublic < TypeDeChamp
|
||||
|
||||
end
|
5
app/serializers/champ_private_serializer.rb
Normal file
5
app/serializers/champ_private_serializer.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class ChampPrivateSerializer < ActiveModel::Serializer
|
||||
attributes :value
|
||||
|
||||
has_one :type_de_champ
|
||||
end
|
5
app/serializers/champ_public_serializer.rb
Normal file
5
app/serializers/champ_public_serializer.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class ChampPublicSerializer < ActiveModel::Serializer
|
||||
attributes :value
|
||||
|
||||
has_one :type_de_champ
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
class ChampSerializer < ActiveModel::Serializer
|
||||
attributes :value
|
||||
|
||||
has_one :type_de_champ
|
||||
end
|
|
@ -12,6 +12,7 @@ class DossierSerializer < ActiveModel::Serializer
|
|||
has_many :cerfa
|
||||
has_many :commentaires
|
||||
has_many :champs
|
||||
has_many :champs_private
|
||||
has_many :pieces_justificatives
|
||||
has_many :types_de_piece_justificative
|
||||
end
|
|
@ -12,6 +12,7 @@ class ProcedureSerializer < ActiveModel::Serializer
|
|||
|
||||
|
||||
has_one :geographic_information, serializer: ModuleApiCartoSerializer
|
||||
has_many :types_de_champ, serializer: TypeDeChampSerializer
|
||||
has_many :types_de_piece_justificative, serializer: TypeDePieceJustificativeSerializer
|
||||
has_many :types_de_champ, serializer: TypeDeChampSerializer
|
||||
has_many :types_de_champ_private, serializer: TypeDeChampSerializer
|
||||
has_many :types_de_piece_justificative, serializer: TypeDePieceJustificativeSerializer
|
||||
end
|
||||
|
|
25
app/services/champs_service.rb
Normal file
25
app/services/champs_service.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
class ChampsService
|
||||
def self.save_formulaire champs, params
|
||||
errors = Array.new
|
||||
|
||||
champs.each do |champ|
|
||||
champ.value = params[:champs]["'#{champ.id}'"]
|
||||
|
||||
if champ.type_champ == 'datetime'
|
||||
champ.value = params[:champs]["'#{champ.id}'"]+
|
||||
' ' +
|
||||
params[:time_hour]["'#{champ.id}'"] +
|
||||
':' +
|
||||
params[:time_minute]["'#{champ.id}'"]
|
||||
end
|
||||
|
||||
if champ.mandatory? && (champ.value.nil? || champ.value.blank?)
|
||||
errors.push({message: "Le champ #{champ.libelle} doit être rempli."})
|
||||
end
|
||||
|
||||
champ.save
|
||||
end
|
||||
|
||||
errors
|
||||
end
|
||||
end
|
|
@ -16,5 +16,9 @@
|
|||
= link_to_unless(@procedure.locked?, 'Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure)) do
|
||||
= link_to('Pièces justificatives', '#')
|
||||
|
||||
%li{ class: ('disabled' if @procedure.locked?) || ('active' if active == 'Champs privés') }
|
||||
= link_to_unless(@procedure.locked?, 'Champs privés', admin_procedure_types_de_champ_private_path(@procedure)) do
|
||||
= link_to('Champs privés', '#')
|
||||
|
||||
%li{ class: ('active' if active == 'Prévisualisation'), style: 'float:right' }
|
||||
= link_to('Prévisualisation', admin_procedure_previsualisation_path(@procedure), {style: 'font-style: italic;'})
|
|
@ -1,4 +1,4 @@
|
|||
= f.fields_for :types_de_champ, types_de_champ, remote: true do |ff|
|
||||
= f.fields_for @types_de_champ_facade.fields_for_var, types_de_champ, remote: true do |ff|
|
||||
.form-inline{class:"#{ff.object.object.type_champ == 'header_section' ? 'header_section' : ''}"}
|
||||
.form-group.libelle
|
||||
%h4 Libellé
|
||||
|
@ -12,26 +12,28 @@
|
|||
%h4 Description
|
||||
= ff.text_area :description, class: 'form-control description', placeholder: 'Description'
|
||||
|
||||
.form-group.mandatory
|
||||
%h4 Obligatoire ?
|
||||
.center
|
||||
= ff.check_box :mandatory, placeholder: 'Obligatoire ?'
|
||||
- unless ff.object.object.class == TypeDeChampPrivate
|
||||
.form-group.mandatory
|
||||
%h4 Obligatoire ?
|
||||
.center
|
||||
= ff.check_box :mandatory, placeholder: 'Obligatoire ?'
|
||||
|
||||
.form-group
|
||||
= ff.hidden_field :order_place, value: ff.index
|
||||
= ff.hidden_field :type
|
||||
= ff.hidden_field :id
|
||||
|
||||
- unless ff.object.id.nil?
|
||||
.form-group
|
||||
%br
|
||||
= ff.object.button_up(index: ff.index, url: move_up_admin_procedure_types_de_champ_path(@procedure, ff.index))
|
||||
= ff.object.button_down(index: ff.index, url: move_down_admin_procedure_types_de_champ_path(@procedure, ff.index))
|
||||
|
||||
= ff.object.button_up(index: ff.index, url: @types_de_champ_facade.move_up_url(ff), private: @types_de_champ_facade.private)
|
||||
= ff.object.button_down(index: ff.index, url: @types_de_champ_facade.move_down_url(ff), private: @types_de_champ_facade.private)
|
||||
|
||||
.form-group
|
||||
%br
|
||||
- if ff.object.id.nil?
|
||||
= f.submit "Ajouter le champ", class: 'btn btn-success', id: :add_type_de_champ
|
||||
= f.submit "Ajouter le champ", class: 'btn btn-success', id: @types_de_champ_facade.add_button_id
|
||||
- else
|
||||
= link_to("", admin_procedure_type_de_champ_path(@procedure, ff.object.id), method: :delete, remote: true, id: "delete_type_de_champ_#{ff.object.id}", class: %w(form-control btn btn-danger fa fa-trash-o) )
|
||||
= link_to("", @types_de_champ_facade.delete_url(ff), method: :delete, remote: true, id: "delete_type_de_champ_#{ff.object.id}", class: %w(form-control btn btn-danger fa fa-trash-o) )
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
= form_for [:admin, @procedure], url: admin_procedure_types_de_champ_path(@procedure) , remote: true do |f|
|
||||
= render partial: 'fields', locals: { types_de_champ: @procedure.types_de_champ_ordered.decorate, f: f }
|
||||
= form_for [:admin, @procedure], url: @types_de_champ_facade.url , remote: true do |f|
|
||||
= render partial: 'admin/types_de_champ/fields', locals: { types_de_champ: @types_de_champ_facade.types_de_champ, f: f }
|
||||
= f.submit "Enregistrer", class: 'btn btn-success', id: :save
|
||||
%hr
|
||||
#new_type_de_champ
|
||||
= render partial: 'fields', locals: { types_de_champ: TypeDeChamp.new.decorate, f: f }
|
||||
= render partial: 'admin/types_de_champ/fields', locals: { types_de_champ: @types_de_champ_facade.new_type_de_champ, f: f }
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
=render partial: 'admin/procedures/head', locals: {active: 'Champs'}
|
||||
=render partial: 'admin/procedures/head', locals: {active: @types_de_champ_facade.active}
|
||||
|
||||
#liste_champ
|
||||
= render partial: 'form'
|
||||
= render partial: 'admin/types_de_champ/form'
|
|
@ -1,5 +1,5 @@
|
|||
<% flash.each do |type, message| %>
|
||||
$("#flash_message").html("<div class=\"alert alert-success move_up\" style=\"display: block:\"> <%= message.html_safe %></div>").children().fadeOut(5000)
|
||||
<% end %>
|
||||
$('#liste_champ').html("<%= escape_javascript(render partial: 'form', locals: { procedure: @procedure, types_de_champ: @types_de_champ } ) %>");
|
||||
$('#liste_champ').html("<%= escape_javascript(render partial: 'admin/types_de_champ/form', locals: { procedure: @procedure, types_de_champ: @types_de_champ } ) %>");
|
||||
on_change_type_de_champ_select ();
|
4
app/views/backoffice/dossiers/formulaire_private.js.erb
Normal file
4
app/views/backoffice/dossiers/formulaire_private.js.erb
Normal file
|
@ -0,0 +1,4 @@
|
|||
<% flash.each do |type, message| %>
|
||||
$("#flash_message").html("<div class=\"alert alert-success move_up\" style=\"display: block:\"> <%= message.html_safe %></div>").children().fadeOut(5000)
|
||||
<% end %>
|
||||
<% flash.clear %>
|
|
@ -14,31 +14,5 @@
|
|||
%br
|
||||
|
||||
%div
|
||||
%ul{class: "nav nav-tabs", role: "tablist"}
|
||||
%li{role: "presentation", class: "active"}
|
||||
%a{href: "#commentaires", 'aria-controls' => "commentaires", role: "tab", 'data-toggle' => "tab"}
|
||||
Commentaires
|
||||
%li{role: "presentation"}
|
||||
%a{href: "#commentaires_files", 'aria-controls' => "commentaires_files", role: "tab", 'data-toggle' => "tab"}
|
||||
Fichiers
|
||||
%li{role: "presentation"}
|
||||
%a{href: "#invites", 'aria-controls' => "invites", role: "tab", 'data-toggle' => "tab"}
|
||||
Invités
|
||||
%li{role: "presentation"}
|
||||
%a{href: "#followers", 'aria-controls' => "followers", role: "tab", 'data-toggle' => "tab"}
|
||||
Abonnés
|
||||
|
||||
%div{class: "tab-content"}
|
||||
%div{role: "tabpanel", class: "tab-pane fade in active", id:"commentaires"}
|
||||
%h3 Flux de commentaires
|
||||
%br
|
||||
= render partial: '/users/recapitulatif/commentaires_flux'
|
||||
%div{role: "tabpanel", class: "tab-pane fade", id:"commentaires_files"}
|
||||
= render partial: '/dossiers/commentaires_files'
|
||||
%div{role: "tabpanel", class: "tab-pane fade", id:"invites"}
|
||||
= render partial: '/dossiers/invites'
|
||||
%div{role: "tabpanel", class: "tab-pane fade", id:"followers"}
|
||||
= render partial: 'followers'
|
||||
|
||||
%br
|
||||
= render partial: 'dossiers/tab_objects_dossier'
|
||||
%br
|
43
app/views/dossiers/_tab_objects_dossier.html.haml
Normal file
43
app/views/dossiers/_tab_objects_dossier.html.haml
Normal file
|
@ -0,0 +1,43 @@
|
|||
%ul{class: "nav nav-tabs", role: "tablist"}
|
||||
%li{role: "presentation", class: "active"}
|
||||
%a{href: "#commentaires", 'aria-controls' => "commentaires", role: "tab", 'data-toggle' => "tab"}
|
||||
Commentaires
|
||||
%li{role: "presentation"}
|
||||
%a{href: "#commentaires_files", 'aria-controls' => "commentaires_files", role: "tab", 'data-toggle' => "tab"}
|
||||
Fichiers
|
||||
|
||||
- if gestionnaire_signed_in?
|
||||
%li{role: "presentation"}
|
||||
%a{href: "#invites", 'aria-controls' => "invites", role: "tab", 'data-toggle' => "tab"}
|
||||
Invités
|
||||
%li{role: "presentation"}
|
||||
%a{href: "#followers", 'aria-controls' => "followers", role: "tab", 'data-toggle' => "tab"}
|
||||
Abonnés
|
||||
%li{role: "presentation"}
|
||||
%a{href: "#champs_private", 'aria-controls' => "champs_private", role: "tab", 'data-toggle' => "tab"}
|
||||
Formulaire
|
||||
|
||||
%div{class: "tab-content"}
|
||||
%div{role: "tabpanel", class: "tab-pane fade in active", id:"commentaires"}
|
||||
%h3 Flux de commentaires
|
||||
%br
|
||||
= render partial: '/users/recapitulatif/commentaires_flux'
|
||||
%div{role: "tabpanel", class: "tab-pane fade", id:"commentaires_files"}
|
||||
= render partial: '/dossiers/commentaires_files'
|
||||
|
||||
- if gestionnaire_signed_in?
|
||||
%div{role: "tabpanel", class: "tab-pane fade", id:"invites"}
|
||||
= render partial: '/dossiers/invites'
|
||||
%div{role: "tabpanel", class: "tab-pane fade", id:"followers"}
|
||||
= render partial: 'followers'
|
||||
%div{role: "tabpanel", class: "tab-pane fade", id:"champs_private"}
|
||||
%h3 Formulaire privé
|
||||
- if @champs.nil? || @champs.empty?
|
||||
%br
|
||||
%h4.text-primary
|
||||
Pas de formulaire privé pour ce dossier
|
||||
- else
|
||||
= form_for @facade.dossier, url: {controller: 'backoffice/private_formulaires', action: :update, dossier_id: @facade.dossier.id}, remote: true do
|
||||
= render partial: '/users/description/champs'
|
||||
%br
|
||||
= submit_tag :Enregistrer, {class: 'btn btn-success', style: 'float: right'}
|
|
@ -24,5 +24,6 @@
|
|||
|
||||
= render partial: '/dossiers/infos_dossier'
|
||||
|
||||
%br
|
||||
= render partial: '/users/recapitulatif/commentaires_flux'
|
||||
%div
|
||||
%br
|
||||
= render partial: 'dossiers/tab_objects_dossier'
|
|
@ -13,6 +13,7 @@ ActiveSupport::Inflector.inflections(:en) do |inflect|
|
|||
inflect.irregular 'piece_justificative', 'pieces_justificatives'
|
||||
inflect.irregular 'type_de_piece_justificative', 'types_de_piece_justificative'
|
||||
inflect.irregular 'type_de_champ', 'types_de_champ'
|
||||
inflect.irregular 'type_de_champ_private', 'types_de_champ_private'
|
||||
inflect.irregular 'assign_to', 'assign_tos'
|
||||
end
|
||||
|
||||
|
|
|
@ -93,10 +93,20 @@ Rails.application.routes.draw do
|
|||
get 'profile' => 'profile#show', as: :profile
|
||||
|
||||
resources :procedures do
|
||||
resources :types_de_champ, only: [:destroy]
|
||||
resource :types_de_champ, only: [:show, :update] do
|
||||
post '/:index/move_up' => 'types_de_champ#move_up', as: :move_up
|
||||
post '/:index/move_down' => 'types_de_champ#move_down', as: :move_down
|
||||
end
|
||||
|
||||
resources :types_de_champ_private, only: [:destroy]
|
||||
resource :types_de_champ_private, only: [:show, :update] do
|
||||
post '/:index/move_up' => 'types_de_champ_private#move_up', as: :move_up
|
||||
post '/:index/move_down' => 'types_de_champ_private#move_down', as: :move_down
|
||||
end
|
||||
|
||||
resource :pieces_justificatives, only: [:show, :update]
|
||||
resources :pieces_justificatives, only: :destroy
|
||||
resource :pieces_justificatives, only: [:show, :update] do
|
||||
post '/:index/move_up' => 'pieces_justificatives#move_up', as: :move_up
|
||||
post '/:index/move_down' => 'pieces_justificatives#move_down', as: :move_down
|
||||
|
@ -111,9 +121,6 @@ Rails.application.routes.draw do
|
|||
|
||||
resource :previsualisation, only: [:show]
|
||||
|
||||
resources :types_de_champ, only: [:destroy]
|
||||
resource :pieces_justificatives, only: [:show, :update]
|
||||
resources :pieces_justificatives, only: :destroy
|
||||
end
|
||||
|
||||
namespace :accompagnateurs do
|
||||
|
@ -138,6 +145,7 @@ Rails.application.routes.draw do
|
|||
get 'filtres' => 'procedure_filter#index'
|
||||
patch 'filtres/update' => 'procedure_filter#update'
|
||||
|
||||
resource :private_formulaire
|
||||
|
||||
namespace :preference_list_dossier do
|
||||
post 'add'
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddPublicAttrOnTypeDeChamp < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :types_de_champ, :private, :boolean, default: false
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class AddTypeAttrOnTypeDeChamp < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :types_de_champ, :type, :string
|
||||
end
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
class FixDefaultTypeOnTypeDeChampTable < ActiveRecord::Migration
|
||||
class TypeDeChamp < ActiveRecord::Base
|
||||
|
||||
end
|
||||
|
||||
def up
|
||||
TypeDeChamp.where("private = false").update_all("type = 'TypeDeChampPublic'")
|
||||
TypeDeChamp.where("private = true").update_all("type = 'TypeDeChampPrivate'")
|
||||
remove_column :types_de_champ, :private
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :types_de_champ, :private, :boolean, default: true
|
||||
TypeDeChamp.where("type = 'TypeDeChampPublic'").update_all("private = false")
|
||||
TypeDeChamp.where("type = 'TypeDeChampPrivate'").update_all("private = true")
|
||||
end
|
||||
end
|
25
db/migrate/20160804130638_add_type_attr_in_champ_table.rb
Normal file
25
db/migrate/20160804130638_add_type_attr_in_champ_table.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
class AddTypeAttrInChampTable < ActiveRecord::Migration
|
||||
|
||||
class TypeDeChamp < ActiveRecord::Base
|
||||
has_many :champs
|
||||
end
|
||||
|
||||
class Champ < ActiveRecord::Base
|
||||
belongs_to :type_de_champ
|
||||
end
|
||||
|
||||
def up
|
||||
add_column :champs, :type, :string
|
||||
|
||||
Champ.all.each do |champ|
|
||||
type = 'ChampPublic' if champ.type_de_champ.class == TypeDeChampPublic
|
||||
type = 'ChampPrivate' if champ.type_de_champ.class == TypeDeChampPrivate
|
||||
|
||||
champ.update_attribute(:type, type)
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :champs, :type
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class AddDepositAttrInDossierTable < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :dossiers, :deposit_datetime, :datetime
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160802113112) do
|
||||
ActiveRecord::Schema.define(version: 20160808115924) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -99,6 +99,7 @@ ActiveRecord::Schema.define(version: 20160802113112) do
|
|||
t.string "value"
|
||||
t.integer "type_de_champ_id"
|
||||
t.integer "dossier_id"
|
||||
t.string "type"
|
||||
end
|
||||
|
||||
create_table "commentaires", force: :cascade do |t|
|
||||
|
@ -123,6 +124,7 @@ ActiveRecord::Schema.define(version: 20160802113112) do
|
|||
t.text "json_latlngs"
|
||||
t.boolean "archived", default: false
|
||||
t.boolean "mandataire_social", default: false
|
||||
t.datetime "deposit_datetime"
|
||||
end
|
||||
|
||||
add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree
|
||||
|
@ -296,6 +298,7 @@ ActiveRecord::Schema.define(version: 20160802113112) do
|
|||
t.integer "procedure_id"
|
||||
t.text "description"
|
||||
t.boolean "mandatory", default: false
|
||||
t.string "type"
|
||||
end
|
||||
|
||||
create_table "types_de_piece_justificative", force: :cascade do |t|
|
||||
|
|
|
@ -121,7 +121,7 @@ describe Admin::TypesDeChampController, type: :controller do
|
|||
end
|
||||
end
|
||||
context 'when procedure and type de champs are not linked' do
|
||||
let(:type_de_champ) { create(:type_de_champ) }
|
||||
let(:type_de_champ) { create(:type_de_champ_public) }
|
||||
let(:type_de_champ_id) { type_de_champ.id }
|
||||
it { expect(subject.status).to eq(404) }
|
||||
end
|
||||
|
@ -136,20 +136,20 @@ describe Admin::TypesDeChampController, type: :controller do
|
|||
end
|
||||
context 'when procedure have only one type de champ' do
|
||||
let(:index) { 1 }
|
||||
let!(:type_de_champ) { create(:type_de_champ, procedure: procedure) }
|
||||
let!(:type_de_champ) { create(:type_de_champ_public, procedure: procedure) }
|
||||
it { expect(subject.status).to eq(400) }
|
||||
end
|
||||
context 'when procedure have tow type de champs' do
|
||||
context 'when index == 0' do
|
||||
let(:index) { 0 }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure) }
|
||||
let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure) }
|
||||
let!(:type_de_champ_2) { create(:type_de_champ_public, procedure: procedure) }
|
||||
it { expect(subject.status).to eq(400) }
|
||||
end
|
||||
context 'when index > 0' do
|
||||
let(:index) { 1 }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
||||
|
||||
it { expect(subject.status).to eq(200) }
|
||||
it { expect(subject).to render_template('show') }
|
||||
|
@ -174,12 +174,12 @@ describe Admin::TypesDeChampController, type: :controller do
|
|||
it { expect(subject.status).to eq(400) }
|
||||
end
|
||||
context 'when procedure have only one type de champ' do
|
||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure) }
|
||||
it { expect(subject.status).to eq(400) }
|
||||
end
|
||||
context 'when procedure have 2 type de champ' do
|
||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
||||
context 'when index represent last type_de_champ' do
|
||||
let(:index) { 1 }
|
||||
it { expect(subject.status).to eq(400) }
|
||||
|
|
202
spec/controllers/admin/types_de_champ_private_controller_spec.rb
Normal file
202
spec/controllers/admin/types_de_champ_private_controller_spec.rb
Normal file
|
@ -0,0 +1,202 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Admin::TypesDeChampPrivateController, type: :controller do
|
||||
let(:admin) { create(:administrateur) }
|
||||
let(:procedure) { create(:procedure, administrateur: admin) }
|
||||
|
||||
before do
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
let(:published) { false }
|
||||
let(:procedure) { create(:procedure, administrateur: admin, published: published) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
|
||||
subject { get :show, procedure_id: procedure_id }
|
||||
|
||||
context 'when procedure is not found' do
|
||||
let(:procedure_id) { 9_999_999 }
|
||||
it { expect(subject.status).to eq(404) }
|
||||
end
|
||||
|
||||
context 'when procedure is published' do
|
||||
let(:published) { true }
|
||||
it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
|
||||
end
|
||||
|
||||
context 'when procedure does not belong to admin' do
|
||||
let(:admin_2) { create(:administrateur) }
|
||||
let(:procedure) { create(:procedure, administrateur: admin_2) }
|
||||
it { expect(subject.status).to eq(404) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#update' do
|
||||
let(:libelle) { 'mon libelle' }
|
||||
let(:type_champ) { 'text' }
|
||||
let(:description) { 'titi' }
|
||||
let(:order_place) { '' }
|
||||
let(:types_de_champ_id) { '' }
|
||||
let(:mandatory) { 'on' }
|
||||
|
||||
let(:procedure_params) do
|
||||
{ types_de_champ_private_attributes:
|
||||
{ '0' =>
|
||||
{
|
||||
libelle: libelle,
|
||||
type_champ: type_champ,
|
||||
description: description,
|
||||
order_place: order_place,
|
||||
id: types_de_champ_id,
|
||||
mandatory: mandatory,
|
||||
type: 'TypeDeChampPrivate'
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
let(:request) { put :update, format: :js, procedure_id: procedure.id, procedure: procedure_params }
|
||||
|
||||
context 'when procedure is found' do
|
||||
it { expect{ request }.to change(TypeDeChamp, :count).by(1) }
|
||||
|
||||
describe 'created type de champ' do
|
||||
before do
|
||||
request
|
||||
procedure.reload
|
||||
end
|
||||
subject { procedure.types_de_champ_private.first }
|
||||
|
||||
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.mandatory).to be_truthy }
|
||||
end
|
||||
|
||||
context 'when type_de_champ already exist' do
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ_private, administrateur: admin) }
|
||||
let(:type_de_champ) { procedure.types_de_champ_private.first }
|
||||
let(:types_de_champ_id) { type_de_champ.id }
|
||||
let(:libelle) { 'toto' }
|
||||
let(:type_champ) { 'text' }
|
||||
let(:description) { 'citrouille' }
|
||||
let(:order_place) { '0' }
|
||||
let(:mandatory) { 'on' }
|
||||
before do
|
||||
request
|
||||
procedure.reload
|
||||
end
|
||||
subject { procedure.types_de_champ_private.first }
|
||||
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 be_truthy }
|
||||
end
|
||||
end
|
||||
context 'when procedure is not found' do
|
||||
subject { put :update, format: :js, procedure_id: 9_999_999, procedure: procedure_params }
|
||||
it 'creates type de champ' do
|
||||
expect(subject.status).to eq(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#destroy' do
|
||||
before do
|
||||
delete :destroy, procedure_id: procedure.id, id: type_de_champ_id, format: :js
|
||||
end
|
||||
|
||||
context 'when type de champs does not exist' do
|
||||
let(:type_de_champ_id) { 99999999 }
|
||||
it { expect(subject.status).to eq(404) }
|
||||
end
|
||||
context 'when types_de_champ exists' do
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ_private, administrateur: admin) }
|
||||
let(:type_de_champ_id) { procedure.types_de_champ_private.first.id }
|
||||
it { expect(subject.status).to eq(200) }
|
||||
it 'destroy type de champ' do
|
||||
procedure.reload
|
||||
expect(procedure.types_de_champ.count).to eq(0)
|
||||
end
|
||||
end
|
||||
context 'when procedure and type de champs are not linked' do
|
||||
let(:type_de_champ) { create(:type_de_champ_public) }
|
||||
let(:type_de_champ_id) { type_de_champ.id }
|
||||
it { expect(subject.status).to eq(404) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #move_up' do
|
||||
subject { post :move_up, procedure_id: procedure.id, index: index, format: :js }
|
||||
|
||||
context 'when procedure have no type de champ' do
|
||||
let(:index) { 0 }
|
||||
it { expect(subject.status).to eq(400) }
|
||||
end
|
||||
context 'when procedure have only one type de champ' do
|
||||
let(:index) { 1 }
|
||||
let!(:type_de_champ) { create(:type_de_champ_private, procedure: procedure) }
|
||||
it { expect(subject.status).to eq(400) }
|
||||
end
|
||||
context 'when procedure have tow type de champs' do
|
||||
context 'when index == 0' do
|
||||
let(:index) { 0 }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure) }
|
||||
let!(:type_de_champ_2) { create(:type_de_champ_private, procedure: procedure) }
|
||||
it { expect(subject.status).to eq(400) }
|
||||
end
|
||||
context 'when index > 0' do
|
||||
let(:index) { 1 }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) }
|
||||
|
||||
it { expect(subject.status).to eq(200) }
|
||||
it { expect(subject).to render_template('show') }
|
||||
it 'changes order places' do
|
||||
post :move_up, procedure_id: procedure.id, index: index, format: :js
|
||||
type_de_champ_0.reload
|
||||
type_de_champ_1.reload
|
||||
expect(type_de_champ_0.order_place).to eq(1)
|
||||
expect(type_de_champ_1.order_place).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #move_down' do
|
||||
let(:request) { post :move_down, procedure_id: procedure.id, index: index, format: :js }
|
||||
let(:index) { 0 }
|
||||
|
||||
subject { request }
|
||||
|
||||
context 'when procedure have no type de champ' do
|
||||
it { expect(subject.status).to eq(400) }
|
||||
end
|
||||
context 'when procedure have only one type de champ' do
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure) }
|
||||
it { expect(subject.status).to eq(400) }
|
||||
end
|
||||
context 'when procedure have 2 type de champ' do
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) }
|
||||
context 'when index represent last type_de_champ' do
|
||||
let(:index) { 1 }
|
||||
it { expect(subject.status).to eq(400) }
|
||||
end
|
||||
context 'when index does not represent last type_de_champ' do
|
||||
let(:index) { 0 }
|
||||
it { expect(subject.status).to eq(200) }
|
||||
it { expect(subject).to render_template('show') }
|
||||
it 'changes order place' do
|
||||
request
|
||||
type_de_champ_0.reload
|
||||
type_de_champ_1.reload
|
||||
expect(type_de_champ_0.order_place).to eq(1)
|
||||
expect(type_de_champ_1.order_place).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe API::V1::DossiersController do
|
||||
let(:admin) { create(:administrateur) }
|
||||
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, administrateur: admin, cerfa_flag: true) }
|
||||
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_type_de_champ_private, administrateur: admin, cerfa_flag: true) }
|
||||
let(:wrong_procedure) { create(:procedure) }
|
||||
|
||||
it { expect(described_class).to be < APIController }
|
||||
|
@ -115,7 +115,7 @@ describe API::V1::DossiersController do
|
|||
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } }
|
||||
let(:dossier_id) { dossier.id }
|
||||
let(:body) { JSON.parse(retour.body, symbolize_names: true) }
|
||||
let(:field_list) { [:id, :created_at, :updated_at, :archived, :mandataire_social, :total_commentaire, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :commentaires, :state] }
|
||||
let(:field_list) { [:id, :created_at, :updated_at, :archived, :mandataire_social, :total_commentaire, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state] }
|
||||
subject { body[:dossier] }
|
||||
|
||||
it 'return REST code 200', :show_in_doc do
|
||||
|
@ -230,7 +230,38 @@ describe API::V1::DossiersController do
|
|||
it { expect(subject[:libelle]).to eq('Description') }
|
||||
it { expect(subject[:description]).to eq('description de votre projet') }
|
||||
it { expect(subject.keys.include?(:order_place)).to be_truthy }
|
||||
it { expect(subject[:type]).to eq('text') }
|
||||
it { expect(subject[:type_champ]).to eq('text') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'champs_private' do
|
||||
let(:field_list) { [
|
||||
:url] }
|
||||
subject { super()[:champs_private] }
|
||||
|
||||
it { expect(subject.length).to eq 1 }
|
||||
|
||||
describe 'first champs' do
|
||||
subject { super().first }
|
||||
|
||||
it { expect(subject.keys.include?(:value)).to be_truthy }
|
||||
it { expect(subject.keys.include?(:type_de_champ)).to be_truthy }
|
||||
|
||||
describe 'type de champ' do
|
||||
let(:field_list) { [
|
||||
:id,
|
||||
:libelle,
|
||||
:description,
|
||||
:order_place,
|
||||
:type] }
|
||||
subject { super()[:type_de_champ] }
|
||||
|
||||
it { expect(subject.keys.include?(:id)).to be_truthy }
|
||||
it { expect(subject[:libelle]).to eq('Description') }
|
||||
it { expect(subject[:description]).to eq('description de votre projet') }
|
||||
it { expect(subject.keys.include?(:order_place)).to be_truthy }
|
||||
it { expect(subject[:type_champ]).to eq('text') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Backoffice::PrivateFormulairesController, type: :controller do
|
||||
let(:gestionnaire) { create :gestionnaire }
|
||||
let(:dossier) { create :dossier }
|
||||
let(:dossier_champs_first) { 'plop' }
|
||||
|
||||
before do
|
||||
create :assign_to, procedure_id: dossier.procedure.id, gestionnaire_id: gestionnaire.id
|
||||
|
||||
sign_in gestionnaire
|
||||
end
|
||||
|
||||
describe '#PATCH update' do
|
||||
subject { patch :update, dossier_id: dossier.id,
|
||||
champs: {
|
||||
"'#{dossier.champs_private.first.id}'" => dossier_champs_first
|
||||
} }
|
||||
|
||||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(response.status).to eq 200 }
|
||||
it { expect(Dossier.find(dossier.id).champs_private.first.value).to eq dossier_champs_first }
|
||||
it { expect(flash[:notice]).to be_present }
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Users::RecapitulatifController, type: :controller do
|
||||
let(:dossier) { create(:dossier, state:'initiated') }
|
||||
let(:dossier) { create(:dossier, state: 'initiated') }
|
||||
let(:bad_dossier_id) { Dossier.count + 100000 }
|
||||
|
||||
before do
|
||||
|
@ -55,16 +55,22 @@ describe Users::RecapitulatifController, type: :controller do
|
|||
|
||||
describe 'POST #submit' do
|
||||
context 'when an user depose his dossier' do
|
||||
let(:deposit_datetime) { Time.local(2016, 8, 1, 10, 5, 0) }
|
||||
|
||||
before do
|
||||
dossier.validated!
|
||||
post :submit, dossier_id: dossier.id
|
||||
Timecop.freeze(deposit_datetime) { post :submit, dossier_id: dossier.id }
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it 'dossier change his state for submitted' do
|
||||
dossier.reload
|
||||
expect(dossier.state).to eq('submitted')
|
||||
end
|
||||
|
||||
it 'dossier deposit datetime is filled' do
|
||||
expect(dossier.deposit_datetime).to eq deposit_datetime
|
||||
end
|
||||
|
||||
it 'a message informe user what his dossier is initiated' do
|
||||
expect(flash[:notice]).to include('Dossier déposé avec succès.')
|
||||
end
|
||||
|
|
|
@ -5,9 +5,9 @@ describe TypeDeChampDecorator do
|
|||
let(:procedure) { create(:procedure) }
|
||||
let(:url) { 'http://localhost' }
|
||||
let(:params) { { url: url, index: index } }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
||||
let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure, order_place: 2) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
||||
let!(:type_de_champ_2) { create(:type_de_champ_public, procedure: procedure, order_place: 2) }
|
||||
|
||||
describe '#button_up' do
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ FactoryGirl.define do
|
|||
|
||||
before(:create) do |dossier, _evaluator|
|
||||
unless dossier.procedure
|
||||
procedure = create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ)
|
||||
procedure = create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_type_de_champ_private)
|
||||
dossier.procedure = procedure
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,15 +24,23 @@ FactoryGirl.define do
|
|||
|
||||
trait :with_type_de_champ do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
type_de_champ = create(:type_de_champ)
|
||||
type_de_champ = create(:type_de_champ_public)
|
||||
|
||||
procedure.types_de_champ << type_de_champ
|
||||
end
|
||||
end
|
||||
|
||||
trait :with_type_de_champ_private do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
type_de_champ = create(:type_de_champ_private)
|
||||
|
||||
procedure.types_de_champ_private << type_de_champ
|
||||
end
|
||||
end
|
||||
|
||||
trait :with_type_de_champ_mandatory do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
type_de_champ = create(:type_de_champ, mandatory: true)
|
||||
type_de_champ = create(:type_de_champ_public, mandatory: true)
|
||||
|
||||
procedure.types_de_champ << type_de_champ
|
||||
end
|
||||
|
@ -40,7 +48,7 @@ FactoryGirl.define do
|
|||
|
||||
trait :with_datetime do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
type_de_champ = create(:type_de_champ, mandatory: true, type_champ: :datetime)
|
||||
type_de_champ = create(:type_de_champ_public, mandatory: true, type_champ: :datetime)
|
||||
|
||||
procedure.types_de_champ << type_de_champ
|
||||
end
|
||||
|
|
9
spec/factories/type_de_champ_private.rb
Normal file
9
spec/factories/type_de_champ_private.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
FactoryGirl.define do
|
||||
factory :type_de_champ_private do
|
||||
libelle 'Description'
|
||||
description 'description de votre projet'
|
||||
type_champ 'text'
|
||||
order_place 1
|
||||
mandatory false
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
FactoryGirl.define do
|
||||
factory :type_de_champ do
|
||||
factory :type_de_champ_public do
|
||||
libelle 'Description'
|
||||
description 'description de votre projet'
|
||||
type_champ 'text'
|
29
spec/features/admin/move_down_type_de_champ_private_spec.rb
Normal file
29
spec/features/admin/move_down_type_de_champ_private_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'move down button type de champs', js: true do
|
||||
let(:administrateur) { create(:administrateur) }
|
||||
|
||||
before do
|
||||
login_as administrateur, scope: :administrateur
|
||||
end
|
||||
|
||||
let(:procedure) { create(:procedure, administrateur: administrateur) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) }
|
||||
let!(:type_de_champ_2) { create(:type_de_champ_private, procedure: procedure, order_place: 2) }
|
||||
let!(:type_de_champ_3) { create(:type_de_champ_private, procedure: procedure, order_place: 3) }
|
||||
|
||||
context 'when clicking on move down for type de champ 1' do
|
||||
before do
|
||||
visit admin_procedure_types_de_champ_private_path procedure.id
|
||||
page.find_by_id('btn_down_1').click
|
||||
wait_for_ajax
|
||||
type_de_champ_1.reload
|
||||
type_de_champ_2.reload
|
||||
end
|
||||
scenario 'it switches type_de_champ 1 and 2 place ' do
|
||||
expect(type_de_champ_1.order_place).to eq(2)
|
||||
expect(type_de_champ_2.order_place).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -8,10 +8,10 @@ feature 'move down button type de champs', js: true do
|
|||
end
|
||||
|
||||
let(:procedure) { create(:procedure, administrateur: administrateur) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
||||
let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure, order_place: 2) }
|
||||
let!(:type_de_champ_3) { create(:type_de_champ, procedure: procedure, order_place: 3) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
||||
let!(:type_de_champ_2) { create(:type_de_champ_public, procedure: procedure, order_place: 2) }
|
||||
let!(:type_de_champ_3) { create(:type_de_champ_public, procedure: procedure, order_place: 3) }
|
||||
|
||||
context 'when clicking on move down for type de champ 1' do
|
||||
before do
|
||||
|
|
29
spec/features/admin/move_up_type_de_champ_private_spec.rb
Normal file
29
spec/features/admin/move_up_type_de_champ_private_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'move up button type de champs', js: true do
|
||||
let(:administrateur) { create(:administrateur) }
|
||||
|
||||
before do
|
||||
login_as administrateur, scope: :administrateur
|
||||
end
|
||||
|
||||
let(:procedure) { create(:procedure, administrateur: administrateur) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) }
|
||||
let!(:type_de_champ_2) { create(:type_de_champ_private, procedure: procedure, order_place: 2) }
|
||||
let!(:type_de_champ_3) { create(:type_de_champ_private, procedure: procedure, order_place: 3) }
|
||||
|
||||
context 'when clicking on move down for type de champ 1' do
|
||||
before do
|
||||
visit admin_procedure_types_de_champ_private_path procedure.id
|
||||
page.find_by_id('btn_up_1').click
|
||||
wait_for_ajax
|
||||
type_de_champ_0.reload
|
||||
type_de_champ_1.reload
|
||||
end
|
||||
scenario 'it switches type_de_champ 1 and 2 place ' do
|
||||
expect(type_de_champ_0.order_place).to eq(1)
|
||||
expect(type_de_champ_1.order_place).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -8,10 +8,10 @@ feature 'move up button type de champs', js: true do
|
|||
end
|
||||
|
||||
let(:procedure) { create(:procedure, administrateur: administrateur) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
||||
let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure, order_place: 2) }
|
||||
let!(:type_de_champ_3) { create(:type_de_champ, procedure: procedure, order_place: 3) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
||||
let!(:type_de_champ_2) { create(:type_de_champ_public, procedure: procedure, order_place: 2) }
|
||||
let!(:type_de_champ_3) { create(:type_de_champ_public, procedure: procedure, order_place: 3) }
|
||||
|
||||
context 'when clicking on move down for type de champ 1' do
|
||||
before do
|
||||
|
|
7
spec/models/champ_private_spec.rb
Normal file
7
spec/models/champ_private_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ChampPrivate do
|
||||
require 'models/champ_shared_example.rb'
|
||||
|
||||
it_should_behave_like "champ_spec"
|
||||
end
|
7
spec/models/champ_public_spec.rb
Normal file
7
spec/models/champ_public_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ChampPublic do
|
||||
require 'models/champ_shared_example.rb'
|
||||
|
||||
it_should_behave_like "champ_spec"
|
||||
end
|
38
spec/models/champ_shared_example.rb
Normal file
38
spec/models/champ_shared_example.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
shared_examples 'champ_spec' do
|
||||
describe 'database columns' do
|
||||
it { is_expected.to have_db_column(:value) }
|
||||
end
|
||||
|
||||
describe 'associations' do
|
||||
it { is_expected.to belong_to(:dossier) }
|
||||
it { is_expected.to belong_to(:type_de_champ) }
|
||||
end
|
||||
|
||||
describe 'delegation' do
|
||||
it { is_expected.to delegate_method(:libelle).to(:type_de_champ) }
|
||||
it { is_expected.to delegate_method(:type_champ).to(:type_de_champ) }
|
||||
it { is_expected.to delegate_method(:order_place).to(:type_de_champ) }
|
||||
end
|
||||
|
||||
describe 'data_provide' do
|
||||
let(:champ) { create :champ }
|
||||
|
||||
subject { champ.data_provide }
|
||||
|
||||
context 'when type_champ is datetime' do
|
||||
before do
|
||||
champ.type_de_champ = create :type_de_champ_public, type_champ: 'datetime'
|
||||
end
|
||||
|
||||
it { is_expected.to eq 'datepicker' }
|
||||
end
|
||||
|
||||
context 'when type_champ is address' do
|
||||
before do
|
||||
champ.type_de_champ = create :type_de_champ_public, type_champ: 'address'
|
||||
end
|
||||
|
||||
it { is_expected.to eq 'typeahead' }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,40 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Champ do
|
||||
describe 'database columns' do
|
||||
it { is_expected.to have_db_column(:value) }
|
||||
end
|
||||
require 'models/champ_shared_example.rb'
|
||||
|
||||
describe 'associations' do
|
||||
it { is_expected.to belong_to(:dossier) }
|
||||
it { is_expected.to belong_to(:type_de_champ) }
|
||||
end
|
||||
|
||||
describe 'delegation' do
|
||||
it { is_expected.to delegate_method(:libelle).to(:type_de_champ) }
|
||||
it { is_expected.to delegate_method(:type_champ).to(:type_de_champ) }
|
||||
it { is_expected.to delegate_method(:order_place).to(:type_de_champ) }
|
||||
end
|
||||
|
||||
describe 'data_provide' do
|
||||
let(:champ) { create :champ }
|
||||
|
||||
subject { champ.data_provide }
|
||||
|
||||
context 'when type_champ is datetime' do
|
||||
before do
|
||||
champ.type_de_champ = create :type_de_champ, type_champ: 'datetime'
|
||||
end
|
||||
|
||||
it { is_expected.to eq 'datepicker' }
|
||||
end
|
||||
|
||||
context 'when type_champ is address' do
|
||||
before do
|
||||
champ.type_de_champ = create :type_de_champ, type_champ: 'address'
|
||||
end
|
||||
|
||||
it { is_expected.to eq 'typeahead' }
|
||||
end
|
||||
end
|
||||
it_should_behave_like "champ_spec"
|
||||
end
|
|
@ -92,12 +92,16 @@ describe Dossier do
|
|||
end
|
||||
|
||||
describe '#build_default_champs' do
|
||||
context 'when dossier is linked to a procedure' do
|
||||
context 'when dossier is linked to a procedure with type_de_champ_public and private' do
|
||||
let(:dossier) { create(:dossier, user: user) }
|
||||
|
||||
it 'build all champs needed' do
|
||||
expect(dossier.champs.count).to eq(1)
|
||||
end
|
||||
|
||||
it 'build all champs_private needed' do
|
||||
expect(dossier.champs_private.count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -591,12 +595,12 @@ describe Dossier do
|
|||
let(:dossier_2) { Dossier.new(id: 0, procedure: procedure_2) }
|
||||
|
||||
before do
|
||||
create :type_de_champ, libelle: 'type_1_1', order_place: 1, procedure: dossier_1.procedure
|
||||
create :type_de_champ, libelle: 'type_1_2', order_place: 2, procedure: dossier_1.procedure
|
||||
create :type_de_champ_public, libelle: 'type_1_1', order_place: 1, procedure: dossier_1.procedure
|
||||
create :type_de_champ_public, libelle: 'type_1_2', order_place: 2, procedure: dossier_1.procedure
|
||||
|
||||
create :type_de_champ, libelle: 'type_2_1', order_place: 1, procedure: dossier_2.procedure
|
||||
create :type_de_champ, libelle: 'type_2_2', order_place: 2, procedure: dossier_2.procedure
|
||||
create :type_de_champ, libelle: 'type_2_3', order_place: 3, procedure: dossier_2.procedure
|
||||
create :type_de_champ_public, libelle: 'type_2_1', order_place: 1, procedure: dossier_2.procedure
|
||||
create :type_de_champ_public, libelle: 'type_2_2', order_place: 2, procedure: dossier_2.procedure
|
||||
create :type_de_champ_public, libelle: 'type_2_3', order_place: 3, procedure: dossier_2.procedure
|
||||
|
||||
dossier_1.build_default_champs
|
||||
dossier_2.build_default_champs
|
||||
|
@ -604,7 +608,7 @@ describe Dossier do
|
|||
|
||||
subject { dossier.ordered_champs }
|
||||
|
||||
it { expect(Champ.where(dossier_id: 0).size).to eq 5 }
|
||||
it { expect(ChampPublic.where(dossier_id: 0).size).to eq 5 }
|
||||
|
||||
describe 'for dossier 1' do
|
||||
let(:dossier) { dossier_1 }
|
||||
|
@ -626,6 +630,48 @@ describe Dossier do
|
|||
|
||||
end
|
||||
|
||||
describe '#ordered_champs_private' do
|
||||
let!(:procedure_1) { create :procedure }
|
||||
let!(:procedure_2) { create :procedure }
|
||||
|
||||
let(:dossier_1) { Dossier.new(id: 0, procedure: procedure_1) }
|
||||
let(:dossier_2) { Dossier.new(id: 0, procedure: procedure_2) }
|
||||
|
||||
before do
|
||||
create :type_de_champ_private, libelle: 'type_1_1', order_place: 1, procedure: dossier_1.procedure
|
||||
create :type_de_champ_private, libelle: 'type_1_2', order_place: 2, procedure: dossier_1.procedure
|
||||
|
||||
create :type_de_champ_private, libelle: 'type_2_1', order_place: 1, procedure: dossier_2.procedure
|
||||
create :type_de_champ_private, libelle: 'type_2_2', order_place: 2, procedure: dossier_2.procedure
|
||||
create :type_de_champ_private, libelle: 'type_2_3', order_place: 3, procedure: dossier_2.procedure
|
||||
|
||||
dossier_1.build_default_champs
|
||||
dossier_2.build_default_champs
|
||||
end
|
||||
|
||||
subject { dossier.ordered_champs_private }
|
||||
|
||||
it { expect(ChampPrivate.where(dossier_id: 0).size).to eq 5 }
|
||||
|
||||
describe 'for dossier 1' do
|
||||
let(:dossier) { dossier_1 }
|
||||
|
||||
it { expect(subject.size).to eq 2 }
|
||||
it { expect(subject.first.type_de_champ.libelle).to eq 'type_1_1' }
|
||||
it { expect(subject.last.type_de_champ.libelle).to eq 'type_1_2' }
|
||||
end
|
||||
|
||||
describe 'for dossier 2' do
|
||||
let(:dossier) { dossier_2 }
|
||||
|
||||
it { expect(subject.size).to eq 3 }
|
||||
|
||||
it { expect(subject.first.type_de_champ.libelle).to eq 'type_2_1' }
|
||||
it { expect(subject.second.type_de_champ.libelle).to eq 'type_2_2' }
|
||||
it { expect(subject.last.type_de_champ.libelle).to eq 'type_2_3' }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#total_follow' do
|
||||
let(:dossier) { create(:dossier, :with_entreprise, user: user) }
|
||||
let(:dossier2) { create(:dossier, :with_entreprise, user: user) }
|
||||
|
|
|
@ -44,8 +44,8 @@ describe Procedure do
|
|||
|
||||
describe '#types_de_champ_ordered' do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
||||
subject { procedure.types_de_champ_ordered }
|
||||
it { expect(subject.first).to eq(type_de_champ_1) }
|
||||
it { expect(subject.last).to eq(type_de_champ_0) }
|
||||
|
@ -60,8 +60,8 @@ describe Procedure do
|
|||
it { expect(subject).to eq(false) }
|
||||
end
|
||||
context 'when procedure have 2 types de champ' do
|
||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
||||
context 'when index is not the last element' do
|
||||
it { expect(subject).to eq(true) }
|
||||
it 'switch order place' do
|
||||
|
@ -128,8 +128,8 @@ describe Procedure do
|
|||
let(:archived) { false }
|
||||
let(:published) { false }
|
||||
let(:procedure) { create(:procedure, archived: archived, published: published) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
||||
let!(:piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) }
|
||||
let!(:piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) }
|
||||
subject { procedure.clone }
|
||||
|
|
7
spec/models/type_de_champ_private_spec.rb
Normal file
7
spec/models/type_de_champ_private_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe TypeDeChampPrivate do
|
||||
require 'models/type_de_champ_shared_example'
|
||||
|
||||
it_should_behave_like "type_de_champ_spec"
|
||||
end
|
7
spec/models/type_de_champ_public_spec.rb
Normal file
7
spec/models/type_de_champ_public_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe TypeDeChampPublic do
|
||||
require 'models/type_de_champ_shared_example'
|
||||
|
||||
it_should_behave_like "type_de_champ_spec"
|
||||
end
|
44
spec/models/type_de_champ_shared_example.rb
Normal file
44
spec/models/type_de_champ_shared_example.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
shared_examples 'type_de_champ_spec' do
|
||||
describe 'database columns' do
|
||||
it { is_expected.to have_db_column(:libelle) }
|
||||
it { is_expected.to have_db_column(:type_champ) }
|
||||
it { is_expected.to have_db_column(:order_place) }
|
||||
it { is_expected.to have_db_column(:description) }
|
||||
end
|
||||
|
||||
describe 'associations' do
|
||||
it { is_expected.to belong_to(:procedure) }
|
||||
it { is_expected.to have_many(:champ) }
|
||||
end
|
||||
|
||||
describe 'validation' do
|
||||
context 'libelle' do
|
||||
it { is_expected.not_to allow_value(nil).for(:libelle) }
|
||||
it { is_expected.not_to allow_value('').for(:libelle) }
|
||||
it { is_expected.to allow_value('Montant projet').for(:libelle) }
|
||||
end
|
||||
|
||||
context 'type' do
|
||||
it { is_expected.not_to allow_value(nil).for(:type_champ) }
|
||||
it { is_expected.not_to allow_value('').for(:type_champ) }
|
||||
|
||||
it { is_expected.to allow_value('text').for(:type_champ) }
|
||||
it { is_expected.to allow_value('textarea').for(:type_champ) }
|
||||
it { is_expected.to allow_value('datetime').for(:type_champ) }
|
||||
it { is_expected.to allow_value('number').for(:type_champ) }
|
||||
it { is_expected.to allow_value('checkbox').for(:type_champ) }
|
||||
end
|
||||
|
||||
context 'order_place' do
|
||||
# it { is_expected.not_to allow_value(nil).for(:order_place) }
|
||||
# it { is_expected.not_to allow_value('').for(:order_place) }
|
||||
it { is_expected.to allow_value(1).for(:order_place) }
|
||||
end
|
||||
|
||||
context 'description' do
|
||||
it { is_expected.to allow_value(nil).for(:description) }
|
||||
it { is_expected.to allow_value('').for(:description) }
|
||||
it { is_expected.to allow_value('blabla').for(:description) }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,46 +1,9 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe TypeDeChamp do
|
||||
describe 'database columns' do
|
||||
it { is_expected.to have_db_column(:libelle) }
|
||||
it { is_expected.to have_db_column(:type_champ) }
|
||||
it { is_expected.to have_db_column(:order_place) }
|
||||
it { is_expected.to have_db_column(:description) }
|
||||
end
|
||||
|
||||
describe 'associations' do
|
||||
it { is_expected.to belong_to(:procedure) }
|
||||
it { is_expected.to have_many(:champ) }
|
||||
end
|
||||
require 'models/type_de_champ_shared_example'
|
||||
|
||||
describe 'validation' do
|
||||
context 'libelle' do
|
||||
it { is_expected.not_to allow_value(nil).for(:libelle) }
|
||||
it { is_expected.not_to allow_value('').for(:libelle) }
|
||||
it { is_expected.to allow_value('Montant projet').for(:libelle) }
|
||||
end
|
||||
|
||||
context 'type' do
|
||||
it { is_expected.not_to allow_value(nil).for(:type_champ) }
|
||||
it { is_expected.not_to allow_value('').for(:type_champ) }
|
||||
|
||||
it { is_expected.to allow_value('text').for(:type_champ) }
|
||||
it { is_expected.to allow_value('textarea').for(:type_champ) }
|
||||
it { is_expected.to allow_value('datetime').for(:type_champ) }
|
||||
it { is_expected.to allow_value('number').for(:type_champ) }
|
||||
it { is_expected.to allow_value('checkbox').for(:type_champ) }
|
||||
end
|
||||
|
||||
context 'order_place' do
|
||||
# it { is_expected.not_to allow_value(nil).for(:order_place) }
|
||||
# it { is_expected.not_to allow_value('').for(:order_place) }
|
||||
it { is_expected.to allow_value(1).for(:order_place) }
|
||||
end
|
||||
|
||||
context 'description' do
|
||||
it { is_expected.to allow_value(nil).for(:description) }
|
||||
it { is_expected.to allow_value('').for(:description) }
|
||||
it { is_expected.to allow_value('blabla').for(:description) }
|
||||
end
|
||||
end
|
||||
it_should_behave_like "type_de_champ_spec"
|
||||
end
|
||||
|
||||
|
|
|
@ -6,11 +6,12 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do
|
|||
describe 'fields sorted' do
|
||||
let(:first_libelle) { 'salut la compagnie' }
|
||||
let(:last_libelle) { 'je suis bien sur la page' }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1, libelle: last_libelle) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0, libelle: first_libelle) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1, libelle: last_libelle) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0, libelle: first_libelle) }
|
||||
before do
|
||||
procedure.reload
|
||||
assign(:procedure, procedure)
|
||||
assign(:types_de_champ_facade, AdminTypesDeChampFacades.new(false, procedure))
|
||||
render
|
||||
end
|
||||
it 'sorts by order place' do
|
||||
|
@ -22,6 +23,7 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do
|
|||
subject do
|
||||
procedure.reload
|
||||
assign(:procedure, procedure)
|
||||
assign(:types_de_champ_facade, AdminTypesDeChampFacades.new(false, procedure))
|
||||
render
|
||||
rendered
|
||||
end
|
||||
|
@ -30,15 +32,15 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do
|
|||
it { expect(subject).not_to have_css('.fa-chevron-up') }
|
||||
end
|
||||
context 'when there is only one field in database' do
|
||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
||||
it { expect(subject).not_to have_css('#btn_down_0') }
|
||||
it { expect(subject).not_to have_css('#btn_up_0') }
|
||||
it { expect(subject).not_to have_css('#btn_up_1') }
|
||||
it { expect(subject).not_to have_css('#btn_down_1') }
|
||||
end
|
||||
context 'when there are 2 fields in database' do
|
||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
||||
it { expect(subject).to have_css('#btn_down_0') }
|
||||
it { expect(subject).not_to have_css('#btn_up_0') }
|
||||
it { expect(subject).to have_css('#btn_up_1') }
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'admin/types_de_champ/show.html.haml', type: :view do
|
||||
let(:procedure) { create(:procedure) }
|
||||
|
||||
describe 'fields sorted' do
|
||||
let(:first_libelle) { 'salut la compagnie' }
|
||||
let(:last_libelle) { 'je suis bien sur la page' }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1, libelle: last_libelle) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0, libelle: first_libelle) }
|
||||
before do
|
||||
procedure.reload
|
||||
assign(:procedure, procedure)
|
||||
assign(:types_de_champ_facade, AdminTypesDeChampFacades.new(true, procedure))
|
||||
render
|
||||
end
|
||||
it 'sorts by order place' do
|
||||
expect(rendered).to match(/#{first_libelle}.*#{last_libelle}/m)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'elements presents or not' do
|
||||
subject do
|
||||
procedure.reload
|
||||
assign(:procedure, procedure)
|
||||
assign(:types_de_champ_facade, AdminTypesDeChampFacades.new(true, procedure))
|
||||
render
|
||||
rendered
|
||||
end
|
||||
|
||||
describe 'mandatory checkbox' do
|
||||
it 'no mandatory checkbox are present' do
|
||||
expect(subject).not_to have_css('.form-group.mandatory')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'arrow button' do
|
||||
context 'when there is no field in database' do
|
||||
it { expect(subject).not_to have_css('.fa-chevron-down') }
|
||||
it { expect(subject).not_to have_css('.fa-chevron-up') }
|
||||
end
|
||||
context 'when there is only one field in database' do
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) }
|
||||
it { expect(subject).not_to have_css('#btn_down_0') }
|
||||
it { expect(subject).not_to have_css('#btn_up_0') }
|
||||
it { expect(subject).not_to have_css('#btn_up_1') }
|
||||
it { expect(subject).not_to have_css('#btn_down_1') }
|
||||
end
|
||||
context 'when there are 2 fields in database' do
|
||||
let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) }
|
||||
it { expect(subject).to have_css('#btn_down_0') }
|
||||
it { expect(subject).not_to have_css('#btn_up_0') }
|
||||
it { expect(subject).to have_css('#btn_up_1') }
|
||||
it { expect(subject).not_to have_css('#btn_down_1') }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue