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 :current_page, :per_page, :offset, :total_entries, :total_pages
delegate_all delegate_all
def date_fr def display_date
date_previsionnelle.to_date.strftime('%d/%m/%Y') date_previsionnelle.to_date.strftime('%d/%m/%Y')
rescue rescue
'dd/mm/YYYY' 'dd/mm/YYYY'
@ -12,7 +12,7 @@ class DossierDecorator < Draper::Decorator
updated_at.localtime.strftime('%d/%m/%Y %H:%M') updated_at.localtime.strftime('%d/%m/%Y %H:%M')
end end
def state_fr def display_state
DossierDecorator.case_state_fr state DossierDecorator.case_state_fr state
end end
@ -27,23 +27,6 @@ class DossierDecorator < Draper::Decorator
end end
def self.case_state_fr state=self.state def self.case_state_fr state=self.state
case state h.t("activerecord.attributes.dossier.state.#{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
end end
end end

View file

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

View file

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

View file

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

View file

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

View file

@ -10,7 +10,7 @@
= dossier.procedure.libelle = dossier.procedure.libelle
%td %td
= link_to(dossier.nom_projet, users_dossier_recapitulatif_path(dossier)) = 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 %td= dossier.last_update
.pagination .pagination

View file

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

View file

@ -9,6 +9,15 @@ fr:
montant_projet: 'Le montant du projet' montant_projet: 'Le montant du projet'
montant_aide_demande: "Le montant d'aide demandée" montant_aide_demande: "Le montant d'aide demandée"
date_previsionnelle: "La date de début prévisionnelle" 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: errors:
models: models:
dossier: dossier:

View file

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

View file

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

View file

@ -4,6 +4,7 @@ describe SIADE::RNAAdapter do
let(:siret) { '50480511000013' } let(:siret) { '50480511000013' }
let(:body) { File.read('spec/support/files/rna.json') } let(:body) { File.read('spec/support/files/rna.json') }
let(:status) { 200 } let(:status) { 200 }
subject { described_class.new(siret).to_params } subject { described_class.new(siret).to_params }
before do before do
@ -15,36 +16,23 @@ describe SIADE::RNAAdapter do
let(:siret) { '234567' } let(:siret) { '234567' }
let(:body) { '' } let(:body) { '' }
let(:status) { '404' } let(:status) { '404' }
it { is_expected.to eq(nil) } it { is_expected.to eq(nil) }
end end
it '#to_params class est une Hash ?' do it { expect(subject).to be_an_instance_of(Hash) }
expect(subject).to be_an_instance_of(Hash)
end
context 'Attributs Associations' do describe 'Attributs Associations' do
it 'L\'associations contient bien un id' do it { expect(subject[:association_id]).to eq('W595001988') }
expect(subject[:association_id]).to eq('W595001988')
end
it 'L\'associations contient bien un titre' do it { expect(subject[:titre]).to eq('UN SUR QUATRE') }
expect(subject[:titre]).to eq('UN SUR QUATRE')
end
it 'L\'associations contient bien un objet' do 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") }
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 'L\'associations contient bien une date de creation' do it { expect(subject[:date_creation]).to eq('2014-01-23') }
expect(subject[:date_creation]).to eq('2014-01-23')
end
it 'L\'associations contient bien une date de de declaration' do it { expect(subject[:date_declaration]).to eq('2014-01-24') }
expect(subject[:date_declaration]).to eq('2014-01-24')
end
it 'L\'associations contient bien une date de publication' do it { expect(subject[:date_publication]).to eq('2014-02-08') }
expect(subject[:date_publication]).to eq('2014-02-08')
end
end end
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_css('#backoffice_index') }
it { is_expected.to have_content(procedure.libelle) } 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.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.to have_content(decorate_dossier_initiated.last_update) }
it { is_expected.not_to have_content(decorate_dossier_replied.nom_projet) } 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_css('#backoffice_index') }
it { is_expected.to have_content(procedure.libelle) } 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.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.to have_content(decorate_dossier_replied.last_update) }
it { is_expected.not_to have_content(decorate_dossier_initiated.nom_projet) } 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_css('#backoffice_index') }
it { is_expected.to have_content(procedure.libelle) } 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.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.to have_content(decorate_dossier_closed.last_update) }
it { is_expected.not_to have_content(decorate_dossier_initiated.nom_projet) } 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 describe 'dossier replied is present' do
it { is_expected.to have_content(dossier_2.procedure.libelle) } 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.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) } it { is_expected.to have_content(dossier_2.last_update) }
end end
@ -53,7 +53,7 @@ describe 'users/dossiers/index.html.haml', type: :view do
describe 'dossier initiated is present' do describe 'dossier initiated is present' do
it { is_expected.to have_content(dossier.procedure.libelle) } 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.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) } it { is_expected.to have_content(dossier.last_update) }
end end
@ -81,7 +81,7 @@ describe 'users/dossiers/index.html.haml', type: :view do
describe 'dossier termine is present' 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.procedure.libelle) }
it { is_expected.to have_content(dossier_termine.nom_projet) } 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) } it { is_expected.to have_content(dossier_termine.last_update) }
end end