Commit 1e6d3f3a authored by Chad Woolley's avatar Chad Woolley

Add Blob#symlink? boolean method

Changelog: added
parent fa814c9e
...@@ -178,6 +178,10 @@ class Blob < SimpleDelegator ...@@ -178,6 +178,10 @@ class Blob < SimpleDelegator
end end
end end
def symlink?
mode == MODE_SYMLINK
end
def extension def extension
@extension ||= extname.downcase.delete('.') @extension ||= extname.downcase.delete('.')
end end
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
= copy_file_path_button(blob.path) = copy_file_path_button(blob.path)
%small.mr-1 %small.mr-1
- if blob.mode == Blob::MODE_SYMLINK - if blob.symlink?
= _('Symbolic link') << ' ·' = _('Symbolic link') << ' ·'
= number_to_human_size(blob.raw_size) = number_to_human_size(blob.raw_size)
......
...@@ -215,6 +215,20 @@ RSpec.describe Blob do ...@@ -215,6 +215,20 @@ RSpec.describe Blob do
end end
end end
describe '#symlink?' do
it 'is true for symlinks' do
symlink_blob = fake_blob(path: 'file', mode: '120000')
expect(symlink_blob.symlink?).to eq true
end
it 'is false for non-symlinks' do
non_symlink_blob = fake_blob(path: 'file', mode: '100755')
expect(non_symlink_blob.symlink?).to eq false
end
end
describe '#extension' do describe '#extension' do
it 'returns the extension' do it 'returns the extension' do
blob = fake_blob(path: 'file.md') blob = fake_blob(path: 'file.md')
......
...@@ -4,13 +4,14 @@ module FakeBlobHelpers ...@@ -4,13 +4,14 @@ module FakeBlobHelpers
class FakeBlob class FakeBlob
include BlobLike include BlobLike
attr_reader :path, :size, :data, :lfs_oid, :lfs_size attr_reader :path, :size, :data, :lfs_oid, :lfs_size, :mode
def initialize(path: 'file.txt', size: 1.kilobyte, data: 'foo', binary: false, lfs: nil) def initialize(path: 'file.txt', size: 1.kilobyte, data: 'foo', binary: false, lfs: nil, mode: nil)
@path = path @path = path
@size = size @size = size
@data = data @data = data
@binary = binary @binary = binary
@mode = mode
@lfs_pointer = lfs.present? @lfs_pointer = lfs.present?
if @lfs_pointer if @lfs_pointer
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment