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
|
||||||
end
|
end
|
||||||
|
|
||||||
def extension
|
|
||||||
File.extname(original_filename)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.generate_digest(path)
|
def self.generate_digest(path)
|
||||||
Digest::SHA1.file(path).hexdigest
|
Digest::SHA1.file(path).hexdigest
|
||||||
end
|
end
|
||||||
|
|
|
@ -95,7 +95,7 @@ module FileStore
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_path_for_upload(upload)
|
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
|
end
|
||||||
|
|
||||||
def get_path_for_optimized_image(optimized_image)
|
def get_path_for_optimized_image(optimized_image)
|
||||||
|
|
|
@ -462,7 +462,11 @@ class Search
|
||||||
posts.where("posts.id IN (
|
posts.where("posts.id IN (
|
||||||
SELECT post_id FROM topic_links
|
SELECT post_id FROM topic_links
|
||||||
WHERE extension IN (?)
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -46,6 +46,11 @@ describe Upload do
|
||||||
|
|
||||||
end
|
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
|
context ".get_from_url" do
|
||||||
let(:url) { "/uploads/default/original/3X/1/0/10f73034616a796dfd70177dc54b6def44c4ba6f.png" }
|
let(:url) { "/uploads/default/original/3X/1/0/10f73034616a796dfd70177dc54b6def44c4ba6f.png" }
|
||||||
let(:upload) { Fabricate(:upload, url: url) }
|
let(:upload) { Fabricate(:upload, url: url) }
|
||||||
|
|
Loading…
Reference in New Issue