Administrateur can be define private champs => same as typical champs
This commit is contained in:
parent
26b5e4cb24
commit
116dd0d94f
41 changed files with 601 additions and 113 deletions
|
@ -21,7 +21,7 @@ class Admin::TypesDeChampController < AdminController
|
||||||
def update_params
|
def update_params
|
||||||
params
|
params
|
||||||
.require(:procedure)
|
.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
|
end
|
||||||
|
|
||||||
def move_up
|
def move_up
|
||||||
|
|
44
app/controllers/admin/types_de_champ_private_controller.rb
Normal file
44
app/controllers/admin/types_de_champ_private_controller.rb
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
class Admin::TypesDeChampPrivateController < AdminController
|
||||||
|
before_action :retrieve_procedure
|
||||||
|
before_action :procedure_locked?
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@procedure.types_de_champ_private.destroy(params[:id])
|
||||||
|
render 'show', format: :js
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render json: { message: 'Champ not found' }, status: 404
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@procedure.update_attributes(update_params)
|
||||||
|
flash.now.notice = 'Modifications sauvegardées'
|
||||||
|
render '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
|
||||||
|
render 'show', format: :js
|
||||||
|
else
|
||||||
|
render json: {}, status: 400
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def move_down
|
||||||
|
if @procedure.switch_types_de_champ_private params[:index].to_i
|
||||||
|
render 'show', format: :js
|
||||||
|
else
|
||||||
|
render json: {}, status: 400
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,12 +1,13 @@
|
||||||
|
|
||||||
class TypeDeChampDecorator < Draper::Decorator
|
class TypeDeChampDecorator < Draper::Decorator
|
||||||
|
|
||||||
delegate_all
|
delegate_all
|
||||||
|
|
||||||
def button_up params
|
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
|
end
|
||||||
|
|
||||||
def button_down params
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -23,15 +24,19 @@ class TypeDeChampDecorator < Draper::Decorator
|
||||||
%w(btn btn-default form-control fa)
|
%w(btn btn-default form-control fa)
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_up_button?(index)
|
def display_up_button?(index, private)
|
||||||
!(index == 0 || count_type_de_champ < 2)
|
!(index == 0 || count_type_de_champ(private) < 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_down_button?(index)
|
def display_down_button?(index, private)
|
||||||
(index + 1) < count_type_de_champ
|
(index + 1) < count_type_de_champ(private)
|
||||||
end
|
end
|
||||||
|
|
||||||
def count_type_de_champ
|
def count_type_de_champ private
|
||||||
@count_type_de_champ ||= procedure.types_de_champ.count
|
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
|
||||||
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
|
|
@ -1,7 +1,7 @@
|
||||||
class Procedure < ActiveRecord::Base
|
class Procedure < ActiveRecord::Base
|
||||||
has_many :types_de_piece_justificative, dependent: :destroy
|
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, class_name: 'TypeDeChampPrivate', dependent: :destroy
|
has_many :types_de_champ_private, dependent: :destroy
|
||||||
has_many :dossiers
|
has_many :dossiers
|
||||||
|
|
||||||
has_one :procedure_path, dependent: :destroy
|
has_one :procedure_path, dependent: :destroy
|
||||||
|
@ -18,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_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 :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 :module_api_carto
|
||||||
|
accepts_nested_attributes_for :types_de_champ_private
|
||||||
|
|
||||||
mount_uploader :logo, ProcedureLogoUploader
|
mount_uploader :logo, ProcedureLogoUploader
|
||||||
|
|
||||||
|
@ -36,6 +37,10 @@ class Procedure < ActiveRecord::Base
|
||||||
types_de_champ.order(:order_place)
|
types_de_champ.order(:order_place)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def types_de_champ_private_ordered
|
||||||
|
types_de_champ_private.order(:order_place)
|
||||||
|
end
|
||||||
|
|
||||||
def types_de_piece_justificative_ordered
|
def types_de_piece_justificative_ordered
|
||||||
types_de_piece_justificative.order(:order_place)
|
types_de_piece_justificative.order(:order_place)
|
||||||
end
|
end
|
||||||
|
@ -52,6 +57,10 @@ class Procedure < ActiveRecord::Base
|
||||||
switch_list_order(types_de_champ_ordered, index_of_first_element)
|
switch_list_order(types_de_champ_ordered, index_of_first_element)
|
||||||
end
|
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
|
def switch_types_de_piece_justificative index_of_first_element
|
||||||
switch_list_order(types_de_piece_justificative_ordered, index_of_first_element)
|
switch_list_order(types_de_piece_justificative_ordered, index_of_first_element)
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,8 +18,6 @@ class TypeDeChamp < ActiveRecord::Base
|
||||||
|
|
||||||
has_many :champ, dependent: :destroy
|
has_many :champ, dependent: :destroy
|
||||||
|
|
||||||
default_scope { where(private: false) }
|
|
||||||
|
|
||||||
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
||||||
validates :type_champ, presence: true, allow_blank: false, allow_nil: false
|
validates :type_champ, presence: true, allow_blank: false, allow_nil: false
|
||||||
# validates :order_place, presence: true, allow_blank: false, allow_nil: false
|
# validates :order_place, presence: true, allow_blank: false, allow_nil: false
|
||||||
|
|
|
@ -1,9 +1,3 @@
|
||||||
class TypeDeChampPrivate < TypeDeChamp
|
class TypeDeChampPrivate < TypeDeChamp
|
||||||
after_initialize :force_private_value
|
|
||||||
|
|
||||||
default_scope { where(private: true) }
|
|
||||||
|
|
||||||
def force_private_value
|
|
||||||
self.private = true
|
|
||||||
end
|
|
||||||
end
|
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
|
|
@ -3,6 +3,5 @@ class TypeDeChampSerializer < ActiveModel::Serializer
|
||||||
:libelle,
|
:libelle,
|
||||||
{:type_champ => :type},
|
{:type_champ => :type},
|
||||||
:order_place,
|
:order_place,
|
||||||
:description,
|
:description
|
||||||
:private
|
|
||||||
end
|
end
|
|
@ -16,5 +16,9 @@
|
||||||
= link_to_unless(@procedure.locked?, 'Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure)) do
|
= link_to_unless(@procedure.locked?, 'Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure)) do
|
||||||
= link_to('Pièces justificatives', '#')
|
= 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' }
|
%li{ class: ('active' if active == 'Prévisualisation'), style: 'float:right' }
|
||||||
= link_to('Prévisualisation', admin_procedure_previsualisation_path(@procedure), {style: 'font-style: italic;'})
|
= link_to('Prévisualisation', admin_procedure_previsualisation_path(@procedure), {style: 'font-style: italic;'})
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
.form-group.type
|
.form-group.type
|
||||||
%h4 Type
|
%h4 Type
|
||||||
= ff.select :type_champ, TypeDeChamp.type_champs, {}, {class: 'form-control type_champ'}
|
= ff.select :type_champ, TypeDeChampPublic.type_champs, {}, {class: 'form-control type_champ'}
|
||||||
|
|
||||||
.form-group.description
|
.form-group.description
|
||||||
%h4 Description
|
%h4 Description
|
||||||
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
= ff.hidden_field :order_place, value: ff.index
|
= ff.hidden_field :order_place, value: ff.index
|
||||||
|
= ff.hidden_field :type
|
||||||
= ff.hidden_field :id
|
= ff.hidden_field :id
|
||||||
- unless ff.object.id.nil?
|
- unless ff.object.id.nil?
|
||||||
.form-group
|
.form-group
|
||||||
|
@ -26,7 +27,6 @@
|
||||||
= ff.object.button_up(index: ff.index, url: move_up_admin_procedure_types_de_champ_path(@procedure, ff.index))
|
= 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_down(index: ff.index, url: move_down_admin_procedure_types_de_champ_path(@procedure, ff.index))
|
||||||
|
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
%br
|
%br
|
||||||
- if ff.object.id.nil?
|
- if ff.object.id.nil?
|
||||||
|
|
|
@ -3,4 +3,4 @@
|
||||||
= f.submit "Enregistrer", class: 'btn btn-success', id: :save
|
= f.submit "Enregistrer", class: 'btn btn-success', id: :save
|
||||||
%hr
|
%hr
|
||||||
#new_type_de_champ
|
#new_type_de_champ
|
||||||
= render partial: 'fields', locals: { types_de_champ: TypeDeChamp.new.decorate, f: f }
|
= render partial: 'fields', locals: { types_de_champ: TypeDeChampPublic.new.decorate, f: f }
|
||||||
|
|
38
app/views/admin/types_de_champ_private/_fields.html.haml
Normal file
38
app/views/admin/types_de_champ_private/_fields.html.haml
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
= f.fields_for :types_de_champ_private, types_de_champ_private, remote: true do |ff|
|
||||||
|
.form-inline{class:"#{ff.object.object.type_champ == 'header_section' ? 'header_section' : ''}"}
|
||||||
|
.form-group.libelle
|
||||||
|
%h4 Libellé
|
||||||
|
= ff.text_field :libelle, class: 'form-control libelle', placeholder: 'Libellé'
|
||||||
|
|
||||||
|
.form-group.type
|
||||||
|
%h4 Type
|
||||||
|
= ff.select :type_champ, TypeDeChampPrivate.type_champs, {}, {class: 'form-control type_champ'}
|
||||||
|
|
||||||
|
.form-group.description
|
||||||
|
%h4 Description
|
||||||
|
= ff.text_area :description, class: 'form-control description', placeholder: 'Description'
|
||||||
|
|
||||||
|
.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_private_path(@procedure, ff.index), private: true)
|
||||||
|
= ff.object.button_down(index: ff.index, url: move_down_admin_procedure_types_de_champ_private_path(@procedure, ff.index), private: true)
|
||||||
|
|
||||||
|
.form-group
|
||||||
|
%br
|
||||||
|
- if ff.object.id.nil?
|
||||||
|
= f.submit "Ajouter le champ", class: 'btn btn-success', id: :add_type_de_champ_private
|
||||||
|
- else
|
||||||
|
= link_to("", admin_procedure_type_de_champ_private_path(@procedure, ff.object.id), method: :delete, remote: true, id: "delete_type_de_champ_private_#{ff.object.id}", class: %w(form-control btn btn-danger fa fa-trash-o) )
|
||||||
|
|
||||||
|
|
6
app/views/admin/types_de_champ_private/_form.html.haml
Normal file
6
app/views/admin/types_de_champ_private/_form.html.haml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
= form_for [:admin, @procedure], url: admin_procedure_types_de_champ_private_path(@procedure) , remote: true do |f|
|
||||||
|
= render partial: 'fields', locals: { types_de_champ_private: @procedure.types_de_champ_private_ordered.decorate, f: f }
|
||||||
|
= f.submit "Enregistrer", class: 'btn btn-success', id: :save
|
||||||
|
%hr
|
||||||
|
#new_type_de_champ
|
||||||
|
= render partial: 'fields', locals: { types_de_champ_private: TypeDeChampPrivate.new.decorate, f: f }
|
4
app/views/admin/types_de_champ_private/show.html.haml
Normal file
4
app/views/admin/types_de_champ_private/show.html.haml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
=render partial: 'admin/procedures/head', locals: {active: 'Champs privés'}
|
||||||
|
|
||||||
|
#liste_champ
|
||||||
|
= render partial: 'form'
|
5
app/views/admin/types_de_champ_private/show.js.erb
Normal file
5
app/views/admin/types_de_champ_private/show.js.erb
Normal file
|
@ -0,0 +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 } ) %>");
|
||||||
|
on_change_type_de_champ_select ();
|
|
@ -13,6 +13,7 @@ ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||||
inflect.irregular 'piece_justificative', 'pieces_justificatives'
|
inflect.irregular 'piece_justificative', 'pieces_justificatives'
|
||||||
inflect.irregular 'type_de_piece_justificative', 'types_de_piece_justificative'
|
inflect.irregular 'type_de_piece_justificative', 'types_de_piece_justificative'
|
||||||
inflect.irregular 'type_de_champ', 'types_de_champ'
|
inflect.irregular 'type_de_champ', 'types_de_champ'
|
||||||
|
inflect.irregular 'type_de_champ_private', 'types_de_champ_private'
|
||||||
inflect.irregular 'assign_to', 'assign_tos'
|
inflect.irregular 'assign_to', 'assign_tos'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -93,10 +93,20 @@ Rails.application.routes.draw do
|
||||||
get 'profile' => 'profile#show', as: :profile
|
get 'profile' => 'profile#show', as: :profile
|
||||||
|
|
||||||
resources :procedures do
|
resources :procedures do
|
||||||
|
resources :types_de_champ, only: [:destroy]
|
||||||
resource :types_de_champ, only: [:show, :update] do
|
resource :types_de_champ, only: [:show, :update] do
|
||||||
post '/:index/move_up' => 'types_de_champ#move_up', as: :move_up
|
post '/:index/move_up' => 'types_de_champ#move_up', as: :move_up
|
||||||
post '/:index/move_down' => 'types_de_champ#move_down', as: :move_down
|
post '/:index/move_down' => 'types_de_champ#move_down', as: :move_down
|
||||||
end
|
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
|
resource :pieces_justificatives, only: [:show, :update] do
|
||||||
post '/:index/move_up' => 'pieces_justificatives#move_up', as: :move_up
|
post '/:index/move_up' => 'pieces_justificatives#move_up', as: :move_up
|
||||||
post '/:index/move_down' => 'pieces_justificatives#move_down', as: :move_down
|
post '/:index/move_down' => 'pieces_justificatives#move_down', as: :move_down
|
||||||
|
@ -111,9 +121,6 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
resource :previsualisation, only: [:show]
|
resource :previsualisation, only: [:show]
|
||||||
|
|
||||||
resources :types_de_champ, only: [:destroy]
|
|
||||||
resource :pieces_justificatives, only: [:show, :update]
|
|
||||||
resources :pieces_justificatives, only: :destroy
|
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :accompagnateurs do
|
namespace :accompagnateurs do
|
||||||
|
|
|
@ -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
|
|
@ -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: 20160802131031) do
|
ActiveRecord::Schema.define(version: 20160803081304) 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"
|
||||||
|
@ -296,7 +296,7 @@ ActiveRecord::Schema.define(version: 20160802131031) do
|
||||||
t.integer "procedure_id"
|
t.integer "procedure_id"
|
||||||
t.text "description"
|
t.text "description"
|
||||||
t.boolean "mandatory", default: false
|
t.boolean "mandatory", default: false
|
||||||
t.boolean "private", default: false
|
t.string "type"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "types_de_piece_justificative", force: :cascade do |t|
|
create_table "types_de_piece_justificative", force: :cascade do |t|
|
||||||
|
|
|
@ -121,7 +121,7 @@ describe Admin::TypesDeChampController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context 'when procedure and type de champs are not linked' do
|
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 }
|
let(:type_de_champ_id) { type_de_champ.id }
|
||||||
it { expect(subject.status).to eq(404) }
|
it { expect(subject.status).to eq(404) }
|
||||||
end
|
end
|
||||||
|
@ -136,20 +136,20 @@ describe Admin::TypesDeChampController, type: :controller do
|
||||||
end
|
end
|
||||||
context 'when procedure have only one type de champ' do
|
context 'when procedure have only one type de champ' do
|
||||||
let(:index) { 1 }
|
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) }
|
it { expect(subject.status).to eq(400) }
|
||||||
end
|
end
|
||||||
context 'when procedure have tow type de champs' do
|
context 'when procedure have tow type de champs' do
|
||||||
context 'when index == 0' do
|
context 'when index == 0' do
|
||||||
let(:index) { 0 }
|
let(:index) { 0 }
|
||||||
let!(:type_de_champ_1) { 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, procedure: procedure) }
|
let!(:type_de_champ_2) { create(:type_de_champ_public, procedure: procedure) }
|
||||||
it { expect(subject.status).to eq(400) }
|
it { expect(subject.status).to eq(400) }
|
||||||
end
|
end
|
||||||
context 'when index > 0' do
|
context 'when index > 0' do
|
||||||
let(:index) { 1 }
|
let(:index) { 1 }
|
||||||
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) }
|
||||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
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.status).to eq(200) }
|
||||||
it { expect(subject).to render_template('show') }
|
it { expect(subject).to render_template('show') }
|
||||||
|
@ -174,12 +174,12 @@ describe Admin::TypesDeChampController, type: :controller do
|
||||||
it { expect(subject.status).to eq(400) }
|
it { expect(subject.status).to eq(400) }
|
||||||
end
|
end
|
||||||
context 'when procedure have only one type de champ' do
|
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) }
|
it { expect(subject.status).to eq(400) }
|
||||||
end
|
end
|
||||||
context 'when procedure have 2 type de champ' do
|
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_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
||||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
||||||
context 'when index represent last type_de_champ' do
|
context 'when index represent last type_de_champ' do
|
||||||
let(:index) { 1 }
|
let(:index) { 1 }
|
||||||
it { expect(subject.status).to eq(400) }
|
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
|
|
@ -230,7 +230,7 @@ describe API::V1::DossiersController do
|
||||||
it { expect(subject[:libelle]).to eq('Description') }
|
it { expect(subject[:libelle]).to eq('Description') }
|
||||||
it { expect(subject[:description]).to eq('description de votre projet') }
|
it { expect(subject[:description]).to eq('description de votre projet') }
|
||||||
it { expect(subject.keys.include?(:order_place)).to be_truthy }
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,9 +5,9 @@ describe TypeDeChampDecorator do
|
||||||
let(:procedure) { create(:procedure) }
|
let(:procedure) { create(:procedure) }
|
||||||
let(:url) { 'http://localhost' }
|
let(:url) { 'http://localhost' }
|
||||||
let(:params) { { url: url, index: index } }
|
let(:params) { { url: url, index: index } }
|
||||||
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) }
|
||||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
||||||
let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure, order_place: 2) }
|
let!(:type_de_champ_2) { create(:type_de_champ_public, procedure: procedure, order_place: 2) }
|
||||||
|
|
||||||
describe '#button_up' do
|
describe '#button_up' do
|
||||||
|
|
||||||
|
|
|
@ -24,15 +24,23 @@ FactoryGirl.define do
|
||||||
|
|
||||||
trait :with_type_de_champ do
|
trait :with_type_de_champ do
|
||||||
after(:build) do |procedure, _evaluator|
|
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
|
procedure.types_de_champ << type_de_champ
|
||||||
end
|
end
|
||||||
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
|
trait :with_type_de_champ_mandatory do
|
||||||
after(:build) do |procedure, _evaluator|
|
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
|
procedure.types_de_champ << type_de_champ
|
||||||
end
|
end
|
||||||
|
@ -40,7 +48,7 @@ FactoryGirl.define do
|
||||||
|
|
||||||
trait :with_datetime do
|
trait :with_datetime do
|
||||||
after(:build) do |procedure, _evaluator|
|
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
|
procedure.types_de_champ << type_de_champ
|
||||||
end
|
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
|
FactoryGirl.define do
|
||||||
factory :type_de_champ do
|
factory :type_de_champ_public do
|
||||||
libelle 'Description'
|
libelle 'Description'
|
||||||
description 'description de votre projet'
|
description 'description de votre projet'
|
||||||
type_champ 'text'
|
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
|
end
|
||||||
|
|
||||||
let(:procedure) { create(:procedure, administrateur: administrateur) }
|
let(:procedure) { create(:procedure, administrateur: administrateur) }
|
||||||
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) }
|
||||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
||||||
let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure, order_place: 2) }
|
let!(:type_de_champ_2) { create(:type_de_champ_public, procedure: procedure, order_place: 2) }
|
||||||
let!(:type_de_champ_3) { create(:type_de_champ, procedure: procedure, order_place: 3) }
|
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
|
context 'when clicking on move down for type de champ 1' do
|
||||||
before 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
|
end
|
||||||
|
|
||||||
let(:procedure) { create(:procedure, administrateur: administrateur) }
|
let(:procedure) { create(:procedure, administrateur: administrateur) }
|
||||||
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) }
|
||||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
||||||
let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure, order_place: 2) }
|
let!(:type_de_champ_2) { create(:type_de_champ_public, procedure: procedure, order_place: 2) }
|
||||||
let!(:type_de_champ_3) { create(:type_de_champ, procedure: procedure, order_place: 3) }
|
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
|
context 'when clicking on move down for type de champ 1' do
|
||||||
before do
|
before do
|
||||||
|
|
|
@ -23,7 +23,7 @@ describe Champ do
|
||||||
|
|
||||||
context 'when type_champ is datetime' do
|
context 'when type_champ is datetime' do
|
||||||
before do
|
before do
|
||||||
champ.type_de_champ = create :type_de_champ, type_champ: 'datetime'
|
champ.type_de_champ = create :type_de_champ_public, type_champ: 'datetime'
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to eq 'datepicker' }
|
it { is_expected.to eq 'datepicker' }
|
||||||
|
@ -31,7 +31,7 @@ describe Champ do
|
||||||
|
|
||||||
context 'when type_champ is address' do
|
context 'when type_champ is address' do
|
||||||
before do
|
before do
|
||||||
champ.type_de_champ = create :type_de_champ, type_champ: 'address'
|
champ.type_de_champ = create :type_de_champ_public, type_champ: 'address'
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to eq 'typeahead' }
|
it { is_expected.to eq 'typeahead' }
|
||||||
|
|
|
@ -591,12 +591,12 @@ describe Dossier do
|
||||||
let(:dossier_2) { Dossier.new(id: 0, procedure: procedure_2) }
|
let(:dossier_2) { Dossier.new(id: 0, procedure: procedure_2) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
create :type_de_champ, libelle: 'type_1_1', order_place: 1, procedure: dossier_1.procedure
|
create :type_de_champ_public, 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_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_public, 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_public, 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_3', order_place: 3, procedure: dossier_2.procedure
|
||||||
|
|
||||||
dossier_1.build_default_champs
|
dossier_1.build_default_champs
|
||||||
dossier_2.build_default_champs
|
dossier_2.build_default_champs
|
||||||
|
|
|
@ -44,8 +44,8 @@ describe Procedure do
|
||||||
|
|
||||||
describe '#types_de_champ_ordered' do
|
describe '#types_de_champ_ordered' do
|
||||||
let(:procedure) { create(:procedure) }
|
let(:procedure) { create(:procedure) }
|
||||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
||||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 0) }
|
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
||||||
subject { procedure.types_de_champ_ordered }
|
subject { procedure.types_de_champ_ordered }
|
||||||
it { expect(subject.first).to eq(type_de_champ_1) }
|
it { expect(subject.first).to eq(type_de_champ_1) }
|
||||||
it { expect(subject.last).to eq(type_de_champ_0) }
|
it { expect(subject.last).to eq(type_de_champ_0) }
|
||||||
|
@ -60,8 +60,8 @@ describe Procedure do
|
||||||
it { expect(subject).to eq(false) }
|
it { expect(subject).to eq(false) }
|
||||||
end
|
end
|
||||||
context 'when procedure have 2 types de champ' do
|
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_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
||||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
||||||
context 'when index is not the last element' do
|
context 'when index is not the last element' do
|
||||||
it { expect(subject).to eq(true) }
|
it { expect(subject).to eq(true) }
|
||||||
it 'switch order place' do
|
it 'switch order place' do
|
||||||
|
@ -128,8 +128,8 @@ describe Procedure do
|
||||||
let(:archived) { false }
|
let(:archived) { false }
|
||||||
let(:published) { false }
|
let(:published) { false }
|
||||||
let(:procedure) { create(:procedure, archived: archived, published: published) }
|
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_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
||||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
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_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) }
|
let!(:piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) }
|
||||||
subject { procedure.clone }
|
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'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe TypeDeChamp do
|
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
|
require 'models/type_de_champ_shared_example'
|
||||||
it { is_expected.to belong_to(:procedure) }
|
|
||||||
it { is_expected.to have_many(:champ) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'validation' do
|
it_should_behave_like "type_de_champ_spec"
|
||||||
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
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do
|
||||||
describe 'fields sorted' do
|
describe 'fields sorted' do
|
||||||
let(:first_libelle) { 'salut la compagnie' }
|
let(:first_libelle) { 'salut la compagnie' }
|
||||||
let(:last_libelle) { 'je suis bien sur la page' }
|
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_1) { create(:type_de_champ_public, 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_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0, libelle: first_libelle) }
|
||||||
before do
|
before do
|
||||||
procedure.reload
|
procedure.reload
|
||||||
assign(:procedure, procedure)
|
assign(:procedure, procedure)
|
||||||
|
@ -30,15 +30,15 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do
|
||||||
it { expect(subject).not_to have_css('.fa-chevron-up') }
|
it { expect(subject).not_to have_css('.fa-chevron-up') }
|
||||||
end
|
end
|
||||||
context 'when there is only one field in database' do
|
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_down_0') }
|
||||||
it { expect(subject).not_to have_css('#btn_up_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_up_1') }
|
||||||
it { expect(subject).not_to have_css('#btn_down_1') }
|
it { expect(subject).not_to have_css('#btn_down_1') }
|
||||||
end
|
end
|
||||||
context 'when there are 2 fields in database' do
|
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_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
||||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
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).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_0') }
|
||||||
it { expect(subject).to have_css('#btn_up_1') }
|
it { expect(subject).to have_css('#btn_up_1') }
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'admin/types_de_champ_private/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)
|
||||||
|
render
|
||||||
|
end
|
||||||
|
it 'sorts by order place' do
|
||||||
|
expect(rendered).to match(/#{first_libelle}.*#{last_libelle}/m)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'arrow button' do
|
||||||
|
subject do
|
||||||
|
procedure.reload
|
||||||
|
assign(:procedure, procedure)
|
||||||
|
render
|
||||||
|
rendered
|
||||||
|
end
|
||||||
|
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
|
Loading…
Reference in a new issue