Skip to content

Commit d33be8a

Browse files
committed
observation reports - allow only pdfs
1 parent 03eb642 commit d33be8a

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

app/admin/observation_report.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def apply_filtering(chain)
137137
f.input :user
138138
f.input :title
139139
f.input :publication_date, as: :date_time_picker, picker_options: {timepicker: false, format: "Y-m-d"}
140-
f.input :attachment, as: :file, hint: f.object&.attachment&.file&.filename
140+
f.input :attachment, as: :file, hint: f.object&.attachment&.file&.filename, input_html: {accept: "application/pdf"}
141141
f.input :observers
142142
end
143143

app/uploaders/observation_report_uploader.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class ObservationReportUploader < ApplicationUploader
44
def extension_allowlist
5-
%w[pdf doc docx txt csv xml jpg jpeg png exif tiff bmp]
5+
%w[pdf]
66
end
77

88
def filename

spec/factories/observation_reports.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
factory :observation_report do
1717
sequence(:title) { |n| "ObservationReportTitle#{n}" }
1818
publication_date { DateTime.current }
19-
attachment { Rack::Test::UploadedFile.new(File.join(Rails.root, "spec", "support", "files", "image.png")) }
19+
attachment { Rack::Test::UploadedFile.new(File.join(Rails.root, "spec", "support", "files", "doc.pdf")) }
2020
observers { build_list(:observer, 1) }
2121

2222
after(:build) do |random_observation_report|

spec/models/observation_report_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@
3131
expect(subject).not_to be_valid
3232
expect(subject.errors.messages[:attachment]).to include("can't be blank")
3333
end
34+
35+
it "accepts only pdf files" do
36+
subject.attachment = Rack::Test::UploadedFile.new(File.join(Rails.root, "spec", "support", "files", "image.png"))
37+
expect(subject).not_to be_valid
38+
expect(subject.errors.messages[:attachment]).to include("You are not allowed to upload \"png\" files, allowed types: pdf")
39+
subject = build(:observation_report) # somehow just changing the attachment do not reset that validation error, probably carrierwave bug
40+
subject.attachment = Rack::Test::UploadedFile.new(File.join(Rails.root, "spec", "support", "files", "doc.pdf"))
41+
expect(subject).to be_valid
42+
end
3443
end
3544

3645
describe "hooks" do

0 commit comments

Comments
 (0)