Merge pull request #1083 from sgmap/fix_1066_dossier_linked

[fix #1066] Fix links to related dossier for experts
This commit is contained in:
Frederic Merizen 2017-12-13 11:40:20 +01:00 committed by GitHub
commit 44c335d53e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 11 deletions

View file

@ -0,0 +1,12 @@
module DossierLinkHelper
def dossier_linked_path(gestionnaire, dossier)
if dossier.procedure.gestionnaires.include?(gestionnaire)
dossier_path(dossier.procedure, dossier)
else
avis = dossier.avis.find_by(gestionnaire: gestionnaire)
if avis.present?
avis_path(avis)
end
end
end
end

View file

@ -21,7 +21,11 @@
%td.rich-text
- dossier = Dossier.includes(:procedure).find_by(id: c.value)
- if dossier
= link_to("Dossier nº #{dossier.id}", dossier_path(dossier.procedure, dossier), target: '_blank')
- path = dossier_linked_path(current_gestionnaire, dossier)
- if path.present?
= link_to("Dossier nº #{dossier.id}", path, target: '_blank')
- else
Dossier nº #{dossier.id}
%br
= dossier.text_summary
- else

View file

@ -0,0 +1,27 @@
describe DossierLinkHelper do
describe "#dossier_linked_path" do
context "when no access" do
let(:gestionnaire) { create(:gestionnaire) }
let(:dossier) { create(:dossier) }
it { expect(helper.dossier_linked_path(gestionnaire, dossier)).to be_nil }
end
context "when access as gestionnaire" do
let(:dossier) { create(:dossier ) }
let(:gestionnaire) { create(:gestionnaire) }
before { dossier.procedure.gestionnaires << gestionnaire }
it { expect(helper.dossier_linked_path(gestionnaire, dossier)).to eq(dossier_path(dossier.procedure, dossier)) }
end
context "when access as expert" do
let(:dossier) { create(:dossier ) }
let(:gestionnaire) { create(:gestionnaire) }
let!(:avis) { create(:avis, dossier: dossier, gestionnaire: gestionnaire) }
it { expect(helper.dossier_linked_path(gestionnaire, dossier)).to eq(avis_path(avis)) }
end
end
end

View file

@ -1,31 +1,51 @@
describe 'new_gestionnaire/dossiers/champs.html.haml', type: :view do
before { render 'new_gestionnaire/dossiers/champs.html.haml', champs: champs }
let(:gestionnaire) { create(:gestionnaire) }
before do
view.extend DossierLinkHelper
allow(view).to receive(:current_gestionnaire).and_return(gestionnaire)
end
subject { render 'new_gestionnaire/dossiers/champs.html.haml', champs: champs }
context "there are some champs" do
let(:dossier) { create(:dossier) }
let(:avis) { create :avis, dossier: dossier, gestionnaire: gestionnaire }
let(:champ1) { create(:champ, :checkbox, value: "true") }
let(:champ2) { create(:champ, :header_section, value: "Section") }
let(:champ3) { create(:champ, :explication, value: "mazette") }
let(:champ4) { create(:champ, :dossier_link, value: dossier.id) }
let(:champs) { [champ1, champ2, champ3, champ4] }
it { expect(rendered).to include(champ1.libelle) }
it { expect(rendered).to include(champ1.value) }
before { dossier.avis << avis }
it { expect(rendered).to have_css(".header-section") }
it { expect(rendered).to include(champ2.libelle) }
it { is_expected.to include(champ1.libelle) }
it { is_expected.to include(champ1.value) }
it { expect(rendered).not_to include(champ3.libelle) }
it { expect(rendered).not_to include(champ3.value) }
it { is_expected.to have_css(".header-section") }
it { is_expected.to include(champ2.libelle) }
it { expect(rendered).to have_link("Dossier nº #{dossier.id}") }
it { expect(rendered).to include(dossier.text_summary) }
it { is_expected.not_to include(champ3.libelle) }
it { is_expected.not_to include(champ3.value) }
it { is_expected.to have_link("Dossier nº #{dossier.id}") }
it { is_expected.to include(dossier.text_summary) }
end
context "with a dossier champ, but we are not authorized to acces the dossier" do
let(:dossier) { create(:dossier) }
let(:champ) { create(:champ, :dossier_link, value: dossier.id) }
let(:champs) { [champ] }
it { is_expected.not_to have_link("Dossier nº #{dossier.id}") }
it { is_expected.to include("Dossier nº #{dossier.id}") }
it { is_expected.to include(dossier.text_summary) }
end
context "with a dossier_link champ but without value" do
let(:champ) { create(:champ, :dossier_link, value: nil) }
let(:champs) { [champ] }
it { expect(rendered).to include("Pas de dossier associé") }
it { is_expected.to include("Pas de dossier associé") }
end
end