procedure.find_column raise NotFound to fit AR interface
This commit is contained in:
parent
14809b35af
commit
34b0379203
2 changed files with 22 additions and 2 deletions
|
@ -9,8 +9,12 @@ module ColumnsConcern
|
||||||
# instead, we are using h_id == { procedure_id:, column_id: }
|
# instead, we are using h_id == { procedure_id:, column_id: }
|
||||||
# another way to find a column is to look for its label
|
# another way to find a column is to look for its label
|
||||||
def find_column(h_id: nil, label: nil)
|
def find_column(h_id: nil, label: nil)
|
||||||
return columns.find { _1.h_id == h_id } if h_id.present?
|
column = columns.find { _1.h_id == h_id } if h_id.present?
|
||||||
return columns.find { _1.label == label } if label.present?
|
column = columns.find { _1.label == label } if label.present?
|
||||||
|
|
||||||
|
raise ActiveRecord::RecordNotFound if column.nil?
|
||||||
|
|
||||||
|
column
|
||||||
end
|
end
|
||||||
|
|
||||||
def columns
|
def columns
|
||||||
|
|
|
@ -1,6 +1,22 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
describe ColumnsConcern do
|
describe ColumnsConcern do
|
||||||
|
describe '#find_column' do
|
||||||
|
let(:procedure) { build(:procedure) }
|
||||||
|
let(:notifications_column) { procedure.notifications_column }
|
||||||
|
|
||||||
|
it do
|
||||||
|
label = notifications_column.label
|
||||||
|
expect(procedure.find_column(label:)).to eq(notifications_column)
|
||||||
|
|
||||||
|
h_id = notifications_column.h_id
|
||||||
|
expect(procedure.find_column(h_id:)).to eq(notifications_column)
|
||||||
|
|
||||||
|
unknwon = 'unknown'
|
||||||
|
expect { procedure.find_column(h_id: unknwon) }.to raise_error(ActiveRecord::RecordNotFound)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#columns" do
|
describe "#columns" do
|
||||||
subject { procedure.columns }
|
subject { procedure.columns }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue