Merge pull request #2338 from tchak/drop-old-champs-editor

Remove old champ editor
This commit is contained in:
Pierre de La Morinerie 2018-08-07 14:24:53 +02:00 committed by GitHub
commit 430763fa02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 0 additions and 1276 deletions

View file

@ -1,5 +0,0 @@
$(document).on('turbolinks:load', activeSelect2);
function activeSelect2() {
$('select.select2').select2({ theme: "bootstrap", width: '100%' });
}

View file

@ -51,8 +51,6 @@
// = require font-awesome
// = require franceconnect
// = require bootstrap-wysihtml5
// = require select2
// = require select2-bootstrap
@import "constants";
@import "bootstrap-sprockets";

View file

@ -1,62 +1,4 @@
class Users::DescriptionController < UsersController
before_action only: [:show] do
authorized_routes? self.class
end
before_action :check_autorisation_donnees, only: [:show]
before_action :check_starter_dossier_informations, only: [:show]
def show
@dossier ||= current_user_dossier.decorate
@procedure = @dossier.procedure
@champs = @dossier.ordered_champs
@headers = @champs.select { |c| c.type_champ == 'header_section' }
if !@dossier.can_be_en_construction?
flash[:alert] = t('errors.messages.procedure_archived')
end
rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for(root_path)
end
def update
dossier = current_user_dossier
procedure = dossier.procedure
return head :forbidden if !dossier.can_be_en_construction?
ChampsService.save_champs(dossier.champs, params) if params[:champs]
errors_upload = PiecesJustificativesService.upload!(dossier, current_user, params) + ChampsService.check_piece_justificative_files(dossier.champs)
return redirect_to_description_with_errors(dossier, errors_upload) if errors_upload.any?
if params[:champs] && !(brouillon_submission? || brouillon_then_dashboard_submission?)
errors =
ChampsService.build_error_messages(dossier.champs) +
PiecesJustificativesService.missing_pj_error_messages(dossier)
return redirect_to_description_with_errors(dossier, errors) if errors.any?
end
if brouillon_submission?
flash.notice = 'Votre brouillon a bien été sauvegardé.'
redirect_to users_dossier_description_path(dossier.id)
elsif brouillon_then_dashboard_submission?
redirect_to url_for(controller: :dossiers, action: :index, liste: :brouillon)
else
if dossier.brouillon?
dossier.en_construction!
# TODO move to model
NotificationMailer.send_initiated_notification(dossier).deliver_later
end
flash.notice = 'Félicitations, votre demande a bien été enregistrée.'
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: dossier.id)
end
end
def pieces_justificatives
invite = current_user.invite? params[:dossier_id]
@ -78,46 +20,4 @@ class Users::DescriptionController < UsersController
redirect_to users_dossier_recapitulatif_path
end
def self.route_authorization
{
states: [:brouillon, :en_construction]
}
end
private
def redirect_to_description_with_errors(dossier, errors)
errors_to_display = if errors.count > 3
errors.take(3) + ['...']
else
errors
end
flash.alert = errors_to_display
redirect_to users_dossier_description_path(dossier_id: dossier.id)
end
def brouillon_submission?
params[:submit_action] == 'brouillon'
end
def brouillon_then_dashboard_submission?
params[:submit_action] == 'brouillon_then_dashboard'
end
def check_autorisation_donnees
@dossier = current_user_dossier
redirect_to url_for(users_dossier_path(@dossier.id)) if @dossier.autorisation_donnees.nil? || !@dossier.autorisation_donnees
end
def check_starter_dossier_informations
@dossier ||= current_user_dossier
if (@dossier.procedure.for_individual? && @dossier.individual.nil?) ||
(!@dossier.procedure.for_individual? && @dossier.etablissement.nil?)
redirect_to url_for(users_dossier_path(@dossier.id))
end
end
end

View file

@ -11,7 +11,6 @@ import jQuery from 'jquery';
// required by the browsers we support will be included.
import 'babel-polyfill';
import 'select2';
import 'typeahead.js';
import '../shared/rails-ujs-fix';

View file

@ -1,14 +0,0 @@
- render_partial_url = private ? 'users/description/champs/header_private_section' : 'users/description/champs/header_section'
- @champs = @champs_private if private
- @headers = @headers_private if private
- if @headers.present?
- if @champs.first.type_champ != 'header_section'
= render partial: render_partial_url, locals: { libelle: 'Dossier', order_place: -1, champs: @champs }
- @headers.each do |header|
.row
%div{ class: "type-champ-#{header.type_champ.gsub('_', '-')}" }
= render partial: render_partial_url, locals: { libelle: header.libelle, order_place: header.order_place, champs: @champs }
- else
.row
= render partial: render_partial_url, locals: { libelle: 'Dossier', order_place: -1, champs: @champs }

View file

@ -1 +0,0 @@
%input{ type: 'checkbox', style: 'margin-left: 15px;', name: "champs['#{champ.id}']", id: "champs_#{champ.id}", checked: ('checked' if champ.object.value == 'on') }

View file

