Commit c900bbff authored by Eduardo Bonet's avatar Eduardo Bonet

Adding tests for ipynb diff transformation

parent aec2c12e
......@@ -51,6 +51,34 @@ RSpec.describe Gitlab::Diff::File do
project.commit(branch_name).diffs.diff_files.first
end
describe 'initialize' do
context 'when file is ipynb' do
let(:commit) { project.commit("f6b7a707") }
let(:diff) { commit.raw_diffs.first }
let(:diff_file) { described_class.new(diff, diff_refs: commit.diff_refs, repository: project.repository) }
context 'and :jupyter_clean_diffs is enabled' do
before do
stub_feature_flags(jupyter_clean_diffs: true)
end
it 'recreates the diff by transforming the files' do
expect(diff_file.diff.diff).not_to include('"| Fake')
end
end
context 'but :jupyter_clean_diffs is disabled' do
before do
stub_feature_flags(jupyter_clean_diffs: false)
end
it 'does not recreate the diff' do
expect(diff_file.diff.diff).to include('"| Fake')
end
end
end
end
describe '#diff_lines' do
let(:diff_lines) { diff_file.diff_lines }
......
......@@ -121,6 +121,43 @@ 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__ }
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) }
......
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