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
end
end
def symlink?
mode == MODE_SYMLINK
end
def extension
@extension ||= extname.downcase.delete('.')
end
......
......@@ -9,7 +9,7 @@
= copy_file_path_button(blob.path)
%small.mr-1
- if blob.mode == Blob::MODE_SYMLINK
- if blob.symlink?
= _('Symbolic link') << ' ·'
= number_to_human_size(blob.raw_size)
......
......@@ -215,6 +215,20 @@ RSpec.describe Blob do
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
it 'returns the extension' do
blob = fake_blob(path: 'file.md')
......
......@@ -4,13 +4,14 @@ module FakeBlobHelpers
class FakeBlob
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
@size = size
@data = data
@binary = binary
@mode = mode
@lfs_pointer = lfs.present?
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