@ -1,8 +0,0 @@
%div
%label.radio-inline
= radio_button_tag "champs['#{champ.id}']", "M.", champ.value == 'Mme' ? false : true
Monsieur
%label.radio-inline
= radio_button_tag "champs['#{champ.id}']", "Mme", champ.value == 'Mme'
Madame

View file

@ -1,5 +0,0 @@
%input.form-control{ name: "champs['#{champ.id}']",
placeholder: "JJ/MM/AAAA",
id: "champs_#{champ.id}",
value: champ.date_for_input,
type: "date" }

View file

@ -1,16 +0,0 @@
= render partial: 'users/description/champs/date', locals: { champ: champ }
%br
%select.form-control{ name: "time_hour['#{champ.id}']", style: 'width:70px;display:inline;', id: "time_hour_#{champ.id}" }
- (0..23).each do |num|
- num = "%.2i" %num
%option{ value: num, selected: (:selected if champ.same_hour?(num)) }
= num
h
%select.form-control{ name: "time_minute['#{champ.id}']", style: 'width:70px;display:inline;', id: "time_minute_#{champ.id}" }
- (0..59).each do |num|
- num = "%.2i" %num
- if num.to_i%5 == 0
%option{ value: num, selected: (:selected if champ.same_minute?(num)) }
= num
min

View file

@ -1,2 +0,0 @@
= select_tag("champs['#{champ.id}']",
options_for_select(Champs::DepartementChamp.departements, selected: champ.object.value))

View file

@ -1,20 +0,0 @@
- dossier = Dossier.find_by(id: champ.value)
- show_text_summary = dossier.present?
- show_warning = !show_text_summary && champ.value.present?
- text_summary = dossier&.text_summary
.dossier-link
%input.form-control{ name: "champs['#{ champ.id }']",
placeholder: "Numéro de dossier",
id: "champs_#{ champ.id }",
value: champ.value,
type: 'number',
'autocomplete' => 'off',
'data-type' => 'dossier-link' }
.help-block
%p.text-info{ style: show_text_summary ? nil : 'display: none;' }
%span.dossier-text-summary= text_summary
%p.text-warning{ style: show_warning ? nil : 'display: none;' }
Ce dossier est inconnu

View file

@ -1,7 +0,0 @@
- if champ.drop_down_list && champ.drop_down_list.options.any?
= select_tag("champs['#{champ.id}']",
options_for_select(champ.drop_down_list.options,
selected: champ.drop_down_list.selected_options(champ),
disabled: champ.drop_down_list.disabled_options),
multiple: champ.drop_down_list.multiple,
class: 'select2')

View file

@ -1,2 +0,0 @@
%input{ type: 'hidden', name: "champs['#{champ.id}']", id: "champs_#{champ.id}", value: '' }
%input{ type: 'checkbox', style: 'margin-left: 15px;', name: "champs['#{champ.id}']", id: "champs_#{champ.id}", checked: ('checked' if champ.object.value == 'on') }

View file

@ -1,6 +0,0 @@
.row
.col-lg-12.col-md-12.col-sm-12.col-xs-12
%br
%h3.text-info
= libelle
= render partial: 'users/description/champs/render_list_champs', locals: { champs: champs, order_place: order_place }

View file

@ -1,11 +0,0 @@
.default-data-block.default_visible
.row.show-block.infos
.header
.col-xs-12.title
.carret-right
.carret-down
.title-content
= libelle
.clearfix
.body
= render partial: 'users/description/champs/render_list_champs', locals: { champs: champs, order_place: order_place }

View file

@ -1,2 +0,0 @@
= select_tag("champs['#{champ.id}']",
options_for_select(Champs::PaysChamp.pays, selected: champ.object.value))

View file

@ -1,15 +0,0 @@
- pj = champ.piece_justificative_file
- if !pj.attached?
= file_field_tag "champs['#{champ.id}']",
id: "champs_#{champ.id}",
direct_upload: true,
mandatory: champ.mandatory?
- else
%a{ href: url_for(pj), target: '_blank' }
= pj.filename.to_s
%br
Modifier :
= file_field_tag "champs['#{champ.id}']",
id: "champs_#{champ.id}",
direct_upload: true

View file

@ -1,2 +0,0 @@
= select_tag("champs['#{champ.id}']",
options_for_select(Champs::RegionChamp.regions, selected: champ.object.value))

View file

