diff --git a/app/models/concerns/columns_concern.rb b/app/models/concerns/columns_concern.rb index 1e02c7370..d845bd7d7 100644 --- a/app/models/concerns/columns_concern.rb +++ b/app/models/concerns/columns_concern.rb @@ -12,6 +12,13 @@ module ColumnsConcern column = columns.find { _1.h_id == h_id } if h_id.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? column diff --git a/spec/models/concerns/columns_concern_spec.rb b/spec/models/concerns/columns_concern_spec.rb index f6666517f..8d68c87f2 100644 --- a/spec/models/concerns/columns_concern_spec.rb +++ b/spec/models/concerns/columns_concern_spec.rb @@ -4,7 +4,8 @@ describe ColumnsConcern do let(:procedure_id) { procedure.id } 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 } it do @@ -16,6 +17,17 @@ describe ColumnsConcern do unknwon = 'unknown' 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