Merge pull request #2351 from betagouv/dev

2018-08-07-01
This commit is contained in:
Pierre de La Morinerie 2018-08-07 15:50:28 +02:00 committed by GitHub
commit fb408d7dc1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 113 additions and 1336 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,4 +1,4 @@
#publish-modal.modal.fade{ "aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1" }
#publish-modal.modal{ "aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1" }
.modal-dialog.modal-lg{ :role => "document" }
= form_tag admin_procedure_publish_path(procedure_id: @procedure.id), method: :put, remote: true do
.modal-content

View file

@ -4,7 +4,7 @@
- if apercu
- form_options = { url: '', method: :get, html: { class: 'form', multipart: true } }
- else
- form_options = { html: { class: 'form', multipart: true, novalidate: dossier.brouillon? } }
- form_options = { url: modifier_dossier_url(dossier), method: :patch, html: { class: 'form', multipart: true, novalidate: dossier.brouillon? } }
= form_for dossier, form_options do |f|

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

@ -1,4 +1,8 @@
Rails.application.routes.draw do
#
# Manager
#
get 'manager/sign_in' => 'administrations/sessions#new'
delete 'manager/sign_out' => 'administrations/sessions#destroy'
namespace :manager do
@ -38,8 +42,16 @@ Rails.application.routes.draw do
root to: "administrateurs#index"
end
#
# Monitoring
#
get "/ping" => "ping#index", :constraints => { :ip => /127.0.0.1/ }
#
# Authentication
#
devise_for :administrations,
skip: [:password, :registrations, :sessions],
controllers: {
@ -77,6 +89,10 @@ Rails.application.routes.draw do
get '/administrateurs/sign_in/demo' => redirect("/users/sign_in")
end
#
# Main routes
#
root 'root#index'
get 'users' => 'users#index'
@ -95,6 +111,17 @@ Rails.application.routes.draw do
get ':champ_id/siret' => 'siret#index', as: 'siret'
end
namespace :commencer do
get '/test/:procedure_path' => '/users/dossiers#commencer_test', as: :test
get '/:procedure_path' => '/users/dossiers#commencer'
end
get "patron" => "root#patron"
#
# Deprecated UI
#
namespace :users do
namespace :dossiers do
resources :invites, only: [:index, :show]
@ -105,9 +132,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'
@ -209,6 +233,10 @@ Rails.application.routes.draw do
resources :gestionnaires, only: [:index, :create, :destroy]
end
#
# Addresses
#
namespace :ban do
get 'search' => 'search#get'
get 'address_point' => 'search#get_address_point'
@ -218,6 +246,10 @@ Rails.application.routes.draw do
post 'dossier/:dossier_id' => '/invites#create', as: 'dossier'
end
#
# API
#
namespace :api do
namespace :v1 do
resources :procedures, only: [:index, :show] do
@ -230,12 +262,9 @@ Rails.application.routes.draw do
end
end
namespace :commencer do
get '/test/:procedure_path' => '/users/dossiers#commencer_test', as: :test
get '/:procedure_path' => '/users/dossiers#commencer'
end
get "patron" => "root#patron"
#
# User
#
scope module: 'new_user' do
resources :dossiers, only: [:index, :update] do
@ -243,6 +272,7 @@ Rails.application.routes.draw do
get 'identite'
patch 'update_identite'
get 'modifier'
patch 'modifier', to: 'dossiers#update'
get 'merci'
post 'ask_deletion'
get 'attestation'
@ -250,13 +280,14 @@ Rails.application.routes.draw do
collection do
post 'recherche'
# FIXME: to remove when show is implemeted
# needed to fix refresh after dossier draft save
get ':id', to: redirect('/dossiers/%{id}/modifier')
end
end
end
#
# Gestionnaire
#
scope module: 'new_gestionnaire', as: 'gestionnaire' do
resources :procedures, only: [:index, :show], param: :procedure_id do
member do
@ -306,6 +337,10 @@ Rails.application.routes.draw do
get "recherche" => "recherche#index"
end
#
# Administrateur
#
scope module: 'new_administrateur' do
resources :procedures, only: [] do
member do
@ -322,7 +357,10 @@ Rails.application.routes.draw do
apipie
#
# Legacy routes
#
get 'backoffice' => redirect('/procedures')
get 'backoffice/sign_in' => redirect('/users/sign_in')
get 'backoffice/dossiers/procedure/:procedure_id' => redirect('/procedures/%{procedure_id}')

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

@ -13,95 +13,107 @@ feature 'As an administrateur I wanna create a new procedure', js: true do
context 'Right after sign_in I shall see all procedure states links' do
scenario 'Finding draft procedures' do
page.find_by_id('draft-procedures').click
click_on 'draft-procedures'
expect(page).to have_current_path(admin_procedures_draft_path)
end
scenario 'Finding active procedures' do
page.find_by_id('active-procedures').click
click_on 'active-procedures'
expect(page).to have_current_path(admin_procedures_path)
end
scenario 'Finding archived procedures' do
page.find_by_id('archived-procedures').click
click_on 'archived-procedures'
expect(page).to have_current_path(admin_procedures_archived_path)
end
end
context 'Creating a new procedure' do
scenario 'Finding new procedure link' do
page.find_by_id('new-procedure').click
page.find_by_id('from-scratch').click
expect(page).to have_current_path(new_admin_procedure_path)
end
scenario 'Finding save button for new procedure, libelle, description and cadre_juridique required' do
page.find_by_id('new-procedure').click
page.find_by_id('from-scratch').click
expect(page).to have_selector('#new-procedure')
find('#new-procedure').click
click_on 'from-scratch'
expect(page).to have_current_path(new_admin_procedure_path)
fill_in 'procedure_duree_conservation_dossiers_dans_ds', with: '3'
fill_in 'procedure_duree_conservation_dossiers_hors_ds', with: '6'
page.find_by_id('save-procedure').click
page.find_by_id('flash_message').visible?
click_on 'save-procedure'
expect(page).to have_text('Libelle doit être rempli')
fill_in_dummy_procedure_details
page.find_by_id('save-procedure').click
expect(page).to have_current_path(admin_procedure_types_de_champ_path(Procedure.first.id.to_s))
click_on 'save-procedure'
expect(page).to have_current_path(admin_procedure_types_de_champ_path(Procedure.first))
end
end
context 'Editing a new procedure' do
before 'Create procedure' do
page.find_by_id('new-procedure').click
page.find_by_id('from-scratch').click
expect(page).to have_selector('#new-procedure')
find('#new-procedure').click
click_on 'from-scratch'
expect(page).to have_current_path(new_admin_procedure_path)
fill_in_dummy_procedure_details
page.find_by_id('save-procedure').click
click_on 'save-procedure'
procedure = Procedure.last
procedure.update(service: create(:service))
end
scenario 'Add champ, add file, visualize them in procedure preview' do
page.find_by_id('procedure_types_de_champ_attributes_0_libelle').set 'libelle de champ'
page.find_by_id('add_type_de_champ').click
page.find_by_id('procedure_types_de_champ_attributes_1_libelle')
fill_in 'procedure_types_de_champ_attributes_0_libelle', with: 'libelle de champ'
click_on 'add_type_de_champ'
expect(page).to have_current_path(admin_procedure_types_de_champ_path(Procedure.first))
expect(page).to have_selector('#procedure_types_de_champ_attributes_1_libelle')
expect(Procedure.first.types_de_champ.first.libelle).to eq('libelle de champ')
page.find_by_id('onglet-pieces').click
expect(page).to have_current_path(admin_procedure_pieces_justificatives_path(Procedure.first.id.to_s))
page.find_by_id('procedure_types_de_piece_justificative_attributes_0_libelle').set 'libelle de piece'
page.find_by_id('add_piece_justificative').click
page.find_by_id('procedure_types_de_piece_justificative_attributes_1_libelle')
click_on 'onglet-pieces'
expect(page).to have_current_path(admin_procedure_pieces_justificatives_path(Procedure.first))
fill_in 'procedure_types_de_piece_justificative_attributes_0_libelle', with: 'libelle de piece'
click_on 'add_piece_justificative'
expect(page).to have_current_path(admin_procedure_pieces_justificatives_path(Procedure.first))
expect(page).to have_selector('#procedure_types_de_piece_justificative_attributes_1_libelle')
preview_window = window_opened_by { page.find_by_id('onglet-preview').click }
preview_window = window_opened_by { click_on 'onglet-preview' }
within_window(preview_window) do
expect(page).to have_current_path(apercu_procedure_path(Procedure.first))
expect(page.find("input[type='text']")['placeholder']).to eq('libelle de champ')
expect(page.first('.pj-input label').text).to eq('libelle de piece')
expect(page).to have_field('libelle de champ')
expect(page).to have_field('libelle de piece')
end
end
scenario 'After adding champ and file, check impossibility to publish procedure, add accompagnateur and make publication' do
page.find_by_id('procedure_types_de_champ_attributes_0_libelle').set 'libelle de champ'
page.find_by_id('add_type_de_champ').click
page.find_by_id('onglet-pieces').click
page.find_by_id('procedure_types_de_piece_justificative_attributes_0_libelle').set 'libelle de piece'
page.find_by_id('add_piece_justificative').click
fill_in 'procedure_types_de_champ_attributes_0_libelle', with: 'libelle de champ'
click_on 'add_type_de_champ'
click_on 'onglet-pieces'
page.find_by_id('onglet-infos').click
expect(page).to have_current_path(admin_procedure_path(Procedure.first.id.to_s))
expect(page.find_by_id('publish-procedure')['disabled']).to eq('true')
expect(page).to have_current_path(admin_procedure_pieces_justificatives_path(Procedure.first))
fill_in 'procedure_types_de_piece_justificative_attributes_0_libelle', with: 'libelle de piece'
click_on 'add_piece_justificative'
page.find_by_id('onglet-accompagnateurs').click
expect(page).to have_current_path(admin_procedure_accompagnateurs_path(Procedure.first.id.to_s))
page.find_by_id('gestionnaire_email').set 'gestionnaire@apientreprise.fr'
page.find_by_id('add-gestionnaire-email').click
click_on 'onglet-infos'
expect(page).to have_current_path(admin_procedure_path(Procedure.first))
expect(page).to have_selector('#publish-procedure')
expect(page.find_by_id('publish-procedure')[:disabled]).to eq('true')
click_on 'onglet-accompagnateurs'
expect(page).to have_current_path(admin_procedure_accompagnateurs_path(Procedure.first))
fill_in 'gestionnaire_email', with: 'gestionnaire@apientreprise.fr'
click_on 'add-gestionnaire-email'
page.first('.gestionnaire-affectation').click
page.find_by_id('onglet-infos').click
click_on 'onglet-infos'
expect(page).to have_current_path(admin_procedure_path(Procedure.first))
expect(page).to have_selector('#publish-procedure', visible: true)
page.find_by_id('publish-procedure').click
find('#publish-procedure').click
expect(page.find_by_id('procedure_path')['value']).to eq('libelle-de-la-procedure')
page.find_by_id('publish').click
within '#publish-modal' do
expect(page).to have_field('procedure_path', with: 'libelle-de-la-procedure')
click_on 'publish'
end
expect(page).to have_text('Procédure publiée')
expect(page).to have_selector('.procedure-lien')
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

@ -96,12 +96,12 @@ feature 'The user' do
click_on 'Enregistrer le brouillon'
expect(user_dossier.reload.brouillon?).to be(true)
expect(page).to have_content('Votre brouillon a bien été sauvegardé')
expect(page).to have_current_path(dossier_path(user_dossier))
expect(page).to have_current_path(modifier_dossier_path(user_dossier))
# Check an incomplete dossier cannot be submitted when mandatory fields are missing
click_on 'Soumettre le dossier'
expect(user_dossier.reload.brouillon?).to be(true)
expect(page).to have_current_path(dossier_path(user_dossier))
expect(page).to have_current_path(modifier_dossier_path(user_dossier))
# Check a dossier can be submitted when all mandatory fields are filled
fill_in('texte obligatoire', with: 'super texte')

View file

@ -81,7 +81,7 @@ feature 'As a User I wanna create a dossier' do
wait_for_ajax
expect(page).to have_css('#recap-info-entreprise')
find(:css, "#dossier_autorisation_donnees[value='1']").set(true)
check 'dossier_autorisation_donnees'
page.find_by_id('etape_suivante').click
expect(page).to have_current_path(users_dossier_carte_path(procedure_with_siret.dossiers.last.id.to_s))
page.find_by_id('etape_suivante').click

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

@ -47,7 +47,7 @@ Capybara.register_driver :headless_chrome do |app|
desired_capabilities: capabilities
end
Capybara.default_max_wait_time = 1
Capybara.default_max_wait_time = 2
# Save a snapshot of the HTML page when an integration test fails
Capybara::Screenshot.autosave_on_failure = true

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