@ -1,66 +0,0 @@
- champs.decorate.each do |champ|
- if champ.order_place > order_place
- if champ.type_champ == 'header_section'
- break
.row
%div{ class: if champ.type_champ == 'textarea' || champ.type_champ == 'engagement' then 'col-md-12' else 'col-md-6' end }
.form-group
%label{ for: "champs_#{champ.id}" }
= champ.libelle
- if champ.mandatory?
*
- case champ.type_champ
- when 'textarea'
= render partial: 'users/description/champs/textarea', locals: { champ: champ }
- when 'checkbox'
= render partial: 'users/description/champs/checkbox', locals: { champ: champ }
- when 'civilite'
= render partial: 'users/description/champs/civilite', locals: { champ: champ }
- when 'datetime'
= render partial: 'users/description/champs/datetime', locals: { champ: champ }
- when 'yes_no'
= render partial: 'users/description/champs/yes_no', locals: { champ: champ }
- when 'drop_down_list', 'multiple_drop_down_list'
= render partial: 'users/description/champs/drop_down_list', locals: { champ: champ }
- when 'pays'
= render partial: 'users/description/champs/pays', locals: { champ: champ }
- when 'regions'
= render partial: 'users/description/champs/regions', locals: { champ: champ }
- when 'engagement'
= render partial: 'users/description/champs/engagement', locals: { champ: champ }
- when 'departements'
= render partial: 'users/description/champs/departements', locals: { champ: champ }
- when 'dossier_link'
= render partial: 'users/description/champs/dossier_link', locals: { champ: champ }
- when 'explication'
- when 'date'
= render partial: 'users/description/champs/date', locals: { champ: champ }
- when 'piece_justificative'
= render partial: 'users/description/champs/piece_justificative', locals: { champ: champ }
- else
%input.form-control{ name: "champs['#{champ.id}']",
placeholder: champ.libelle,
id: "champs_#{champ.id}",
value: champ.value,
type: champ.type_champ }
- if champ.description.present?
%div{ id: "description_champs_#{champ.id}", class: ('help-block' if champ.type_champ != 'engagement') }
= simple_format(sanitize(champ.description_with_links, attributes: %w(href target)))

View file

@ -1,5 +0,0 @@
%textarea.form-control.wysihtml5{ name: "champs['#{champ.id}']",
placeholder: champ.description,
id: "champs_#{champ.id}",
row: '6' }
= champ.value

View file

@ -1,8 +0,0 @@
%div
%label.radio-inline
= radio_button_tag "champs['#{champ.id}']", "true", champ.object.value == 'true'
Oui
%label.radio-inline
= radio_button_tag "champs['#{champ.id}']", "false", champ.object.value == 'false'
Non

View file

@ -1,64 +0,0 @@
.container#description-page
- if notice_url(@dossier.procedure).present?
#lien_notice_panel.row{ style: 'width: 280px; position: fixed; background-color: white; right: 5%; top: 80px; z-index: 200;' }
.panel.panel-info{ style: 'margin-bottom: 0;' }
.panel-body.center
.row
.col-xs-1
.fa.fa-info-circle.text-info{ style: 'font-size: 2em; margin-top: 20%;' }
.col-xs-10{ style: 'padding-right: 0px;' }
%b
= link_to 'Accéder au guide', notice_url(@dossier.procedure), { target: '_blank' }
pour remplir pour votre dossier
%h2.text-info
= @dossier.procedure.libelle
-# TODO use form_for
= form_tag(url_for({ controller: 'users/description', action: :update, dossier_id: @dossier.id }), class: 'form', method: 'POST', multipart: true) do
- if @champs.present?
#liste-champs
= render partial: 'users/description/champs', locals: { private: false }
- if @procedure.lien_demarche.present? || @dossier.types_de_piece_justificative.size > 0
%br
%h3 Pièces jointes
-# TODO a refactorer
.row
.col-lg-8
= render partial: 'users/description/pieces_justificatives', locals: { dossier: @dossier }
%div{ style: 'text-align: right;' }
%h6 Tous les champs portant un * sont obligatoires.
- if !@dossier.can_be_en_construction?
.alert.alert-danger
= t('errors.messages.procedure_archived')
- elsif !@dossier.brouillon?
= render partial: '/layouts/modifications_terminees'
- else
= hidden_field_tag 'submit_action', 'brouillon'
= submit_tag 'Bonjour Active Storage !', style: 'display: none;'
= button_tag 'Soumettre mon dossier',
id: 'suivant',
type: 'submit',
class: 'btn btn btn-success',
style: 'float: right;',
disabled: @procedure.archivee?,
data: { disable: true, action: 'nouveaux' }
= button_tag 'Enregistrer un brouillon',
id: 'brouillon',
type: 'submit',
class: 'btn btn-xs btn-default',
style: 'float: right; margin-right: 10px; margin-top: 6px;',
disabled: @procedure.archivee?,
data: { disable: true, action: 'brouillon' }
= button_tag "Enregistrer et voir mes dossiers",
id: 'brouillon_then_dashboard',
type: 'submit',
class: 'btn btn-xs btn-default',
style: 'float: right; margin-right: 10px; margin-top: 6px;',
disabled: @procedure.archivee?,
data: { disable: true, action: 'brouillon_then_dashboard' }

View file

@ -105,9 +105,6 @@ Rails.application.routes.draw do
resources :dossiers do
get '/add_siret' => 'dossiers/add_siret#show'
get 'description' => 'description#show'
post 'description' => 'description#update'
patch 'pieces_justificatives' => 'description#pieces_justificatives'
get '/recapitulatif' => 'recapitulatif#show'

View file

