Merge pull request #232 from sgmap/fix-dossier-link

Change the link to a linked dossier depending on the user profile
This commit is contained in:
gregoirenovel 2017-05-04 17:46:06 +02:00 committed by GitHub
commit 99b232947e
4 changed files with 45 additions and 2 deletions

View file

@ -10,5 +10,4 @@ class ChampDecorator < Draper::Decorator
def description_with_links
description.gsub(URI.regexp, '<a target="_blank" href="\0">\0</a>').html_safe if description
end
end

View file

@ -1,4 +1,6 @@
class DossierDecorator < Draper::Decorator
include Rails.application.routes.url_helpers
delegate :current_page, :per_page, :offset, :total_entries, :total_pages
delegate_all
@ -14,6 +16,16 @@ class DossierDecorator < Draper::Decorator
DossierDecorator.case_state_fr state
end
def url(gestionnaire_signed_in)
if gestionnaire_signed_in
backoffice_dossier_path(id)
elsif brouillon?
users_dossier_description_path(id)
else
users_dossier_recapitulatif_path(id)
end
end
def self.case_state_fr state=self.state
h.t("activerecord.attributes.dossier.state.#{state}")
end

View file

@ -41,7 +41,7 @@
- if champ.type_champ == 'dossier_link'
- dossier = Dossier.includes(:procedure).find_by(id: champ.decorate.value)
- if dossier
= link_to("Dossier #{dossier.id}", backoffice_dossier_path(champ.decorate.value), target: '_blank')
= link_to("Dossier #{dossier.id}", dossier.decorate.url(gestionnaire_signed_in?), target: '_blank')
%br
= dossier.text_summary
- else

View file

@ -57,4 +57,36 @@ describe DossierDecorator do
expect(subject).to eq('Refusé')
end
end
describe '#url' do
context "when a gestionnaire is signed_in" do
subject { super().url(true) }
it { is_expected.to eq("/backoffice/dossiers/#{dossier.id}") }
end
context "when a gestionnaire is not signed_in" do
context "when the dossier is in brouillon state" do
before do
dossier.state = 'draft'
dossier.save
end
subject { super().url(false) }
it { is_expected.to eq("/users/dossiers/#{dossier.id}/description") }
end
context "when the dossier is not in brouillon state" do
before do
dossier.state = 'updated'
dossier.save
end
subject { super().url(false) }
it { is_expected.to eq("/users/dossiers/#{dossier.id}/recapitulatif") }
end
end
end
end