Add extraction of file extension in TopicLink and related rspec tests.

This commit is contained in:
Jakub Macina 2017-06-19 17:09:54 +02:00
parent 4c22f3a0e2
commit eaf46431d4
2 changed files with 9 additions and 3 deletions

View File

@ -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

View File

@ -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: '<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
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