@ -1,439 +0,0 @@
shared_examples 'description_controller_spec' do
describe 'GET #show' do
before do
dossier.update_column :autorisation_donnees, true
end
context 'user is not connected' do
before do
sign_out dossier.user
end
it 'redirects to users/sign_in' do
get :show, params: { dossier_id: dossier_id }
expect(response).to redirect_to('/users/sign_in')
end
end
context 'when all is ok' do
before do
dossier.etablissement = create(:etablissement)
get :show, params: { dossier_id: dossier_id }
end
it 'returns http success' do
expect(response).to have_http_status(:success)
end
context 'procedure is archived' do
render_views
let(:archived) { true }
it { expect(response).to have_http_status(:success) }
it { expect(response.body).to_not have_content(I18n.t('errors.messages.procedure_archived')) }
context 'dossier is a brouillon' do
let(:state) { 'brouillon' }
it { expect(response).to have_http_status(:success) }
it { expect(response.body).to have_content(I18n.t('errors.messages.procedure_archived')) }
end
end
end
it 'redirection vers start si mauvais dossier ID' do
get :show, params: { dossier_id: bad_dossier_id }
expect(flash[:alert]).to be_present
expect(response).to redirect_to(root_path)
end
it_behaves_like "not owner of dossier", :show
describe 'before_action authorized_routes?' do
context 'when dossier does not have a valid state' do
before do
dossier.state = 'en_instruction'
dossier.save
get :show, params: { dossier_id: dossier.id }
end
it { is_expected.to redirect_to root_path }
end
end
describe 'before action check_autorisation_donnees' do
subject { get :show, params: { dossier_id: dossier_id } }
context 'when dossier does not have a valid autorisations_donness (nil)' do
before do
dossier.update_column :autorisation_donnees, nil
end
it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
end
context 'when dossier does not have a valid autorisations_donness (false)' do
before do
dossier.update_column :autorisation_donnees, false
end
it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
end
end
describe 'before action check_starter_dossier_informations' do
subject { get :show, params: { dossier_id: dossier_id } }
context 'when dossier does not have an etablissement datas' do
it { expect(dossier.etablissement).to be_nil }
it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
end
context 'when dossier does not have an individual datas' do
before do
procedure.update_column :for_individual, true
end
it { expect(dossier.individual).to be_nil }
it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
end
end
end
describe 'POST #update' do
context 'Tous les attributs sont bons' do
describe 'Premier enregistrement des données' do
let(:state) { 'brouillon' }
def submit_dossier
post :update, params: { dossier_id: dossier_id, submit_action: submit }
dossier.reload
end
context "when the user submits the dossier" do
let(:submit) { 'nouveaux' }
it "redirection vers la page recapitulative" do
submit_dossier
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
end
it 'etat du dossier est en construction' do
submit_dossier
expect(dossier.state).to eq('en_construction')
end
context 'sending the accusé de réception mail' do
before { Timecop.freeze(DateTime.now) }
after { Timecop.return }
it 'sets the state of the dossier before sending the mail' do
sender = double("notification sender")
allow(sender).to receive(:deliver_later)
expect(NotificationMailer)
.to receive(:send_initiated_notification)
.with(have_attributes(en_construction_at: DateTime.now))
.and_return(sender)
submit_dossier
end
end
end
context 'when user saves a brouillon' do
let(:submit) { 'brouillon' }
it "reste sur la page du dossier" do
submit_dossier
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/description")
end
it 'etat du dossier est brouillon' do
submit_dossier
expect(dossier.state).to eq('brouillon')
end
end
context 'when user saves a brouillon and goes to dashboard' do
let(:submit) { 'brouillon_then_dashboard' }
it "goes to dashboard" do
submit_dossier
expect(response).to redirect_to("/users/dossiers?liste=brouillon")
end
it 'etat du dossier est brouillon' do
submit_dossier
expect(dossier.state).to eq('brouillon')
end
end
end
context 'En train de manipuler un dossier non brouillon' do
before do
dossier.en_construction!
post :update, params: { dossier_id: dossier_id }
dossier.reload
end
it 'Redirection vers la page récapitulatif' do
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
end
it 'etat du dossier n\'est pas soumis' do
expect(dossier.state).not_to eq('brouillon')
end
end
end
describe 'Sauvegarde des champs' do
let(:champs_dossier) { dossier.champs }
let(:dossier_text_value) { 'test value' }
let(:dossier_date_value) { '2018-01-31' }
let(:dossier_hour_value) { '17' }
let(:dossier_minute_value) { '00' }
let(:dossier_datetime_champ_id) { dossier.champs.find { |c| c.type_champ == "datetime" }.id }
let(:dossier_text_champ_id) { dossier.champs.find { |c| c.type_champ == "text" }.id }
let(:params) {
{
dossier_id: dossier_id,
champs: {
"'#{dossier_text_champ_id}'" => dossier_text_value,
"'#{dossier_datetime_champ_id}'" => dossier_date_value
},
time_hour: {
"'#{dossier_datetime_champ_id}'" => dossier_hour_value,
},
time_minute: {
"'#{dossier_datetime_champ_id}'" => dossier_minute_value,
}
}
}
before do
post :update, params: params
dossier.reload
end
it { expect(dossier.champs.find(dossier_text_champ_id).value).to eq(dossier_text_value) }
it { expect(response).to redirect_to users_dossier_recapitulatif_path }
context 'when champs is type_de_champ datetime' do
it { expect(dossier.champs.find(dossier_datetime_champ_id).value).to eq("#{dossier_date_value} #{dossier_hour_value}:#{dossier_minute_value}") }
end
context 'when champs value is empty' do
let(:dossier_text_value) { '' }
it { expect(dossier.champs.find(dossier_text_champ_id).value).to eq(dossier_text_value) }
it { expect(response).to redirect_to users_dossier_recapitulatif_path }
context 'when champs is mandatory' do
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ_mandatory, :with_datetime) }
it { expect(response).not_to redirect_to users_dossier_recapitulatif_path }
it { expect(flash[:alert]).to be_present }
end
end
end
context 'Sauvegarde des pièces justificatives', vcr: { cassette_name: 'controllers_users_description_controller_sauvegarde_pj' } do
let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids }
before do
post :update, params: {
dossier_id: dossier_id,
"piece_justificative_#{all_pj_type[0].to_s}" => piece_justificative_0,
"piece_justificative_#{all_pj_type[1].to_s}" => piece_justificative_1
}
dossier.reload
end
describe 'clamav anti-virus presence', vcr: { cassette_name: 'controllers_users_description_controller_clamav_presence' } do
it 'ClamavService safe_file? is call' do
expect(ClamavService).to receive(:safe_file?).twice
post :update, params: {
dossier_id: dossier_id,
"piece_justificative_#{all_pj_type[0].to_s}" => piece_justificative_0,
"piece_justificative_#{all_pj_type[1].to_s}" => piece_justificative_1
}
end
end
context 'for piece 0' do
subject { dossier.retrieve_last_piece_justificative_by_type all_pj_type[0].to_s }
it { expect(subject.content).not_to be_nil }
it { expect(subject.user).to eq user }
end
context 'for piece 1' do
subject { dossier.retrieve_last_piece_justificative_by_type all_pj_type[1].to_s }
it { expect(subject.content).not_to be_nil }
it { expect(subject.user).to eq user }
end
end
context 'La procédure est archivée' do
let(:archived) { true }
before do
post :update, params: { dossier_id: dossier.id }
end
it { expect(response.status).to eq(302) }
context 'Le dossier est en brouillon' do
let(:state) { 'brouillon' }
it { expect(response.status).to eq(403) }
end
end
end
describe 'POST #pieces_justificatives', vcr: { cassette_name: 'controllers_users_description_controller_pieces_justificatives' } do
let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids }
subject {
patch :pieces_justificatives, params: {
dossier_id: dossier.id,
"piece_justificative_#{all_pj_type[0].to_s}" => piece_justificative_0,
"piece_justificative_#{all_pj_type[1].to_s}" => piece_justificative_1
}
}
context 'when user is a guest' do
let(:guest) { create :user }
before do
create :invite, dossier: dossier, email: guest.email, user: guest
sign_in guest
end
context 'when PJ have no documents' do
it { expect(dossier.pieces_justificatives.size).to eq 0 }
context 'when upload two PJ' do
before do
subject
dossier.reload
end
it { expect(dossier.pieces_justificatives.size).to eq 2 }
it { expect(flash[:notice]).to be_present }
it { is_expected.to redirect_to users_dossiers_invite_path(id: guest.invites.find_by(dossier_id: dossier.id).id) }
end
end
context 'when PJ have already a document' do
before do
create :piece_justificative, :rib, dossier: dossier, type_de_piece_justificative_id: all_pj_type[0]
create :piece_justificative, :contrat, dossier: dossier, type_de_piece_justificative_id: all_pj_type[1]
end
it { expect(dossier.pieces_justificatives.size).to eq 2 }
context 'when upload two PJ', vcr: { cassette_name: 'controllers_users_description_controller_upload_2pj' } do
before do
subject
dossier.reload
end
it { expect(dossier.pieces_justificatives.size).to eq 4 }
it { expect(flash[:notice]).to be_present }
it { is_expected.to redirect_to users_dossiers_invite_path(id: guest.invites.find_by(dossier_id: dossier.id).id) }
end
end
context 'when one of PJs is not valid' do
let(:piece_justificative_0) { Rack::Test::UploadedFile.new("./spec/support/files/entreprise.json", 'application/json') }
it { expect(dossier.pieces_justificatives.size).to eq 0 }
context 'when upload two PJ' do
before do
subject
dossier.reload
end
it { expect(dossier.pieces_justificatives.size).to eq 1 }
it { expect(flash[:alert]).to be_present }
it { is_expected.to redirect_to users_dossiers_invite_path(id: guest.invites.find_by(dossier_id: dossier.id).id) }
end
end
end
end
end
shared_examples 'description_controller_spec_POST_piece_justificatives_for_owner' do
let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids }
subject {
patch :pieces_justificatives, params: {
dossier_id: dossier.id,
"piece_justificative_#{all_pj_type[0].to_s}" => piece_justificative_0,
"piece_justificative_#{all_pj_type[1].to_s}" => piece_justificative_1
}
}
context 'when user is the owner', vcr: { cassette_name: 'controllers_users_description_controller_pieces_justificatives' } do
before do
sign_in user
end
context 'when PJ have no documents' do
it { expect(dossier.pieces_justificatives.size).to eq 0 }
context 'when upload two PJ' do
before do
subject
dossier.reload
end
it { expect(dossier.pieces_justificatives.size).to eq 2 }
it { expect(flash[:notice]).to be_present }
it { is_expected.to redirect_to recapitulatif_path }
end
end
context 'when PJ have already a document', vcr: { cassette_name: 'controllers_users_description_controller_pj_already_exist' } do
before do
create :piece_justificative, :rib, dossier: dossier, type_de_piece_justificative_id: all_pj_type[0]
create :piece_justificative, :contrat, dossier: dossier, type_de_piece_justificative_id: all_pj_type[1]
end
it { expect(dossier.pieces_justificatives.size).to eq 2 }
context 'when upload two PJ', vcr: { cassette_name: 'controllers_users_description_controller_pj_already_exist_upload_2pj' } do
before do
subject
dossier.reload
end
it { expect(dossier.pieces_justificatives.size).to eq 4 }
it { expect(flash[:notice]).to be_present }
it { is_expected.to redirect_to recapitulatif_path }
end
end
context 'when one of PJs is not valid' do
let(:piece_justificative_0) { Rack::Test::UploadedFile.new("./spec/support/files/entreprise.json", 'application/json') }
it { expect(dossier.pieces_justificatives.size).to eq 0 }
context 'when upload two PJ' do
before do
subject
dossier.reload
end
it { expect(dossier.pieces_justificatives.size).to eq 1 }
it { expect(flash[:alert]).to be_present }
it { is_expected.to redirect_to recapitulatif_path }
end
end
end
end

