Skip to content

Commit

Permalink
Fix label printing error message
Browse files Browse the repository at this point in the history
  • Loading branch information
dasunpubudumal committed Jan 30, 2025
1 parent 005358f commit 55d5ab3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/models/print_job_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions spec/models/print_job_wrapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 55d5ab3

Please sign in to comment.