Merge branch 'dev'

This commit is contained in:
gregoirenovel 2018-10-09 18:03:11 +02:00
commit 3278769096
29 changed files with 177 additions and 537 deletions

View file

@ -87,10 +87,6 @@ gem 'bootstrap-wysihtml5-rails', '~> 0.3.3.8'
gem 'spreadsheet_architect' gem 'spreadsheet_architect'
gem 'axlsx', '~> 3.0.0.pre' # https://github.com/randym/axlsx/issues/501#issuecomment-373640365 gem 'axlsx', '~> 3.0.0.pre' # https://github.com/randym/axlsx/issues/501#issuecomment-373640365
gem 'apipie-rails'
# For Markdown support in apipie
gem 'maruku'
gem 'openstack' gem 'openstack'
gem 'browser' gem 'browser'

View file

@ -89,8 +89,6 @@ GEM
selectize-rails (~> 0.6) selectize-rails (~> 0.6)
aes_key_wrap (1.0.1) aes_key_wrap (1.0.1)
after_party (1.10.0) after_party (1.10.0)
apipie-rails (0.5.10)
rails (>= 4.1)
arel (9.0.0) arel (9.0.0)
ast (2.4.0) ast (2.4.0)
attr_required (1.0.1) attr_required (1.0.1)
@ -483,7 +481,6 @@ GEM
rest-client rest-client
marcel (0.3.2) marcel (0.3.2)
mimemagic (~> 0.3.2) mimemagic (~> 0.3.2)
maruku (0.7.3)
method_source (0.9.0) method_source (0.9.0)
mime-types (3.1) mime-types (3.1)
mime-types-data (~> 3.2015) mime-types-data (~> 3.2015)
@ -812,7 +809,6 @@ DEPENDENCIES
active_model_serializers active_model_serializers
administrate administrate
after_party after_party
apipie-rails
axlsx (~> 3.0.0.pre) axlsx (~> 3.0.0.pre)
bcrypt bcrypt
bootstrap-sass (~> 3.3.5) bootstrap-sass (~> 3.3.5)
@ -858,7 +854,6 @@ DEPENDENCIES
lograge lograge
logstash-event logstash-event
mailjet mailjet
maruku
mina! mina!
omniauth-github omniauth-github
openid_connect openid_connect
@ -906,4 +901,4 @@ DEPENDENCIES
zxcvbn-ruby zxcvbn-ruby
BUNDLED WITH BUNDLED WITH
1.16.5 1.16.6

View file

@ -44,14 +44,6 @@ class Admin::ProceduresController < AdminController
@mine = @procedure.path_is_mine?(@path) @mine = @procedure.path_is_mine?(@path)
end end
def hide
procedure = current_administrateur.procedures.find(params[:id])
procedure.hide!
flash.notice = "Démarche supprimée, en cas d'erreur #{helpers.contact_link('contactez nous', tags: 'démarche supprimée')}"
redirect_to admin_procedures_draft_path
end
def destroy def destroy
procedure = current_administrateur.procedures.find(params[:id]) procedure = current_administrateur.procedures.find(params[:id])

View file

@ -3,17 +3,6 @@ class API::V1::DossiersController < APIController
DEFAULT_PAGE_SIZE = 100 DEFAULT_PAGE_SIZE = 100
resource_description do
description AUTHENTICATION_TOKEN_DESCRIPTION
end
api :GET, '/procedures/:procedure_id/dossiers/', 'Liste de tous les dossiers d\'une démarche'
param :procedure_id, Integer, desc: "L'identifiant de la démarche", required: true
param :page, String, desc: "Numéro de la page", required: false
param :resultats_par_page, String, desc: "Nombre de résultats par page (#{DEFAULT_PAGE_SIZE} par défaut, maximum 1 000)", required: false
error code: 401, desc: "Non authorisé"
error code: 404, desc: "Démarche inconnue"
def index def index
dossiers = @procedure.dossiers.state_not_brouillon.page(params[:page]).per(per_page) dossiers = @procedure.dossiers.state_not_brouillon.page(params[:page]).per(per_page)
@ -22,12 +11,6 @@ class API::V1::DossiersController < APIController
render json: {}, status: 404 render json: {}, status: 404
end end
api :GET, '/procedures/:procedure_id/dossiers/:id', 'Informations du dossier d\'une démarche'
param :procedure_id, Integer, desc: "L'identifiant de la démarche", required: true
param :dossier_id, Integer, desc: "L'identifiant du dossier", required: true
error code: 401, desc: "Non authorisé"
error code: 404, desc: "Démarche ou dossier inconnu"
def show def show
dossier = @procedure.dossiers.find(params[:id]) dossier = @procedure.dossiers.find(params[:id])

