Skip to content

Commit 4259505

Browse files
committed
Fix: must select to create or select samples in boxes#new
1 parent 7e4f760 commit 4259505

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

app/models/box_form.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ def validate_batches_or_samples_for_purpose
131131
case @option
132132
when "add_batches"
133133
case @box.purpose
134-
when "LOD", "Other"
135-
@box.errors.add(:base, "A batch is required") unless unique_batch_count >= 1
136134
when "Variants"
137135
@box.errors.add(:base, "You must select at least two different batches") unless unique_batch_count >= 2
138136
when "Challenge"
139137
@box.errors.add(:base, "You must select at least one non-distractor batch") unless have_virus_batch?
140138
@box.errors.add(:base, "You must select at least one distractor batch") unless have_distractor_batch?
139+
else
140+
@box.errors.add(:base, "A batch is required") unless unique_batch_count >= 1
141141
end
142142
when "add_samples"
143143
if @samples.empty?
@@ -153,6 +153,8 @@ def validate_batches_or_samples_for_purpose
153153
@box.errors.add(:base, "You must select at least one distractor sample") unless have_distractor_sample?
154154
end
155155
end
156+
else
157+
@box.errors.add(:base, "You must create or select samples")
156158
end
157159
end
158160

spec/controllers/boxes_controller_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,13 @@ def expect_samples(batch, concentrations: [1], replicates:)
442442
end.to change(institution.boxes, :count).by(0)
443443
end
444444
end
445+
446+
it "validates option" do
447+
expect do
448+
post :create, params: { box: { purpose: "Other", option: "" } }
449+
expect(response).to have_http_status(:unprocessable_entity)
450+
end.to change(institution.boxes, :count).by(0)
451+
end
445452
end
446453

447454
describe "destroy" do

0 commit comments

Comments
 (0)