View file

@ -1,51 +0,0 @@
require 'spec_helper'
require 'controllers/users/description_controller_shared_example'
describe Users::DescriptionController, type: :controller, vcr: { cassette_name: 'controllers_users_description_controller' } do
let(:owner_user) { create(:user) }
let(:invite_by_user) { create :user, email: 'invite@plop.com' }
let(:archived) { false }
let(:state) { 'en_construction' }
let(:procedure) do
if archived
create(:procedure, :archived, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime)
else
create(:procedure, :published, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime)
end
end
let(:dossier) { create(:dossier, procedure: procedure, user: owner_user, state: state) }
let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 10000 }
let(:name_piece_justificative) { 'dossierPDF.pdf' }
let(:name_piece_justificative_0) { 'piece_justificative_0.pdf' }
let(:name_piece_justificative_1) { 'piece_justificative_1.pdf' }
let(:piece_justificative_0) { Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_justificative_0}", 'application/pdf') }
let(:piece_justificative_1) { Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_justificative_1}", 'application/pdf') }
before do
allow(ClamavService).to receive(:safe_file?).and_return(true)
create :invite, dossier: dossier, user: invite_by_user, email: invite_by_user.email, type: 'InviteUser'
sign_in user
end
context 'when sign in user is the owner' do
let(:user) { owner_user }
let(:recapitulatif_path) { users_dossier_recapitulatif_path }
it_should_behave_like "description_controller_spec"
it_should_behave_like "description_controller_spec_POST_piece_justificatives_for_owner"
end
context 'when sign in user is an invite by owner' do
let(:user) { invite_by_user }
let(:recapitulatif_path) { users_dossiers_invite_path(id: dossier_id) }
it_should_behave_like "description_controller_spec"
end
end

