Refactor dossier decorators

This commit is contained in:
Xavier J 2015-12-24 16:12:16 +01:00
parent 9fb575ef8c
commit 39b15e8b3d
13 changed files with 37 additions and 59 deletions

View file

@ -2,7 +2,7 @@ class DossierDecorator < Draper::Decorator
delegate :current_page, :per_page, :offset, :total_entries, :total_pages
delegate_all
def date_fr
def display_date
date_previsionnelle.to_date.strftime('%d/%m/%Y')
rescue
'dd/mm/YYYY'
@ -12,7 +12,7 @@ class DossierDecorator < Draper::Decorator
updated_at.localtime.strftime('%d/%m/%Y %H:%M')
end
def state_fr
def display_state
DossierDecorator.case_state_fr state
end
@ -27,23 +27,6 @@ class DossierDecorator < Draper::Decorator
end
def self.case_state_fr state=self.state
case state
when 'draft'
'Brouillon'
when 'initiated'
'Soumis'
when 'replied'
'Répondu'
when 'updated'
'Mis à jour'
when 'validated'
'Validé'
when 'submitted'
'Déposé'
when 'closed'
'Traité'
else
fail 'State not valid'
end
h.t("activerecord.attributes.dossier.state.#{state}")
end
end

View file

@ -73,7 +73,7 @@
%ul
- @facade.dossiers_archived_by_state_total.each do |dossier|
%li
= dossier.state_fr
= dossier.display_state
\:
= dossier.total
- else

View file

@ -9,7 +9,7 @@
%td= dossier.procedure.libelle
%td
= link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}")
%td= dossier.state_fr
%td= dossier.display_state
%td= dossier.last_update
.pagination

View file

@ -19,7 +19,7 @@
%td.col-md-2.col-lg-2
= @dossier.etablissement.siret
%td.col-md-1.col-lg-1{class: @dossier.state_color_class}
= @dossier.state_fr
= @dossier.display_state
%br
- if @dossiers_search.empty? && @dossier.nil?
@ -44,7 +44,7 @@
%td= dossier.entreprise.raison_sociale
%td= dossier.user.email
%td= dossier.etablissement.siret
%td{class: dossier.state_color_class}= dossier.state_fr
%td{class: dossier.state_color_class}= dossier.display_state
.pagination
= will_paginate @dossiers_search, renderer: BootstrapPagination::Rails

View file

@ -3,7 +3,7 @@
= "Dossier n°#{@facade.dossier.id}"
%h3{:class => 'text-success', :style => 'text-align:right'}
= @facade.dossier.state_fr
= @facade.dossier.display_state
= render partial: '/dossiers/infos_entreprise'

View file

@ -10,7 +10,7 @@
= dossier.procedure.libelle
%td
= link_to(dossier.nom_projet, users_dossier_recapitulatif_path(dossier))
%td{id: "dossier_#{dossier.id}_state"}= dossier.state_fr
%td{id: "dossier_#{dossier.id}_state"}= dossier.display_state
%td= dossier.last_update
.pagination

View file

@ -30,7 +30,7 @@
= 'Déposer mon dossier'
-else
%h3{:class => 'text-success', :style => 'text-align:right'}
= @facade.dossier.state_fr
= @facade.dossier.display_state
%br

View file

@ -9,6 +9,15 @@ fr:
montant_projet: 'Le montant du projet'
montant_aide_demande: "Le montant d'aide demandée"
date_previsionnelle: "La date de début prévisionnelle"
state:
draft: "Brouillon"
initiated: "Soumis"
replied: "Répondu"
updated: "Mis à jour"
validated: "Validé"
submitted: "Déposé"
closed: "Traité"
errors:
models:
dossier:

View file

@ -10,7 +10,7 @@ describe DossierDecorator do
end
describe 'state_fr' do
subject{ super().state_fr }
subject{ super().display_state }
it 'draft is brouillon' do
dossier.draft!

View file

@ -109,9 +109,7 @@ describe SIADE::API do
let(:status) { 200 }
let(:body) { File.read('spec/support/files/rna.json') }
it 'raises RestClient::Unauthorized' do
expect(subject).to eq(body)
end
it{ expect(subject).to eq(body) }
end
end
end

View file

