diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 10:00:54 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 10:00:54 +0000 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /spec/lib/gitlab/blame_spec.rb | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) | |
download | gitlab-ce-3cccd102ba543e02725d247893729e5c73b38295.tar.gz |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'spec/lib/gitlab/blame_spec.rb')
-rw-r--r-- | spec/lib/gitlab/blame_spec.rb | 79 |
1 files changed, 77 insertions, 2 deletions
diff --git a/spec/lib/gitlab/blame_spec.rb b/spec/lib/gitlab/blame_spec.rb index e22399723ac..f636ce283ae 100644 --- a/spec/lib/gitlab/blame_spec.rb +++ b/spec/lib/gitlab/blame_spec.rb @@ -3,13 +3,31 @@ require 'spec_helper' RSpec.describe Gitlab::Blame do - let(:project) { create(:project, :repository) } + let_it_be(:project) { create(:project, :repository) } + let(:path) { 'files/ruby/popen.rb' } let(:commit) { project.commit('master') } let(:blob) { project.repository.blob_at(commit.id, path) } + let(:range) { nil } + + subject(:blame) { described_class.new(blob, commit, range: range) } + + describe '#first_line' do + subject { blame.first_line } + + it { is_expected.to eq(1) } + + context 'with a range' do + let(:range) { 2..3 } + + it { is_expected.to eq(range.first) } + end + end describe "#groups" do - let(:subject) { described_class.new(blob, commit).groups(highlight: false) } + let(:highlighted) { false } + + subject(:groups) { blame.groups(highlight: highlighted) } it 'groups lines properly' do expect(subject.count).to eq(18) @@ -22,5 +40,62 @@ RSpec.describe Gitlab::Blame do expect(subject[-1][:commit].sha).to eq('913c66a37b4a45b9769037c55c2d238bd0942d2e') expect(subject[-1][:lines]).to eq([" end", "end"]) end + + context 'with a range 1..5' do + let(:range) { 1..5 } + + it 'returns the correct lines' do + expect(groups.count).to eq(2) + expect(groups[0][:lines]).to eq(["require 'fileutils'", "require 'open3'", ""]) + expect(groups[1][:lines]).to eq(['module Popen', ' extend self']) + end + + context 'with highlighted lines' do + let(:highlighted) { true } + + it 'returns the correct lines' do + expect(groups.count).to eq(2) + expect(groups[0][:lines][0]).to match(/LC1.*fileutils/) + expect(groups[0][:lines][1]).to match(/LC2.*open3/) + expect(groups[0][:lines][2]).to eq("<span id=\"LC3\" class=\"line\" lang=\"ruby\"></span>\n") + expect(groups[1][:lines][0]).to match(/LC4.*Popen/) + expect(groups[1][:lines][1]).to match(/LC5.*extend/) + end + end + end + + context 'with a range 2..4' do + let(:range) { 2..4 } + + it 'returns the correct lines' do + expect(groups.count).to eq(2) + expect(groups[0][:lines]).to eq(["require 'open3'", ""]) + expect(groups[1][:lines]).to eq(['module Popen']) + end + + context 'with highlighted lines' do + let(:highlighted) { true } + + it 'returns the correct lines' do + expect(groups.count).to eq(2) + expect(groups[0][:lines][0]).to match(/LC2.*open3/) + expect(groups[0][:lines][1]).to eq("<span id=\"LC3\" class=\"line\" lang=\"ruby\"></span>\n") + expect(groups[1][:lines][0]).to match(/LC4.*Popen/) + end + end + end + + context 'renamed file' do + let(:path) { 'files/plain_text/renamed' } + let(:commit) { project.commit('blame-on-renamed') } + + it 'adds previous path' do + expect(subject[0][:previous_path]).to be nil + expect(subject[0][:lines]).to match_array(['Initial commit', 'Initial commit']) + + expect(subject[1][:previous_path]).to eq('files/plain_text/initial-commit') + expect(subject[1][:lines]).to match_array(['Renamed as "filename"']) + end + end end end |