Fix backend code for searching by a filetype as a combination of uploads and topic links. Add rspec test for extracting file extension in upload.
This commit is contained in:
parent
f0a674d620
commit
8c445e9f17
|
@ -52,10 +52,6 @@ class Upload < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def extension
|
||||
File.extname(original_filename)
|
||||
end
|
||||
|
||||
def self.generate_digest(path)
|
||||
Digest::SHA1.file(path).hexdigest
|
||||
end
|
||||
|
|
|
@ -95,7 +95,7 @@ module FileStore
|
|||
end
|
||||
|
||||
def get_path_for_upload(upload)
|
||||
get_path_for("original".freeze, upload.id, upload.sha1, upload.extension)
|
||||
get_path_for("original".freeze, upload.id, upload.sha1, File.extname(upload.original_filename))
|
||||
end
|
||||
|
||||
def get_path_for_optimized_image(optimized_image)
|
||||
|
|
|
@ -462,7 +462,11 @@ class Search
|
|||
posts.where("posts.id IN (
|
||||
SELECT post_id FROM topic_links
|
||||
WHERE extension IN (?)
|
||||
)", file_extensions)
|
||||
UNION
|
||||
SELECT post_uploads.post_id FROM uploads
|
||||
JOIN post_uploads ON post_uploads.upload_id = uploads.id
|
||||
WHERE lower(uploads.extension) IN (?)
|
||||
)", file_extensions, file_extensions)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -46,6 +46,11 @@ describe Upload do
|
|||
|
||||
end
|
||||
|
||||
it "extracts file extension" do
|
||||
created_upload = UploadCreator.new(image, image_filename).create_for(user_id)
|
||||
expect(created_upload.extension).to eq("png")
|
||||
end
|
||||
|
||||
context ".get_from_url" do
|
||||
let(:url) { "/uploads/default/original/3X/1/0/10f73034616a796dfd70177dc54b6def44c4ba6f.png" }
|
||||
let(:upload) { Fabricate(:upload, url: url) }
|
||||
|
|
Loading…
Reference in New Issue