@ -4,6 +4,7 @@ describe SIADE::RNAAdapter do
let(:siret) { '50480511000013' }
let(:body) { File.read('spec/support/files/rna.json') }
let(:status) { 200 }
subject { described_class.new(siret).to_params }
before do
@ -15,36 +16,23 @@ describe SIADE::RNAAdapter do
let(:siret) { '234567' }
let(:body) { '' }
let(:status) { '404' }
it { is_expected.to eq(nil) }
end
it '#to_params class est une Hash ?' do
expect(subject).to be_an_instance_of(Hash)
end
it { expect(subject).to be_an_instance_of(Hash) }
context 'Attributs Associations' do
it 'L\'associations contient bien un id' do
expect(subject[:association_id]).to eq('W595001988')
end
describe 'Attributs Associations' do
it { expect(subject[:association_id]).to eq('W595001988') }
it 'L\'associations contient bien un titre' do
expect(subject[:titre]).to eq('UN SUR QUATRE')
end
it { expect(subject[:titre]).to eq('UN SUR QUATRE') }
it 'L\'associations contient bien un objet' do
expect(subject[:objet]).to eq("valoriser, transmettre et partager auprès des publics les plus larges possibles, les bienfaits de l'immigration, la richesse de la diversité et la curiosité de l'autre autrement")
end
it { expect(subject[:objet]).to eq("valoriser, transmettre et partager auprès des publics les plus larges possibles, les bienfaits de l'immigration, la richesse de la diversité et la curiosité de l'autre autrement") }
it 'L\'associations contient bien une date de creation' do
expect(subject[:date_creation]).to eq('2014-01-23')
end
it { expect(subject[:date_creation]).to eq('2014-01-23') }
it 'L\'associations contient bien une date de de declaration' do
expect(subject[:date_declaration]).to eq('2014-01-24')
end
it { expect(subject[:date_declaration]).to eq('2014-01-24') }
it 'L\'associations contient bien une date de publication' do
expect(subject[:date_publication]).to eq('2014-02-08')
end
it { expect(subject[:date_publication]).to eq('2014-02-08') }
end
end

View file

@ -22,7 +22,7 @@ describe 'backoffice/dossiers/index.html.haml', type: :view do
it { is_expected.to have_css('#backoffice_index') }
it { is_expected.to have_content(procedure.libelle) }
it { is_expected.to have_content(decorate_dossier_initiated.nom_projet) }
it { is_expected.to have_content(decorate_dossier_initiated.state_fr) }
it { is_expected.to have_content(decorate_dossier_initiated.display_state) }
it { is_expected.to have_content(decorate_dossier_initiated.last_update) }
it { is_expected.not_to have_content(decorate_dossier_replied.nom_projet) }
@ -47,7 +47,7 @@ describe 'backoffice/dossiers/index.html.haml', type: :view do
it { is_expected.to have_css('#backoffice_index') }
it { is_expected.to have_content(procedure.libelle) }
it { is_expected.to have_content(decorate_dossier_replied.nom_projet) }
it { is_expected.to have_content(decorate_dossier_replied.state_fr) }
it { is_expected.to have_content(decorate_dossier_replied.display_state) }
it { is_expected.to have_content(decorate_dossier_replied.last_update) }
it { is_expected.not_to have_content(decorate_dossier_initiated.nom_projet) }
@ -70,7 +70,7 @@ describe 'backoffice/dossiers/index.html.haml', type: :view do
it { is_expected.to have_css('#backoffice_index') }
it { is_expected.to have_content(procedure.libelle) }
it { is_expected.to have_content(decorate_dossier_closed.nom_projet) }
it { is_expected.to have_content(decorate_dossier_closed.state_fr) }
it { is_expected.to have_content(decorate_dossier_closed.display_state) }
it { is_expected.to have_content(decorate_dossier_closed.last_update) }
it { is_expected.not_to have_content(decorate_dossier_initiated.nom_projet) }

View file

@ -25,7 +25,7 @@ describe 'users/dossiers/index.html.haml', type: :view do
describe 'dossier replied is present' do
it { is_expected.to have_content(dossier_2.procedure.libelle) }
it { is_expected.to have_content(dossier_2.nom_projet) }
it { is_expected.to have_content(dossier_2.state_fr) }
it { is_expected.to have_content(dossier_2.display_state) }
it { is_expected.to have_content(dossier_2.last_update) }
end
@ -53,7 +53,7 @@ describe 'users/dossiers/index.html.haml', type: :view do
describe 'dossier initiated is present' do
it { is_expected.to have_content(dossier.procedure.libelle) }
it { is_expected.to have_content(dossier.nom_projet) }
it { is_expected.to have_content(dossier.state_fr) }
it { is_expected.to have_content(dossier.display_state) }
it { is_expected.to have_content(dossier.last_update) }
end
@ -81,7 +81,7 @@ describe 'users/dossiers/index.html.haml', type: :view do
describe 'dossier termine is present' do
it { is_expected.to have_content(dossier_termine.procedure.libelle) }
it { is_expected.to have_content(dossier_termine.nom_projet) }
it { is_expected.to have_content(dossier_termine.state_fr) }
it { is_expected.to have_content(dossier_termine.display_state) }
it { is_expected.to have_content(dossier_termine.last_update) }
end