View file

@ -1,15 +1,6 @@
class API::V1::ProceduresController < APIController class API::V1::ProceduresController < APIController
before_action :fetch_procedure_and_check_token before_action :fetch_procedure_and_check_token
resource_description do
description AUTHENTICATION_TOKEN_DESCRIPTION
end
api :GET, '/procedures/:id', 'Informations concernant une démarche'
param :id, Integer, desc: "L'identifiant de la démarche", required: true
error code: 401, desc: "Non authorisé"
error code: 404, desc: "Démarche inconnue"
def show def show
render json: { procedure: ProcedureSerializer.new(@procedure.decorate).as_json } render json: { procedure: ProcedureSerializer.new(@procedure.decorate).as_json }
end end

View file

@ -1,12 +1,4 @@
class APIController < ApplicationController class APIController < ApplicationController
AUTHENTICATION_TOKEN_DESCRIPTION = <<-EOS
L'authentification de l'API se fait via un header HTTP :
```
Authorization: Bearer &lt;Token administrateur&gt;
```
EOS
before_action :default_format_json before_action :default_format_json
protected protected

View file

@ -6,5 +6,16 @@ module Manager
flash[:notice] = "Démarche whitelistée." flash[:notice] = "Démarche whitelistée."
redirect_to manager_procedure_path(procedure) redirect_to manager_procedure_path(procedure)
end end
def draft
procedure = Procedure.find(params[:id])
if procedure.dossiers.empty?
procedure.draft!
flash[:notice] = "La démarche a bien été passée en brouillon."
else
flash[:alert] = "Impossible de repasser en brouillon une démarche à laquelle sont rattachés des dossiers."
end
redirect_to manager_procedure_path(procedure)
end
end end
end end

View file

@ -16,7 +16,7 @@ class Users::DossiersController < UsersController
procedure_path = ProcedurePath.find_by(path: params[:procedure_path]) procedure_path = ProcedurePath.find_by(path: params[:procedure_path])
procedure = procedure_path&.procedure procedure = procedure_path&.procedure
if procedure&.brouillon_avec_lien? if procedure&.brouillon? && procedure&.path.present?
redirect_to new_users_dossier_path(procedure_id: procedure.id, brouillon: true) redirect_to new_users_dossier_path(procedure_id: procedure.id, brouillon: true)
else else
flash.alert = "La démarche est inconnue." flash.alert = "La démarche est inconnue."

View file

@ -19,29 +19,4 @@ module ProcedureHelper
action = procedure.archivee? ? :reopen : :publish action = procedure.archivee? ? :reopen : :publish
t(action, scope: [:modal, :publish, key]) t(action, scope: [:modal, :publish, key])
end end
def dossiers_deletion_warning(procedure)
dossiers_count = procedure.dossiers.state_not_brouillon.count
brouillons_count = procedure.dossiers.state_brouillon.count
formatted_dossiers_count = nil
formatted_brouillons_count = nil
if dossiers_count > 0
formatted_dossiers_count = pluralize(dossiers_count, "dossier", "dossiers")
end
if brouillons_count > 0
formatted_brouillons_count = pluralize(brouillons_count, "brouillon", "brouillons")
end
formatted_combination = [formatted_dossiers_count, formatted_brouillons_count]
.compact
.join(" et ")
[
formatted_combination,
dossiers_count + brouillons_count == 1 ? "est rattaché" : "sont rattachés",
"à cette démarche, la suppression de cette démarche entrainera également leur suppression."
].join(" ")
end
end end

View file

@ -277,6 +277,23 @@ class Dossier < ApplicationRecord
DossierMailer.notify_deletion_to_user(deleted_dossier, user.email).deliver_later DossierMailer.notify_deletion_to_user(deleted_dossier, user.email).deliver_later
end end
def old_state_value
case state
when Dossier.states.fetch(:en_construction)
'initiated'
when Dossier.states.fetch(:en_instruction)
'received'
when Dossier.states.fetch(:accepte)
'closed'
when Dossier.states.fetch(:refuse)
'refused'
when Dossier.states.fetch(:sans_suite)
'without_continuation'
else
state
end
end
private private
def update_state_dates def update_state_dates

