Add extraction of upload extension. Add rspec test for search of post

with upload by extension.
This commit is contained in:
Jakub Macina 2017-07-03 19:08:59 +02:00
parent bb392973ca
commit f0a674d620
4 changed files with 7 additions and 3 deletions

View File

@ -164,7 +164,7 @@ SQL
added_urls << url
unless TopicLink.exists?(topic_id: post.topic_id, post_id: post.id, url: url)
file_extension = File.extname(parsed.path)[1..5].downcase unless File.extname(parsed.path).empty?
file_extension = File.extname(parsed.path)[1..10].downcase unless File.extname(parsed.path).empty?
begin
TopicLink.create!(post_id: post.id,
user_id: post.user_id,

View File

@ -73,6 +73,7 @@ class UploadCreator
@upload.sha1 = sha1
@upload.url = ""
@upload.origin = @opts[:origin][0...1000] if @opts[:origin]
@upload.extension = File.extname(@filename)[1..10]
if FileHelper.is_image?(@filename)
@upload.width, @upload.height = ImageSizer.resize(*@image_info.size)

View File

@ -712,14 +712,16 @@ describe Search do
raw: "Discourse logo\n"\
"https://www.discourse.org/a/img/favicon.png\n"\
"https://www.discourse.org/a/img/trust-1x.jpg")
post_with_upload = Fabricate(:post)
post_with_upload.uploads = [Fabricate(:upload)]
Fabricate(:post)
TopicLink.extract_from(post1)
TopicLink.extract_from(post2)
expect(Search.execute('filetype:jpg').posts.map(&:id)).to eq([post2.id])
expect(Search.execute('filetype:png').posts.map(&:id)).to contain_exactly(post1.id, post2.id)
expect(Search.execute('logo filetype:jpg').posts.map(&:id)).to eq([post2.id])
expect(Search.execute('filetype:png').posts.map(&:id)).to contain_exactly(post1.id, post2.id, post_with_upload.id)
expect(Search.execute('logo filetype:png').posts.map(&:id)).to eq([post2.id])
end
end

View File

@ -6,6 +6,7 @@ Fabricator(:upload) do
width 100
height 200
url { sequence(:url) { |n| "/uploads/default/#{n}/1234567890123456.png" } }
extension "png"
end
Fabricator(:upload_s3, from: :upload) do