fix: assign_to.procedure_presentation should return an ActiveModel::Errors if needed
the caller will then calls `errors.full_messages`
This commit is contained in:
parent
59b7b3dc91
commit
f27598f235
2 changed files with 4 additions and 2 deletions
|
@ -24,7 +24,9 @@ class AssignTo < ApplicationRecord
|
||||||
errors = begin
|
errors = begin
|
||||||
procedure_presentation.errors if procedure_presentation&.invalid?
|
procedure_presentation.errors if procedure_presentation&.invalid?
|
||||||
rescue ActiveRecord::RecordNotFound => e
|
rescue ActiveRecord::RecordNotFound => e
|
||||||
[e.message]
|
errors = ActiveModel::Errors.new(self)
|
||||||
|
errors.add(:procedure_presentation, e.message)
|
||||||
|
errors
|
||||||
end
|
end
|
||||||
|
|
||||||
if errors.present?
|
if errors.present?
|
||||||
|
|
|
@ -45,7 +45,7 @@ describe AssignTo, type: :model do
|
||||||
it do
|
it do
|
||||||
expect(procedure_presentation_or_default).to be_persisted
|
expect(procedure_presentation_or_default).to be_persisted
|
||||||
expect(procedure_presentation_or_default).to be_valid
|
expect(procedure_presentation_or_default).to be_valid
|
||||||
expect(errors).to be_present
|
expect(errors.full_messages).to include(/unable to find procedure 666/)
|
||||||
expect(assign_to.procedure_presentation).not_to be(procedure_presentation)
|
expect(assign_to.procedure_presentation).not_to be(procedure_presentation)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue