Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/models/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def self.attachable_to
'image/bmp',
'image/jpeg',
'image/jpg',
'image/heic',
'image/heif',
'image/gif',
'image/png',
'application/pdf',
Expand All @@ -45,13 +47,14 @@ def self.attachable_to
/png|PNG\z/,
/jpg|JPG\z/,
/jpeg|JPEG\z/,
/heif|HEIF\z/,
/heic|HEIC\z/,
/pdf|PDF\z/,
/gif|GIF\z/,
/zip|ZIP\z/,
/rar|RAR\z/,
]


def attached_to_something
return unless attached_to.nil?
errors.add(:base, 'must_be_attached_to_something')
Expand Down
3 changes: 2 additions & 1 deletion config/initializers/paperclip.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Paperclip::DataUriAdapter.register
Paperclip::DataUriAdapter.register
Paperclip.options[:content_type_mappings] = { heic: 'image/heic', heif: 'image/heif' }
Binary file added spec/fixtures/files/simple.heic
Binary file not shown.
2 changes: 1 addition & 1 deletion spec/helpers/request_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def api_response

def mime_for(ext)
case ext
when :bmp, :png, :jpg, :jpeg, :JPEG, :gif, :BMP, :JPG, :PNG, :GIF then "image/#{ext.downcase}"
when :bmp, :png, :jpg, :jpeg, :JPEG, :gif, :BMP, :JPG, :PNG, :GIF, :heic, :heif, :HEIC, :HEIF then "image/#{ext.downcase}"
when :pdf, :zip, :PDF, :ZIP then "application/#{ext.downcase}"
when :rar, :RAR then "application/x-rar-compressed"
else raise "No fixture for #{ext.downcase} files"
Expand Down
26 changes: 26 additions & 0 deletions spec/requests/api/attachments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@
end
end

it 'handles heic images' do
allow_any_instance_of(Paperclip::MediaTypeSpoofDetector).to(
receive(:type_from_file_command).and_return('image/heic')
)
issue = create(:basic_issue)
seed = create(:full_natural_docket_seed,
issue: issue, add_all_attachments: false)

api_create "/attachments",
{
type: "attachments",
relationships: {attached_to_seed: {data: {id: seed.id, type: 'natural_docket_seeds'}}},
attributes: {
document: "data:#{mime_for(:heic)};base64,#{bytes_for(:heic)}",
document_file_name: 'simple.heic',
document_content_type: mime_for(:heic)
}
}
file_attachment = api_response.data

api_get "/attachments/#{file_attachment.id}"
expect(api_response.data.relationships.attached_to_seed.data.to_h).to(
eq(type: 'natural_docket_seeds', id: seed.id.to_s)
)
end

it "Can validate max people request limit on show" do
Redis.new.flushall

Expand Down