2018-10-04 09:16:51 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe BlobLanguageFromGitAttributes do
|
2018-10-04 09:16:51 +00:00
|
|
|
include FakeBlobHelpers
|
|
|
|
|
|
|
|
let(:project) { build(:project, :repository) }
|
|
|
|
|
|
|
|
describe '#language_from_gitattributes' do
|
|
|
|
subject(:blob) { fake_blob(path: 'file.md') }
|
|
|
|
|
|
|
|
it 'returns return value from gitattribute' do
|
2020-02-25 09:09:10 +00:00
|
|
|
allow(blob.repository).to receive(:exists?).and_return(true)
|
|
|
|
expect(blob.repository).to receive(:gitattribute).with(blob.path, 'gitlab-language').and_return('erb?parent=json')
|
2018-10-04 09:16:51 +00:00
|
|
|
|
|
|
|
expect(blob.language_from_gitattributes).to eq('erb?parent=json')
|
|
|
|
end
|
|
|
|
|
2020-02-25 09:09:10 +00:00
|
|
|
it 'returns nil if repository is absent' do
|
|
|
|
allow(blob).to receive(:repository).and_return(nil)
|
|
|
|
|
|
|
|
expect(blob.language_from_gitattributes).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil if repository does not exist' do
|
|
|
|
allow(blob.repository).to receive(:exists?).and_return(false)
|
2018-10-04 09:16:51 +00:00
|
|
|
|
|
|
|
expect(blob.language_from_gitattributes).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|