2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-02 17:03:30 +02:00
|
|
|
describe AssignTo, type: :model do
|
2018-10-23 11:39:54 +02:00
|
|
|
describe '#procedure_presentation_or_default_and_errors' do
|
2018-10-23 11:03:43 +02:00
|
|
|
let(:procedure) { create(:procedure) }
|
2020-07-20 16:13:51 +02:00
|
|
|
let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: create(:instructeur)) }
|
2018-10-23 11:03:43 +02:00
|
|
|
|
2018-10-23 11:39:54 +02:00
|
|
|
let(:procedure_presentation_and_errors) { assign_to.procedure_presentation_or_default_and_errors }
|
|
|
|
let(:procedure_presentation_or_default) { procedure_presentation_and_errors.first }
|
|
|
|
let(:errors) { procedure_presentation_and_errors.second }
|
2017-10-02 17:03:30 +02:00
|
|
|
|
2024-10-11 15:29:52 +02:00
|
|
|
context "without a preexisting procedure_presentation" do
|
|
|
|
it 'creates a default pp' do
|
|
|
|
expect(procedure_presentation_or_default).to be_persisted
|
|
|
|
expect(procedure_presentation_or_default).to be_valid
|
|
|
|
expect(errors).to be_nil
|
|
|
|
end
|
2017-10-02 17:03:30 +02:00
|
|
|
end
|
|
|
|
|
2024-10-11 15:29:52 +02:00
|
|
|
context "with a preexisting procedure_presentation" do
|
|
|
|
let!(:procedure_presentation) { ProcedurePresentation.create(assign_to:) }
|
2017-10-02 17:03:30 +02:00
|
|
|
|
2024-10-11 15:29:52 +02:00
|
|
|
it 'returns the preexisting pp' do
|
|
|
|
expect(procedure_presentation_or_default).to eq(procedure_presentation)
|
|
|
|
expect(procedure_presentation_or_default).to be_valid
|
|
|
|
expect(errors).to be_nil
|
|
|
|
end
|
2017-10-02 17:03:30 +02:00
|
|
|
end
|
2018-10-23 11:48:25 +02:00
|
|
|
|
|
|
|
context "with an invalid procedure_presentation" do
|
|
|
|
let!(:procedure_presentation) do
|
2024-10-11 15:29:52 +02:00
|
|
|
pp = ProcedurePresentation.create(assign_to: assign_to)
|
|
|
|
|
|
|
|
sql = <<-SQL.squish
|
|
|
|
UPDATE procedure_presentations
|
|
|
|
SET displayed_columns = ARRAY['{\"procedure_id\":666}'::jsonb]
|
|
|
|
WHERE id = #{pp.id} ;
|
|
|
|
SQL
|
|
|
|
|
|
|
|
pp.class.connection.execute(sql)
|
|
|
|
|
|
|
|
assign_to.reload
|
2018-10-23 11:48:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
2024-10-11 15:29:52 +02:00
|
|
|
expect(procedure_presentation_or_default).to be_persisted
|
|
|
|
expect(procedure_presentation_or_default).to be_valid
|
2024-10-31 03:27:05 +01:00
|
|
|
expect(errors.full_messages).to include(/unable to find procedure 666/)
|
2018-10-23 11:48:25 +02:00
|
|
|
expect(assign_to.procedure_presentation).not_to be(procedure_presentation)
|
|
|
|
end
|
|
|
|
end
|
2017-10-02 17:03:30 +02:00
|
|
|
end
|
|
|
|
end
|