Skip to content

Commit

Permalink
[#9513] Display previous_paths on /path page
Browse files Browse the repository at this point in the history
  • Loading branch information
mmagn committed Jan 14, 2025
1 parent ccd7ac1 commit 04aa481
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/concerns/procedure_path_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def path_available?(path)
other_procedure_with_path(path).blank?
end

def previous_paths
procedure_paths.reject { |path| path.path == self.path || path.uuid_path? }
end

def path_customized?
!path.match?(/[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}/)
end
Expand Down
9 changes: 9 additions & 0 deletions app/views/administrateurs/procedures/path.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@
data: { controller: 'turbo-input', turbo_input_url_value: admin_procedure_check_path_path })
#check_path

- if @procedure.previous_paths.any?
.fr-mt-2w
%p.fr-text--sm.fr-mb-1w
Pour information les liens précédents resteront accessibles tant qu'ils ne sont pas utilisés par une autre de vos démarches :
%ul
- @procedure.previous_paths.each do |path|
%li.fr-mb-1w
= link_to commencer_url(path: path.path), commencer_url(path: path.path), class: 'fr-link fr-link--sm'

= render Procedure::FixedFooterComponent.new(procedure: @procedure, form: f)
15 changes: 15 additions & 0 deletions spec/models/concerns/procedure_path_concern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,19 @@

# test if the procedure path is owned by another administrateur
end

describe '#previous_paths' do
let(:procedure) { create(:procedure) }

context 'when the path has been changed twice' do
before do
procedure.claim_path!(procedure.administrateurs.first, 'custom_path')
procedure.claim_path!(procedure.administrateurs.first, 'custom_path_2')
end

it "should only contain the paths that are not the current one nor the uuid" do
expect(procedure.previous_paths.map(&:path)).to eq(['custom_path'])
end
end
end
end

0 comments on commit 04aa481

Please sign in to comment.