summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2017-06-08 17:15:16 +0000
committerGrzegorz Bizon <grzegorz@gitlab.com>2017-06-08 17:15:16 +0000
commit6cbe38675dcd0547d9127373851471008e624e2b (patch)
tree82a89b246a2fa06a0eee9756929e06e059c17a7d
parent299a3a9aa0a91229f2767113145c3166ac642379 (diff)
parent369d681eec8177f03bf3b4f694e03098447dae09 (diff)
downloadgitlab-ce-6cbe38675dcd0547d9127373851471008e624e2b.tar.gz
Merge branch 'dm-blob-file-type' into 'master'
Add Blob#file_type convenience method See merge request !11982
-rw-r--r--app/models/blob.rb4
-rw-r--r--app/models/blob_viewer/base.rb2
-rw-r--r--spec/models/blob_spec.rb8
3 files changed, 13 insertions, 1 deletions
diff --git a/app/models/blob.rb b/app/models/blob.rb
index 6f7cf35a767..3869e79ba75 100644
--- a/app/models/blob.rb
+++ b/app/models/blob.rb
@@ -155,6 +155,10 @@ class Blob < SimpleDelegator
@extension ||= extname.downcase.delete('.')
end
+ def file_type
+ Gitlab::FileDetector.type_of(path)
+ end
+
def video?
UploaderHelper::VIDEO_EXT.include?(extension)
end
diff --git a/app/models/blob_viewer/base.rb b/app/models/blob_viewer/base.rb
index e6119d25fab..d2aa33d994e 100644
--- a/app/models/blob_viewer/base.rb
+++ b/app/models/blob_viewer/base.rb
@@ -52,7 +52,7 @@ module BlobViewer
def self.can_render?(blob, verify_binary: true)
return false if verify_binary && binary? != blob.binary?
return true if extensions&.include?(blob.extension)
- return true if file_types&.include?(Gitlab::FileDetector.type_of(blob.path))
+ return true if file_types&.include?(blob.file_type)
false
end
diff --git a/spec/models/blob_spec.rb b/spec/models/blob_spec.rb
index f19e1af65a6..e1193e0d19a 100644
--- a/spec/models/blob_spec.rb
+++ b/spec/models/blob_spec.rb
@@ -199,6 +199,14 @@ describe Blob do
end
end
+ describe '#file_type' do
+ it 'returns the file type' do
+ blob = fake_blob(path: 'README.md')
+
+ expect(blob.file_type).to eq(:readme)
+ end
+ end
+
describe '#simple_viewer' do
context 'when the blob is empty' do
it 'returns an empty viewer' do