Add extraction of upload extension. Add rspec test for search of post
with upload by extension.
This commit is contained in:
parent
bb392973ca
commit
f0a674d620
|
@ -164,7 +164,7 @@ SQL
|
||||||
added_urls << url
|
added_urls << url
|
||||||
|
|
||||||
unless TopicLink.exists?(topic_id: post.topic_id, post_id: post.id, url: 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
|
begin
|
||||||
TopicLink.create!(post_id: post.id,
|
TopicLink.create!(post_id: post.id,
|
||||||
user_id: post.user_id,
|
user_id: post.user_id,
|
||||||
|
|
|
@ -73,6 +73,7 @@ class UploadCreator
|
||||||
@upload.sha1 = sha1
|
@upload.sha1 = sha1
|
||||||
@upload.url = ""
|
@upload.url = ""
|
||||||
@upload.origin = @opts[:origin][0...1000] if @opts[:origin]
|
@upload.origin = @opts[:origin][0...1000] if @opts[:origin]
|
||||||
|
@upload.extension = File.extname(@filename)[1..10]
|
||||||
|
|
||||||
if FileHelper.is_image?(@filename)
|
if FileHelper.is_image?(@filename)
|
||||||
@upload.width, @upload.height = ImageSizer.resize(*@image_info.size)
|
@upload.width, @upload.height = ImageSizer.resize(*@image_info.size)
|
||||||
|
|
|
@ -712,14 +712,16 @@ describe Search do
|
||||||
raw: "Discourse logo\n"\
|
raw: "Discourse logo\n"\
|
||||||
"https://www.discourse.org/a/img/favicon.png\n"\
|
"https://www.discourse.org/a/img/favicon.png\n"\
|
||||||
"https://www.discourse.org/a/img/trust-1x.jpg")
|
"https://www.discourse.org/a/img/trust-1x.jpg")
|
||||||
|
post_with_upload = Fabricate(:post)
|
||||||
|
post_with_upload.uploads = [Fabricate(:upload)]
|
||||||
Fabricate(:post)
|
Fabricate(:post)
|
||||||
|
|
||||||
TopicLink.extract_from(post1)
|
TopicLink.extract_from(post1)
|
||||||
TopicLink.extract_from(post2)
|
TopicLink.extract_from(post2)
|
||||||
|
|
||||||
expect(Search.execute('filetype:jpg').posts.map(&:id)).to eq([post2.id])
|
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('filetype:png').posts.map(&:id)).to contain_exactly(post1.id, post2.id, post_with_upload.id)
|
||||||
expect(Search.execute('logo filetype:jpg').posts.map(&:id)).to eq([post2.id])
|
expect(Search.execute('logo filetype:png').posts.map(&:id)).to eq([post2.id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ Fabricator(:upload) do
|
||||||
width 100
|
width 100
|
||||||
height 200
|
height 200
|
||||||
url { sequence(:url) { |n| "/uploads/default/#{n}/1234567890123456.png" } }
|
url { sequence(:url) { |n| "/uploads/default/#{n}/1234567890123456.png" } }
|
||||||
|
extension "png"
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:upload_s3, from: :upload) do
|
Fabricator(:upload_s3, from: :upload) do
|
||||||
|
|
Loading…
Reference in New Issue