diff --git a/app/models/print_job_wrapper.rb b/app/models/print_job_wrapper.rb index dc21de2..833e055 100644 --- a/app/models/print_job_wrapper.rb +++ b/app/models/print_job_wrapper.rb @@ -42,7 +42,11 @@ def printer end def label_template - LabelTemplate.find_by(name: label_template_name) + lt = LabelTemplate.find_by(name: label_template_name) + if lt.nil? + errors.add(:label_template_name, 'does not exist') + end + lt end def copies=(copies) diff --git a/spec/models/print_job_wrapper_spec.rb b/spec/models/print_job_wrapper_spec.rb index fae7cc7..fe4ce84 100644 --- a/spec/models/print_job_wrapper_spec.rb +++ b/spec/models/print_job_wrapper_spec.rb @@ -91,6 +91,12 @@ expect(print_job_wrapper).to be_valid expect(print_job_wrapper.print).to be_truthy end + + it 'raises a StandardError with a 422 status code if label_template validation fails' do + print_job_wrapper = PrintJobWrapper.new(attributes.except(:label_template_name)) + expect(print_job_wrapper).to_not be_valid + expect(print_job_wrapper.print).to be_falsy + end end end