View file

@ -86,6 +86,10 @@ class Procedure < ApplicationRecord
transitions from: :publiee, to: :hidden transitions from: :publiee, to: :hidden
transitions from: :archivee, to: :hidden transitions from: :archivee, to: :hidden
end end
event :draft, after: :after_draft do
transitions from: :publiee, to: :brouillon
end
end end
def publish_or_reopen!(path) def publish_or_reopen!(path)
@ -372,6 +376,10 @@ class Procedure < ApplicationRecord
publish_with_path!(path) publish_with_path!(path)
end end
def after_draft
update!(published_at: nil)
end
def update_juridique_required def update_juridique_required
self.juridique_required ||= (cadre_juridique.present? || deliberation.attached?) self.juridique_required ||= (cadre_juridique.present? || deliberation.attached?)
true true

View file

@ -43,20 +43,7 @@ class DossierSerializer < ActiveModel::Serializer
end end
def state def state
case object.state object.old_state_value
when Dossier.states.fetch(:en_construction)
'initiated'
when Dossier.states.fetch(:en_instruction)
'received'
when Dossier.states.fetch(:accepte)
'closed'
when Dossier.states.fetch(:refuse)
'refused'
when Dossier.states.fetch(:sans_suite)
'without_continuation'
else
object.state
end
end end
def simplified_state def simplified_state

View file

@ -1,9 +1,14 @@
class DossiersSerializer < ActiveModel::Serializer class DossiersSerializer < ActiveModel::Serializer
attributes :id, attributes :id,
:updated_at, :updated_at,
:initiated_at :initiated_at,
:state
def initiated_at def initiated_at
object.en_construction_at object.en_construction_at
end end
def state
object.old_state_value
end
end end

View file

@ -74,23 +74,3 @@
- else - else
.alert.alert-info .alert.alert-info
Cette démarche na pas encore de lien, et nest donc pas accessible par le public. Cette démarche na pas encore de lien, et nest donc pas accessible par le public.
%br
- if @procedure.publiee_ou_archivee?
%h3 Supprimer la démarche
.alert.alert-danger
%p
Attention : la suppression dune démarche est définitive.
- dossiers_count = @procedure.dossiers.count
- if dossiers_count > 0
%p
= dossiers_deletion_warning(@procedure)
%p.text-right
= link_to "J'ai compris, je supprime la démarche",
hide_admin_procedure_path(@procedure),
method: :post,
class: "btn btn-danger",
data: { confirm: "Voulez-vous supprimer la démarche ?", disable: true }

View file

@ -36,6 +36,10 @@ as well as a link to its edit page.
<% if !procedure.whitelisted? %> <% if !procedure.whitelisted? %>
<%= link_to 'whitelister', whitelist_manager_procedure_path(procedure), method: :post, class: 'button' %> <%= link_to 'whitelister', whitelist_manager_procedure_path(procedure), method: :post, class: 'button' %>
<% end %> <% end %>
<% if procedure.publiee? && procedure.dossiers.empty? %>
<%= link_to 'passer en brouillon', draft_manager_procedure_path(procedure), method: :post, class: 'button' %>
<% end %>
<div> <div>
</header> </header>

View file

@ -34,7 +34,7 @@
%li.footer-link %li.footer-link
= link_to "Documentation", DOC_URL, :class => "footer-link", :target => "_blank", rel: "noopener noreferrer" = link_to "Documentation", DOC_URL, :class => "footer-link", :target => "_blank", rel: "noopener noreferrer"
%li.footer-link %li.footer-link
= link_to "Documentation de l'API", "/docs", :class => "footer-link", :target => "_blank", rel: "noopener noreferrer" = link_to "Documentation de l'API", API_DOC_URL, :class => "footer-link", :target => "_blank", rel: "noopener noreferrer"
%li.footer-link %li.footer-link
= link_to "FAQ", FAQ_URL, :class => "footer-link", :target => "_blank", rel: "noopener noreferrer" = link_to "FAQ", FAQ_URL, :class => "footer-link", :target => "_blank", rel: "noopener noreferrer"
%li.footer-link %li.footer-link

