mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Add extraction of file extension in TopicLink and related rspec tests.
This commit is contained in:
parent
4c22f3a0e2
commit
eaf46431d4
@ -164,6 +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?
|
||||||
begin
|
begin
|
||||||
TopicLink.create!(post_id: post.id,
|
TopicLink.create!(post_id: post.id,
|
||||||
user_id: post.user_id,
|
user_id: post.user_id,
|
||||||
@ -173,7 +174,8 @@ SQL
|
|||||||
internal: internal,
|
internal: internal,
|
||||||
link_topic_id: topic_id,
|
link_topic_id: topic_id,
|
||||||
link_post_id: reflected_post.try(:id),
|
link_post_id: reflected_post.try(:id),
|
||||||
quote: link.is_quote)
|
quote: link.is_quote,
|
||||||
|
extension: file_extension)
|
||||||
rescue ActiveRecord::RecordNotUnique, PG::UniqueViolation
|
rescue ActiveRecord::RecordNotUnique, PG::UniqueViolation
|
||||||
# it's fine
|
# it's fine
|
||||||
end
|
end
|
||||||
|
@ -193,7 +193,7 @@ http://b.com/#{'a'*500}
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "link to a local attachments" do
|
context "link to a local attachments" do
|
||||||
let(:post) { topic.posts.create(user: user, raw: '<a class="attachment" href="/uploads/default/208/87bb3d8428eb4783.rb">ruby.rb</a>') }
|
let(:post) { topic.posts.create(user: user, raw: '<a class="attachment" href="/uploads/default/208/87bb3d8428eb4783.rb?foo=bar">ruby.rb</a>') }
|
||||||
|
|
||||||
it "extracts the link" do
|
it "extracts the link" do
|
||||||
TopicLink.extract_from(post)
|
TopicLink.extract_from(post)
|
||||||
@ -203,9 +203,11 @@ http://b.com/#{'a'*500}
|
|||||||
# is set to internal
|
# is set to internal
|
||||||
expect(link).to be_internal
|
expect(link).to be_internal
|
||||||
# has the correct url
|
# has the correct url
|
||||||
expect(link.url).to eq("/uploads/default/208/87bb3d8428eb4783.rb")
|
expect(link.url).to eq("/uploads/default/208/87bb3d8428eb4783.rb?foo=bar")
|
||||||
# should not be the reflection
|
# should not be the reflection
|
||||||
expect(link).not_to be_reflection
|
expect(link).not_to be_reflection
|
||||||
|
# should have file extension
|
||||||
|
expect(link.extension).to eq('rb')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -224,6 +226,8 @@ http://b.com/#{'a'*500}
|
|||||||
expect(link.url).to eq("//s3.amazonaws.com/bucket/2104a0211c9ce41ed67989a1ed62e9a394c1fbd1446.rb")
|
expect(link.url).to eq("//s3.amazonaws.com/bucket/2104a0211c9ce41ed67989a1ed62e9a394c1fbd1446.rb")
|
||||||
# should not be the reflection
|
# should not be the reflection
|
||||||
expect(link).not_to be_reflection
|
expect(link).not_to be_reflection
|
||||||
|
# should have file extension
|
||||||
|
expect(link.extension).to eq('rb')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user