View file

@ -1,44 +0,0 @@
require 'spec_helper'
feature 'user is on description page' do
let!(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ) }
let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, autorisation_donnees: true) }
before do
allow(ClamavService).to receive(:safe_file?).and_return(true)
visit users_dossier_description_path dossier
within('#new_user') do
page.find_by_id('user_email').set dossier.user.email
page.find_by_id('user_password').set dossier.user.password
page.click_on 'Se connecter'
end
end
it { expect(page).to have_css('#description-page') }
context 'he fill description fields' do
before do
find_by_id("champs_#{dossier.champs.first.id}").set 'mon nom'
end
context 'before submit' do
it 'pieces_justificatives are empty' do
dossier.pieces_justificatives.each do |piece_justificative|
expect(piece_justificative).to be_empty
end
end
end
context 'when he adds a piece_justificative and submit form', vcr: { cassette_name: 'description_page_upload_piece_justificative_adds_cerfa_and_submit' } do
before do
file_input_id = "piece_justificative_#{dossier.types_de_piece_justificative.first.id.to_s}"
attach_file(file_input_id, File.path('spec/support/files/dossierPDF.pdf'))
click_on('Soumettre mon dossier')
dossier.reload
end
scenario 'fills the given piece_justificative' do
expect(dossier.pieces_justificatives.first).not_to be_empty
end
end
end
end

View file

@ -69,25 +69,6 @@ describe UserRoutesAuthorizationService do
end
end
describe 'Users::DescriptionController' do
let(:controller) { Users::DescriptionController }
describe 'brouillon' do
let(:state) { 'brouillon' }
it { is_expected.to be_truthy }
end
describe 'en_construction' do
let(:state) { 'en_construction' }
it { is_expected.to be_truthy }
end
describe 'accepte' do
let(:state) { 'accepte' }
it { is_expected.to be_falsey }
end
end
describe 'recapitulatif' do
let(:controller) { Users::RecapitulatifController }

View file