View file

@ -1,19 +0,0 @@
Apipie.configure do |config|
config.app_name = "API demarches-simplifiees.fr"
config.api_base_url = "/api/v1"
config.doc_base_url = "/docs"
config.api_controllers_matcher = Rails.root.join("app", "controllers"," api", "v1", "**", "*.rb")
config.markup = Apipie::Markup::Markdown.new
config.default_version = '1.0'
config.validate = false
config.namespaced_resources = true
config.show_all_examples = true
config.languages = ['fr']
config.default_locale = 'fr'
config.app_info = <<~EOS
Description
EOS
end

View file

@ -13,4 +13,5 @@ DOC_URL = "https://doc.demarches-simplifiees.fr"
LISTE_DES_DEMARCHES_URL = [DOC_URL, "listes-des-demarches"].join("/") LISTE_DES_DEMARCHES_URL = [DOC_URL, "listes-des-demarches"].join("/")
CGU_URL = [DOC_URL, "cgu"].join("/") CGU_URL = [DOC_URL, "cgu"].join("/")
MENTIONS_LEGALES_URL = [CGU_URL, "4-mentions-legales"].join("#") MENTIONS_LEGALES_URL = [CGU_URL, "4-mentions-legales"].join("#")
API_DOC_URL = [DOC_URL, "pour-aller-plus-loin", "api"].join("/")
FAQ_URL = "https://faq.demarches-simplifiees.fr" FAQ_URL = "https://faq.demarches-simplifiees.fr"

View file

@ -33,8 +33,6 @@ fr:
previous: Précédent previous: Précédent
first: Premier first: Premier
truncate: '&hellip;' truncate: '&hellip;'
apipie:
api_documentation: "Documentation de l'API demarches-simplifiees.fr"
mail: mail:
administration: administration:

View file

@ -8,6 +8,7 @@ Rails.application.routes.draw do
namespace :manager do namespace :manager do
resources :procedures, only: [:index, :show] do resources :procedures, only: [:index, :show] do
post 'whitelist', on: :member post 'whitelist', on: :member
post 'draft', on: :member
end end
resources :dossiers, only: [:index, :show] do resources :dossiers, only: [:index, :show] do
@ -196,7 +197,6 @@ Rails.application.routes.draw do
end end
member do member do
post :hide
delete :delete_logo delete :delete_logo
delete :delete_deliberation delete :delete_deliberation
delete :delete_notice delete :delete_notice
@ -379,8 +379,6 @@ Rails.application.routes.draw do
get 'renew-api-token' => redirect('/profil') get 'renew-api-token' => redirect('/profil')
end end
apipie
# #
# Legacy routes # Legacy routes
# #

View file

