Skip to content

Commit 951ad80

Browse files
committed
observation report: add validate for mission_type
1 parent a3d0c1e commit 951ad80

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

app/models/observation_report.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ObservationReport < ApplicationRecord
2020

2121
acts_as_paranoid
2222

23-
enum :mission_type, {mandated: 0, semi_mandated: 1, external: 2}, prefix: true, scopes: false
23+
enum :mission_type, {mandated: 0, semi_mandated: 1, external: 2}, prefix: true, scopes: false, validate: true
2424
ransacker :mission_type, formatter: proc { |v| mission_types[v] }
2525

2626
normalizes :title, with: -> { it.strip }

spec/models/observation_report_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
expect(subject.errors.messages[:attachment]).to include("can't be blank")
3333
end
3434

35+
it "validates mission_type inclusion" do
36+
subject.mission_type = nil
37+
expect(subject).not_to be_valid
38+
expect(subject.errors.messages[:mission_type]).to include("is not included in the list")
39+
end
40+
3541
it "accepts only pdf files" do
3642
subject.attachment = Rack::Test::UploadedFile.new(File.join(Rails.root, "spec", "support", "files", "image.png"))
3743
expect(subject).not_to be_valid

0 commit comments

Comments
 (0)