@ -1,41 +0,0 @@
require 'spec_helper'
describe 'users/description/_pieces_justificatives.html.haml', type: :view do
let!(:procedure) { create(:procedure) }
let!(:tpj1) do
create(
:type_de_piece_justificative,
procedure: procedure,
libelle: "Première pièce jointe",
description: "Première description",
order_place: 1,
mandatory: true
)
end
let!(:tpj2) do
create(
:type_de_piece_justificative,
procedure: procedure,
libelle: "Seconde pièce jointe",
description: "Seconde description",
order_place: 2,
lien_demarche: "https://www.google.fr"
)
end
let!(:dossier) { create(:dossier, :procedure => procedure) }
before do
render 'users/description/pieces_justificatives.html.haml', dossier: dossier
end
it 'should render two PJ with their title, mandatory status and description' do
expect(rendered).to include("Première pièce jointe *")
expect(rendered).to include("Seconde pièce jointe")
expect(rendered.index("Première pièce jointe")).to be < rendered.index("Seconde pièce jointe")
expect(rendered).to include("Première description")
expect(rendered).to include("Seconde description")
expect(rendered).to have_selector("input[type=file]", count: 2)
end
end

View file

@ -1,15 +0,0 @@
require 'spec_helper'
describe 'users/description/champs/date.html.haml', type: :view do
let(:type_champ) { create(:type_de_champ_date) }
before do
render 'users/description/champs/date.html.haml', champ: champ
end
let!(:champ) { create(:champ, type_de_champ: type_champ, value: "2017-09-19").decorate }
it 'should render an input for the dossier link' do
expect(rendered).to have_css("input[value='2017-09-19']")
end
end

View file

@ -1,13 +0,0 @@
require 'spec_helper'
describe 'users/description/champs/departements.html.haml', vcr: { cassette_name: 'geoapi_departements' }, type: :view do
let(:champ) { create(:champ) }
before do
render 'users/description/champs/departements.html.haml', champ: champ.decorate
end
it 'should render departments drop down list' do
expect(rendered).to include("Ain")
end
end

View file

@ -1,55 +0,0 @@
require 'spec_helper'
describe 'users/description/champs/dossier_link.html.haml', type: :view do
let(:type_champ) { create(:type_de_champ_dossier_link) }
before do
render 'users/description/champs/dossier_link.html.haml', champ: champ
end
context 'in all cases' do
let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) }
it 'should render an input for the dossier link' do
expect(rendered).to have_css("input[type=number][placeholder='Numéro de dossier']")
end
end
context 'When no dossier is provided' do
let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) }
it 'should not display the procedure libelle' do
expect(rendered).to have_css('.text-info[style*="display: none"]')
end
it 'should not display a warning' do
expect(rendered).to have_css('.text-warning[style*="display: none"]')
end
end
context 'When a dossier whith a procedure is provided' do
let!(:procedure) { create(:procedure) }
let!(:dossier) { create(:dossier, procedure: procedure) }
let!(:champ) { create(:champ, type_de_champ: type_champ, value: dossier.id) }
it 'should display the procedure libelle' do
expect(rendered).not_to have_css('.text-info[style*="display: none"]')
end
it 'should not display a warning' do
expect(rendered).to have_css('.text-warning[style*="display: none"]')
end
end
context 'When a unknown dossier id is provided' do
let!(:champ) { create(:champ, type_de_champ: type_champ, value: 666) }
it 'should not display the procedure libelle' do
expect(rendered).to have_css('.text-info[style*="display: none"]')
end
it 'should display a warning' do
expect(rendered).not_to have_css('.text-warning[style*="display: none"]')
end
end
end

View file

@ -1,20 +0,0 @@
require 'spec_helper'
describe 'users/description/champs/engagement.html.haml', type: :view do
let(:type_champ) { create(:type_de_champ_engagement) }
subject { render 'users/description/champs/engagement.html.haml', champ: champ }
context "when the value is on" do
let!(:champ) { create(:champ, type_de_champ: type_champ, value: "on").decorate }
it { is_expected.to have_selector("input[type='checkbox'][checked]") }
end
context "when the value is nil" do
let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil).decorate }
it { is_expected.to have_selector("input[type='checkbox']") }
it { is_expected.not_to have_selector("input[type='checkbox'][checked]") }
end
end

View file

@ -1,13 +0,0 @@
require 'spec_helper'
describe 'users/description/champs/pays.html.haml', type: :view do
let(:champ) { create(:champ) }
before do
render 'users/description/champs/pays.html.haml', champ: champ.decorate
end
it 'should render pays drop down list' do
expect(rendered).to include("FRANCE")
end
end

View file

@ -1,13 +0,0 @@
require 'spec_helper'
describe 'users/description/champs/regions.html.haml', vcr: { cassette_name: 'geoapi_regions' }, type: :view do
let(:champ) { create(:champ) }
before do
render 'users/description/champs/regions.html.haml', champ: champ.decorate
end
it 'should render regions drop down list' do
expect(rendered).to include("Normandie")
end
end

View file