@ -1,295 +0,0 @@
{
"dossiers#index": [
{
"verb": "GET",
"path": "/api/v1/procedures/2/dossiers",
"versions": [
"1.0"
],
"query": "token=92cf04673cb66ab57a0c45e085b5140398ab4b6c",
"request_data": null,
"response_data": {
"dossiers": [
{
"id": 2,
"nom_projet": "Demande de subvention dans le cadre d'accompagnement d'enfant à l'étranger",
"updated_at": "2008-09-01T08:05:00.000Z",
"initiated_at": "2008-09-02T08:05:00.000Z"
}
],
"pagination": {
"page": 1,
"resultats_par_page": 12,
"nombre_de_page": 1
}
},
"code": "200",
"show_in_doc": 1,
"recorded": true
}
],
"dossiers#show": [
{
"verb": "GET",
"path": "/api/v1/procedures/1/dossiers/1",
"versions": [
"1.0"
],
"query": "token=7cba5df87cf134d07c3c467eb21b4f2a2b2605be",
"request_data": null,
"response_data": {
"dossier": {
"id": 1,
"nom_projet": "Demande de subvention dans le cadre d'accompagnement d'enfant à l'étranger",
"description": "Ma super description",
"created_at": "2008-09-01T08:05:00.000Z",
"updated_at": "2008-09-01T08:05:00.000Z",
"archived": false,
"state": "initiated",
"simplified_state": "En construction",
"initiated_at": "2017-04-11T12:00:12.000Z",
"received_at": null,
"processed_at": null,
"motivation": null,
"instructeurs": [
"gestionnaire@apientreprise.fr"
],
"invites": [
"nom@domaine.fr"
],
"individual": {
"nom": "Monmari",
"prenom": "René"
},
"entreprise": {
"siren": "440117620",
"capital_social": 537100000,
"numero_tva_intracommunautaire": "FR27440117620",
"forme_juridique": "SA à conseil d'administration (s.a.i.)",
"forme_juridique_code": "5599",
"nom_commercial": "GRTGAZ",
"raison_sociale": "GRTGAZ",
"siret_siege_social": "44011762001530",
"code_effectif_entreprise": "51",
"date_creation": "2016-01-28T10:16:29.000Z",
"nom": null,
"prenom": null
},
"etablissement": {
"siret": "44011762001530",
"siege_social": true,
"naf": "4950Z",
"libelle_naf": "Transports par conduites",
"adresse": "GRTGAZ\r IMMEUBLE BORA\r 6 RUE RAOUL NORDLING\r 92270 BOIS COLOMBES\r",
"numero_voie": "6",
"type_voie": "RUE",
"nom_voie": "RAOUL NORDLING",
"complement_adresse": "IMMEUBLE BORA",
"code_postal": "92270",
"localite": "BOIS COLOMBES",
"code_insee_localite": "92009"
},
"cerfa": null,
"champs": [
{
"value": null,
"type_de_champ": {
"id": 1,
"libelle": "Description",
"type": "textarea",
"order_place": 1,
"description": "description de votre projet"
}
},
{
"value": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
2.3050735,
48.8401501
],
[
2.3052329,
48.8402106
],
[
2.3053759,
48.8400422
],
[
2.3050735,
48.8401501
]
]
]
]
},
"type_de_champ": {
"id": -1,
"libelle": "cadastre",
"type_champ": "cadastre",
"order_place": -1,
"descripton": ""
}
},
{
"value": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
2.3050735,
48.8401501
],
[
2.3052329,
48.8402106
],
[
2.3053759,
48.8400422
],
[
2.3050735,
48.8401501
]
]
]
]
},
"type_de_champ": {
"id": -1,
"libelle": "quartier prioritaire",
"type_champ": "quartier_prioritaire",
"order_place": -1,
"descripton": ""
}
},
{
"value": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
2.3049509525299072,
48.84028511554904
],
[
2.305165529251098,
48.84014035882062
],
[
2.3049670457839966,
48.84005562298059
],
[
2.3049509525299072,
48.84028511554904
]
]
]
]
},
"type_de_champ": {
"id": -1,
"libelle": "user_geometry",
"type_champ": "user_geometry",
"order_place": -1,
"descripton": ""
}
}
],
"champs_private": [
{
"value": null,
"type_de_champ": {
"id": 1,
"libelle": "Description privée",
"type_champ": "text",
"order_place": 0,
"description": "description privée"
}
}
],
"pieces_justificatives": [
{
"url": null,
"type_de_piece_justificative": {
"id": 1,
"libelle": "RIB",
"description": "Releve identité bancaire"
}
},
{
"url": null,
"type_de_piece_justificative": {
"id": 2,
"libelle": "Attestation MSA",
"description": "recuperation automatique"
}
}
]
}
},
"code": "200",
"show_in_doc": 1,
"recorded": true
}
],
"procedures#show": [
{
"verb": "GET",
"path": "/api/v1/procedures/3",
"versions": [
"1.0"
],
"query": "token=cc00dc59ddc89f64c6310bb4e25c55eeb63ee89c",
"request_data": null,
"response_data": {
"procedure": {
"label": "Demande de subvention",
"link": "http://localhost",
"id": 3,
"description": "Demande de subvention à l'intention des associations",
"organisation": "Orga DINSIC",
"direction": "direction DINSIC",
"archived_at": null,
"geographic_information": {
"use_api_carto": true,
"quartiers_prioritaires": true,
"cadastre": true
},
"types_de_champ": [
{
"id": 3,
"libelle": "Description",
"type": "textarea",
"order_place": 1,
"description": "description de votre projet"
}
],
"types_de_piece_justificative": [
{
"id": 5,
"libelle": "RIB",
"description": "Releve identité bancaire"
},
{
"id": 6,
"libelle": "Attestation MSA",
"description": "recuperation automatique"
}
]
}
},
"code": "200",
"show_in_doc": 1,
"recorded": true
}
]
}

