diff --git a/app/models/topic_link.rb b/app/models/topic_link.rb
index 12ae7dcaab0..c9abf160c42 100644
--- a/app/models/topic_link.rb
+++ b/app/models/topic_link.rb
@@ -164,6 +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?
begin
TopicLink.create!(post_id: post.id,
user_id: post.user_id,
@@ -173,7 +174,8 @@ SQL
internal: internal,
link_topic_id: topic_id,
link_post_id: reflected_post.try(:id),
- quote: link.is_quote)
+ quote: link.is_quote,
+ extension: file_extension)
rescue ActiveRecord::RecordNotUnique, PG::UniqueViolation
# it's fine
end
diff --git a/spec/models/topic_link_spec.rb b/spec/models/topic_link_spec.rb
index 9ee96750f24..f9f0c9d3099 100644
--- a/spec/models/topic_link_spec.rb
+++ b/spec/models/topic_link_spec.rb
@@ -193,7 +193,7 @@ http://b.com/#{'a'*500}
end
context "link to a local attachments" do
- let(:post) { topic.posts.create(user: user, raw: 'ruby.rb') }
+ let(:post) { topic.posts.create(user: user, raw: 'ruby.rb') }
it "extracts the link" do
TopicLink.extract_from(post)
@@ -203,9 +203,11 @@ http://b.com/#{'a'*500}
# is set to internal
expect(link).to be_internal
# 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
expect(link).not_to be_reflection
+ # should have file extension
+ expect(link.extension).to eq('rb')
end
end
@@ -224,6 +226,8 @@ http://b.com/#{'a'*500}
expect(link.url).to eq("//s3.amazonaws.com/bucket/2104a0211c9ce41ed67989a1ed62e9a394c1fbd1446.rb")
# should not be the reflection
expect(link).not_to be_reflection
+ # should have file extension
+ expect(link.extension).to eq('rb')
end
end