fix: allow previous id with -> to work

This commit is contained in:
simon lehericey 2024-11-15 17:00:44 +01:00
parent aa0b7f53ef
commit 38e998c279
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
2 changed files with 20 additions and 1 deletions

View file

@ -12,6 +12,13 @@ module ColumnsConcern
column = columns.find { _1.h_id == h_id } if h_id.present? column = columns.find { _1.h_id == h_id } if h_id.present?
column = columns.find { _1.label == label } if label.present? column = columns.find { _1.label == label } if label.present?
# TODO: to remove after linked_drop_down column column_id migration
if column.nil? && h_id.is_a?(Hash) && h_id[:column_id].present?
h_id[:column_id].gsub!('->', '.')
column = columns.find { _1.h_id == h_id }
end
raise ActiveRecord::RecordNotFound.new("Column: unable to find h_id: #{h_id} or label: #{label} for procedure_id #{id}") if column.nil? raise ActiveRecord::RecordNotFound.new("Column: unable to find h_id: #{h_id} or label: #{label} for procedure_id #{id}") if column.nil?
column column

View file

@ -4,7 +4,8 @@ describe ColumnsConcern do
let(:procedure_id) { procedure.id } let(:procedure_id) { procedure.id }
describe '#find_column' do describe '#find_column' do
let(:procedure) { build(:procedure) } let(:types_de_champ_public) { [{ type: :linked_drop_down_list, libelle: 'linked' }] }
let(:procedure) { create(:procedure, types_de_champ_public:) }
let(:notifications_column) { procedure.notifications_column } let(:notifications_column) { procedure.notifications_column }
it do it do
@ -16,6 +17,17 @@ describe ColumnsConcern do
unknwon = 'unknown' unknwon = 'unknown'
expect { procedure.find_column(h_id: unknwon) }.to raise_error(ActiveRecord::RecordNotFound) expect { procedure.find_column(h_id: unknwon) }.to raise_error(ActiveRecord::RecordNotFound)
value_column = procedure.find_column(label: 'linked')
procedure_id = procedure.id
linked_tdc = procedure.active_revision.types_de_champ
.find { _1.type_champ == 'linked_drop_down_list' }
column_id = "type_de_champ/#{linked_tdc.stable_id}->value"
h_id = { procedure_id:, column_id: }
expect(procedure.find_column(h_id:)).to eq(value_column)
end end
end end