diff options
Diffstat (limited to 'spec/presenters/blob_presenter_spec.rb')
-rw-r--r-- | spec/presenters/blob_presenter_spec.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/presenters/blob_presenter_spec.rb b/spec/presenters/blob_presenter_spec.rb index 466a2b55e76..28e18708eab 100644 --- a/spec/presenters/blob_presenter_spec.rb +++ b/spec/presenters/blob_presenter_spec.rb @@ -31,6 +31,20 @@ RSpec.describe BlobPresenter do it { expect(presenter.replace_path).to eq("/#{project.full_path}/-/create/#{blob.commit_id}/#{blob.path}") } end + describe '#pipeline_editor_path' do + context 'when blob is .gitlab-ci.yml' do + before do + project.repository.create_file(user, '.gitlab-ci.yml', '', + message: 'Add a ci file', + branch_name: 'main') + end + + let(:blob) { repository.blob_at('main', '.gitlab-ci.yml') } + + it { expect(presenter.pipeline_editor_path).to eq("/#{project.full_path}/-/ci/editor?branch_name=#{blob.commit_id}") } + end + end + describe '#ide_edit_path' do it { expect(presenter.ide_edit_path).to eq("/-/ide/project/#{project.full_path}/edit/HEAD/-/files/ruby/regex.rb") } end @@ -121,6 +135,47 @@ RSpec.describe BlobPresenter do end end + describe '#highlight_transformed' do + context 'when blob is ipynb' do + let(:blob) { repository.blob_at('f6b7a707', 'files/ipython/markdown-table.ipynb') } + let(:git_blob) { blob.__getobj__ } + + before do + allow(git_blob).to receive(:transformed_for_diff).and_return(true) + end + + it 'uses md as the transformed language' do + expect(Gitlab::Highlight).to receive(:highlight).with('files/ipython/markdown-table.ipynb', anything, plain: nil, language: 'md') + + presenter.highlight_transformed + end + + it 'transforms the blob' do + expect(Gitlab::Highlight).to receive(:highlight).with('files/ipython/markdown-table.ipynb', include("%%"), plain: nil, language: 'md') + + presenter.highlight_transformed + end + end + + context 'when blob is other file type' do + let(:git_blob) { blob.__getobj__ } + + before do + allow(git_blob) + .to receive(:data) + .and_return("line one\nline two\nline 3") + + allow(blob).to receive(:language_from_gitattributes).and_return('ruby') + end + + it 'does not transform the file' do + expect(Gitlab::Highlight).to receive(:highlight).with('files/ruby/regex.rb', git_blob.data, plain: nil, language: 'ruby') + + presenter.highlight_transformed + end + end + end + describe '#raw_plain_data' do let(:blob) { repository.blob_at('HEAD', file) } |