View file

@ -0,0 +1,94 @@
namespace :'2018_10_03_fix_mailjet_mistakes' do
task activation_emails: :environment do
activation_file_path = ENV['ACTIVATION']
if File.file?(activation_file_path)
rake_puts "loading #{activation_file_path} file for account activation"
else
rake_puts "no file #{activation_file_path} found"
end
emails = File.new(activation_file_path).readlines.map(&:strip)
emails.each do |email|
user = User.find_by(email: email)
if user.present?
rake_puts "sending activation mail for #{email}"
if user.confirmed?
UserMailer.new_account_warning(user).deliver_later
else
user.resend_confirmation_instructions
end
else
rake_puts "user #{email} does not exist"
end
end
end
task password_emails: :environment do
password_file_path = ENV['PASSWORD']
if File.file?(password_file_path)
rake_puts "loading #{password_file_path} file for changing password"
else
rake_puts "no file #{password_file_path} found"
end
emails = File.new(password_file_path).readlines.map(&:strip)
emails.each do |email|
user = User.find_by(email: email)
if user.present?
rake_puts "sending changing password mail for #{email}"
user.send_reset_password_instructions
else
rake_puts "user #{email} does not exist"
end
end
end
task notification_emails: :environment do
notification_file_path = ENV['NOTIFICATION']
if File.file?(notification_file_path)
rake_puts "loading #{notification_file_path} file for notification"
else
rake_puts "no file #{notification_file_path} found"
end
lines = File.new(notification_file_path).readlines.map(&:strip)
lines.each do |line|
email, *subject = line.split(',')
subject = *subject.join
user = User.find_by(email: email)
body = <<-EOS
Bonjour,
Suite à un incident technique concernant les envois d'emails sur le site demarches-simplifiees.fr, nous n'avons pas pu vous remettre l'email intitulé #{subject}.
Vous pouvez néanmoins le consulter directement dans la messagerie de votre dossier en vous connectant sur https://www.demarches-simplifiees.fr/users/sign_in .
Veuillez nous excuser pour la gêne occasionnée.
Cordialement,
L'équipe de demarches-simplifiees.fr
EOS
if user.present?
rake_puts "sending notification for #{email}"
ActionMailer::Base.mail(
from: "contact@demarches-simplifiees.fr",
to: email,
subject: subject,
body: body
).deliver_later
else
rake_puts "user #{email} does not exist"
end
end
end
end

View file

@ -680,38 +680,6 @@ describe Admin::ProceduresController, type: :controller do
end end
end end
describe "POST #hide" do
subject { post :hide, params: { id: procedure.id } }
context "when procedure is not owned by administrateur" do
let(:procedure) { create :procedure, administrateur: create(:administrateur) }
it { expect{ subject }.to raise_error(ActiveRecord::RecordNotFound) }
end
context "when procedure is owned by administrateur" do
let(:procedure) { create :procedure, :published, administrateur: admin }
before do
subject
procedure.reload
end
it { expect(procedure.hidden_at).not_to be_nil }
it { expect(procedure.procedure_path).to be_nil }
end
context "when procedure has no path" do
let(:procedure) { create :procedure, administrateur: admin }
it { expect{ subject }.not_to raise_error }
it do
subject
expect(procedure.reload.hidden_at).not_to be_nil
end
end
end
describe "DELETE #delete_deliberation" do describe "DELETE #delete_deliberation" do
context "with a demarche the admin owns" do context "with a demarche the admin owns" do
let(:procedure) { create(:procedure, :with_deliberation, administrateur: admin) } let(:procedure) { create(:procedure, :with_deliberation, administrateur: admin) }

View file

@ -77,7 +77,8 @@ describe API::V1::DossiersController do
it { expect(subject[:id]).to eq(dossier.id) } it { expect(subject[:id]).to eq(dossier.id) }
it { expect(subject[:updated_at]).to eq("2008-09-01T10:05:00.000Z") } it { expect(subject[:updated_at]).to eq("2008-09-01T10:05:00.000Z") }
it { expect(subject[:initiated_at]).to eq("2008-09-01T10:06:00.000Z") } it { expect(subject[:initiated_at]).to eq("2008-09-01T10:06:00.000Z") }
it { expect(subject.keys.size).to eq(3) } it { expect(subject[:state]).to eq("initiated") }
it { expect(subject.keys.size).to eq(4) }
end end
end end