@ -1,55 +0,0 @@
describe 'users/description/champs/render_list_champs.html.haml', type: :view do
let(:type_champ) { create(:type_de_champ_checkbox) }
context "with any champ" do
let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) }
before do
render 'users/description/champs/render_list_champs.html.haml', champs: Champ.all, order_place: 0
end
it "should render the champ's libelle" do
expect(rendered).to have_content(champ.libelle)
end
end
context "with a checkbox champ" do
context "whose value equals nil" do
let!(:champ_checkbox_checked) { create(:champ, type_de_champ: type_champ, value: nil) }
before do
render 'users/description/champs/render_list_champs.html.haml', champs: Champ.all, order_place: 0
end
it 'should not render a checked checkbox' do
expect(rendered).not_to have_css('input[type=checkbox][checked]')
end
end
context "whose value equals 'on'" do
let!(:champ_checkbox_checked) { create(:champ, type_de_champ: type_champ, value: 'on') }
before do
render 'users/description/champs/render_list_champs.html.haml', champs: Champ.all, order_place: 0
end
it 'should render a checked checkbox' do
expect(rendered).to have_css('input[type=checkbox][checked]')
end
end
end
context 'with a dossier_link' do
let(:type_champ) { create(:type_de_champ_dossier_link) }
let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) }
before do
render 'users/description/champs/render_list_champs.html.haml', champs: Champ.all, order_place: 0
end
it 'should render the _dossier_link partial' do
expect(view).to render_template(partial: 'users/description/champs/_dossier_link',
locals: { champ: champ })
end
end
end

View file

@ -1,25 +0,0 @@
require 'spec_helper'
describe 'users/description/champs/yes_no.html.haml', type: :view do
let(:type_champ) { create(:type_de_champ_yes_no) }
before do
render 'users/description/champs/yes_no.html.haml', champ: champ
end
context "when the value is Oui" do
let!(:champ) { create(:champ, type_de_champ: type_champ, value: "true").decorate }
it 'should select the Oui radio button' do
expect(rendered).to have_selector("input[value='true'][checked]")
end
end
context "when the value is Non" do
let!(:champ) { create(:champ, type_de_champ: type_champ, value: "false").decorate }
it 'should select the Non radio button' do
expect(rendered).to have_selector("input[value='false'][checked]")
end
end
end

View file

@ -1,108 +0,0 @@
require 'spec_helper'
describe 'users/description/show.html.haml', type: :view do
let(:user) { create(:user) }
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime) }
let(:dossier) { create(:dossier, procedure: procedure, user: user) }
let(:dossier_id) { dossier.id }
before do
sign_in user
assign(:dossier, dossier)
assign(:procedure, dossier.procedure)
assign(:champs, dossier.ordered_champs)
end
context 'tous les attributs sont présents sur la page' do
before do
render
end
it 'Le formulaire envoie vers /users/dossiers/:dossier_id/description en #POST' do
expect(rendered).to have_selector("form[action='/users/dossiers/#{dossier_id}/description'][method=post]")
end
end
context 'si la page précédente n\'est pas recapitulatif' do
before do
render
end
it 'le bouton "Terminer" est présent' do
expect(rendered).to have_selector('#suivant')
end
end
context 'si la page précédente est recapitularif' do
before do
dossier.en_construction!
dossier.reload
render
end
it 'le bouton "Terminer" n\'est pas présent' do
expect(rendered).to_not have_selector('#suivant')
end
it 'le bouton "Modification terminé" est présent' do
expect(rendered).to have_selector('#modification_terminee')
end
it 'le lien de retour au récapitulatif est présent' do
expect(rendered).to have_selector("a[href='/users/dossiers/#{dossier_id}/recapitulatif']")
end
end
context 'Champs' do
let(:champs) { dossier.champs }
let(:types_de_champ) { procedure.types_de_champ.where(type_champ: 'datetime').first }
let(:champ_datetime) { champs.where(type_de_champ_id: types_de_champ.id).first }
before do
champ_datetime.value = "2016-06-22 12:05"
champ_datetime.save
render
end
describe 'first champs' do
subject { dossier.champs.first }
it { expect(rendered).to have_css("#champs_#{subject.id}") }
end
describe 'last champs' do
subject { dossier.champs.last }
it { expect(rendered).to have_css("#champs_#{subject.id}") }
end
describe 'datetime value is correctly setup when is not nil' do
it { expect(rendered).to have_css("input[type='date'][id='champs_#{champ_datetime.id}'][value='2016-06-22']") }
it { expect(rendered).to have_css("option[value='12'][selected='selected']") }
it { expect(rendered).to have_css("option[value='05'][selected='selected']") }
end
end
context 'Pièces justificatives' do
let(:all_type_pj_procedure_id) { dossier.procedure.type_de_piece_justificative_ids }
before do
render
end
context 'la liste des pièces justificatives a envoyé est affichée' do
it 'RIB' do
expect(rendered).to have_css("#piece_justificative_#{all_type_pj_procedure_id[0]}")
end
end
end
describe 'display title Documents administratifs' do
before do
render
end
let(:procedure) { create :procedure, lien_demarche: '' }
let(:dossier) { create(:dossier, procedure: procedure) }
context 'when dossier not have piece justificative and demarche link' do
it { expect(rendered).not_to have_content 'Documents administratifs' }
end
end
end