diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/lib/gitlab/diff | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/lib/gitlab/diff')
-rw-r--r-- | spec/lib/gitlab/diff/file_spec.rb | 55 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/formatters/text_formatter_spec.rb | 18 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/position_spec.rb | 4 |
3 files changed, 75 insertions, 2 deletions
diff --git a/spec/lib/gitlab/diff/file_spec.rb b/spec/lib/gitlab/diff/file_spec.rb index 61d7400b95e..d1592e60d3d 100644 --- a/spec/lib/gitlab/diff/file_spec.rb +++ b/spec/lib/gitlab/diff/file_spec.rb @@ -567,6 +567,61 @@ describe Gitlab::Diff::File do end end + describe '#alternate_viewer' do + subject { diff_file.alternate_viewer } + + where(:viewer_class) do + [ + DiffViewer::Image, + DiffViewer::Collapsed, + DiffViewer::NotDiffable, + DiffViewer::Text, + DiffViewer::NoPreview, + DiffViewer::Added, + DiffViewer::Deleted, + DiffViewer::ModeChanged, + DiffViewer::ModeChanged, + DiffViewer::NoPreview + ] + end + + with_them do + let(:viewer) { viewer_class.new(diff_file) } + + before do + allow(diff_file).to receive(:viewer).and_return(viewer) + end + + it { is_expected.to be_nil } + end + + context 'when viewer is DiffViewer::Renamed' do + let(:viewer) { DiffViewer::Renamed.new(diff_file) } + + before do + allow(diff_file).to receive(:viewer).and_return(viewer) + end + + context 'when it can be rendered as text' do + it { is_expected.to be_a(DiffViewer::Text) } + end + + context 'when it can be rendered as image' do + let(:commit) { project.commit('2f63565e7aac07bcdadb654e253078b727143ec4') } + let(:diff_file) { commit.diffs.diff_file_with_new_path('files/images/6049019_460s.jpg') } + + it { is_expected.to be_a(DiffViewer::Image) } + end + + context 'when it is something else' do + let(:commit) { project.commit('ae73cb07c9eeaf35924a10f713b364d32b2dd34f') } + let(:diff_file) { commit.diffs.diff_file_with_new_path('Gemfile.zip') } + + it { is_expected.to be_nil } + end + end + end + describe '#rendered_as_text?' do context 'when the simple viewer is text-based' do let(:commit) { project.commit('570e7b2abdd848b95f2f578043fc23bd6f6fd24d') } diff --git a/spec/lib/gitlab/diff/formatters/text_formatter_spec.rb b/spec/lib/gitlab/diff/formatters/text_formatter_spec.rb index e275ebef2c9..fa129a20e58 100644 --- a/spec/lib/gitlab/diff/formatters/text_formatter_spec.rb +++ b/spec/lib/gitlab/diff/formatters/text_formatter_spec.rb @@ -26,6 +26,7 @@ describe Gitlab::Diff::Formatters::TextFormatter do # Specific text formatter examples let!(:formatter) { described_class.new(attrs) } + let(:attrs) { base } describe '#line_age' do subject { formatter.line_age } @@ -42,4 +43,21 @@ describe Gitlab::Diff::Formatters::TextFormatter do it { is_expected.to eq('old') } end end + + describe "#==" do + it "is false when the line_range changes" do + formatter_1 = described_class.new(base.merge(line_range: { start_line_code: "foo", end_line_code: "bar" })) + formatter_2 = described_class.new(base.merge(line_range: { start_line_code: "foo", end_line_code: "baz" })) + + expect(formatter_1).not_to eq(formatter_2) + end + + it "is true when the line_range doesn't change" do + attrs = base.merge({ line_range: { start_line_code: "foo", end_line_code: "baz" } }) + formatter_1 = described_class.new(attrs) + formatter_2 = described_class.new(attrs) + + expect(formatter_1).to eq(formatter_2) + end + end end diff --git a/spec/lib/gitlab/diff/position_spec.rb b/spec/lib/gitlab/diff/position_spec.rb index a83c0f35d92..10749ec024d 100644 --- a/spec/lib/gitlab/diff/position_spec.rb +++ b/spec/lib/gitlab/diff/position_spec.rb @@ -639,11 +639,11 @@ describe Gitlab::Diff::Position do let(:diff_position) { described_class.new(args) } it "returns the position as JSON" do - expect(JSON.parse(diff_position.to_json)).to eq(args.stringify_keys) + expect(Gitlab::Json.parse(diff_position.to_json)).to eq(args.stringify_keys) end it "works when nested under another hash" do - expect(JSON.parse(JSON.generate(pos: diff_position))).to eq('pos' => args.stringify_keys) + expect(Gitlab::Json.parse(Gitlab::Json.generate(pos: diff_position))).to eq('pos' => args.stringify_keys) end end |