View file

@ -1,51 +0,0 @@
RSpec.describe ProcedureHelper, type: :helper do
let(:procedure) { create(:procedure) }
describe '#dossiers_deletion_warning' do
subject { dossiers_deletion_warning(procedure) }
context 'with 1 submitted dossier' do
before do
dossier_1 = create(:dossier, :en_construction, procedure: procedure)
end
it { is_expected.to eq('1 dossier est rattaché à cette démarche, la suppression de cette démarche entrainera également leur suppression.') }
end
context 'with 2 submitted dossiers' do
before do
dossier_1 = create(:dossier, :en_construction, procedure: procedure)
dossier_2 = create(:dossier, :en_instruction, procedure: procedure)
end
it { is_expected.to eq('2 dossiers sont rattachés à cette démarche, la suppression de cette démarche entrainera également leur suppression.') }
end
context 'with 1 brouillon dossier' do
before do
dossier_1 = create(:dossier, procedure: procedure)
end
it { is_expected.to eq('1 brouillon est rattaché à cette démarche, la suppression de cette démarche entrainera également leur suppression.') }
end
context 'with 2 brouillons dossiers' do
before do
dossier_1 = create(:dossier, procedure: procedure)
dossier_2 = create(:dossier, procedure: procedure)
end
it { is_expected.to eq('2 brouillons sont rattachés à cette démarche, la suppression de cette démarche entrainera également leur suppression.') }
end
context 'with 2 submitted dossiers and 1 brouillon dossier' do
before do
dossier_1 = create(:dossier, :en_instruction, procedure: procedure)
dossier_2 = create(:dossier, :en_instruction, procedure: procedure)
dossier_3 = create(:dossier, procedure: procedure)
end
it { is_expected.to eq('2 dossiers et 1 brouillon sont rattachés à cette démarche, la suppression de cette démarche entrainera également leur suppression.') }
end
end
end

View file

@ -1004,4 +1004,32 @@ describe Dossier do
it { expect(long_expired_dossier).to be_retention_expired } it { expect(long_expired_dossier).to be_retention_expired }
end end
end end
describe 'old_state_value' do
subject { dossier.old_state_value }
context 'when the dossier is en instruction' do
let(:dossier) { create(:dossier, :en_instruction) }
it { is_expected.to eq('received') }
end
context 'when the dossier is accepte' do
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:accepte)) }
it { is_expected.to eq('closed') }
end
context 'when the dossier is refuse' do
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:refuse)) }
it { is_expected.to eq('refused') }
end
context 'when the dossier is sans_suite' do
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:sans_suite)) }
it { is_expected.to eq('without_continuation') }
end
end
end end

View file

@ -13,25 +13,6 @@ describe DossierSerializer do
let(:dossier) { create(:dossier, :en_instruction) } let(:dossier) { create(:dossier, :en_instruction) }
it { is_expected.to include(received_at: dossier.en_instruction_at) } it { is_expected.to include(received_at: dossier.en_instruction_at) }
it { is_expected.to include(state: 'received') }
end
context 'when the dossier is accepte' do
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:accepte)) }
it { is_expected.to include(state: 'closed') }
end
context 'when the dossier is refuse' do
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:refuse)) }
it { is_expected.to include(state: 'refused') }
end
context 'when the dossier is sans_suite' do
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:sans_suite)) }
it { is_expected.to include(state: 'without_continuation') }
end end
end end
end end

View file

@ -6,6 +6,7 @@ describe DossiersSerializer do
let(:dossier) { create(:dossier, :en_construction) } let(:dossier) { create(:dossier, :en_construction) }
it { is_expected.to include(initiated_at: dossier.en_construction_at) } it { is_expected.to include(initiated_at: dossier.en_construction_at) }
it { is_expected.to include(state: 'initiated') }
end end
end end
end end

View file

@ -111,7 +111,6 @@ RSpec.configure do |config|
config.infer_base_class_for_anonymous_controllers = false config.infer_base_class_for_anonymous_controllers = false
config.run_all_when_everything_filtered = true config.run_all_when_everything_filtered = true
config.filter_run :show_in_doc => true if ENV['APIPIE_RECORD']
config.filter_run :focus => true config.filter_run :focus => true
config.order = 'random' config.order = 'random'